2024-09-disk-defrag/blocks_test.go
2024-12-09 12:30:41 -06:00

31 lines
703 B
Go

package defrag
import (
"testing"
"github.com/stretchr/testify/require"
)
type tt struct {
name string
diskMap []byte
blocks []byte
defragged []byte
}
func sampleTests() []tt {
return []tt{
{"short", []byte("12345"), []byte("0..111....22222"), []byte("022111222......")},
{"longer", []byte("2333133121414131402"), []byte("00...111...2...333.44.5555.6666.777.888899"), []byte("0099811188827773336446555566..............")},
}
}
func TestBlocks(t *testing.T) {
for _, testcase := range sampleTests() {
t.Run(testcase.name, func(sub *testing.T) {
blocks, err := Blocks(testcase.diskMap)
require.NoError(sub, err)
require.Equal(sub, testcase.blocks, blocks)
})
}
}