MCPcopy
hub / github.com/TheAlgorithms/Go / TestDelete

Function TestDelete

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

Source from the content-addressed store, hash-verified

45}
46
47func TestDelete(t *testing.T) {
48 td := []struct {
49 name string
50 input int
51 expElems []int
52 }{
53 {"delete exiting element", 3, []int{1, 2}},
54 {"delete not existing element", 5, []int{1, 2, 3}},
55 }
56 for _, tc := range td {
57 t.Run(tc.name, func(t *testing.T) {
58 s := New(1, 2, 3)
59 s.Delete(tc.input)
60 if s.Len() != len(tc.expElems) {
61 t.Errorf("expecting %d elements in the set but got %d: set is %v", len(tc.expElems), s.Len(), s.GetItems())
62 }
63 for _, n := range tc.expElems {
64 if !s.In(n) {
65 t.Errorf("expecting %d to be present in the set but was not; set is %v", n, s.GetItems())
66 }
67 }
68 })
69 }
70}
71
72func TestIsSubsetOf(t *testing.T) {
73 s1, s2 := New(1, 2, 3), New(1, 2, 3, 4)

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
DeleteMethod · 0.65
LenMethod · 0.65
GetItemsMethod · 0.65
InMethod · 0.65

Tested by

no test coverage detected