1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
package net.sourceforge.combean.test.graph.containers; |
23 | |
|
24 | |
import junit.framework.TestCase; |
25 | |
import net.sourceforge.combean.graph.NumberNode; |
26 | |
import net.sourceforge.combean.interfaces.graph.NodeIterator; |
27 | |
import net.sourceforge.combean.interfaces.graph.containers.NodeSet; |
28 | |
import net.sourceforge.combean.test.helpers.checks.CheckGraph; |
29 | |
import net.sourceforge.combean.util.except.UnsupportedMethodException; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
abstract class AbstractTestNodeSet extends TestCase { |
36 | |
|
37 | |
protected static final int GRAPHSIZE = 5; |
38 | |
|
39 | 30 | private NodeSet nodeSet = null; |
40 | 30 | private NumberNode v = null; |
41 | 30 | private NumberNode otherV = null; |
42 | 30 | private NumberNode w = null; |
43 | |
|
44 | |
|
45 | |
public static void main(String[] args) { |
46 | 0 | junit.textui.TestRunner.run(AbstractTestNodeSet.class); |
47 | 0 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
protected void setUp() throws Exception { |
53 | |
|
54 | |
|
55 | |
|
56 | 0 | throw new UnsupportedMethodException(); |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
protected void setUp(NodeSet nodeSet) throws Exception { |
63 | 30 | super.setUp(); |
64 | |
|
65 | 30 | this.nodeSet = nodeSet; |
66 | 30 | this.v = new NumberNode(1); |
67 | 30 | this.otherV = new NumberNode(1); |
68 | 30 | this.w = new NumberNode(GRAPHSIZE-1); |
69 | 30 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
protected void tearDown() throws Exception { |
75 | 30 | super.tearDown(); |
76 | 30 | } |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public AbstractTestNodeSet(String name) { |
83 | 30 | super(name); |
84 | 30 | } |
85 | |
|
86 | |
private void checkEmptySet() { |
87 | 12 | assertTrue("empty set seems to be non-empty", this.nodeSet.isEmpty()); |
88 | 12 | assertEquals("empty set has non-zero size", this.nodeSet.size(), 0); |
89 | 12 | assertFalse("empty set contains a node", this.nodeSet.contains(this.v)); |
90 | 12 | } |
91 | |
|
92 | |
public void testAccessToEmptySet() { |
93 | 6 | checkEmptySet(); |
94 | 6 | } |
95 | |
|
96 | |
public void testReadAndWriteAccess() { |
97 | 6 | this.nodeSet.add(this.v); |
98 | 6 | assertFalse("set is empty after adding node", this.nodeSet.isEmpty()); |
99 | 6 | assertEquals("wrong size", this.nodeSet.size(), 1); |
100 | 6 | assertTrue("node not in set after adding it", this.nodeSet.contains(this.v)); |
101 | 6 | this.nodeSet.add(this.w); |
102 | 6 | assertEquals("wrong size", 2, this.nodeSet.size()); |
103 | 6 | this.nodeSet.remove(this.v); |
104 | 6 | assertEquals("wrong size", 1, this.nodeSet.size()); |
105 | 6 | assertFalse("node still in set after removing it", this.nodeSet.contains(this.v)); |
106 | 6 | this.nodeSet.remove(this.w); |
107 | 6 | assertTrue("set must be empty", this.nodeSet.isEmpty()); |
108 | 6 | } |
109 | |
|
110 | |
public void testClear() { |
111 | 6 | this.nodeSet.add(this.v); |
112 | 6 | this.nodeSet.add(this.w); |
113 | 6 | this.nodeSet.clear(); |
114 | 6 | checkEmptySet(); |
115 | 6 | } |
116 | |
|
117 | |
public void testContains() { |
118 | 6 | this.nodeSet.add(this.v); |
119 | 6 | assertTrue("node not in set after adding it", this.nodeSet.contains(this.otherV)); |
120 | 6 | this.nodeSet.remove(this.otherV); |
121 | 6 | assertTrue("set must be empty", this.nodeSet.isEmpty()); |
122 | 6 | } |
123 | |
|
124 | |
public void testIterator() { |
125 | 6 | this.nodeSet.add(this.v); |
126 | 6 | this.nodeSet.add(this.w); |
127 | |
|
128 | 6 | NodeIterator it = this.nodeSet.iterator(); |
129 | 6 | CheckGraph.checkNumIterations(it, 2); |
130 | 6 | } |
131 | |
} |