|
1 | 1 | package diff |
2 | 2 |
|
3 | | -import "testing" |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | +) |
4 | 7 |
|
5 | | -func Test_Diff(t *testing.T) { |
6 | | - a := []int{1, 2, 3, 4, 5} |
7 | | - b := []int{2, 4, 5} |
8 | | - |
9 | | - allOfA := Diff[int](a, []int{}) |
10 | | - if len(allOfA) != len(a) { |
11 | | - t.Errorf("Expected empty b to return full list, got %v", allOfA) |
12 | | - } |
13 | | - |
14 | | - empty := Diff([]int{}, []int{}) |
15 | | - if len(empty) != 0 { |
16 | | - t.Errorf("Expected empty from empty / empty") |
| 8 | +func Test_DisjunctiveUnion(t *testing.T) { |
| 9 | + tests := []struct { |
| 10 | + a []int |
| 11 | + b []int |
| 12 | + notInA []int |
| 13 | + notInB []int |
| 14 | + }{ |
| 15 | + { |
| 16 | + []int{1, 2, 3, 8, 9, 10}, |
| 17 | + []int{3, 4, 5}, |
| 18 | + []int{4, 5}, |
| 19 | + []int{1, 2, 8, 9, 10}, |
| 20 | + }, |
| 21 | + { |
| 22 | + []int{1, 2, 3}, |
| 23 | + []int{1, 2, 3}, |
| 24 | + []int{}, |
| 25 | + []int{}, |
| 26 | + }, |
| 27 | + { |
| 28 | + []int{1, 2, 3}, |
| 29 | + []int{1, 2, 3, 4}, |
| 30 | + []int{4}, |
| 31 | + []int{}, |
| 32 | + }, |
17 | 33 | } |
18 | 34 |
|
19 | | - result := Diff(a, b) |
20 | | - if len(result) != len(a)-len(b) { |
21 | | - t.Errorf("Expected diff of %v and %v to be %d long, but got %v", a, b, len(a)-len(b), result) |
22 | | - } |
| 35 | + for _, test := range tests { |
| 36 | + notInA, notInB := DisjunctiveUnion(test.a, test.b) |
23 | 37 |
|
24 | | - same := Diff(a, a) |
25 | | - if len(same) != 0 { |
26 | | - t.Errorf("Expected diffing the same thing against itself to come up empty, got %v", same) |
| 38 | + if !reflect.DeepEqual(notInA, test.notInA) { |
| 39 | + t.Errorf("Expected notInA to be %v, got %v", test.notInA, notInA) |
| 40 | + } |
| 41 | + if !reflect.DeepEqual(notInB, test.notInB) { |
| 42 | + t.Errorf("Expected notInB to be %v, got %v", test.notInB, notInB) |
| 43 | + } |
27 | 44 | } |
28 | 45 | } |
0 commit comments