Share occurrence duplicate grouping bookkeeping
This commit is contained in:
21
internal/modules/dnd/shared/duplicates_test.go
Normal file
21
internal/modules/dnd/shared/duplicates_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGroupDuplicatesKeepsIneligibleAndRepresentativeOrder(t *testing.T) {
|
||||
keys := []string{"a", "b", "invalid", "b", "invalid", "a", "c"}
|
||||
retained, groups := GroupDuplicates(len(keys), func(index int) (string, bool) { return keys[index], keys[index] != "invalid" })
|
||||
if want := []int{0, 1, 2, 4, 6}; !reflect.DeepEqual(retained, want) {
|
||||
t.Fatalf("retained = %v, want %v", retained, want)
|
||||
}
|
||||
if want := []DuplicatePositions{{Representative: 0, Removed: []int{5}}, {Representative: 1, Removed: []int{3}}}; !reflect.DeepEqual(groups, want) {
|
||||
t.Fatalf("groups = %#v, want %#v", groups, want)
|
||||
}
|
||||
retained, groups = GroupDuplicates(0, func(int) (string, bool) { t.Fatal("unexpected callback"); return "", false })
|
||||
if retained == nil || len(retained) != 0 || len(groups) != 0 {
|
||||
t.Fatalf("empty result = %#v, %#v", retained, groups)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user