github.com/grafana/pyroscope@v1.18.0/pkg/phlaredb/query/util_test.go (about) 1 package query 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_SplitRows(t *testing.T) { 10 type testCase struct { 11 rows []int64 12 groups []int64 13 expected [][]int64 14 } 15 16 testCases := []testCase{ 17 { 18 // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, .............. 100] 19 // [ ][10 ][50 ][77 ][110] 20 // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][ 0, 1 ][ ][ 23][ ] 21 rows: []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 100}, 22 groups: []int64{10, 50, 77, 101, 110}, 23 expected: [][]int64{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, {0, 1}, nil, {23}, nil}, 24 }, 25 { 26 // * 27 // [0, 1][2, 3][4] 28 // [0, 1][0, 1][0] 29 // * 30 // [0][ ][ ] 31 rows: []int64{0}, 32 groups: []int64{2, 4, 5}, 33 expected: [][]int64{{0}, nil, nil}, 34 }, 35 { 36 // * 37 // [0, 1][2, 3][4] 38 // [0, 1][0, 1][0] 39 // * 40 // [ ][ ][0] 41 rows: []int64{4}, 42 groups: []int64{2, 4, 5}, 43 expected: [][]int64{{}, nil, {0}}, 44 }, 45 { 46 // * * * * 47 // [0, 1][2, 3][4, 5][6, 7][8, 9] 48 // [0, 1][0, 1][0, 1][0, 1][0, 1] 49 // * * * * 50 // [ ][ 1][0 ][ 1][ 1] 51 rows: []int64{3, 4, 7, 9}, 52 groups: []int64{2, 4, 6, 8, 10}, 53 expected: [][]int64{{}, {1}, {0}, {1}, {1}}, 54 }, 55 } 56 57 for _, tc := range testCases { 58 tc := tc 59 t.Run("", func(t *testing.T) { 60 assert.Equal(t, tc.expected, SplitRows(tc.rows, tc.groups)) 61 }) 62 } 63 }