From 4cc13f2fde11241919d3699574c30b2590060833 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 18 Mar 2022 22:11:13 -0400 Subject: add dbstore/cisasearchrow_test.go --- dbstore/cisasearchrow_test.go | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 dbstore/cisasearchrow_test.go diff --git a/dbstore/cisasearchrow_test.go b/dbstore/cisasearchrow_test.go new file mode 100644 index 0000000..ce03aab --- /dev/null +++ b/dbstore/cisasearchrow_test.go @@ -0,0 +1,79 @@ +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) + } + }) + } +} -- cgit v1.2.3