/** * Checks the correct reading of a POI's color. * * @throws IOException */ @Test public void testPOIColor() throws IOException { Repository<POI> poiRepo = conn.getPOIRepository(); POI poi = poiRepo.getByID("0"); Color c = new Color(255, 128, 0); assertEquals(c, poi.getColor()); }
/** * Tests that the vehicle at step 1 is at beginning of its departure lane. * * @throws IOException */ @Test public void testVehiclePositionAtStepOne() throws IOException { conn.nextSimStep(); final Repository<Vehicle> repo = conn.getVehicleRepository(); Vehicle v0 = repo.getByID("0.0"); assertEquals(0, v0.getLanePosition(), DELTA); }
/** * Checks the correct setting of a POI's type. * * @throws IOException */ @Test public void testSetPOIType() throws IOException { Repository<POI> poiRepo = conn.getPOIRepository(); POI poi = poiRepo.getByID("0"); final String newType = "NEW_TYPE"; poi.changeType(newType); assertEquals(newType, poi.getType()); }
/** * Checks the correct setting of a POI's color. * * @throws IOException */ @Test public void testSetPOIColor() throws IOException { Repository<POI> poiRepo = conn.getPOIRepository(); POI poi = poiRepo.getByID("0"); final Color newColor = Color.cyan; poi.changeColor(newColor); assertEquals(newColor, poi.getColor()); }
/** * Checks the correct reading of a POI's position. * * @throws IOException */ @Test public void testPOIPosition() throws IOException { Repository<POI> poiRepo = conn.getPOIRepository(); POI poi = poiRepo.getByID("0"); Point2D pos = new Point2D.Double(100, 50); Point2D poiPos = poi.getPosition(); assertEquals(pos.getX(), poiPos.getX(), DELTA); assertEquals(pos.getY(), poiPos.getY(), DELTA); }
/** * Checks the correct setting of a POI's position. * * @throws IOException */ @Test public void testSetPOIPosition() throws IOException { Repository<POI> poiRepo = conn.getPOIRepository(); POI poi = poiRepo.getByID("0"); final Point2D newPos = new Point2D.Double(0, 0); poi.changePosition(newPos); final Point2D pos = poi.getPosition(); assertEquals(newPos.getX(), pos.getX(), DELTA); assertEquals(newPos.getY(), pos.getY(), DELTA); }
/** * Checks for the correct behaviour of a MeMe detector. * * @throws IOException */ @Test public void testMeMeDetectorIsDetecting() throws IOException { for (int t = 0; t < 100; t++) { conn.nextSimStep(); } Repository<MeMeDetector> memeRepo = conn.getMeMeDetectorRepository(); MeMeDetector detector = memeRepo.getByID("e3_0"); assertEquals(38, (int) detector.getVehicleNumber()); }
@Test public void testChangingCompleteProgramDefinition() throws IOException { TrafficLight tl = repo.getByID("0"); final Logic expectedLogic = new Logic( "0", 0, new Phase[] { new Phase(10000, new TLState("rrGGyyyyggrryryr")), new Phase(15000, new TLState("GGyyrrrrrrGGrGrG")), new Phase(55000, new TLState("yyrrGGGGGGyyGyGy")) }); tl.queryChangeCompleteProgramDefinition().setValue(expectedLogic); tl.queryChangeCompleteProgramDefinition().run(); Program newProgram = tl.queryReadCompleteDefinition().get(); assertEquals(1, newProgram.getLogics().length); Logic actualLogic = newProgram.getLogics()[0]; assertEquals(expectedLogic.getSubID(), actualLogic.getSubID()); assertEquals(expectedLogic.getCurrentPhaseIndex(), actualLogic.getCurrentPhaseIndex()); Phase[] actualPhases = actualLogic.getPhases(); Phase[] expectedPhases = expectedLogic.getPhases(); assertEquals(expectedPhases.length, actualPhases.length); for (int i = 0; i < actualPhases.length; i++) { Phase actualPhase = actualPhases[i]; Phase expectedPhase = expectedPhases[i]; assertEquals(expectedPhase.getDuration(), actualPhase.getDuration()); assertArrayEquals(expectedPhase.getState().lightStates, actualPhase.getState().lightStates); } }
@Test public void testStateUpdate() throws IOException { TrafficLight tl = repo.getByID("0"); final ReadObjectVarQuery<TLState> query = tl.queryReadState(); // looks like SUMO shifts all TL timings ahead one second conn.nextSimStep(); for (int p = 0; p < PHASES.length; p++) { TLState tlState = query.get(); final LightState[] states = tlState.lightStates; log.info( "state at t=" + conn.getCurrentSimTime() + "ms\n" + " expected " + Arrays.toString(PHASES[p]) + "\n" + " actual " + Arrays.toString(states)); assertArrayEquals("state at t=" + conn.getCurrentSimTime() + "ms", PHASES[p], states); for (int t = 0; t < PHASES_DURATION[p]; t++) conn.nextSimStep(); } }
@Test public void testStateAtFirstStep() throws IOException { TrafficLight tl = repo.getByID("0"); TLState tlState = tl.queryReadState().get(); final LightState[] states = tlState.lightStates; assertEquals(16, states.length); assertArrayEquals(PHASES[0], states); }
@Test public void testChangeState() throws IOException { TrafficLight tl = repo.getByID("0"); ChangeLightsStateQuery q = tl.queryChangeLightsState(); q.setValue(TEST_TL_STATE); q.run(); assertEquals(TEST_TL_STATE, tl.queryReadState().get()); }
@Test public void testCurrentDuration() throws IOException { TrafficLight tl = repo.getByID("0"); final ReadObjectVarQuery<Integer> query = tl.queryReadDefaultCurrentPhaseDuration(); // looks like SUMO shifts all TL timings ahead one second conn.nextSimStep(); for (int p = 0; p < PHASES.length; p++) { int phaseDuration = query.get(); assertEquals(PHASES_DURATION[p], phaseDuration / 1000); for (int t = 0; t < PHASES_DURATION[p]; t++) conn.nextSimStep(); } }
@Test public void testControlledLinks() throws IOException { TrafficLight tl = repo.getByID("0"); ControlledLinks links = tl.queryReadControlledLinks().get(); assertEquals(linksLaneIDs.length, links.getLinks().length); for (int i = 0; i < linksLaneIDs.length; i++) { ControlledLink[] linksForSignal = links.getLinks()[i]; assertEquals(1, linksForSignal.length); ControlledLink link = linksForSignal[0]; assertEquals(linksLaneIDs[i][0], link.getIncomingLane().getID()); assertEquals(linksLaneIDs[i][1], link.getAcrossLane().getID()); assertEquals(linksLaneIDs[i][2], link.getOutgoingLane().getID()); } }
@Test public void testTrafficLightsPosition() throws IOException { TrafficLight tl = repo.getByID("0"); List<Lane> lanes = tl.queryReadControlledLanes().get(); assertEquals(16, lanes.size()); for (Lane lane : lanes) { Point2D lastPoint = getLastPointOfALane(lane); assertTrue(lastPoint.getX() > 486.0); assertTrue(lastPoint.getY() > 486.0); assertTrue(lastPoint.getX() < 513.0); assertTrue(lastPoint.getY() < 513.0); } }
@Test public void testCompleteProgramDefinition() throws IOException { TrafficLight tl = repo.getByID("0"); Program program = tl.queryReadCompleteDefinition().get(); assertEquals(1, program.getLogics().length); Logic logic = program.getLogics()[0]; assertEquals("0", logic.getSubID()); assertEquals(0, logic.getCurrentPhaseIndex()); Phase[] phases = logic.getPhases(); assertEquals(8, phases.length); for (int i = 0; i < phases.length; i++) { Phase ph = phases[i]; assertEquals(PHASES_DURATION[i] * 1000, ph.getDuration()); assertArrayEquals(PHASES[i], ph.getState().lightStates); } }
/** * Checks for presence of a Multi-entry/Multi-exit detector. * * @throws IOException */ @Test public void testMeMeExistence() throws IOException { Repository<MeMeDetector> memeRepo = conn.getMeMeDetectorRepository(); assertNotNull(memeRepo.getByID("e3_0")); }
/** * Checks the correct reading of a POI's type. * * @throws IOException */ @Test public void testPOIType() throws IOException { Repository<POI> poiRepo = conn.getPOIRepository(); POI poi = poiRepo.getByID("0"); assertEquals("TEST_TYPE", poi.getType()); }
/** * Checks for presence of a Point of Interest. * * @throws IOException */ @Test public void testPOIExistence() throws IOException { Repository<POI> poiRepo = conn.getPOIRepository(); assertNotNull(poiRepo.getByID("0")); }
/** * Returns the first vehicle entered in the simulation. Since all vehicles depart from the same * road, and SUMO lets at most one vehicle to depart from a given road at each step, the vehicle * returned from this function will always be the same. * * @throws IOException */ public void getFirstVehicle() throws IOException { Repository<Vehicle> repo = conn.getVehicleRepository(); while (repo.getAll().isEmpty()) conn.nextSimStep(); firstVehicle = repo.getAll().values().iterator().next(); }
/** * Tests that the vehicle's ID of the first vehicle is correct. * * @throws IOException */ @Test public void testVehicleIDAtStepOne() throws IOException { conn.nextSimStep(); final Repository<Vehicle> repo = conn.getVehicleRepository(); assertThat(repo.getIDs(), equalTo(Collections.singleton("0.0"))); }
/** * In this simulation, there should be exactly one vehicle at step one. * * @throws IOException */ @Test public void testOneVehicleAtStepOne() throws IOException { conn.nextSimStep(); final Repository<Vehicle> repo = conn.getVehicleRepository(); assertThat(repo.getIDs().size(), equalTo(1)); }
@Test public void testTrafficLightExistence() throws IOException { assertNotNull(repo.getByID("0")); }