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.samples.simplegraphs; |
23 | |
|
24 | |
import java.util.BitSet; |
25 | |
|
26 | |
import junit.framework.TestCase; |
27 | |
import net.sourceforge.combean.graph.NumberNode; |
28 | |
import net.sourceforge.combean.interfaces.graph.EdgeIterator; |
29 | |
import net.sourceforge.combean.interfaces.graph.NodeIterator; |
30 | |
import net.sourceforge.combean.samples.simplegraphs.Clique; |
31 | |
import net.sourceforge.combean.samples.simplegraphs.CompositeNumberGraph; |
32 | |
import net.sourceforge.combean.samples.simplegraphs.NumberGraph; |
33 | |
import net.sourceforge.combean.samples.simplegraphs.Path; |
34 | |
import net.sourceforge.combean.test.helpers.checks.CheckGraph; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 15 | public class TestCompositeNumberGraph extends TestCase { |
41 | |
|
42 | |
private static final int PATHLEN = 5; |
43 | |
private Path path; |
44 | |
|
45 | |
private static final int CLIQUESIZE = 5; |
46 | |
private Clique clique; |
47 | |
|
48 | |
private NumberNode firstNode; |
49 | |
private NumberNode lastPathNode; |
50 | |
|
51 | |
private CompositeNumberGraph lollypop; |
52 | |
private CompositeNumberGraph mix; |
53 | |
|
54 | |
public static void main(String[] args) { |
55 | 0 | junit.textui.TestRunner.run(TestCompositeNumberGraph.class); |
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
protected void setUp() throws Exception { |
62 | 15 | super.setUp(); |
63 | |
|
64 | 15 | this.path = new Path(PATHLEN); |
65 | |
|
66 | 15 | this.clique = new Clique(CLIQUESIZE); |
67 | |
|
68 | 15 | this.firstNode = new NumberNode(0); |
69 | 15 | this.lastPathNode = new NumberNode(PATHLEN-1); |
70 | |
|
71 | 15 | this.lollypop = new CompositeNumberGraph(); |
72 | 15 | this.lollypop.add(this.path); |
73 | 15 | this.lollypop.add(this.clique, this.lastPathNode.getNodeNum()); |
74 | |
|
75 | 15 | this.mix = new CompositeNumberGraph(); |
76 | 15 | this.mix.add(this.path); |
77 | 15 | this.mix.add(this.clique); |
78 | 15 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
protected void tearDown() throws Exception { |
84 | 15 | super.tearDown(); |
85 | 15 | } |
86 | |
|
87 | |
public final void testGetNumGraphs() { |
88 | 3 | assertEquals("two graphs have been added", 2, |
89 | |
this.lollypop.getNumGraphs()); |
90 | 3 | assertEquals("two graphs have been added", 2, |
91 | |
this.mix.getNumGraphs()); |
92 | 3 | } |
93 | |
|
94 | |
public final void testGetNumNodes() { |
95 | 3 | assertEquals("number of nodes in joined graphs must equal" + |
96 | |
"the sum minus one overlapping node", |
97 | |
PATHLEN+CLIQUESIZE-1, this.lollypop.getNumNodes()); |
98 | 3 | assertEquals("number of nodes in joined graphs must equal" + |
99 | |
"the maximum of nodes in the individual graphs", |
100 | |
Math.max(PATHLEN, CLIQUESIZE), this.mix.getNumNodes()); |
101 | 3 | } |
102 | |
|
103 | |
public final void testGetAllNodesIterator() { |
104 | 3 | NodeIterator itAllNodes = this.lollypop.getAllNodesIterator(); |
105 | 3 | BitSet nodesSeen = new BitSet(PATHLEN+CLIQUESIZE); |
106 | 3 | nodesSeen.clear(); |
107 | 30 | while (itAllNodes.hasNext()) { |
108 | 27 | NumberNode currNode = (NumberNode) itAllNodes.next(); |
109 | 27 | nodesSeen.set(currNode.getNodeNum()); |
110 | 27 | } |
111 | 3 | assertEquals("all nodes must have been seen", PATHLEN+CLIQUESIZE-1, |
112 | |
nodesSeen.nextClearBit(0)); |
113 | 3 | } |
114 | |
|
115 | |
public final void testGetIncidentEdges() { |
116 | 3 | EdgeIterator itNeigh = null; |
117 | |
|
118 | 3 | itNeigh = this.lollypop.getIncidentEdges(this.firstNode); |
119 | 3 | CheckGraph.checkNumIterations(itNeigh, 1); |
120 | 3 | itNeigh = this.lollypop.getIncidentEdges(this.lastPathNode); |
121 | 3 | CheckGraph.checkNumIterations(itNeigh, CLIQUESIZE-1+1); |
122 | |
|
123 | 3 | itNeigh = this.mix.getIncidentEdges(this.firstNode); |
124 | 3 | CheckGraph.checkNumIterations(itNeigh, CLIQUESIZE-1); |
125 | 3 | itNeigh = this.mix.getIncidentEdges(this.lastPathNode); |
126 | 3 | CheckGraph.checkNumIterations(itNeigh, CLIQUESIZE-1); |
127 | 3 | } |
128 | |
|
129 | |
public final void testContains() { |
130 | 3 | assertTrue(this.lollypop.contains(new NumberNode(0))); |
131 | 3 | assertTrue(this.lollypop.contains(new NumberNode(PATHLEN+CLIQUESIZE-2))); |
132 | 3 | assertFalse(this.lollypop.contains(new NumberNode(PATHLEN+CLIQUESIZE-1))); |
133 | 3 | assertFalse(this.lollypop.contains(new NumberNode(NumberGraph.NOSUCHNODE))); |
134 | 3 | } |
135 | |
|
136 | |
} |