| 116 | } |
| 117 | |
| 118 | func TestUnion(t *testing.T) { |
| 119 | td := []struct { |
| 120 | name string |
| 121 | s1 Set[int] |
| 122 | s2 Set[int] |
| 123 | expSet Set[int] |
| 124 | }{ |
| 125 | {"union of different sets", New(1, 2, 3), New(4, 5, 6), New(1, 2, 3, 4, 5, 6)}, |
| 126 | {"union of sets with elements in common", New(1, 2, 3), New(1, 2, 4), New(1, 2, 3, 4)}, |
| 127 | {"union of same sets", New(1, 2, 3), New(1, 2, 3), New(1, 2, 3)}, |
| 128 | } |
| 129 | for _, tc := range td { |
| 130 | t.Run(tc.name, func(t *testing.T) { |
| 131 | s := tc.s1.Union(tc.s2) |
| 132 | if s.Len() != tc.expSet.Len() { |
| 133 | t.Errorf("expecting %d elements in the set but got %d: set is %v", tc.expSet.Len(), s.Len(), s.GetItems()) |
| 134 | } |
| 135 | for _, n := range tc.expSet.GetItems() { |
| 136 | if !s.In(n) { |
| 137 | t.Errorf("expecting %d to be present in the set but was not; set is %v", n, s.GetItems()) |
| 138 | } |
| 139 | } |
| 140 | }) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | func TestIntersection(t *testing.T) { |
| 145 | td := []struct { |