No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NodeTest.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package org.insa.graph;
  2. import static org.junit.Assert.assertEquals;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import org.insa.graph.RoadInformation.RoadType;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8. public class NodeTest {
  9. // List of nodes
  10. private Node[] nodes;
  11. @Before
  12. public void initAll() throws IOException {
  13. // Create nodes
  14. nodes = new Node[6];
  15. for (int i = 0; i < nodes.length; ++i) {
  16. nodes[i] = new Node(i, null);
  17. }
  18. Node.linkNodes(nodes[0], nodes[1], 0,
  19. new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
  20. new ArrayList<>());
  21. Node.linkNodes(nodes[0], nodes[2], 0,
  22. new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
  23. new ArrayList<>());
  24. Node.linkNodes(nodes[0], nodes[4], 0,
  25. new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
  26. Node.linkNodes(nodes[1], nodes[2], 0,
  27. new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
  28. new ArrayList<>());
  29. Node.linkNodes(nodes[2], nodes[3], 0,
  30. new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
  31. Node.linkNodes(nodes[2], nodes[3], 0,
  32. new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
  33. Node.linkNodes(nodes[2], nodes[3], 0,
  34. new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
  35. Node.linkNodes(nodes[3], nodes[0], 0,
  36. new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
  37. new ArrayList<>());
  38. Node.linkNodes(nodes[3], nodes[4], 0,
  39. new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
  40. Node.linkNodes(nodes[4], nodes[0], 0,
  41. new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
  42. }
  43. /**
  44. * @return The first arc between from a to b, or null.
  45. */
  46. private Arc getFirstArcBetween(Node a, Node b) {
  47. for (Arc arc: a) {
  48. if (arc.getDestination().equals(b)) {
  49. return arc;
  50. }
  51. }
  52. return null;
  53. }
  54. @Test
  55. public void testGetNumberOfSuccessors() {
  56. final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 };
  57. assertEquals(nodes.length, expNbSucc.length);
  58. for (int i = 0; i < expNbSucc.length; ++i) {
  59. assertEquals(nodes[i].getNumberOfSuccessors(), expNbSucc[i]);
  60. }
  61. }
  62. @Test
  63. public void testHasSuccessors() {
  64. final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 };
  65. assertEquals(nodes.length, expNbSucc.length);
  66. for (int i = 0; i < expNbSucc.length; ++i) {
  67. assertEquals(nodes[i].hasSuccessors(), expNbSucc[i] != 0);
  68. }
  69. }
  70. @Test
  71. public void testLinkNodes() {
  72. assertEquals(getFirstArcBetween(nodes[0], nodes[1]).getRoadInformation(),
  73. getFirstArcBetween(nodes[1], nodes[0]).getRoadInformation());
  74. }
  75. }