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

Function TestAdd

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

Source from the content-addressed store, hash-verified

20}
21
22func TestAdd(t *testing.T) {
23 td := []struct {
24 name string
25 input int
26 expElems []int
27 }{
28 {"add new element", 5, []int{1, 2, 3, 5}},
29 {"add exiting element", 3, []int{1, 2, 3}},
30 }
31 for _, tc := range td {
32 t.Run(tc.name, func(t *testing.T) {
33 s := New(1, 2, 3)
34 s.Add(tc.input)
35 if s.Len() != len(tc.expElems) {
36 t.Errorf("expecting %d elements in the set but got %d: set is %v", len(tc.expElems), s.Len(), s.GetItems())
37 }
38 for _, n := range tc.expElems {
39 if !s.In(n) {
40 t.Errorf("expecting %d to be present in the set but was not; set is %v", n, s.GetItems())
41 }
42 }
43 })
44 }
45}
46
47func TestDelete(t *testing.T) {
48 td := []struct {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
AddMethod · 0.65
LenMethod · 0.65
GetItemsMethod · 0.65
InMethod · 0.65

Tested by

no test coverage detected