| 20 | } |
| 21 | |
| 22 | func 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 | |
| 47 | func TestDelete(t *testing.T) { |
| 48 | td := []struct { |