package dbstore import ( "fmt" "reflect" "testing" ) func TestByRankLen(t *testing.T) { tests := []struct { val []CisaSearchRow exp int } {{ val: []CisaSearchRow {}, exp: 0, }, { val: []CisaSearchRow { {}, {}, {}, {} }, exp: 4, }} for _, test := range(tests) { t.Run(fmt.Sprintf("%d", test.exp), func(t *testing.T) { got := byRank(test.val).Len() if got != test.exp { t.Errorf("got %d, exp %d", got, test.exp) } }) } } func TestByRankLess(t *testing.T) { tests := []struct { key string val []CisaSearchRow exp bool } {{ key: "lt", val: []CisaSearchRow { { Rank: 0 }, { Rank: 1 } }, exp: true, }, { key: "eq", val: []CisaSearchRow { { Rank: 1 }, { Rank: 1 } }, exp: false, }, { key: "gt", val: []CisaSearchRow { { Rank: 1 }, { Rank: 0 } }, exp: false, }} for _, test := range(tests) { t.Run(test.key, func(t *testing.T) { got := byRank(test.val).Less(0, 1) if got != test.exp { t.Errorf("got %v, exp %v", got, test.exp) } }) } } func TestByRankSwap(t *testing.T) { tests := []struct { key string val []CisaSearchRow exp []CisaSearchRow } {{ key: "yup", val: []CisaSearchRow { { Rank: 0 }, { Rank: 1 } }, exp: []CisaSearchRow { { Rank: 1 }, { Rank: 0 } }, }} for _, test := range(tests) { t.Run(test.key, func(t *testing.T) { byRank(test.val).Swap(0, 1) if !reflect.DeepEqual(test.val, test.exp) { t.Errorf("got %#v, exp %#v", test.val, test.exp) } }) } }