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

Function TestIntersection

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

Source from the content-addressed store, hash-verified

142}
143
144func TestIntersection(t *testing.T) {
145 td := []struct {
146 name string
147 s1 Set[int]
148 s2 Set[int]
149 expSet Set[int]
150 }{
151 {"intersection of different sets", New(0, 1, 2, 3), New(4, 5, 6), New[int]()},
152 {"intersection of sets with elements in common", New(1, 2, 3), New(1, 2, 4), New(1, 2)},
153 {"intersection of same sets", New(1, 2, 3), New(1, 2, 3), New(1, 2, 3)},
154 }
155 for _, tc := range td {
156 t.Run(tc.name, func(t *testing.T) {
157 s := tc.s1.Intersection(tc.s2)
158 if s.Len() != tc.expSet.Len() {
159 t.Errorf("expecting %d elements in the set but got %d: set is %v", tc.expSet.Len(), s.Len(), s.GetItems())
160 }
161 for _, n := range tc.expSet.GetItems() {
162 if !s.In(n) {
163 t.Errorf("expecting %d to be present in the set but was not; set is %v", n, s.GetItems())
164 }
165 }
166 })
167 }
168}
169
170func TestDifference(t *testing.T) {
171 td := []struct {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
IntersectionMethod · 0.65
LenMethod · 0.65
GetItemsMethod · 0.65
InMethod · 0.65

Tested by

no test coverage detected