MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestDifference

Function TestDifference

structure/set/set_test.go:170–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

168}
169
170func TestDifference(t *testing.T) {
171 td := []struct {
172 name string
173 s1 Set[int]
174 s2 Set[int]
175 expSet Set[int]
176 }{
177 {"difference of different sets", New(1, 2, 3), New(4, 5, 6), New(1, 2, 3)},
178 {"difference of sets with elements in common", New(1, 2, 3), New(1, 2, 4), New(3)},
179 {"difference of same sets", New(1, 2, 3), New(1, 2, 3), New[int]()},
180 }
181 for _, tc := range td {
182 t.Run(tc.name, func(t *testing.T) {
183 s := tc.s1.Difference(tc.s2)
184 if s.Len() != tc.expSet.Len() {
185 t.Errorf("expecting %d elements in the set but got %d: set is %v", tc.expSet.Len(), s.Len(), s.GetItems())
186 }
187 for _, n := range tc.expSet.GetItems() {
188 if !s.In(n) {
189 t.Errorf("expecting %d to be present in the set but was not; set is %v", n, s.GetItems())
190 }
191 }
192 })
193 }
194}
195
196func TestSymmetricDifference(t *testing.T) {
197 td := []struct {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
DifferenceMethod · 0.65
LenMethod · 0.65
GetItemsMethod · 0.65
InMethod · 0.65

Tested by

no test coverage detected