diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2016-01-13 21:36:44 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-01-14 01:12:49 +0900 |
commit | 8d3a302a1754a4e28cc1085b95e9a03981372d02 (patch) | |
tree | a5b95363609d3acebda69890fd6b7b59b18f9c02 /src/item_test.go | |
parent | 1d2d32c847e39818bedae5f86ca75e6b70b60444 (diff) |
Simplify Item structure
This commit compensates for the performance overhead from the
extended tiebreak option.
Diffstat (limited to 'src/item_test.go')
-rw-r--r-- | src/item_test.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/item_test.go b/src/item_test.go index f26f8370..d1c30d77 100644 --- a/src/item_test.go +++ b/src/item_test.go @@ -23,17 +23,17 @@ func TestOffsetSort(t *testing.T) { } func TestRankComparison(t *testing.T) { - if compareRanks([]int32{3, 0, 5}, []int32{2, 0, 7}, false) || - !compareRanks([]int32{3, 0, 5}, []int32{3, 0, 6}, false) || - !compareRanks([]int32{1, 2, 3}, []int32{1, 3, 2}, false) || - !compareRanks([]int32{0, 0, 0}, []int32{0, 0, 0}, false) { + if compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{2, 0, 0, 0, 7}, false) || + !compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{3, 0, 0, 0, 6}, false) || + !compareRanks([5]int32{1, 2, 0, 0, 3}, [5]int32{1, 3, 0, 0, 2}, false) || + !compareRanks([5]int32{0, 0, 0, 0, 0}, [5]int32{0, 0, 0, 0, 0}, false) { t.Error("Invalid order") } - if compareRanks([]int32{3, 0, 5}, []int32{2, 0, 7}, true) || - !compareRanks([]int32{3, 0, 5}, []int32{3, 0, 6}, false) || - !compareRanks([]int32{1, 2, 3}, []int32{1, 3, 2}, true) || - !compareRanks([]int32{0, 0, 0}, []int32{0, 0, 0}, false) { + if compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{2, 0, 0, 0, 7}, true) || + !compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{3, 0, 0, 0, 6}, false) || + !compareRanks([5]int32{1, 2, 0, 0, 3}, [5]int32{1, 3, 0, 0, 2}, true) || + !compareRanks([5]int32{0, 0, 0, 0, 0}, [5]int32{0, 0, 0, 0, 0}, false) { t.Error("Invalid order (tac)") } } @@ -41,16 +41,16 @@ func TestRankComparison(t *testing.T) { // Match length, string length, index func TestItemRank(t *testing.T) { // FIXME global - sortCriteria = []criterion{byMatchLen, byLength, byIndex} + sortCriteria = []criterion{byMatchLen, byLength} strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")} - item1 := Item{text: strs[0], index: 1, offsets: []Offset{}} + item1 := Item{text: strs[0], offsets: []Offset{}, rank: [5]int32{0, 0, 0, 0, 1}} rank1 := item1.Rank(true) - if rank1[0] != math.MaxInt32 || rank1[1] != 3 || rank1[2] != 1 { + if rank1[0] != math.MaxInt32 || rank1[1] != 3 || rank1[4] != 1 { t.Error(item1.Rank(true)) } // Only differ in index - item2 := Item{text: strs[0], index: 0, offsets: []Offset{}} + item2 := Item{text: strs[0], offsets: []Offset{}} items := []*Item{&item1, &item2} sort.Sort(ByRelevance(items)) @@ -66,10 +66,10 @@ func TestItemRank(t *testing.T) { } // Sort by relevance - item3 := Item{text: strs[1], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} - item4 := Item{text: strs[1], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} - item5 := Item{text: strs[2], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} - item6 := Item{text: strs[2], rank: []int32{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} + item3 := Item{text: strs[1], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} + item4 := Item{text: strs[1], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} + item5 := Item{text: strs[2], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} + item6 := Item{text: strs[2], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} items = []*Item{&item1, &item2, &item3, &item4, &item5, &item6} sort.Sort(ByRelevance(items)) if items[0] != &item6 || items[1] != &item4 || |