* Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* $LastChangedDate: 2015-09-16 19:20:07 +0200 (Wed, 16 Sep 2015) $, @version $Revision: 1405 $, by $Author: averbraeck $,
* initial version Jul 11, 2014
* @author Peter Knoppers
*/
public class CarTest implements UNITS
{
/**
* Test some basics of the Car class.
* @throws NetworkException on ???
* @throws SimRuntimeException on ???
* @throws NamingException on ???
* @throws GTUException on ???
* @throws OTSGeometryException when center line or contour of a link or lane cannot be generated
*/
@SuppressWarnings("static-method")
@Test
public final void carTest()
throws NetworkException, SimRuntimeException, NamingException, GTUException, OTSGeometryException
{
Time initialTime = new Time(0, SECOND);
GTUType gtuType = CAR;
Set compatibility = new HashSet();
compatibility.add(gtuType);
LaneType laneType = new LaneType("CarLane", compatibility);
OTSNetwork network = new OTSNetwork("network");
Lane lane = makeLane(network, laneType);
Length initialPosition = new Length(12, METER);
Speed initialSpeed = new Speed(34, KM_PER_HOUR);
OTSDEVSSimulator simulator = makeSimulator();
GTUFollowingModelOld gtuFollowingModel =
new FixedAccelerationModel(new Acceleration(0, METER_PER_SECOND_2), new Duration(10, SECOND));
LaneChangeModel laneChangeModel = new Egoistic();
LaneBasedIndividualGTU referenceCar = makeReferenceCar("12345", gtuType, lane, initialPosition, initialSpeed, simulator,
gtuFollowingModel, laneChangeModel, network);
assertEquals("The car should store it's ID", "12345", referenceCar.getId());
assertEquals("At t=initialTime the car should be at it's initial position", initialPosition.getSI(),
referenceCar.position(lane, referenceCar.getReference(), initialTime).getSI(), 0.0001);
assertEquals("The car should store it's initial speed", initialSpeed.getSI(), referenceCar.getSpeed().getSI(), 0.00001);
assertEquals("The car should have an initial acceleration equal to 0", 0, referenceCar.getAcceleration().getSI(),
0.0001);
// TODO check with following model as part of tactical planner
// assertEquals("The gtu following model should be " + gtuFollowingModel, gtuFollowingModel, referenceCar
// .getBehavioralCharacteristics().getGTUFollowingModel());
// There is (currently) no way to retrieve the lane change model of a GTU.
}
/**
* Create the simplest possible simulator.
* @return OTSDEVSSimulator
* @throws SimRuntimeException on ???
* @throws NamingException on ???
*/
public static OTSDEVSSimulator makeSimulator() throws SimRuntimeException, NamingException
{
OTSDEVSSimulator simulator = new OTSDEVSSimulator();
Model model = new Model();
Experiment