| 10 | ) |
| 11 | |
| 12 | func TestSet(t *testing.T) { |
| 13 | s := Set[int]{} |
| 14 | s.Add(1) |
| 15 | s.Add(2) |
| 16 | if !s.Contains(1) { |
| 17 | t.Error("missing 1") |
| 18 | } |
| 19 | if !s.Contains(2) { |
| 20 | t.Error("missing 2") |
| 21 | } |
| 22 | if s.Contains(3) { |
| 23 | t.Error("shouldn't have 3") |
| 24 | } |
| 25 | if s.Len() != 2 { |
| 26 | t.Errorf("wrong len %d; want 2", s.Len()) |
| 27 | } |
| 28 | |
| 29 | more := []int{3, 4} |
| 30 | s.AddSlice(more) |
| 31 | if !s.Contains(3) { |
| 32 | t.Error("missing 3") |
| 33 | } |
| 34 | if !s.Contains(4) { |
| 35 | t.Error("missing 4") |
| 36 | } |
| 37 | if s.Contains(5) { |
| 38 | t.Error("shouldn't have 5") |
| 39 | } |
| 40 | if s.Len() != 4 { |
| 41 | t.Errorf("wrong len %d; want 4", s.Len()) |
| 42 | } |
| 43 | |
| 44 | es := s.Slice() |
| 45 | if len(es) != 4 { |
| 46 | t.Errorf("slice has wrong len %d; want 4", len(es)) |
| 47 | } |
| 48 | for _, e := range []int{1, 2, 3, 4} { |
| 49 | if !slices.Contains(es, e) { |
| 50 | t.Errorf("slice missing %d (%#v)", e, es) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestSetOf(t *testing.T) { |
| 56 | s := Of(1, 2, 3, 4, 4, 1) |