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

Function TestSymmetricDifference

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

Source from the content-addressed store, hash-verified

194}
195
196func TestSymmetricDifference(t *testing.T) {
197 td := []struct {
198 name string
199 s1 Set[int]
200 s2 Set[int]
201 expSet Set[int]
202 }{
203 {"symmetric difference of different sets", New(1, 2, 3), New(4, 5, 6), New(1, 2, 3, 4, 5, 6)},
204 {"symmetric difference of sets with elements in common", New(1, 2, 3), New(1, 2, 4), New(3, 4)},
205 {"symmetric difference of same sets", New(1, 2, 3), New(1, 2, 3), New[int]()},
206 }
207 for _, tc := range td {
208 t.Run(tc.name, func(t *testing.T) {
209 s := tc.s1.SymmetricDifference(tc.s2)
210 if s.Len() != tc.expSet.Len() {
211 t.Errorf("expecting %d elements in the set but got %d: set is %v", tc.expSet.Len(), s.Len(), s.GetItems())
212 }
213 for _, n := range tc.expSet.GetItems() {
214 if !s.In(n) {
215 t.Errorf("expecting %d to be present in the set but was not; set is %v", n, s.GetItems())
216 }
217 }
218 })
219 }
220}

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
SymmetricDifferenceMethod · 0.65
LenMethod · 0.65
GetItemsMethod · 0.65
InMethod · 0.65

Tested by

no test coverage detected