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

Function TestUnion

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

Source from the content-addressed store, hash-verified

116}
117
118func 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
144func TestIntersection(t *testing.T) {
145 td := []struct {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
UnionMethod · 0.65
LenMethod · 0.65
GetItemsMethod · 0.65
InMethod · 0.65

Tested by

no test coverage detected