-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringSetTest.java
88 lines (71 loc) · 1.72 KB
/
StringSetTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import junit.framework.TestCase;
import set.*;
public class StringSetTest extends TestCase{
public void testSimpleAdd() {
StringSet s = new StringSet();
s.add("foo");
s.add("foo");
s.add("bar");
s.add("baz");
assertEquals(s.size(), 3);
}
public void testSimpleUnion() {
StringSet s1 = new StringSet();
StringSet s2 = new StringSet();
s1.add("lbl1");
s2.add("lbl2");
s2.add("lbl1");
s2.add("lbl3");
s2.add("lbl4");
StringSet s3 = s1.union(s2);
assertEquals(s3.size(), 4);
assertEquals(s3.contains("lbl4"), true);
assertEquals(s3.contains("lbl1"), true);
}
public void testSimpleIntersect() {
StringSet s1 = new StringSet();
StringSet s2 = new StringSet();
s1.add("lbl1");
s1.add("lbl1");
s1.add("lbl2");
s2.add("lbl2");
s2.add("lbl9");
s2.add("foobar");
StringSet s3 = s1.intersect(s2);
assertEquals(s3.size(), 1);
assertEquals(s3.contains("lbl2"), true);
}
public void testNegIntersect() {
StringSet s1 = new StringSet();
StringSet s2 = new StringSet();
s1.add("lbl1");
s1.add("2");
StringSet s3 = s1.intersect(s2);
assertEquals(s3.size(), 0);
s2 = null;
s3 = s1.intersect(s2);
assertEquals(s3.size(), 0);
}
public void testCrossProd (){
StringSet s1 = new StringSet();
StringSet s2 = new StringSet();
s1.add("1");
s1.add("2");
s1.add("3");
s2.add("a");
s2.add("b");
s2.add("c");
StringPairSet result = s1.cross(s2);
assertEquals(result.contains(new StringPair("1", "a")), true);
assertEquals(result.size(), 9);
}
public void testCrossProdEmpty() {
StringSet s1 = new StringSet();
StringSet s2 = new StringSet();
s1.add("1");
s1.add("2");
s1.add("3");
StringPairSet result = s1.cross(s2);
assertEquals(result.size(), 0);
}
}