Details
-
Bug
-
Resolution: Fixed
-
Major
-
master
-
None
-
Untriaged
-
0
-
No
Description
What's the issue?
The Union function in our functional package should return the set union but actually implements the intersection.
It also doesn't handle duplicates on the input very well, nor does it document that duplicates shouldn't be provided.
Union of the sets A and B, denoted A ∪ B, is the set of all objects that are a member of A, or B, or both.[9] For example, the union of
Unknown macro: {1, 2, 3}and
Unknown macro: {2, 3, 4}is the set
Unknown macro: {1, 2, 3, 4}.
$ git diff
|
diff --git a/functional/slices/union_test.go b/functional/slices/union_test.go
|
index 4d9c1fd7..b7e089e3 100644
|
--- a/functional/slices/union_test.go
|
+++ b/functional/slices/union_test.go
|
@@ -37,6 +37,18 @@ func TestUnionString(t *testing.T) {
|
37 ⋮ 37 │ a: []string{"alpha"},
|
38 ⋮ 38 │ expected: []string{},
|
39 ⋮ 39 │ },
|
⋮ 40 │+ {
|
⋮ 41 │+ name: "ActuallyIntersection",
|
⋮ 42 │+ a: []string{"1", "2", "3"},
|
⋮ 43 │+ b: []string{"2", "3", "4"},
|
⋮ 44 │+ expected: []string{"1", "2", "3", "4"},
|
⋮ 45 │+ },
|
⋮ 46 │+ {
|
⋮ 47 │+ name: "IncorrectIntersection",
|
⋮ 48 │+ a: []string{"1", "1"},
|
⋮ 49 │+ b: make([]string, 0),
|
⋮ 50 │+ expected: make([]string, 0),
|
⋮ 51 │+ },
|
40 ⋮ 52 │ }
|
41 ⋮ 53 │
|
42 ⋮ 54 │ for _, tc := range tests {
|
$ go test ./...
|
--- FAIL: TestUnionString (0.00s)
|
--- FAIL: TestUnionString/ActuallyIntersection (0.00s)
|
union_test.go:58:
|
Error Trace: /home/james/Projects/tools-common/functional/slices/union_test.go:58
|
Error: Not equal:
|
expected: []string{"1", "2", "3", "4"}
|
actual : []string{"2", "3"}
|
|
Diff:
|
--- Expected
|
+++ Actual
|
@@ -1,6 +1,4 @@
|
-([]string) (len=4) {
|
- (string) (len=1) "1",
|
+([]string) (len=2) {
|
(string) (len=1) "2",
|
- (string) (len=1) "3",
|
- (string) (len=1) "4"
|
+ (string) (len=1) "3"
|
}
|
Test: TestUnionString/ActuallyIntersection
|
--- FAIL: TestUnionString/IncorrectIntersection (0.00s)
|
union_test.go:58:
|
Error Trace: /home/james/Projects/tools-common/functional/slices/union_test.go:58
|
Error: Not equal:
|
expected: []string{}
|
actual : []string{"1"}
|
|
Diff:
|
--- Expected
|
+++ Actual
|
@@ -1,2 +1,3 @@
|
-([]string) {
|
+([]string) (len=1) {
|
+ (string) (len=1) "1"
|
}
|
Test: TestUnionString/IncorrectIntersection
|
FAIL
|
FAIL github.com/couchbase/tools-common/functional/slices 0.003s
|
FAIL
|
What's the fix?
The Union function should return the union of the two slices, it should support duplicates on input but not return duplicates.