@Test public void testNextDirectZone() { NdPoint begin = new NdPoint(zones[0][0].getLocation().getX(), zones[0][0].getLocation().getY()); NdPoint end = new NdPoint(zones[0][1].getLocation().getX() + 3, zones[0][1].getLocation().getY() - 4); Queue<NdPoint> expected = new ArrayDeque<>(); expected.add(end); Queue<NdPoint> actual = NavigatingRobot.planPath(begin, end, zones[0][0], zones[0][1], graph); assertEqual(expected, actual); }
@Test public void testSameZone() { final Zone zone = zones[0][0]; final NdPoint zLocation = zone.getLocation(); NdPoint begin = new NdPoint(zLocation.getX() + 2, zLocation.getY() + 1); NdPoint end = new NdPoint(zLocation.getX() + 3, zLocation.getY() - 4); Queue<NdPoint> expected = new ArrayDeque<>(); expected.add(end); Queue<NdPoint> actual = NavigatingRobot.planPath(begin, end, zone, zone, graph); assertEqual(expected, actual); }
@Test(expected = IllegalArgumentException.class) public void testNoConnectionZone() { final Zone bzone = zones[2][0]; final Zone ezone = zones[1][1]; NdPoint begin = new NdPoint(bzone.getLocation().getX(), bzone.getLocation().getY()); NdPoint end = new NdPoint(ezone.getLocation().getX() + 1, ezone.getLocation().getY() - 1); // disconnect the middle zone when(zones[0][1].getNeighbours()) .thenReturn(new HashSet<Zone>(Arrays.asList(zones[0][2], zones[0][0]))); when(ezone.getNeighbours()).thenReturn(new HashSet<Zone>()); NavigatingRobot.planPath(begin, end, bzone, ezone, graph); }
@Test public void testBreakRoom() { final Zone bzone = zones[1][1]; final Zone ezone = zones[0][1]; NdPoint begin = new NdPoint(bzone.getLocation().getX() - 1, bzone.getLocation().getY() + 3); NdPoint end = new NdPoint(ezone.getLocation().getX() + 1, ezone.getLocation().getY() - 1); assertTrue(bzone instanceof Room); Queue<NdPoint> expected = new ArrayDeque<>(); expected.add(bzone.getLocation()); expected.add(ezone.getLocation()); expected.add(end); Queue<NdPoint> actual = NavigatingRobot.planPath(begin, end, bzone, ezone, graph); assertEqual(expected, actual); }
@Test public void testRoundZone() { final Zone bzone = zones[2][0]; final Zone ezone = zones[1][1]; NdPoint begin = new NdPoint(bzone.getLocation().getX(), bzone.getLocation().getY()); NdPoint end = new NdPoint(ezone.getLocation().getX() + 1, ezone.getLocation().getY() - 1); Queue<NdPoint> expected = new ArrayDeque<>(); expected.add(zones[1][0].getLocation()); expected.add(zones[0][0].getLocation()); expected.add(zones[0][1].getLocation()); expected.add(ezone.getLocation()); expected.add(end); Queue<NdPoint> actual = NavigatingRobot.planPath(begin, end, bzone, ezone, graph); assertEqual(expected, actual); }