Debian Codegraph @

set/set_test.go

raw symbols SCIP
1 package set
2
3 import (
4 "testing"
5 )
6
7 func Test(t *testing.T) {
8 s := New()
9
10 s.Insert(5)
11
12 if s.Len() != 1 {
13 t.Errorf("Length should be 1")
14 }
15
16 if !s.Has(5) {
17 t.Errorf("Membership test failed")
18 }
19
20 s.Remove(5)
21
22 if s.Len() != 0 {
23 t.Errorf("Length should be 0")
24 }
25
26 if s.Has(5) {
27 t.Errorf("The set should be empty")
28 }
29
30 // Difference
31 s1 := New(1,2,3,4,5,6)
32 s2 := New(4,5,6)
33 s3 := s1.Difference(s2)
34
35 if s3.Len() != 3 {
36 t.Errorf("Length should be 3")
37 }
38
39 if !(s3.Has(1) && s3.Has(2) && s3.Has(3)) {
40 t.Errorf("Set should only contain 1, 2, 3")
41 }
42
43 // Intersection
44 s3 = s1.Intersection(s2)
45 if s3.Len() != 3 {
46 t.Errorf("Length should be 3 after intersection")
47 }
48
49 if !(s3.Has(4) && s3.Has(5) && s3.Has(6)) {
50 t.Errorf("Set should contain 4, 5, 6")
51 }
52
53 // Union
54 s4 := New(7,8,9)
55 s3 = s2.Union(s4)
56
57 if s3.Len() != 6 {
58 t.Errorf("Length should be 6 after union")
59 }
60
61 if !(s3.Has(7)) {
62 t.Errorf("Set should contain 4, 5, 6, 7, 8, 9")
63 }
64
65 // Subset
66 if !s1.SubsetOf(s1) {
67 t.Errorf("set should be a subset of itself")
68 }
69 // Proper Subset
70 if s1.ProperSubsetOf(s1) {
71 t.Errorf("set should not be a subset of itself")
72 }
73
74 }