@Test(expected = RuntimeException.class) public void impossiblePath() throws InstantiationException, IllegalAccessException { final Graph<?> gg = rmType.newInstance(); final GraphRoadModel roads = RoadModelBuilders.staticGraph(gg).build( mock(DependencyProvider.class)); gg.addConnection(a, b); gg.addConnection(b, c); Graphs.shortestPathEuclideanDistance(roads.getGraph(), b, a); }
@Override public GenericRoadModel create(ForwardingRoadModelTest testClass) { return new ForwardingRoadModel(RoadModelBuilders.staticGraph(testClass .createGraph()).build(mock(DependencyProvider.class))); } }}, {new Creator() {
/** * Tests that unregistering a model is not possible. */ @Test(expected = IllegalArgumentException.class) public void unregisterFailModel() { emptyManager.unregister(RoadModelBuilders.staticGraph( new MultimapGraph<LengthData>()).build(mock(DependencyProvider.class))); }
graph = rmType.newInstance(); rm = RoadModelBuilders.staticGraph(graph) .build(mock(DependencyProvider.class));
@Test public void moveToHeuristicTest() { final MovingRoadUser fastestPathAgent = new SpeedyRoadUser(10); final MovingRoadUser shortestPathAgent = new SpeedyRoadUser(10); final Point origin = new Point(0, 0); final Point destination = new Point(0, 10); final Point midway = new Point(5, 5); // Graph with slow direct (shortest) route, but fast longer route. final Graph<MultiAttributeData> graph = new TableGraph<>(); graph.addConnection(origin, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(1).build()); graph.addConnection(origin, midway, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); graph.addConnection(midway, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); final RoadModel moveModel = RoadModelBuilders.staticGraph(graph) .withDistanceUnit(SI.KILOMETER).withSpeedUnit(NonSI.KILOMETERS_PER_HOUR) .build(mock(DependencyProvider.class)); moveModel.addObjectAt(fastestPathAgent, origin); moveModel.addObjectAt(shortestPathAgent, origin); moveModel.moveTo(fastestPathAgent, destination, hour(1), GeomHeuristics.time(10)); moveModel.moveTo(shortestPathAgent, destination, hour(1), GeomHeuristics.euclidean()); // Agent chose speedy route assertEquals(midway, moveModel.getPosition(fastestPathAgent)); // Agent chose shortest route assertEquals(new Point(0, 1), moveModel.getPosition(shortestPathAgent)); }
/** * Tests that an exception thrown by a model during unregister bubbles up. */ @Test public void unregisterWithBrokenModel() { final ModelManager mm = new ModelManager( ImmutableSet.of(RoadModelBuilders.staticGraph( new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)), new BrokenRoadModel(new MultimapGraph<LengthData>()))); boolean fail = false; try { mm.unregister(new RoadUser() { @Override public void initRoadUser(RoadModel model) {} }); } catch (final RuntimeException e) { fail = true; } assertThat(fail).isTrue(); }
@SuppressWarnings("unchecked") @Test public void getMaxSpeed() { final Point A = new Point(0, 0); final Point B = new Point(10, 0); final Graph<LengthData> g = new MultimapGraph<>(); final GraphRoadModelImpl rm = RoadModelBuilders.staticGraph(g).build( mock(DependencyProvider.class)); g.addConnection(A, B, LengthData.create(3)); final UnitConverter conv = NonSI.KILOMETERS_PER_HOUR .getConverterTo(RoadUnits.INTERNAL_SPEED_UNIT); assertEquals(conv.convert(10), rm.getMaxSpeed(new SpeedyRoadUser(10), A, B), EPSILON); ((Graph<MultiAttributeData>) graph).addConnection(SE, SW, MultiAttributeData.builder().setLength(3).setMaxSpeed(5d).build()); assertEquals(conv.convert(5), model.getMaxSpeed(new SpeedyRoadUser(10), SE, SW), EPSILON); ((Graph<MultiAttributeData>) graph).addConnection(NE, SE, MultiAttributeData.builder().setLength(3).build()); assertEquals(conv.convert(10), model.getMaxSpeed(new SpeedyRoadUser(10), NE, SE), EPSILON); }
/** * Tests that unregistering an not registered object fails. */ @Test public void unregisterFailNotRegisteredObject() { final ModelManager mm = new ModelManager( ImmutableSet.of( RoadModelBuilders.staticGraph(new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)), RoadModelBuilders.staticGraph(new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)))); boolean fail = false; try { mm.unregister(new RoadUser() { @Override public void initRoadUser(RoadModel model) {} }); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); }
/** * Tests that exception thrown by the broken model bubbles up. */ @Test(expected = RuntimeException.class) public void registerWithBrokenModel() { final ModelManager mm = new ModelManager(ImmutableSet.of( RoadModelBuilders.staticGraph( new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)), new BrokenRoadModel(new MultimapGraph<LengthData>()))); mm.register(new RoadUser() { @Override public void initRoadUser(RoadModel model) {} }); }
/** * A model can not be registered. */ @Test(expected = IllegalArgumentException.class) public void canNotRegisterModel() { emptyManager.register(RoadModelBuilders.staticGraph( new MultimapGraph<LengthData>()).build(mock(DependencyProvider.class))); }
@Test public void getGraphTest() { final Graph<ConnectionData> g = new MultimapGraph<ConnectionData>(); g.addConnection(NE, SW); g.addConnection(SW, NW); final GraphRoadModel rm = RoadModelBuilders.staticGraph(g) .withDistanceUnit(SI.METER) .withSpeedUnit(SI.METERS_PER_SECOND) .build(mock(DependencyProvider.class)); assertEquals(g, rm.getGraph()); g.addConnection(NE, NW); assertEquals(g, rm.getGraph()); }
@Override public GenericRoadModel create(ForwardingRoadModelTest testClass) { return new ForwardingRoadModel(new ForwardingRoadModel( new ForwardingRoadModel(RoadModelBuilders.staticGraph(testClass .createGraph()).build(mock(DependencyProvider.class))))); } }}});