| 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 junit.framework.TestCase; |
| 25 | |
import net.sourceforge.combean.graph.NumberNode; |
| 26 | |
import net.sourceforge.combean.interfaces.graph.Edge; |
| 27 | |
import net.sourceforge.combean.interfaces.graph.EdgeIterator; |
| 28 | |
import net.sourceforge.combean.interfaces.graph.Node; |
| 29 | |
import net.sourceforge.combean.interfaces.graph.NodeIterator; |
| 30 | |
import net.sourceforge.combean.samples.simplegraphs.DirectedCircle; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public class TestDirectedCircle extends TestCase { |
| 37 | |
|
| 38 | |
private static final int CIRCLESIZE = 5; |
| 39 | 3 | private DirectedCircle circle = null; |
| 40 | |
|
| 41 | |
public static void main(String[] args) { |
| 42 | 0 | junit.textui.TestRunner.run(TestDirectedCircle.class); |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
protected void setUp() throws Exception { |
| 49 | 3 | super.setUp(); |
| 50 | |
|
| 51 | 3 | this.circle = new DirectedCircle(CIRCLESIZE); |
| 52 | 3 | } |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
protected void tearDown() throws Exception { |
| 58 | 3 | super.tearDown(); |
| 59 | 3 | } |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public TestDirectedCircle(String name) { |
| 66 | 3 | super(name); |
| 67 | 3 | } |
| 68 | |
|
| 69 | |
public final void testGetNeighbors() { |
| 70 | 3 | EdgeIterator it = null; |
| 71 | 3 | Edge e = null; |
| 72 | 3 | Node v = null; |
| 73 | |
|
| 74 | 3 | int i = 0; |
| 75 | 3 | NodeIterator allNodesIt = this.circle.getAllNodesIterator(); |
| 76 | 18 | while (allNodesIt.hasNext()) { |
| 77 | 15 | Node w = allNodesIt.next(); |
| 78 | |
|
| 79 | 15 | it = this.circle.getIncidentEdges(w); |
| 80 | 15 | assertTrue("every node has one neighbor", it.hasNext()); |
| 81 | 15 | e = it.next(); |
| 82 | 15 | v = this.circle.getOtherNode(e, w); |
| 83 | 15 | assertEquals((i+1)%CIRCLESIZE, ((NumberNode)v).getNodeNum()); |
| 84 | 15 | assertFalse(it.hasNext()); |
| 85 | |
|
| 86 | 15 | i++; |
| 87 | 15 | } |
| 88 | 3 | } |
| 89 | |
|
| 90 | |
} |