package defrag import ( "testing" "github.com/stretchr/testify/require" ) type tt struct { name string diskMap []byte blocks []int } func sampleTests() []tt { return []tt{ {"short", []byte("12345"), []int{0, -1, -1, 1, 1, 1, -1, -1, -1, -1, 2, 2, 2, 2, 2}}, {"longer", []byte("2333133121414131402"), []int{0, 0, -1, -1, -1, 1, 1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 3, 3, -1, 4, 4, -1, 5, 5, 5, 5, -1, 6, 6, 6, 6, -1, 7, 7, 7, -1, 8, 8, 8, 8, 9, 9}}, } } 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) }) } }