package writecachebitcask import ( "math" "testing" "github.com/stretchr/testify/require" ) func TestDispatchRecoveredIndices(t *testing.T) { max := uint32(math.MaxUint32) tests := []struct { indices []uint32 wantOrder []uint32 wantIndex uint32 }{ {[]uint32{0}, []uint32{0}, 1}, {[]uint32{42}, []uint32{42}, 43}, {[]uint32{5, 6, 7, 8}, []uint32{5, 6, 7, 8}, 9}, {[]uint32{max - 2, max - 1, max}, []uint32{max - 2, max - 1, max}, 0}, {[]uint32{0, 1, 2, max - 2, max - 1, max}, []uint32{max - 2, max - 1, max, 0, 1, 2}, 3}, {[]uint32{0, max}, []uint32{max, 0}, 1}, } for _, tc := range tests { var gotOrder []uint32 gotIndex := dispatchRecoveredLogIndices(tc.indices, func(i uint32) { gotOrder = append(gotOrder, i) }) require.Equal(t, tc.wantOrder, gotOrder) require.Equal(t, tc.wantIndex, gotIndex) } }