@Test public void testAStar_distance_slantedRoad() { MapGraph mapGraph = new MapGraph(); mapGraph.addRoad("Road 1", new Point2D.Double(0, 20), new Point2D.Double(100, 20), 35); mapGraph.addRoad("Road 2", new Point2D.Double(20, 0), new Point2D.Double(20, 100), 35); mapGraph.addRoad("Road 3", new Point2D.Double(0, 80), new Point2D.Double(100, 80), 35); mapGraph.addRoad("Road 4", new Point2D.Double(80, 0), new Point2D.Double(80, 100), 35); mapGraph.addRoad("Slanted road", new Point2D.Double(25, 15), new Point2D.Double(75, 85), 35); GraphVisualizer gv = new GraphVisualizer(mapGraph); LinkedList<Intersection> shortestPath1 = mapGraph.shortestPath_distance( mapGraph.getIntersectionByName("Road 1 + Road 2"), mapGraph.getIntersectionByName("Road 1 + Slanted road")); if (shortestPath1 == null) fail(); Iterator<Intersection> test = shortestPath1.iterator(); assertEquals("Road 1 + Road 2", test.next().toString()); assertEquals("Road 1 + Slanted road", test.next().toString()); assertFalse(test.hasNext()); LinkedList<Intersection> shortestPath2 = mapGraph.shortestPath_distance( mapGraph.getIntersectionByName("Road 1 + Road 2"), mapGraph.getIntersectionByName("Road 3 + Road 4")); if (shortestPath2 == null) fail(); test = shortestPath2.iterator(); assertEquals("Road 1 + Road 2", test.next().toString()); assertEquals("Road 1 + Slanted road", test.next().toString()); assertEquals("Road 3 + Slanted road", test.next().toString()); assertEquals("Road 3 + Road 4", test.next().toString()); assertFalse(test.hasNext()); }
@Test public void testAStar_distance_tictac() { MapGraph mapGraph = new MapGraph(); mapGraph.addRoad("Road 1", new Point2D.Double(0, 20), new Point2D.Double(100, 20), 35); mapGraph.addRoad("Road 2", new Point2D.Double(20, 0), new Point2D.Double(20, 100), 35); mapGraph.addRoad("Road 3", new Point2D.Double(0, 80), new Point2D.Double(100, 80), 35); LinkedList<Intersection> shortestPath1 = mapGraph.shortestPath_distance( mapGraph.getIntersectionByName("Road 1 + Road 2"), mapGraph.getIntersectionByName("Road 2 + Road 3")); if (shortestPath1 == null) fail(); Iterator<Intersection> test = shortestPath1.iterator(); assertEquals("Road 1 + Road 2", test.next().toString()); assertEquals("Road 2 + Road 3", test.next().toString()); assertFalse(test.hasNext()); mapGraph.addRoad("Road 4", new Point2D.Double(80, 0), new Point2D.Double(80, 100), 35); LinkedList<Intersection> shortestPath1b = mapGraph.shortestPath_distance( mapGraph.getIntersectionByName("Road 1 + Road 2"), mapGraph.getIntersectionByName("Road 3 + Road 4")); if (shortestPath1b == null) fail(); // System.out.println(shortestPath1b); // test = shortestPath1b.iterator(); // assertEquals("Road 1 + Road 2",test.next().toString()); // assertEquals("Road 2 + Road 3",test.next().toString()); // assertFalse(test.hasNext()); }