use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class CarManagerTest method testListCarsAvailableByTrain.
public void testListCarsAvailableByTrain() {
resetCarManager();
CarManager manager = CarManager.instance();
Route r = new Route("id", "Test");
r.addLocation(l1);
r.addLocation(l2);
RouteLocation last = r.addLocation(l3);
Train t1;
Train t3;
t1 = new Train("id1", "F");
t1.setRoute(r);
t3 = new Train("id3", "E");
t3.setRoute(r);
c1.setTrain(t1);
c2.setTrain(t3);
c3.setTrain(t3);
c4.setTrain(new Train("id4", "B"));
c5.setTrain(t3);
c6.setTrain(new Train("id6", "A"));
// how many cars available?
List<Car> carList = manager.getAvailableTrainList(t1);
Assert.assertEquals("Number of Cars available for t1", 1, carList.size());
Assert.assertEquals("1st car in list available for t1", c1, carList.get(0));
carList = manager.getAvailableTrainList(t3);
Assert.assertEquals("Number of Cars available for t3", 3, carList.size());
Assert.assertEquals("1st car in list available for t3", c5, carList.get(0));
Assert.assertEquals("2nd car in list available for t3", c2, carList.get(1));
Assert.assertEquals("3rd car in list available for t3", c3, carList.get(2));
// now don't allow pickups at the last location in the train's route
last.setPickUpAllowed(false);
carList = manager.getAvailableTrainList(t3);
Assert.assertEquals("Number of Cars available for t3", 2, carList.size());
Assert.assertEquals("1st car in list available for t3", c2, carList.get(0));
Assert.assertEquals("2nd car in list available for t3", c3, carList.get(1));
// note that c5 isn't available since it is located at the end of the train's route
// release cars from trains
c2.setTrain(null);
c4.setTrain(null);
// c6 is located at the end of the route, therefore not available
c6.setTrain(null);
// there should be more cars now
carList = manager.getAvailableTrainList(t1);
Assert.assertEquals("Number of Cars available t1 after release", 3, carList.size());
// should be sorted by moves
Assert.assertEquals("1st car in list available for t1", c1, carList.get(0));
Assert.assertEquals("2nd car in list available for t1", c4, carList.get(1));
Assert.assertEquals("3rd car in list available for t1", c2, carList.get(2));
carList = manager.getAvailableTrainList(t3);
Assert.assertEquals("Number of Cars available for t3 after release", 3, carList.size());
Assert.assertEquals("1st car in list available for t3", c4, carList.get(0));
Assert.assertEquals("2nd car in list available for t3", c2, carList.get(1));
Assert.assertEquals("3rd car in list available for t3", c3, carList.get(2));
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilderTest method testCarBlockingFromStaging.
public void testCarBlockingFromStaging() {
// create 5 locations with tracks
Location harvard = lmanager.newLocation("Harvard");
Track loc1trk1 = harvard.addTrack("Harvard Yard 1", Track.YARD);
loc1trk1.setLength(1000);
Track loc1trk2 = harvard.addTrack("Harvard Yard 2", Track.YARD);
loc1trk2.setLength(1000);
Location arlington = lmanager.newLocation("Arlington");
Track loc2trk1 = arlington.addTrack("Arlington Siding", Track.YARD);
loc2trk1.setLength(1000);
Location boston = lmanager.newLocation("Boston");
Track loc3trk1 = boston.addTrack("Boston Yard 1", Track.YARD);
loc3trk1.setLength(1000);
Track loc3trk2 = boston.addTrack("Boston Yard 2", Track.YARD);
loc3trk2.setLength(1000);
Location chelmsford = lmanager.newLocation("Chelmsford");
Track loc4trk1 = chelmsford.addTrack("Chelmsford Yard 1", Track.YARD);
loc4trk1.setLength(1000);
Track loc4trk2 = chelmsford.addTrack("Chelmsford Yard 2", Track.YARD);
loc4trk2.setLength(1000);
// Staging and enable blocking
Location westford = lmanager.newLocation("Westford Staging");
westford.setLocationOps(Location.STAGING);
Track loc5trk1 = westford.addTrack("Westford Staging", Track.STAGING);
loc5trk1.setLength(1000);
loc5trk1.setBlockCarsEnabled(true);
// create two trains, one into staging, the other out of staging
// Create route with 5 location
// set default to 20 moves per location
Setup.setCarMoves(20);
Route rte1 = rmanager.newRoute("Route Harvard to Westford Staging");
rte1.addLocation(harvard);
RouteLocation rl2 = rte1.addLocation(arlington);
// only do pulls for this test
rl2.setDropAllowed(false);
RouteLocation rl3 = rte1.addLocation(boston);
// only do pulls for this test
rl3.setDropAllowed(false);
RouteLocation rl4 = rte1.addLocation(chelmsford);
// only do pulls for this test
rl4.setDropAllowed(false);
// staging
rte1.addLocation(westford);
// Create train
Train train1 = tmanager.newTrain("TestCarBlockingFromStaging");
train1.setRoute(rte1);
train1.setRequirements(Train.CABOOSE);
// create and place cars
Car c1 = cmanager.newCar("PU", "113");
c1.setTypeName("Caboose");
c1.setLength("32");
c1.setMoves(10);
c1.setOwner("AT");
c1.setBuilt("1943");
c1.setCaboose(true);
Car c2 = cmanager.newCar("SP", "123");
c2.setTypeName("Boxcar");
c2.setLength("30");
c2.setMoves(5);
c2.setOwner("DAB");
c2.setBuilt("1957");
Car c3 = cmanager.newCar("UP", "133");
c3.setTypeName("Boxcar");
c3.setLength("33");
c3.setMoves(0);
c3.setOwner("DAB");
c3.setBuilt("1944");
Car c4 = cmanager.newCar("UP", "143");
c4.setTypeName("Boxcar");
c4.setLength("40");
c4.setMoves(16);
c4.setOwner("DAB");
c4.setBuilt("1958");
Car c5 = cmanager.newCar("SP", "153");
c5.setTypeName("Boxcar");
c5.setLength("40");
c5.setMoves(8);
c5.setOwner("DAB");
c5.setBuilt("1958");
Car c6 = cmanager.newCar("NH", "163");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(2);
c6.setOwner("DAB");
c6.setBuilt("1958");
Car c7 = cmanager.newCar("UP", "173");
c7.setTypeName("Boxcar");
c7.setLength("40");
c7.setMoves(5);
c7.setOwner("DAB");
c7.setBuilt("1958");
Car c8 = cmanager.newCar("SP", "183");
c8.setTypeName("Boxcar");
c8.setLength("40");
c8.setMoves(4);
c8.setOwner("DAB");
c8.setBuilt("1958");
Car c9 = cmanager.newCar("NH", "193");
c9.setTypeName("Boxcar");
c9.setLength("40");
c9.setMoves(3);
c9.setOwner("DAB");
c9.setBuilt("1944");
Car c10 = cmanager.newCar("NH", "1103");
c10.setTypeName("Boxcar");
c10.setLength("40");
c10.setMoves(10);
c10.setOwner("DAB");
c10.setBuilt("1958");
Car c11 = cmanager.newCar("SP", "1113");
c11.setTypeName("Boxcar");
c11.setLength("40");
c11.setMoves(3);
c11.setOwner("DAB");
c11.setBuilt("1958");
// Place cars
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(harvard, loc1trk1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(harvard, loc1trk2));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(harvard, loc1trk2));
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(harvard, loc1trk1));
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(harvard, loc1trk2));
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(harvard, loc1trk1));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(boston, loc3trk1));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(boston, loc3trk2));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(chelmsford, loc4trk1));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(chelmsford, loc4trk2));
Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(chelmsford, loc4trk2));
// check car's last known location id
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c1.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c2.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c3.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c4.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c5.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c6.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c7.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c8.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c9.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c10.getLastLocationId());
Assert.assertEquals("Last location isn't known", Car.LOCATION_UNKNOWN, c11.getLastLocationId());
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// terminate train into staging
train1.terminate();
// now check car's last known location id
Assert.assertEquals("Car departed Harvard", harvard.getId(), c1.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c2.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c3.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c4.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c5.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c6.getLastLocationId());
Assert.assertEquals("Car departed Boston", boston.getId(), c7.getLastLocationId());
Assert.assertEquals("Car departed Boston", boston.getId(), c8.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", chelmsford.getId(), c9.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", chelmsford.getId(), c10.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", chelmsford.getId(), c11.getLastLocationId());
// now build a train that departs staging
Route rte2 = rmanager.newRoute("Route Westford Staging to Harvard");
// staging
rte2.addLocation(westford);
RouteLocation rlArlington = rte2.addLocation(arlington);
rlArlington.setMaxCarMoves(4);
RouteLocation rlBoston = rte2.addLocation(boston);
// largest block of cars goes here
rlBoston.setMaxCarMoves(7);
RouteLocation rlChelmsford = rte2.addLocation(chelmsford);
rlChelmsford.setMaxCarMoves(2);
RouteLocation rlHarvard = rte2.addLocation(harvard);
rlHarvard.setMaxCarMoves(3);
// Create train, there are 3 blocks of cars in staging that were picked up by train 1
Train train2 = tmanager.newTrain("Westford Staging to Harvard");
train2.setRoute(rte2);
new TrainBuilder().build(train2);
Assert.assertEquals("Train should build", true, train2.isBuilt());
// car's last known location id doesn't change when building train
Assert.assertEquals("Car departed Harvard", harvard.getId(), c1.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c2.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c3.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c4.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c5.getLastLocationId());
Assert.assertEquals("Car departed Harvard", harvard.getId(), c6.getLastLocationId());
Assert.assertEquals("Car departed Boston", boston.getId(), c7.getLastLocationId());
Assert.assertEquals("Car departed Boston", boston.getId(), c8.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", chelmsford.getId(), c9.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", chelmsford.getId(), c10.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", chelmsford.getId(), c11.getLastLocationId());
// now check to see if cars were blocked to the right locations
Assert.assertEquals("Caboose must go to terminal", harvard, c1.getDestination());
// largest block 5 cars
Assert.assertEquals("Car departed Harvard destination Boston", boston, c2.getDestination());
Assert.assertEquals("Car departed Harvard destination Boston", boston, c3.getDestination());
Assert.assertEquals("Car departed Harvard destination Boston", boston, c4.getDestination());
Assert.assertEquals("Car departed Harvard destination Boston", boston, c5.getDestination());
Assert.assertEquals("Car departed Harvard destination Boston", boston, c6.getDestination());
// smallest block, 2 cars
Assert.assertEquals("Car departed Boston destination Harvard", harvard, c7.getDestination());
Assert.assertEquals("Car departed Boston destination Harvard", harvard, c8.getDestination());
// middle block, 3 cars
Assert.assertEquals("Car departed Chelmsford destination Arlington", arlington, c9.getDestination());
Assert.assertEquals("Car departed Chelmsford destination Arlington", arlington, c10.getDestination());
Assert.assertEquals("Car departed Chelmsford destination Arlington", arlington, c11.getDestination());
// now try the case where the largest block is greater than any requested moves for a location
rlBoston.setMaxCarMoves(4);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train should build", true, train2.isBuilt());
// now check to see if cars were blocked to the right locations
Assert.assertEquals("Caboose must go to terminal", harvard, c1.getDestination());
// largest block 5 cars was broken up since they all couldn't go to the same location
Assert.assertEquals("Car departed Harvard", harvard, c2.getDestination());
Assert.assertEquals("Car departed Harvard", chelmsford, c3.getDestination());
Assert.assertEquals("Car departed Harvard", arlington, c4.getDestination());
Assert.assertEquals("Car departed Harvard", chelmsford, c5.getDestination());
Assert.assertEquals("Car departed Harvard", harvard, c6.getDestination());
// smallest block, 2 cars
Assert.assertEquals("Car departed Boston destination Arlington", arlington, c7.getDestination());
Assert.assertEquals("Car departed Boston destination Arlington", arlington, c8.getDestination());
// middle block, now the largest that can move as a group, 3 cars
Assert.assertEquals("Car departed Chelmsford destination Boston", boston, c9.getDestination());
Assert.assertEquals("Car departed Chelmsford destination Boston", boston, c10.getDestination());
Assert.assertEquals("Car departed Chelmsford destination Boston", boston, c11.getDestination());
// now check car last destination out of staging
train2.terminate();
Assert.assertEquals("Car departed Harvard", westford.getId(), c1.getLastLocationId());
Assert.assertEquals("Car departed Harvard", westford.getId(), c2.getLastLocationId());
Assert.assertEquals("Car departed Harvard", westford.getId(), c3.getLastLocationId());
Assert.assertEquals("Car departed Harvard", westford.getId(), c4.getLastLocationId());
Assert.assertEquals("Car departed Harvard", westford.getId(), c5.getLastLocationId());
Assert.assertEquals("Car departed Harvard", westford.getId(), c6.getLastLocationId());
Assert.assertEquals("Car departed Boston", westford.getId(), c7.getLastLocationId());
Assert.assertEquals("Car departed Boston", westford.getId(), c8.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", westford.getId(), c9.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", westford.getId(), c10.getLastLocationId());
Assert.assertEquals("Car departed Chelmsford", westford.getId(), c11.getLastLocationId());
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilderTest method testAutoEnginesBuildFailNoEngines.
public void testAutoEnginesBuildFailNoEngines() {
// This test uses the maximum length of a train in route
Setup.setMaxTrainLength(1000);
Train train = tmanager.newTrain("TestAutoEnginesBuildFailNoEngines");
train.setNumberEngines(Train.AUTO);
Route route = rmanager.newRoute("AutoEngineTest");
train.setRoute(route);
Location A = lmanager.newLocation("A");
Location B = lmanager.newLocation("B");
Location C = lmanager.newLocation("C");
Track At = A.addTrack("track", Track.SPUR);
Track Bt = B.addTrack("track", Track.SPUR);
Track Ct = C.addTrack("track", Track.SPUR);
At.setLength(300);
Bt.setLength(300);
Ct.setLength(300);
RouteLocation rA = route.addLocation(A);
RouteLocation rB = route.addLocation(B);
RouteLocation rC = route.addLocation(C);
rA.setMaxCarMoves(5);
rB.setMaxCarMoves(5);
rC.setMaxCarMoves(5);
// Auto Engines calculates the number of engines based on requested moves in the route
train.reset();
new TrainBuilder().build(train);
Assert.assertFalse("Train should not build, no engines", train.isBuilt());
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilderTest method testStagingtoStaging.
// testStagingtoStaging tests the build procedure
// through the train's build method.
// test train staging to staging
public void testStagingtoStaging() {
Setup.setSwitchTime(11);
Setup.setTravelTime(111);
// register the car and engine types used
ct.addName("Boxcar");
ct.addName("Caboose");
ct.addName("Flat");
et.addName("Diesel");
// Set up four engines in two consists
Consist con1 = emanager.newConsist("C16");
Consist con2 = emanager.newConsist("C14");
Engine e1 = new Engine("PC", "5016");
e1.setModel("GP40");
e1.setConsist(con1);
e1.setMoves(123);
e1.setOwner("AT");
e1.setBuilt("1990");
Assert.assertEquals("Engine 1 Length", "59", e1.getLength());
emanager.register(e1);
Engine e2 = new Engine("PC", "5019");
e2.setModel("GP40");
e2.setConsist(con1);
e2.setMoves(321);
e2.setOwner("AT");
e2.setBuilt("1990");
Assert.assertEquals("Engine 2 Length", "59", e2.getLength());
emanager.register(e2);
Engine e3 = new Engine("PC", "5524");
e3.setModel("SD45");
e3.setConsist(con2);
e3.setOwner("DAB");
e3.setBuilt("1980");
Assert.assertEquals("Engine 3 Length", "66", e3.getLength());
emanager.register(e3);
Engine e4 = new Engine("PC", "5559");
e4.setModel("SD45");
e4.setConsist(con2);
e4.setOwner("DAB");
e4.setBuilt("1980");
Assert.assertEquals("Engine 4 Length", "66", e4.getLength());
emanager.register(e4);
// Set up two cabooses and six box cars
Car c1 = new Car("CP", "C10099");
c1.setTypeName("Caboose");
c1.setLength("32");
c1.setMoves(23);
c1.setOwner("AT");
c1.setBuilt("1980");
c1.setCaboose(true);
Assert.assertEquals("Caboose 1 Length", "32", c1.getLength());
cmanager.register(c1);
Car c2 = new Car("CP", "C20099");
c2.setTypeName("Caboose");
c2.setLength("32");
c2.setMoves(54);
c2.setOwner("DAB");
c2.setBuilt("1984");
c2.setCaboose(true);
Assert.assertEquals("Caboose 2 Length", "32", c2.getLength());
cmanager.register(c2);
Car c3 = new Car("CP", "X10001");
c3.setTypeName("Boxcar");
c3.setLength("40");
c3.setOwner("DAB");
c3.setBuilt("1984");
Assert.assertEquals("Box Car X10001 Length", "40", c3.getLength());
cmanager.register(c3);
Car c4 = new Car("CP", "X10002");
c4.setTypeName("Boxcar");
c4.setLength("40");
c4.setOwner("AT");
c4.setBuilt("1-84");
c4.setMoves(4444);
Assert.assertEquals("Box Car X10002 Length", "40", c4.getLength());
cmanager.register(c4);
Car c5 = new Car("CP", "X20001");
c5.setTypeName("Boxcar");
c5.setLength("40");
c5.setOwner("DAB");
c5.setBuilt("1980");
Assert.assertEquals("Box Car X20001 Length", "40", c5.getLength());
cmanager.register(c5);
Car c6 = new Car("CP", "X20002");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setOwner("DAB");
c6.setBuilt("1978");
Assert.assertEquals("Box Car X20002 Length", "40", c6.getLength());
cmanager.register(c6);
Car c7 = new Car("CP", "777");
c7.setTypeName("Flat");
c7.setLength("50");
c7.setOwner("AT");
c7.setBuilt("1990");
c7.setMoves(6);
Assert.assertEquals("Box Car 777 Length", "50", c7.getLength());
cmanager.register(c7);
Car c8 = new Car("CP", "888");
c8.setTypeName("Boxcar");
c8.setLength("60");
c8.setOwner("DAB");
c8.setBuilt("1985");
Assert.assertEquals("Box Car 888 Length", "60", c8.getLength());
cmanager.register(c8);
Car c9 = new Car("CP", "99");
c9.setTypeName("Flat");
c9.setLength("90");
c9.setOwner("AT");
c9.setBuilt("6-80");
Assert.assertEquals("Box Car 888 Length", "90", c9.getLength());
cmanager.register(c9);
// do cars have the right default loads?
Assert.assertEquals("Car c1 load should be E", "E", c1.getLoadName());
Assert.assertEquals("Car c2 load should be E", "E", c2.getLoadName());
Assert.assertEquals("Car c3 load should be E", "E", c3.getLoadName());
Assert.assertEquals("Car c4 load should be E", "E", c4.getLoadName());
Assert.assertEquals("Car c5 load should be E", "E", c5.getLoadName());
Assert.assertEquals("Car c6 load should be E", "E", c6.getLoadName());
Assert.assertEquals("Car c7 load should be E", "E", c7.getLoadName());
Assert.assertEquals("Car c8 load should be E", "E", c8.getLoadName());
Assert.assertEquals("Car c9 load should be E", "E", c9.getLoadName());
// Set up a route of 3 locations: North End Staging (2 tracks),
// North Industries (1 track), and South End Staging (2 tracks).
Location l1 = new Location("1", "North End");
Assert.assertEquals("Location 1 Id", "1", l1.getId());
Assert.assertEquals("Location 1 Name", "North End", l1.getName());
Assert.assertEquals("Location 1 Initial Length", 0, l1.getLength());
l1.setLocationOps(Location.STAGING);
l1.setTrainDirections(DIRECTION_ALL);
l1.setSwitchListEnabled(true);
lmanager.register(l1);
Track l1s1 = new Track("1s1", "North End 1", Track.STAGING, l1);
l1s1.setLength(300);
Assert.assertEquals("Location 1s1 Id", "1s1", l1s1.getId());
Assert.assertEquals("Location 1s1 Name", "North End 1", l1s1.getName());
Assert.assertEquals("Location 1s1 LocType", "Staging", l1s1.getTrackType());
Assert.assertEquals("Location 1s1 Length", 300, l1s1.getLength());
l1s1.setTrainDirections(DIRECTION_ALL);
l1s1.setRoadOption(Track.ALL_ROADS);
l1s1.setDropOption(Track.ANY);
l1s1.setPickupOption(Track.ANY);
Track l1s2 = new Track("1s2", "North End 2", Track.STAGING, l1);
l1s2.setLength(400);
Assert.assertEquals("Location 1s2 Id", "1s2", l1s2.getId());
Assert.assertEquals("Location 1s2 Name", "North End 2", l1s2.getName());
Assert.assertEquals("Location 1s2 LocType", "Staging", l1s2.getTrackType());
Assert.assertEquals("Location 1s2 Length", 400, l1s2.getLength());
l1s2.setTrainDirections(DIRECTION_ALL);
l1s2.setRoadOption(Track.ALL_ROADS);
l1s2.setDropOption(Track.ANY);
l1s2.setPickupOption(Track.ANY);
l1.addTrack("North End 1", Track.STAGING);
l1.addTrack("North End 2", Track.STAGING);
List<Track> templist1 = l1.getTrackByNameList(null);
for (int i = 0; i < templist1.size(); i++) {
if (i == 0) {
Assert.assertEquals("RL 1 Staging 1 Name", "North End 1", templist1.get(i).getName());
}
if (i == 1) {
Assert.assertEquals("RL 1 Staging 2 Name", "North End 2", templist1.get(i).getName());
}
}
l1.register(l1s1);
l1.register(l1s2);
Assert.assertEquals("Location 1 Length", 700, l1.getLength());
Location l2 = new Location("2", "North Industries");
Assert.assertEquals("Location 2 Id", "2", l2.getId());
Assert.assertEquals("Location 2 Name", "North Industries", l2.getName());
l2.setLocationOps(Location.NORMAL);
l2.setTrainDirections(DIRECTION_ALL);
l2.setSwitchListEnabled(true);
lmanager.register(l2);
Track l2s1 = new Track("2s1", "NI Yard", Track.YARD, l2);
l2s1.setLength(432);
Assert.assertEquals("Location 2s1 Id", "2s1", l2s1.getId());
Assert.assertEquals("Location 2s1 Name", "NI Yard", l2s1.getName());
Assert.assertEquals("Location 2s1 LocType", Track.YARD, l2s1.getTrackType());
Assert.assertEquals("Location 2s1 Length", 432, l2s1.getLength());
l2s1.setTrainDirections(DIRECTION_ALL);
l2.register(l2s1);
Assert.assertEquals("Location 2 Length", 432, l2.getLength());
Location l3 = new Location("3", "South End");
Assert.assertEquals("Location 3 Id", "3", l3.getId());
Assert.assertEquals("Location 3 Name", "South End", l3.getName());
Assert.assertEquals("Location 3 Initial Length", 0, l3.getLength());
l3.setLocationOps(Location.STAGING);
l3.setTrainDirections(DIRECTION_ALL);
l3.setSwitchListEnabled(true);
lmanager.register(l3);
Track l3s1 = new Track("3s1", "South End 1", Track.STAGING, l3);
l3s1.setLength(300);
Assert.assertEquals("Location 3s1 Id", "3s1", l3s1.getId());
Assert.assertEquals("Location 3s1 Name", "South End 1", l3s1.getName());
Assert.assertEquals("Location 3s1 LocType", "Staging", l3s1.getTrackType());
Assert.assertEquals("Location 3s1 Length", 300, l3s1.getLength());
l3s1.setTrainDirections(DIRECTION_ALL);
l3s1.setRoadOption(Track.ALL_ROADS);
l3s1.setDropOption(Track.ANY);
l3s1.setPickupOption(Track.ANY);
Track l3s2 = new Track("3s2", "South End 2", Track.STAGING, l3);
l3s2.setLength(401);
Assert.assertEquals("Location 3s2 Id", "3s2", l3s2.getId());
Assert.assertEquals("Location 3s2 Name", "South End 2", l3s2.getName());
Assert.assertEquals("Location 3s2 LocType", "Staging", l3s2.getTrackType());
Assert.assertEquals("Location 3s2 Length", 401, l3s2.getLength());
l3s2.setTrainDirections(DIRECTION_ALL);
l3s2.setRoadOption(Track.ALL_ROADS);
l3s2.setDropOption(Track.ANY);
l3s2.setPickupOption(Track.ANY);
l3.addTrack("South End 1", Track.STAGING);
l3.addTrack("South End 2", Track.STAGING);
List<Track> templist3 = l3.getTrackByNameList(null);
for (int i = 0; i < templist3.size(); i++) {
if (i == 0) {
Assert.assertEquals("RL 3 Staging 1 Name", "South End 1", templist3.get(i).getName());
}
if (i == 1) {
Assert.assertEquals("RL 3 Staging 2 Name", "South End 2", templist3.get(i).getName());
}
}
l3.register(l3s1);
l3.register(l3s2);
Assert.assertEquals("Location 3 Length", 701, l3.getLength());
// Place 4 Boxcars on Staging tracks
Assert.assertTrue("l1 Accepts Boxcar", l1.acceptsTypeName("Boxcar"));
Assert.assertTrue("l1s1 Accepts Boxcar", l1s1.acceptsTypeName("Boxcar"));
Assert.assertEquals("Location 1s1 Init Used Length", 0, l1s1.getUsedLength());
Assert.assertEquals("Location 1s2 Init Used Length", 0, l1s2.getUsedLength());
Assert.assertEquals("Location 1 Init Used Length", 0, l1s1.getUsedLength());
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(l1, l1s1));
Assert.assertEquals("Location 1s1 c3 Used Length", 44, l1s1.getUsedLength());
Assert.assertEquals("Location 1 c3 Used Length", 44, l1.getUsedLength());
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(l1, l1s1));
Assert.assertEquals("Location 1s1 c4 Used Length", 88, l1s1.getUsedLength());
Assert.assertEquals("Location 1 c4 Used Length", 88, l1.getUsedLength());
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(l1, l1s2));
Assert.assertEquals("Location 1s2 c5 Used Length", 44, l1s2.getUsedLength());
Assert.assertEquals("Location 1 c5 Used Length", 132, l1.getUsedLength());
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(l1, l1s2));
Assert.assertEquals("Location 1s2 c6 Used Length", 88, l1s2.getUsedLength());
Assert.assertEquals("Location 1 c6 Used Length", 176, l1.getUsedLength());
// Place 2 Boxcars and Flat in yard
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l2, l2s1));
Assert.assertEquals("Location 2s1 c7 Used Length", 54, l2s1.getUsedLength());
Assert.assertEquals("Location 2 c7 Used Length", 54, l2.getUsedLength());
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l2, l2s1));
Assert.assertEquals("Location 2s1 c4 Used Length", 118, l2s1.getUsedLength());
Assert.assertEquals("Location 2 c4 Used Length", 118, l2.getUsedLength());
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(l2, l2s1));
Assert.assertEquals("Location 2s1 c9 Used Length", 212, l2s1.getUsedLength());
Assert.assertEquals("Location 2 c9 Used Length", 212, l2.getUsedLength());
// Place Cabooses on Staging tracks
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(l1, l1s1));
Assert.assertEquals("Location 1s1 c1 Used Length", 124, l1s1.getUsedLength());
Assert.assertEquals("Location 1 c1 Used Length", 212, l1.getUsedLength());
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(l1, l1s2));
Assert.assertEquals("Location 1s2 c2 Used Length", 124, l1s2.getUsedLength());
Assert.assertEquals("Location 1 c2 Used Length", 248, l1.getUsedLength());
// Define the route.
Route route1 = new Route("1", "Southbound Main Route");
Assert.assertEquals("Route Id", "1", route1.getId());
Assert.assertEquals("Route Name", "Southbound Main Route", route1.getName());
RouteLocation rl1 = new RouteLocation("1r1", l1);
rl1.setSequenceId(1);
rl1.setTrainDirection(RouteLocation.SOUTH);
rl1.setMaxCarMoves(5);
rl1.setMaxTrainLength(1000);
// set the train icon coordinates
rl1.setTrainIconX(25);
rl1.setTrainIconY(25);
Assert.assertEquals("Route Location 1 Id", "1r1", rl1.getId());
Assert.assertEquals("Route Location 1 Name", "North End", rl1.getName());
RouteLocation rl2 = new RouteLocation("1r2", l2);
rl2.setSequenceId(2);
rl2.setTrainDirection(RouteLocation.SOUTH);
// test for only 1 pickup and 1 drop
rl2.setMaxCarMoves(2);
rl2.setMaxTrainLength(1000);
// set the train icon coordinates
rl2.setTrainIconX(75);
rl2.setTrainIconY(25);
Assert.assertEquals("Route Location 2 Id", "1r2", rl2.getId());
Assert.assertEquals("Route Location 2 Name", "North Industries", rl2.getName());
RouteLocation rl3 = new RouteLocation("1r3", l3);
rl3.setSequenceId(3);
rl3.setTrainDirection(RouteLocation.SOUTH);
rl3.setMaxCarMoves(5);
rl3.setMaxTrainLength(1000);
// set the train icon coordinates
rl3.setTrainIconX(125);
rl3.setTrainIconY(25);
Assert.assertEquals("Route Location 3 Id", "1r3", rl3.getId());
Assert.assertEquals("Route Location 3 Name", "South End", rl3.getName());
route1.register(rl1);
route1.register(rl2);
route1.register(rl3);
rmanager.register(route1);
// Finally ready to define the trains.
Train train1 = new Train("1", "STF");
Assert.assertEquals("Train Id", "1", train1.getId());
Assert.assertEquals("Train Name", "STF", train1.getName());
train1.setRequirements(Train.CABOOSE);
train1.setCabooseRoad("CP");
train1.deleteTypeName("Flat");
train1.setRoadOption(Train.ALL_ROADS);
train1.setRoute(route1);
train1.setDepartureTime("6", "5");
tmanager.register(train1);
Train train2 = new Train("2", "SFF");
Assert.assertEquals("Train Id", "2", train2.getId());
Assert.assertEquals("Train Name", "SFF", train2.getName());
// there are boxcars waiting in staging so build should fail
train2.deleteTypeName("Boxcar");
train2.deleteTypeName("Flat");
train2.setRoute(route1);
train2.setDepartureTime("22", "45");
tmanager.register(train2);
// Last minute checks.
Assert.assertEquals("Train 1 Departs Name", "North End", train1.getTrainDepartsName());
Assert.assertEquals("Train 1 Route Departs Name", "North End", train1.getTrainDepartsRouteLocation().getName());
Assert.assertEquals("Train 1 Terminates Name", "South End", train1.getTrainTerminatesName());
Assert.assertEquals("Train 1 Route Terminates Name", "South End", train1.getTrainTerminatesRouteLocation().getName());
Assert.assertEquals("Train 1 Next Location Name", "", train1.getNextLocationName());
Assert.assertEquals("Train 1 Route Name", "Southbound Main Route", train1.getRoute().getName());
Assert.assertEquals("Train 2 Departs Name", "North End", train2.getTrainDepartsName());
Assert.assertEquals("Train 2 Route Departs Name", "North End", train2.getTrainDepartsRouteLocation().getName());
Assert.assertEquals("Train 2 Terminates Name", "South End", train2.getTrainTerminatesName());
Assert.assertEquals("Train 2 Route Terminates Name", "South End", train2.getTrainTerminatesRouteLocation().getName());
Assert.assertEquals("Train 2 Next Location Name", "", train2.getNextLocationName());
Assert.assertEquals("Train 2 Route Name", "Southbound Main Route", train2.getRoute().getName());
// Try building without engines
train1.reset();
new TrainBuilder().build(train1);
train2.reset();
new TrainBuilder().build(train2);
// Only train 1 should build
Assert.assertEquals("Train 1 After 1st Build without engines", true, train1.isBuilt());
Assert.assertEquals("Train 2 After 1st Build exclude Boxcar", false, train2.isBuilt());
// now allow train 2 to service Boxcars
train2.addTypeName("Boxcar");
// Try again, but exclude road name CP
train2.setRoadOption(Train.EXCLUDE_ROADS);
train2.addRoadName("CP");
Assert.assertEquals("Number of road names for train", 1, train2.getRoadNames().length);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build but exclude road CP", false, train2.isBuilt());
train2.setRoadOption(Train.ALL_ROADS);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build include Boxcar", true, train2.isBuilt());
// check train 1
Assert.assertEquals("Car c1 After Build without engines should be assigned to Train 1", train1, c1.getTrain());
Assert.assertEquals("Car c3 After Build without engines should be assigned to Train 1", train1, c3.getTrain());
Assert.assertEquals("Car c4 After Build without engines should be assigned to Train 1", train1, c4.getTrain());
Assert.assertEquals("Car c8 After Build without engines should be assigned to Train 1", train1, c8.getTrain());
// car destinations correct?
Assert.assertEquals("Car c1 After Build without engines destination", "South End", c1.getDestinationName());
Assert.assertEquals("Car c3 After Build without engines destination", "North Industries", c3.getDestinationName());
Assert.assertEquals("Car c4 After Build without engines destination", "South End", c4.getDestinationName());
Assert.assertEquals("Car c8 After Build without engines destination", "South End", c8.getDestinationName());
// car destination track correct?
Assert.assertEquals("Car c1 After without engines Build track", "South End 1", c1.getDestinationTrackName());
Assert.assertEquals("Car c3 After without engines Build track", "NI Yard", c3.getDestinationTrackName());
Assert.assertEquals("Car c4 After without engines Build track", "South End 1", c4.getDestinationTrackName());
Assert.assertEquals("Car c8 After without engines Build track", "South End 1", c8.getDestinationTrackName());
// Try again building without engines on staging tracks but require them
train1.setEngineRoad("PC");
train1.setEngineModel("GP40");
train1.setNumberEngines("2");
train2.setNumberEngines("2");
train1.reset();
new TrainBuilder().build(train1);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 1 After 2nd Build without engines", false, train1.isBuilt());
Assert.assertEquals("Train 2 After 2nd Build without engines", false, train2.isBuilt());
// Place Engines on Staging tracks
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
Assert.assertEquals("Location 1s1 e1 Used Length", 187, l1s1.getUsedLength());
Assert.assertEquals("Location 1 e1 Used Length", 311, l1.getUsedLength());
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(l1, l1s1));
Assert.assertEquals("Location 1s1 e2 Used Length", 250, l1s1.getUsedLength());
Assert.assertEquals("Location 1 e2 Used Length", 374, l1.getUsedLength());
Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(l1, l1s2));
Assert.assertEquals("Location 1s2 e3 Used Length", 194, l1s2.getUsedLength());
Assert.assertEquals("Location 1 e3 Used Length", 444, l1.getUsedLength());
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(l1, l1s2));
Assert.assertEquals("Location 1s2 e4 Used Length", 264, l1s2.getUsedLength());
Assert.assertEquals("Location 1 e4 Used Length", 514, l1.getUsedLength());
// Build the trains with engines
train1.reset();
new TrainBuilder().build(train1);
train2.reset();
new TrainBuilder().build(train2);
// Both should build
Assert.assertEquals("Train 1 After Build with engines", true, train1.isBuilt());
Assert.assertEquals("Train 2 After Build with engines", true, train2.isBuilt());
// Check train 1
Assert.assertEquals("Train 1 After Build Departs Name", "North End", train1.getTrainDepartsName());
Assert.assertEquals("Train 1 After Build Terminates Name", "South End", train1.getTrainTerminatesName());
Assert.assertEquals("Train 1 After Build Next Location Name", "North Industries", train1.getNextLocationName());
Assert.assertEquals("Train 1 After Build Built Status", true, train1.isBuilt());
// Are the proper engines and cars assigned to train 1?
Assert.assertEquals("Engine e1 After Build should be assigned to Train 1", train1, e1.getTrain());
Assert.assertEquals("Engine e2 After Build should be assigned to Train 1", train1, e2.getTrain());
Assert.assertEquals("Car c1 After Build should be assigned to Train 1", train1, c1.getTrain());
Assert.assertEquals("Car c3 After Build should be assigned to Train 1", train1, c3.getTrain());
Assert.assertEquals("Car c4 After Build should be assigned to Train 1", train1, c4.getTrain());
Assert.assertEquals("Car c8 After Build should be assigned to Train 1", train1, c8.getTrain());
// Are the proper engines and cars assigned to train 2?
Assert.assertEquals("Engine e3 After Build should be assigned to Train 2", train2, e3.getTrain());
Assert.assertEquals("Engine e4 After Build should be assigned to Train 2", train2, e4.getTrain());
Assert.assertEquals("Car c2 After Build should be assigned to Train 2", train2, c2.getTrain());
Assert.assertEquals("Car c5 After Build should be assigned to Train 2", train2, c5.getTrain());
Assert.assertEquals("Car c7 After Build should be not be assigned", null, c7.getTrain());
Assert.assertEquals("Car c9 After Build should be not be assigned", null, c9.getTrain());
// Are the engine and car destinations correct?
Assert.assertEquals("Engine e1 After Build destination", "South End", e1.getDestinationName());
Assert.assertEquals("Engine e2 After Build destination", "South End", e2.getDestinationName());
Assert.assertEquals("Car c1 After Build destination", "South End", c1.getDestinationName());
Assert.assertEquals("Car c3 After Build destination", "North Industries", c3.getDestinationName());
Assert.assertEquals("Car c4 After Build destination", "South End", c4.getDestinationName());
Assert.assertEquals("Car c8 After Build destination", "South End", c8.getDestinationName());
// Are the engine and car destination track correct?
Assert.assertEquals("Engine e1 After Build track", "South End 2", e1.getDestinationTrackName());
Assert.assertEquals("Engine e2 After Build track", "South End 2", e2.getDestinationTrackName());
Assert.assertEquals("Car c1 After Build track", "South End 2", c1.getDestinationTrackName());
Assert.assertEquals("Car c3 After Build track", "NI Yard", c3.getDestinationTrackName());
Assert.assertEquals("Car c4 After Build track", "South End 2", c4.getDestinationTrackName());
Assert.assertEquals("Car c8 After Build track", "South End 2", c8.getDestinationTrackName());
// Are the location pickup and drop counts correct?
Assert.assertEquals("Drop count for North End", 0, l1.getDropRS());
// Each train has one drop at North Industries
Assert.assertEquals("Drop count for North Industries", 2, l2.getDropRS());
// Train1 has 5 drops and Train2 has 4 drops for South End
Assert.assertEquals("Drop count for South End", 9, l3.getDropRS());
// Each train has 5 pickups
Assert.assertEquals("Pickup count for North End", 10, l1.getPickupRS());
Assert.assertEquals("Pickup count for North Industries", 1, l2.getPickupRS());
Assert.assertEquals("Pickup count for South End", 0, l3.getPickupRS());
// Are the track pickup and drop counts correct?
Assert.assertEquals("Drop count for North End, track North End 1", 0, l1s1.getDropRS());
Assert.assertEquals("Drop count for North End, track North End 2", 0, l1s2.getDropRS());
Assert.assertEquals("Pickup count for North End, track North End 1", 5, l1s1.getPickupRS());
Assert.assertEquals("Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
// Each train has one drop at NI Yard
Assert.assertEquals("Drop count for North Industries, track NI Yard", 2, l2s1.getDropRS());
Assert.assertEquals("Pickup count for North Industries, track NI Yard", 1, l2s1.getPickupRS());
Assert.assertEquals("Drop count for South End, track South End 1", 4, l3s1.getDropRS());
Assert.assertEquals("Drop count for South End, track South End 2", 5, l3s2.getDropRS());
Assert.assertEquals("Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
Assert.assertEquals("Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
// Are the other engines and cars assigned correctly?
Assert.assertEquals("Engine e3 After Build should NOT be assigned to Train 1", train2, e3.getTrain());
Assert.assertEquals("Engine e4 After Build should NOT be assigned to Train 1", train2, e4.getTrain());
Assert.assertEquals("Car c2 After Build should NOT be assigned to Train 1", train2, c2.getTrain());
Assert.assertEquals("Car c5 After Build should NOT be assigned to Train 1", train2, c5.getTrain());
Assert.assertEquals("Car c6 After Build should NOT be assigned to Train 1", train2, c6.getTrain());
Assert.assertEquals("Car c7 After Build should NOT be assigned to Train 1", null, c7.getTrain());
Assert.assertEquals("Car c9 After Build should NOT be assigned to Train 1", null, c9.getTrain());
// Check expected arrival times
Assert.assertEquals("Train 1 expected departure time", "06:05", train1.getExpectedArrivalTime(rl1));
// Check time for car moves and train travel times
Assert.assertEquals("Per Car move time", 11, Setup.getSwitchTime());
Assert.assertEquals("Train travel time", 111, Setup.getTravelTime());
Assert.assertEquals("Train 1 expected North End", "07:56", train1.getExpectedArrivalTime(rl2));
// one car dropped and one is picked up at North End, so travel time + two car moves
Assert.assertEquals("Train 1 expected North Industries", "10:09", train1.getExpectedArrivalTime(rl3));
// Reset the train!
Assert.assertEquals("Train 1 Reset should be true", true, train1.reset());
Assert.assertEquals("Train 1 After Reset Departs Name", "North End", train1.getTrainDepartsName());
Assert.assertEquals("Train 1 After Reset Terminates Name", "South End", train1.getTrainTerminatesName());
Assert.assertEquals("Train 1 After Reset Next Location Name", "", train1.getNextLocationName());
Assert.assertEquals("Train 1 After Reset Built Status", false, train1.isBuilt());
// Are the engines and cars released from train 1?
Assert.assertEquals("Engine e1 After Reset should NOT be assigned to Train 1", null, e1.getTrain());
Assert.assertEquals("Engine e2 After Reset should NOT be assigned to Train 1", null, e2.getTrain());
Assert.assertEquals("Car c1 After Reset should NOT be assigned to Train 1", null, c1.getTrain());
Assert.assertEquals("Car c3 After Reset should NOT be assigned to Train 1", null, c3.getTrain());
Assert.assertEquals("Car c4 After Reset should NOT be assigned to Train 1", null, c4.getTrain());
Assert.assertEquals("Car c8 After Reset should NOT be assigned to Train 1", null, c8.getTrain());
// Are the location pickup and drop counts correct?
Assert.assertEquals("Reset Drop count for North End", 0, l1.getDropRS());
Assert.assertEquals("Reset Drop count for North Industries", 1, l2.getDropRS());
Assert.assertEquals("Reset Drop count for South End", 4, l3.getDropRS());
Assert.assertEquals("Reset Pickup count for North End", 5, l1.getPickupRS());
Assert.assertEquals("Reset Pickup count for North Industries", 0, l2.getPickupRS());
Assert.assertEquals("Reset Pickup count for South End", 0, l3.getPickupRS());
// Are the track pickup and drop counts correct?
Assert.assertEquals("Reset Drop count for North End, track North End 1", 0, l1s1.getDropRS());
Assert.assertEquals("Reset Drop count for North End, track North End 2", 0, l1s2.getDropRS());
Assert.assertEquals("Reset Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
Assert.assertEquals("Reset Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
Assert.assertEquals("Reset Drop count for North Industries, track NI Yard", 1, l2s1.getDropRS());
Assert.assertEquals("Reset Pickup count for North Industries, track NI Yard", 1, l2s1.getDropRS());
Assert.assertEquals("Reset Drop count for South End, track South End 1", 4, l3s1.getDropRS());
Assert.assertEquals("Reset Drop count for South End, track South End 2", 0, l3s2.getDropRS());
Assert.assertEquals("Reset Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
Assert.assertEquals("Reset Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
// Try again, but exclude caboose
// there are cabooses waiting in staging so build should fail
train1.deleteTypeName("Caboose");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build with engines but exclude Caboose", false, train1.isBuilt());
train1.addTypeName("Caboose");
// Try again, but exclude road name CP
train1.setRoadOption(Train.EXCLUDE_ROADS);
train1.addRoadName("CP");
Assert.assertEquals("Number of road names for train", 1, train1.getRoadNames().length);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build with engines but exclude road CP", false, train1.isBuilt());
train1.setRoadOption(Train.ALL_ROADS);
// try again, but set the caboose destination to NI yard
c1.setDestination(l2, null);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 build should fail, caboose destination isn't terminal", false, train1.isBuilt());
// send caboose to last location which is staging
c1.setDestination(l3, null);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 build, caboose destination is terminal", true, train1.isBuilt());
// don't allow cabooses road
l3.deleteTypeName("Caboose");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 build, caboose destination is terminal", false, train1.isBuilt());
l3.addTypeName("Caboose");
// Try again, but only allow rolling stock built before 1985
train2.reset();
train1.setBuiltEndYear("1985");
train1.reset();
new TrainBuilder().build(train1);
// should fail, required engines have built dates after 1985
Assert.assertEquals("Train 1 After Build with rs built before 1985", false, train1.isBuilt());
// change the engine built date
e1.setBuilt("7-84");
e2.setBuilt("1984");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 2nd Build with rs built before 1985", true, train1.isBuilt());
// change one of the car's built date to after 1985
c4.setBuilt("1-85");
train1.reset();
new TrainBuilder().build(train1);
// should fail
Assert.assertEquals("Train 1 After 3rd Build with rs built before 1985", false, train1.isBuilt());
train1.setBuiltEndYear("");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 4th Build with rs built before 1985", true, train1.isBuilt());
// Try again, but now exclude engine type Diesel
train1.deleteTypeName("Diesel");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 1st Build type Diesel not serviced", false, train1.isBuilt());
train1.addTypeName("Diesel");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 2nd Build type Diesel serviced", true, train1.isBuilt());
// Try again, but now restrict owner
train1.addOwnerName("DAB");
train1.setOwnerOption(Train.INCLUDE_OWNERS);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 1st Build owner DAB", false, train1.isBuilt());
train1.addOwnerName("AT");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 2nd Build owners DAB and AT", true, train1.isBuilt());
train1.setOwnerOption(Train.EXCLUDE_OWNERS);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 3rd Build exclude owners DAB and AT", false, train1.isBuilt());
train1.deleteOwnerName("AT");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 4th Build exclude owner DAB", false, train1.isBuilt());
train1.setOwnerOption(Train.ALL_OWNERS);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 5th Build all owners", true, train1.isBuilt());
// Try again, but now restrict load
train1.addLoadName("L");
train1.setLoadOption(Train.INCLUDE_LOADS);
train1.reset();
new TrainBuilder().build(train1);
// build should fail, cars in staging have E loads
Assert.assertEquals("Train 1 After include load L", false, train1.isBuilt());
train1.deleteLoadName("L");
// this car shouldn't be picked up.
c8.setLoadName("L");
train1.addLoadName("E");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After include load E", true, train1.isBuilt());
Assert.assertEquals("car C10099 in staging should be assigned to train", train1, c1.getTrain());
Assert.assertEquals("car X1001 in staging should be assigned to train", train1, c3.getTrain());
Assert.assertEquals("car X1002 in staging should be assigned to train", train1, c4.getTrain());
Assert.assertEquals("car 888 at siding has load L, excluded", null, c8.getTrain());
train1.addLoadName("L");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After include load L", true, train1.isBuilt());
Assert.assertEquals("car C10099 in staging should be assigned to train", train1, c1.getTrain());
Assert.assertEquals("car X1001 in staging should be assigned to train", train1, c3.getTrain());
Assert.assertEquals("car X1002 in staging should be assigned to train", train1, c4.getTrain());
Assert.assertEquals("car 888 at siding has load L, now included", train1, c8.getTrain());
train1.setLoadOption(Train.EXCLUDE_LOADS);
// cars in staging have E loads, so build should fail
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After exclude loads", false, train1.isBuilt());
// allow train to carry E loads
train1.deleteLoadName("E");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After exclude loads L", true, train1.isBuilt());
Assert.assertEquals("car C10099 in staging should be assigned to train", train1, c1.getTrain());
Assert.assertEquals("car X1001 in staging should be assigned to train", train1, c3.getTrain());
Assert.assertEquals("car X1002 in staging should be assigned to train", train1, c4.getTrain());
Assert.assertEquals("car 888 at siding has load L, now excluded", null, c8.getTrain());
// done
train1.setLoadOption(Train.ALL_LOADS);
// Try again, but now set staging track service direction NORTH, train departs to the south
l1s1.setTrainDirections(Location.NORTH);
l1s2.setTrainDirections(Location.NORTH);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 1st Build staging set to North", false, train1.isBuilt());
l1s1.setTrainDirections(Location.SOUTH);
l1s2.setTrainDirections(Location.SOUTH);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After 2nd Build staging set to South", true, train1.isBuilt());
// need to reset train to release cars
train1.reset();
// Try again, but now have a car with a destination not serviced by train
Location nowhere = lmanager.newLocation("nowhere");
c4.setDestination(nowhere, null);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build car to nowhere", false, train1.isBuilt());
c4.setDestination(null, null);
// Build the trains again!!
train1.reset();
new TrainBuilder().build(train1);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 1 After Build with engines include all roads", true, train1.isBuilt());
Assert.assertEquals("Train 1 After Build Departs Name", "North End", train1.getTrainDepartsName());
Assert.assertEquals("Train 1 After Build Terminates Name", "South End", train1.getTrainTerminatesName());
Assert.assertEquals("Train 1 After Build Next Location Name", "North Industries", train1.getNextLocationName());
// now trying limiting the number of cars that can depart staging
// there are three cars in staging
rl1.setMaxCarMoves(2);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build limit train to 2 cars out of staging", false, train1.isBuilt());
// try again but now the train can have three cars departing staging
// there are three cars in staging
rl1.setMaxCarMoves(3);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build limit train to 3 cars out of staging", true, train1.isBuilt());
// Move the train #1
train1.move();
Assert.assertEquals("Train 1 After 1st Move Current Name", "North Industries", train1.getCurrentLocationName());
Assert.assertEquals("Train 1 After 1st Move Next Location Name", "South End", train1.getNextLocationName());
// Is the train in route?
Assert.assertEquals("Train 1 in route after 1st", true, train1.isTrainEnRoute());
// Try and reset the train
Assert.assertEquals("Train 1 Reset should be false", false, train1.reset());
// Are the engine and car locations correct?
Assert.assertEquals("Engine e1 After After 1st Move", "North Industries", e1.getLocationName());
Assert.assertEquals("Engine e2 After After 1st Move", "North Industries", e2.getLocationName());
Assert.assertEquals("Car c1 After After 1st Move", "North Industries", c1.getLocationName());
Assert.assertEquals("Car c3 After After 1st Move", "North Industries", c3.getLocationName());
Assert.assertEquals("Car c4 After After 1st Move", "North Industries", c4.getLocationName());
Assert.assertEquals("Car c8 After After 1st Move", "North Industries", c8.getLocationName());
// Are the location pickup and drop counts correct?
Assert.assertEquals("Move 1 Drop count for North End", 0, l1.getDropRS());
Assert.assertEquals("Move 1 Drop count for North Industries", 2, l2.getDropRS());
Assert.assertEquals("Move 1 Drop count for South End", 9, l3.getDropRS());
Assert.assertEquals("Move 1 Pickup count for North End", 5, l1.getPickupRS());
Assert.assertEquals("Move 1 Pickup count for North Industries", 1, l2.getPickupRS());
Assert.assertEquals("Move 1 Pickup count for South End", 0, l3.getPickupRS());
// Are the track pickup and drop counts correct?
Assert.assertEquals("Move 1 Drop count for North End, track North End 1", 0, l1s1.getDropRS());
Assert.assertEquals("Move 1 Drop count for North End, track North End 2", 0, l1s2.getDropRS());
Assert.assertEquals("Move 1 Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
Assert.assertEquals("Move 1 Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
Assert.assertEquals("Move 1 Drop count for North Industries, track NI Yard", 2, l2s1.getDropRS());
Assert.assertEquals("Move 1 Pickup count for North Industries, track NI Yard", 1, l2s1.getPickupRS());
Assert.assertEquals("Move 1 Drop count for South End, track South End 1", 4, l3s1.getDropRS());
Assert.assertEquals("Move 1 Drop count for South End, track South End 2", 5, l3s2.getDropRS());
Assert.assertEquals("Move 1 Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
Assert.assertEquals("Move 1 Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
// Move the train #2
train1.move();
Assert.assertEquals("Train 1 After 2nd Move Current Name", "South End", train1.getCurrentLocationName());
Assert.assertEquals("Train 1 After 2nd Move Next Location Name", "", train1.getNextLocationName());
// Is the train in route?
Assert.assertEquals("Train 1 in route after 2nd", true, train1.isTrainEnRoute());
// Are the engine and car locations correct?
Assert.assertEquals("Engine e1 After After 2nd Move", "South End", e1.getLocationName());
Assert.assertEquals("Engine e2 After After 2nd Move", "South End", e2.getLocationName());
Assert.assertEquals("Car c1 After After 2nd Move", "South End", c1.getLocationName());
Assert.assertEquals("Car c3 After After 2nd Move", "North Industries", c3.getLocationName());
Assert.assertEquals("Car c4 After After 2nd Move", "South End", c4.getLocationName());
Assert.assertEquals("Car c8 After After 2nd Move", "South End", c8.getLocationName());
// was c3 released from train?
Assert.assertEquals("Car c3 After drop should NOT be assigned to Train 1", null, c3.getTrain());
Assert.assertEquals("Car c3 destination After 2nd Move", "", c3.getDestinationTrackName());
Assert.assertEquals("Car c3 After 2nd Move location", "North Industries", c3.getLocationName());
Assert.assertEquals("Car c3 After 2nd Move", "NI Yard", c3.getTrackName());
Assert.assertEquals("Car c3 Moves after drop should be 14", 14, c3.getMoves());
// Are the location pickup and drop counts correct?
Assert.assertEquals("Move 2 Drop count for North End", 0, l1.getDropRS());
Assert.assertEquals("Move 2 Drop count for North Industries", 1, l2.getDropRS());
Assert.assertEquals("Move 2 Drop count for South End", 9, l3.getDropRS());
Assert.assertEquals("Move 2 Pickup count for North End", 5, l1.getPickupRS());
Assert.assertEquals("Move 2 Pickup count for North Industries", 0, l2.getPickupRS());
Assert.assertEquals("Move 2 Pickup count for South End", 0, l3.getPickupRS());
// Are the track pickup and drop counts correct?
Assert.assertEquals("Move 2 Drop count for North End, track North End 1", 0, l1s1.getDropRS());
Assert.assertEquals("Move 2 Drop count for North End, track North End 2", 0, l1s2.getDropRS());
Assert.assertEquals("Move 2 Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
Assert.assertEquals("Move 2 Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
Assert.assertEquals("Move 2 Drop count for North Industries, track NI Yard", 1, l2s1.getDropRS());
Assert.assertEquals("Move 2 Pickup count for North Industries, track NI Yard", 0, l2s1.getPickupRS());
Assert.assertEquals("Move 2 Drop count for South End, track South End 1", 4, l3s1.getDropRS());
Assert.assertEquals("Move 2 Drop count for South End, track South End 2", 5, l3s2.getDropRS());
Assert.assertEquals("Move 2 Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
Assert.assertEquals("Move 2 Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
// Move the train #3 (Terminate)
train1.move();
Assert.assertEquals("Train 1 After 3rd Move Current Name", "", train1.getCurrentLocationName());
Assert.assertEquals("Train 1 After 3rd Move Next Location Name", "", train1.getNextLocationName());
Assert.assertEquals("Train 1 After 3rd Move Status", Train.TERMINATED, getTrainStatus(train1));
// Is the train in route?
Assert.assertEquals("Train 1 in route after 3rd", false, train1.isTrainEnRoute());
// Are the engine and car destinations correct?
Assert.assertEquals("Engine e1 After 3rd Move", "", e1.getDestinationTrackName());
Assert.assertEquals("Engine e2 After 3rd Move", "", e2.getDestinationTrackName());
Assert.assertEquals("Car c1 After 3rd Move", "", c1.getDestinationTrackName());
Assert.assertEquals("Car c4 After 3rd Move", "", c4.getDestinationTrackName());
Assert.assertEquals("Car c8 After 3rd Move", "", c8.getDestinationTrackName());
// Are the engine and car final locations correct?
Assert.assertEquals("Engine e1 After Terminate location", "South End", e1.getLocationName());
Assert.assertEquals("Engine e2 After Terminate location", "South End", e2.getLocationName());
Assert.assertEquals("Car c1 After Terminate location", "South End", c1.getLocationName());
Assert.assertEquals("Car c4 After Terminate location", "South End", c4.getLocationName());
Assert.assertEquals("Car c8 After Terminate location", "South End", c8.getLocationName());
// Are the engine and car final staging track correct?
Assert.assertEquals("Engine e1 After Terminate track", "South End 2", e1.getTrackName());
Assert.assertEquals("Engine e2 After Terminate track", "South End 2", e2.getTrackName());
Assert.assertEquals("Car c1 After Terminate track", "South End 2", c1.getTrackName());
Assert.assertEquals("Car c4 After Terminate track", "South End 2", c4.getTrackName());
Assert.assertEquals("Car c8 After Terminate track", "South End 2", c8.getTrackName());
// Are the engine and car moves correct
Assert.assertEquals("Engine e1 Moves after Terminate should be 137", 137, e1.getMoves());
Assert.assertEquals("Engine e2 Moves after Terminate should be 335", 335, e2.getMoves());
Assert.assertEquals("Car c1 Moves after Terminate should be 37", 37, c1.getMoves());
Assert.assertEquals("Car c4 Moves after Terminate should be 4458", 4458, c4.getMoves());
Assert.assertEquals("Car c8 Moves after Terminate should be 11", 11, c8.getMoves());
// Are the location pickup and drop counts correct?
Assert.assertEquals("Move 3 Drop count for North End", 0, l1.getDropRS());
Assert.assertEquals("Move 3 Drop count for North Industries", 1, l2.getDropRS());
Assert.assertEquals("Move 3 Drop count for South End", 4, l3.getDropRS());
Assert.assertEquals("Move 3 Pickup count for North End", 5, l1.getPickupRS());
Assert.assertEquals("Move 3 Pickup count for North Industries", 0, l2.getPickupRS());
Assert.assertEquals("Move 3 Pickup count for South End", 0, l3.getPickupRS());
// Are the track pickup and drop counts correct?
Assert.assertEquals("Move 3 Drop count for North End, track North End 1", 0, l1s1.getDropRS());
Assert.assertEquals("Move 3 Drop count for North End, track North End 2", 0, l1s2.getDropRS());
Assert.assertEquals("Move 3 Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
Assert.assertEquals("Move 3 Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
Assert.assertEquals("Move 3 Drop count for North Industries, track NI Yard", 1, l2s1.getDropRS());
Assert.assertEquals("Move 3 Pickup count for North Industries, track NI Yard", 0, l2s1.getPickupRS());
Assert.assertEquals("Move 3 Drop count for South End, track South End 1", 4, l3s1.getDropRS());
Assert.assertEquals("Move 3 Drop count for South End, track South End 2", 0, l3s2.getDropRS());
Assert.assertEquals("Move 3 Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
Assert.assertEquals("Move 3 Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
// Move the train 1 for the forth time, this shouldn't change anything
train1.move();
Assert.assertEquals("Train 1 After 4th Move Current Name", "", train1.getCurrentLocationName());
Assert.assertEquals("Train 1 After 4th Move Next Location Name", "", train1.getNextLocationName());
Assert.assertEquals("Train 1 After 4th Move Status", Train.TERMINATED, getTrainStatus(train1));
// Is the train in route?
Assert.assertEquals("Train 1 sould not be in route", false, train1.isTrainEnRoute());
// Are the engines and cars released from train 1?
Assert.assertEquals("Engine e1 After Terminate should NOT be assigned to Train 1", null, e1.getTrain());
Assert.assertEquals("Engine e2 After Terminate should NOT be assigned to Train 1", null, e2.getTrain());
Assert.assertEquals("Car c1 After Terminate should NOT be assigned to Train 1", null, c1.getTrain());
Assert.assertEquals("Car c4 After Terminate should NOT be assigned to Train 1", null, c4.getTrain());
// do cars have the right loads?
Assert.assertEquals("Car c1 load after Terminate", "E", c1.getLoadName());
Assert.assertEquals("Car c2 load after Terminate", "E", c2.getLoadName());
Assert.assertEquals("Car c3 load after Terminate", "E", c3.getLoadName());
Assert.assertEquals("Car c4 load after Terminate", "E", c4.getLoadName());
Assert.assertEquals("Car c5 load after Terminate", "E", c5.getLoadName());
Assert.assertEquals("Car c6 load after Terminate", "E", c6.getLoadName());
Assert.assertEquals("Car c7 load after Terminate", "E", c7.getLoadName());
Assert.assertEquals("Car c8 load after Terminate", "L", c8.getLoadName());
Assert.assertEquals("Car c9 load after Terminate", "E", c9.getLoadName());
// reset train 2
Assert.assertTrue("reset train2", train2.reset());
// Are the location pickup and drop counts correct?
Assert.assertEquals("Terminated Drop count for North End", 0, l1.getDropRS());
Assert.assertEquals("Terminated Drop count for North Industries", 0, l2.getDropRS());
Assert.assertEquals("Terminated Drop count for South End", 0, l3.getDropRS());
Assert.assertEquals("Terminated Pickup count for North End", 0, l1.getPickupRS());
Assert.assertEquals("Terminated Pickup count for North Industries", 0, l2.getPickupRS());
Assert.assertEquals("Terminated Pickup count for South End", 0, l3.getPickupRS());
// Are the track pickup and drop counts correct?
Assert.assertEquals("Terminated Drop count for North End, track North End 1", 0, l1s1.getDropRS());
Assert.assertEquals("Terminated Drop count for North End, track North End 2", 0, l1s2.getDropRS());
Assert.assertEquals("Terminated Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
Assert.assertEquals("Terminated Pickup count for North End, track North End 2", 0, l1s2.getPickupRS());
Assert.assertEquals("Terminated Drop count for North Industries, track NI Yard", 0, l2s1.getDropRS());
Assert.assertEquals("Terminated Pickup count for North Industries, track NI Yard", 0, l2s1.getDropRS());
Assert.assertEquals("Terminated Drop count for South End, track South End 1", 0, l3s1.getDropRS());
Assert.assertEquals("Terminated Drop count for South End, track South End 2", 0, l3s2.getDropRS());
Assert.assertEquals("Terminated Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
Assert.assertEquals("Terminated Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
// this should fail, there are two engines in staging
train2.setNumberEngines("1");
// now build train 2 testing failure modes
train2.reset();
new TrainBuilder().build(train2);
// build required 1 engine and there were two
Assert.assertEquals("Train 2 After Build require 1 engine", false, train2.isBuilt());
// take one engine out of the consist
e4.setConsist(null);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build require 1 engine, but 2 engines on staging track", false, train2.isBuilt());
// remove engine from staging
e4.setLocation(null, null);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build require 1 engine, 1 consisted engine on staging track", true, train2.isBuilt());
// take lead engine out of consist
e3.setConsist(null);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build require 1 engine, single engine on staging track", true, train2.isBuilt());
// restore engines and place back on staging tracks
e3.setConsist(con2);
e4.setConsist(con2);
e3.setLocation(l1, l1s2);
e4.setLocation(l1, l1s2);
// should work for 0
train2.setNumberEngines("0");
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build require 0 engine", true, train2.isBuilt());
train2.setNumberEngines("3");
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build require 3 engines", false, train2.isBuilt());
train2.setNumberEngines("2");
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build require 2 engine", true, train2.isBuilt());
// take engine out of service
e3.setOutOfService(true);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build engine out of service", false, train2.isBuilt());
// put back into service
e3.setOutOfService(false);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build engine in service", true, train2.isBuilt());
// try different road
train2.setEngineRoad("CP");
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build require road CP", false, train2.isBuilt());
train2.setEngineRoad("PC");
// try requiring FRED, should fail
train2.setRequirements(Train.FRED);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build requires FRED", false, train2.isBuilt());
// Add FRED to boxcar
c5.setFred(true);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build 2 requires FRED", true, train2.isBuilt());
// try engine wrong model
train2.setEngineModel("DS45");
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build 2 requires model DS45", false, train2.isBuilt());
// try engine correct model
train2.setEngineModel("SD45");
train2.reset();
new TrainBuilder().build(train2);
Assert.assertEquals("Train 2 After Build 2 requires model SD45", true, train2.isBuilt());
// Are the engines and cars assigned to train 2?
Assert.assertEquals("Engine e3 After Build should be assigned to Train 2", train2, e3.getTrain());
Assert.assertEquals("Engine e4 After Build should be assigned to Train 2", train2, e4.getTrain());
Assert.assertEquals("Car c2 After Build should be assigned to Train 2", train2, c2.getTrain());
Assert.assertEquals("Car c3 After Build should be assigned to Train 2", train2, c3.getTrain());
Assert.assertEquals("Car c5 After Build should be assigned to Train 2", train2, c5.getTrain());
Assert.assertEquals("Car c6 After Build should be assigned to Train 2", train2, c6.getTrain());
// train 2 does not accept Flat
Assert.assertEquals("Car c7 After Build should NOT be assigned to Train 2", null, c7.getTrain());
Assert.assertEquals("Car c9 After Build should NOT be assigned to Train 2", null, c9.getTrain());
// now allow Flat
train2.addTypeName("Flat");
c9.setLength("200");
train2.reset();
new TrainBuilder().build(train2);
// c9 and c7 have less moves than c3, but there's not enough room for c9 at destination
Assert.assertEquals("Car c3 After Build 3 should be assigned to Train 2", null, c3.getTrain());
Assert.assertEquals("Car c7 After Build 3 should be assigned to Train 2", train2, c7.getTrain());
Assert.assertEquals("Car c9 After Build 3 should NOT be assigned to Train 2", null, c9.getTrain());
// c7 is assigned to Staging Track South End 1 its load will swap
Assert.assertEquals("Car c7 After Build 3 destination", "South End 1", c7.getDestinationTrackName());
Assert.assertEquals("Car c7 load After Build 3", "E", c7.getLoadName());
// increase the size of staging
l3s2.setLength(500);
// allow default load swaps
// South End 2
l3s2.setLoadSwapEnabled(true);
train2.reset();
new TrainBuilder().build(train2);
// Check expected arrival times
Assert.assertEquals("Train 2 expected departure time", "22:45", train2.getExpectedArrivalTime(rl1));
Assert.assertEquals("Train 2 expected North End", "1:00:36", train2.getExpectedArrivalTime(rl2));
// one car dropped and one is picked up at North End, so travel time + two car moves
Assert.assertEquals("Train 2 expected North Industries", "1:02:49", train2.getExpectedArrivalTime(rl3));
// the build first resets which removes cars from the train, c3 load should NOT swap
Assert.assertEquals("Car c3 load After Build 4", "E", c3.getLoadName());
// c9 has less moves than c3 and c7, and now there's enough room for c9
Assert.assertEquals("Car c3 After Build 4 should NOT be assigned to Train 2", null, c3.getTrain());
Assert.assertEquals("Car c7 After Build 4 should be assigned to Train 2", train2, c7.getTrain());
Assert.assertEquals("Car c9 After Build 4 should NOT be assigned to Train 2", null, c9.getTrain());
// move the train #1
train2.move();
// Is the train in route?
Assert.assertEquals("Train 2 in route after 1st", true, train2.isTrainEnRoute());
// #2
train2.move();
// Is the train in route?
Assert.assertEquals("Train 2 in route after 2nd", true, train2.isTrainEnRoute());
// #3
train2.move();
// Is the train in route?
Assert.assertEquals("Train 2 in route after 3rd", false, train2.isTrainEnRoute());
// Are the engine and car final tracks correct?
Assert.assertEquals("Engine e1 After Terminate track", "South End 2", e1.getTrackName());
Assert.assertEquals("Engine e2 After Terminate track", "South End 2", e2.getTrackName());
Assert.assertEquals("Engine e3 After Terminate track", "South End 1", e3.getTrackName());
Assert.assertEquals("Engine e4 After Terminate track", "South End 1", e4.getTrackName());
Assert.assertEquals("Car c1 After Terminate track", "South End 2", c1.getTrackName());
Assert.assertEquals("Car c2 After Terminate track", "South End 1", c2.getTrackName());
Assert.assertEquals("Car c3 After Terminate track", "NI Yard", c3.getTrackName());
Assert.assertEquals("Car c4 After Terminate track", "South End 2", c4.getTrackName());
Assert.assertEquals("Car c5 After Terminate track", "South End 1", c5.getTrackName());
Assert.assertEquals("Car c6 After Terminate track", "NI Yard", c6.getTrackName());
Assert.assertEquals("Car c7 After Terminate track", "South End 1", c7.getTrackName());
Assert.assertEquals("Car c8 After Terminate track", "South End 2", c8.getTrackName());
Assert.assertEquals("Car c9 After Terminate track", "NI Yard", c9.getTrackName());
// do cars have the right loads?
Assert.assertEquals("Car c1 load after Terminate Train 2", "E", c1.getLoadName());
Assert.assertEquals("Car c2 load after Terminate Train 2", "E", c2.getLoadName());
Assert.assertEquals("Car c3 load after Terminate Train 2", "E", c3.getLoadName());
Assert.assertEquals("Car c4 load after Terminate Train 2", "E", c4.getLoadName());
Assert.assertEquals("Car c5 load after Terminate Train 2", "E", c5.getLoadName());
Assert.assertEquals("Car c6 load after Terminate Train 2", "E", c6.getLoadName());
Assert.assertEquals("Car c7 load after Terminate Train 2", "E", c7.getLoadName());
Assert.assertEquals("Car c8 load after Terminate Train 2", "L", c8.getLoadName());
Assert.assertEquals("Car c9 load after Terminate Train 2", "E", c9.getLoadName());
// try building again
// Place caboose on Staging tracks
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(l1, l1s1));
train2.setRequirements(Train.CABOOSE);
train2.setNumberEngines("0");
train2.reset();
new TrainBuilder().build(train2);
// Should fail both staging tracks are full
Assert.assertFalse("Train 2 not built", train2.isBuilt());
// add a new staging track
Track l3s3 = l3.addTrack("South End 3", Track.STAGING);
l3s3.setLength(200);
train2.reset();
new TrainBuilder().build(train2);
// Should build
Assert.assertTrue("Train 2 built", train2.isBuilt());
// make staging track too small for caboose
l3s3.setLength(20);
train2.reset();
new TrainBuilder().build(train2);
// Should not build
Assert.assertFalse("Train 2 built", train2.isBuilt());
// restore
l3s3.setLength(200);
// Car X10001 is a location North Industries, NI Yard, send boxcar X10001 to staging
Assert.assertEquals("set destination", Track.OKAY, c3.setDestination(l3, null));
train2.reset();
new TrainBuilder().build(train2);
// Should build
Assert.assertTrue("Train 2 built", train2.isBuilt());
Assert.assertEquals("Car X10001 to staging track", l3s3, c3.getDestinationTrack());
Assert.assertEquals("Car X10001 assigned to train 2", train2, c3.getTrain());
// Send car X10001 to staging and track that isn't being used
train2.reset();
Assert.assertEquals("set destination", Track.OKAY, c3.setDestination(l3, l3s2));
train2.reset();
new TrainBuilder().build(train2);
// Should build
Assert.assertTrue("Train 2 built", train2.isBuilt());
Assert.assertEquals("Car X10001 not assigned to train 2", train2, c3.getTrain());
// Send car X10001 to staging and the only track available
train2.reset();
// this removes track, it is now reserved
c3.setDestination(l3, l3s3);
train2.reset();
new TrainBuilder().build(train2);
// Should not build
Assert.assertFalse("Train 2 built", train2.isBuilt());
Assert.assertEquals("Car X10001 assigned to train 2", null, c3.getTrain());
train2.setRequirements(Train.NO_CABOOSE_OR_FRED);
train2.reset();
ct.addName("BOXCAR");
train2.addTypeName("BOXCAR");
c3.setTypeName("BOXCAR");
l3.addTypeName("BOXCAR");
c3.setDestination(l3, null);
train2.reset();
new TrainBuilder().build(train2);
// Should Not build, staging track South End 3 doesn't service type BOXCAR
Assert.assertFalse("Train 2 will not build due to BOXCAR", train2.isBuilt());
Assert.assertEquals("Car X10001 NOT assigned to train 2", null, c3.getTrain());
// turn off staging check
Setup.setTrainIntoStagingCheckEnabled(false);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertTrue("Train 2 will now build ignoring BOXCAR", train2.isBuilt());
Assert.assertEquals("Car X10001 NOT assigned to train 2", null, c3.getTrain());
Setup.setTrainIntoStagingCheckEnabled(true);
train2.deleteTypeName("BOXCAR");
c3.setTypeName("Boxcar");
// control which road will go into staging
l3s3.setRoadOption(Track.INCLUDE_ROADS);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertFalse("Train 2 will NOT build road restriction", train2.isBuilt());
train2.setRoadOption(Train.INCLUDE_ROADS);
Assert.assertEquals("Number of road names for train", 1, train2.getRoadNames().length);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertFalse("Train 2 will NOT build road restriction CP", train2.isBuilt());
l3s3.addRoadName("CP");
Assert.assertEquals("Number of road names", 1, l3s3.getRoadNames().length);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertTrue("Train 2 will build road restriction CP removed", train2.isBuilt());
train2.setRoadOption(Train.EXCLUDE_ROADS);
train2.deleteRoadName("CP");
Assert.assertEquals("Number of road names for train", 0, train2.getRoadNames().length);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertFalse("Train 2 will NOT build road restriction exclude road CP", train2.isBuilt());
// now allow road into staging
l3s3.setRoadOption(Track.EXCLUDE_ROADS);
l3s3.deleteRoadName("CP");
Assert.assertEquals("Number of road names", 0, l3s3.getRoadNames().length);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertTrue("Train 2 will build no road restrictions", train2.isBuilt());
l3s3.addRoadName("BM");
Assert.assertEquals("Number of road names", 1, l3s3.getRoadNames().length);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertFalse("Train 2 will Not build, staging track will not accept road BM", train2.isBuilt());
// end staging to staging 1
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilderTest method testInterchange.
public void testInterchange() {
Setup.setMaxTrainLength(500);
ct.addName("Gon");
ct.addName("Coil Car");
ct.addName("Flat Car");
ct.addName("XCaboose");
ct.addName("Boxcar");
// confirm no locations
Assert.assertEquals("number of locations", 0, lmanager.getNumberOfLocations());
// Create locations used
Location loc1;
loc1 = lmanager.newLocation("Old Westford");
loc1.setTrainDirections(DIRECTION_ALL);
Location loc2;
loc2 = lmanager.newLocation("Old Chelmsford");
loc2.setTrainDirections(DIRECTION_ALL);
Location loc3;
loc3 = lmanager.newLocation("Old Bedford");
loc3.setTrainDirections(DIRECTION_ALL);
Track loc1trk1;
loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
loc1trk1.setLength(900);
Track loc1trk2;
loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
loc1trk2.setLength(500);
loc1trk2.deleteTypeName("Coil Car");
loc1trk2.deleteTypeName("XCaboose");
Track loc2trk1;
loc2trk1 = loc2.addTrack("Chelmsford Interchange 1", Track.INTERCHANGE);
loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
loc2trk1.setLength(900);
loc2trk1.deleteTypeName("Coil Car");
loc2trk1.deleteTypeName("XCaboose");
Track loc2trk2;
loc2trk2 = loc2.addTrack("Chelmsford Interchange 2", Track.INTERCHANGE);
loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
loc2trk2.setLength(900);
loc2trk2.deleteTypeName("XCaboose");
Track loc2trk3;
loc2trk3 = loc2.addTrack("Chelmsford Yard 3", Track.YARD);
loc2trk3.setTrainDirections(Track.WEST + Track.EAST);
loc2trk3.setLength(900);
loc2trk3.deleteTypeName("Gon");
loc2trk3.deleteTypeName("Coil Car");
loc2trk3.deleteTypeName("XCaboose");
Track loc2trk4;
loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
loc2trk4.setLength(900);
loc2trk4.deleteTypeName("Gon");
loc2trk4.deleteTypeName("XCaboose");
// bias interchange tracks
loc2trk3.setMoves(20);
loc2trk4.setMoves(20);
Track loc3trk1;
loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.YARD);
loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
loc3trk1.setLength(900);
// Create route with 3 location
Route rte1;
rte1 = rmanager.newRoute("Route 1 East");
RouteLocation r1l1 = rte1.addLocation(loc1);
r1l1.setTrainDirection(RouteLocation.EAST);
r1l1.setMaxCarMoves(4);
// set the train icon coordinates
r1l1.setTrainIconX(125);
r1l1.setTrainIconY(100);
RouteLocation r1l2 = rte1.addLocation(loc2);
r1l2.setTrainDirection(RouteLocation.EAST);
r1l2.setMaxCarMoves(3);
// set the train icon coordinates
r1l2.setTrainIconX(25);
r1l2.setTrainIconY(125);
RouteLocation r1l3 = rte1.addLocation(loc3);
r1l3.setTrainDirection(RouteLocation.EAST);
r1l3.setMaxCarMoves(3);
// set the train icon coordinates
r1l3.setTrainIconX(75);
r1l3.setTrainIconY(125);
// Create route with 3 location
Route rte2;
rte2 = rmanager.newRoute("Route 2 East");
RouteLocation r2l1 = rte2.addLocation(loc1);
r2l1.setTrainDirection(RouteLocation.EAST);
r2l1.setMaxCarMoves(2);
// set the train icon coordinates
r2l1.setTrainIconX(125);
r2l1.setTrainIconY(125);
RouteLocation r2l2 = rte2.addLocation(loc2);
r2l2.setTrainDirection(RouteLocation.EAST);
r2l2.setMaxCarMoves(6);
// set the train icon coordinates
r2l2.setTrainIconX(175);
r2l2.setTrainIconY(125);
RouteLocation r2l3 = rte2.addLocation(loc3);
r2l3.setTrainDirection(RouteLocation.EAST);
r2l3.setMaxCarMoves(6);
// set the train icon coordinates
r2l3.setTrainIconX(25);
r2l3.setTrainIconY(150);
// Create trains
Train train1;
train1 = tmanager.newTrain("T1OWOB");
train1.setRoute(rte1);
Train train2;
train2 = tmanager.newTrain("T2OWOB");
train2.setRoute(rte1);
Train train3;
train3 = tmanager.newTrain("T3OWOB");
train3.setRoute(rte1);
// Set up 7 box cars and 2 flat cars
Car c1 = new Car("BM", "Q1");
c1.setTypeName("Gon");
c1.setLength("100");
c1.setMoves(100);
c1.setLoadName("L");
c1.setWeightTons("10");
cmanager.register(c1);
Car c2 = new Car("UP", "Q2");
c2.setTypeName("Boxcar");
c2.setLength("80");
c2.setMoves(90);
c2.setWeightTons("20");
cmanager.register(c2);
Car c3 = new Car("XP", "Q3");
c3.setTypeName("Flat Car");
c3.setLength("70");
c3.setMoves(70);
c3.setWeightTons("30");
cmanager.register(c3);
Car c4 = new Car("PU", "Q4");
c4.setTypeName("Boxcar");
c4.setLength("60");
c4.setMoves(60);
c4.setWeightTons("40");
cmanager.register(c4);
Car c5 = new Car("UP", "Q5");
c5.setTypeName("Gon");
c5.setLength("50");
c5.setMoves(50);
c5.setLoadName("L");
c5.setWeightTons("50");
cmanager.register(c5);
Car c6 = new Car("CP", "Q6");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(40);
c6.setLoadName("L");
c6.setWeightTons("60");
cmanager.register(c6);
Car c7 = new Car("UP", "Q7");
c7.setTypeName("Boxcar");
c7.setLength("50");
c7.setMoves(30);
c7.setWeightTons("70");
cmanager.register(c7);
Car c8 = new Car("XP", "Q8");
c8.setTypeName("Gon");
c8.setLength("60");
c8.setMoves(20);
c8.setWeightTons("80");
cmanager.register(c8);
Car c9 = new Car("XP", "Q9");
c9.setTypeName("Flat Car");
c9.setLength("90");
c9.setMoves(10);
c9.setLoadName("L");
c9.setWeightTons("90");
cmanager.register(c9);
Car c10 = new Car("CP", "Q10");
c10.setTypeName("Coil Car");
c10.setLength("40");
c10.setMoves(8);
c10.setLoadName("L");
c10.setWeightTons("100");
cmanager.register(c10);
Car c11 = new Car("CP", "Q11");
c11.setTypeName("Coil Car");
c11.setLength("40");
c11.setMoves(9);
c11.setLoadName("Coils");
c11.setWeightTons("110");
cmanager.register(c11);
Car c12 = new Car("CP", "Q12");
c12.setTypeName("Coil Car");
c12.setLength("40");
c12.setMoves(10);
c12.setWeightTons("120");
cmanager.register(c12);
Car c13 = new Car("CP", "Q13");
c13.setTypeName("XCaboose");
c13.setCaboose(true);
c13.setLength("40");
c13.setMoves(7);
c13.setWeightTons("130");
cmanager.register(c13);
// place the cars in the yards
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c12", Track.OKAY, c12.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c13", Track.OKAY, c13.setLocation(loc1, loc1trk1));
train1.reset();
new TrainBuilder().build(train1);
train2.reset();
new TrainBuilder().build(train2);
// now check to where cars are going to be delivered
Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination", "", c4.getDestinationTrackName());
Assert.assertEquals("c9 destination", "Chelmsford Interchange 1", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination", "Bedford Yard 1", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination", "Chelmsford Interchange 2", c11.getDestinationTrackName());
Assert.assertEquals("c12 destination", "Bedford Yard 1", c12.getDestinationTrackName());
Assert.assertEquals("c5 destination", "Chelmsford Interchange 2", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination", "Bedford Yard 1", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination", "Chelmsford Interchange 1", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination", "Bedford Yard 1", c8.getDestinationTrackName());
// now check which trains
Assert.assertEquals("c9 train", train1, c9.getTrain());
Assert.assertEquals("c10 train", train1, c10.getTrain());
Assert.assertEquals("c11 train", train1, c11.getTrain());
Assert.assertEquals("c12 train", train1, c12.getTrain());
Assert.assertEquals("c5 train", train2, c5.getTrain());
Assert.assertEquals("c6 train", train2, c6.getTrain());
Assert.assertEquals("c7 train", train2, c7.getTrain());
Assert.assertEquals("c8 train", train2, c8.getTrain());
// try restricting interchange 1 to train1 and interchange 2 to train2
loc2trk1.setDropOption(Track.TRAINS);
loc2trk1.addDropId(train1.getId());
loc2trk2.setDropOption(Track.TRAINS);
loc2trk2.addDropId(train2.getId());
train1.reset();
new TrainBuilder().build(train1);
train2.reset();
new TrainBuilder().build(train2);
// now check to where cars are going to be delivered
Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination", "", c4.getDestinationTrackName());
Assert.assertEquals("c9 destination 2", "Chelmsford Interchange 1", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 2", "Bedford Yard 1", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 2", "Bedford Yard 1", c11.getDestinationTrackName());
Assert.assertEquals("c12 destination 2", "Chelmsford Freight 4", c12.getDestinationTrackName());
Assert.assertEquals("c5 destination 2", "Chelmsford Interchange 2", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 2", "Bedford Yard 1", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 2", "Chelmsford Interchange 2", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 2", "Bedford Yard 1", c8.getDestinationTrackName());
// now check which trains
Assert.assertEquals("c9 train", train1, c9.getTrain());
Assert.assertEquals("c10 train", train1, c10.getTrain());
Assert.assertEquals("c11 train", train1, c11.getTrain());
Assert.assertEquals("c12 train", train1, c12.getTrain());
Assert.assertEquals("c5 train", train2, c5.getTrain());
Assert.assertEquals("c6 train", train2, c6.getTrain());
Assert.assertEquals("c7 train", train2, c7.getTrain());
Assert.assertEquals("c8 train", train2, c8.getTrain());
// move and terminate
Assert.assertEquals("Check train 1 departure location name", "Old Westford", train1.getCurrentLocationName());
Assert.assertEquals("Check train 1 departure location", r1l1, train1.getCurrentLocation());
// #1
train1.move();
Assert.assertEquals("Check train 1 location name", "Old Chelmsford", train1.getCurrentLocationName());
Assert.assertEquals("Check train 1 location", r1l2, train1.getCurrentLocation());
// #2
train1.move();
Assert.assertEquals("Check train 1 location name", "Old Bedford", train1.getCurrentLocationName());
Assert.assertEquals("Check train 1 location", r1l3, train1.getCurrentLocation());
// #3 terminate
train1.move();
Assert.assertEquals("Check train 1 location name", "", train1.getCurrentLocationName());
Assert.assertEquals("Check train 1 location", null, train1.getCurrentLocation());
Assert.assertEquals("Check train 2 departure location name", "Old Westford", train2.getCurrentLocationName());
Assert.assertEquals("Check train 2 departure location", r1l1, train2.getCurrentLocation());
// #1
train2.move();
Assert.assertEquals("Check train 2 location name", "Old Chelmsford", train2.getCurrentLocationName());
Assert.assertEquals("Check train 2 location", r1l2, train2.getCurrentLocation());
// #2
train2.move();
Assert.assertEquals("Check train 2 location name", "Old Bedford", train2.getCurrentLocationName());
Assert.assertEquals("Check train 2 location", r1l3, train2.getCurrentLocation());
// #3 terminate
train2.move();
Assert.assertEquals("Check train 2 location name", "", train2.getCurrentLocationName());
Assert.assertEquals("Check train 2 location", null, train2.getCurrentLocation());
r1l1.setMaxCarMoves(2);
r1l2.setMaxCarMoves(6);
r1l3.setMaxCarMoves(6);
train3.reset();
// note that train3 uses rte1, should not pickup cars at interchange
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 3", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 3", "Chelmsford Yard 3", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 3", "Bedford Yard 1", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 3", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 3", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 3", "", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 3", "", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 3", "", c9.getDestinationTrackName());
Assert.assertEquals("c12 destination 3", "Bedford Yard 1", c12.getDestinationTrackName());
// Change the route to 2, should be able to pickup c4, c7, c9
train3.reset();
train3.setRoute(rte2);
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 4", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 4", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 4", "Chelmsford Yard 3", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 4", "Bedford Yard 1", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 4", "Bedford Yard 1", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 4", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 4", "Bedford Yard 1", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 4", "", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 4", "Bedford Yard 1", c9.getDestinationTrackName());
Assert.assertEquals("c12 destination 4", "Bedford Yard 1", c12.getDestinationTrackName());
// Change back to route to 1, should be able to pickup c4, c7
train3.reset();
train3.setRoute(rte1);
loc2trk2.setPickupOption(Track.TRAINS);
loc2trk2.addPickupId(train3.getId());
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 5", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 5", "Chelmsford Freight 4", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 5", "Bedford Yard 1", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 5", "Bedford Yard 1", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 5", "Bedford Yard 1", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 5", "", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 5", "", c9.getDestinationTrackName());
Assert.assertEquals("c12 destination 5", "Bedford Yard 1", c12.getDestinationTrackName());
// Change back to route to 1, should be able to pickup c4, c7, and c9
train3.reset();
train3.setRoute(rte1);
loc2trk1.setPickupOption(Track.ROUTES);
loc2trk1.addPickupId(rte1.getId());
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 6", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 6", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 6", "Chelmsford Yard 3", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 6", "Bedford Yard 1", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 6", "Bedford Yard 1", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 6", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 6", "Bedford Yard 1", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 6", "", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 6", "Bedford Yard 1", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 6", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 6", "", c11.getDestinationTrackName());
Assert.assertEquals("c12 destination 6", "Bedford Yard 1", c12.getDestinationTrackName());
// now allow train 3 to drop
train3.reset();
loc2trk1.setDropOption(Track.ROUTES);
loc2trk1.addDropId(rte1.getId());
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 7", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 7", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 7", "Chelmsford Interchange 1", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 7", "Bedford Yard 1", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 7", "Bedford Yard 1", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 7", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 7", "Bedford Yard 1", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 7", "", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 7", "Bedford Yard 1", c9.getDestinationTrackName());
Assert.assertEquals("c12 destination 7", "Bedford Yard 1", c12.getDestinationTrackName());
// move and terminate
train3.move();
train3.move();
train3.move();
train3.move();
// check tracks
Assert.assertEquals("c1 track", "Westford Yard 1", c1.getTrackName());
Assert.assertEquals("c2 track", "Westford Yard 1", c2.getTrackName());
Assert.assertEquals("c3 track", "Chelmsford Interchange 1", c3.getTrackName());
Assert.assertEquals("c4 track", "Bedford Yard 1", c4.getTrackName());
Assert.assertEquals("c5 track", "Bedford Yard 1", c5.getTrackName());
Assert.assertEquals("c6 track", "Bedford Yard 1", c6.getTrackName());
Assert.assertEquals("c7 track", "Bedford Yard 1", c7.getTrackName());
Assert.assertEquals("c8 track", "Bedford Yard 1", c8.getTrackName());
Assert.assertEquals("c9 track", "Bedford Yard 1", c9.getTrackName());
Assert.assertEquals("c10 track", "Bedford Yard 1", c10.getTrackName());
Assert.assertEquals("c11 track", "Bedford Yard 1", c11.getTrackName());
Assert.assertEquals("c12 track", "Bedford Yard 1", c12.getTrackName());
// check train length and tonnage
Assert.assertEquals("Depart Westford length", 138, r1l1.getTrainLength());
Assert.assertEquals("Depart Old Chelmsford length", 310, r1l2.getTrainLength());
// In train 2 cars, c3 E and c4 E car weight 20/3 + 50/3 = 23
Assert.assertEquals("Depart Old Westford tonnage", 23, r1l1.getTrainWeight());
// In train 5 cars, c4 E, c5 L, c7 E, c9 L, c12 L = 40/3 + 50 + 70/3 + 90 + 120 = 296
Assert.assertEquals("Depart Old Chelmsford tonnage", 296, r1l2.getTrainWeight());
// test route pickup and drop controls
train3.setRequirements(Train.CABOOSE);
r1l1.setPickUpAllowed(false);
train3.reset();
// c1, c2, and c13 at start of train's route
// c3 at Old Chelmsford, second stop
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 8", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 8", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 8", "Bedford Yard 1", c3.getDestinationTrackName());
Assert.assertEquals("c13 destination 8", "Bedford Yard 1", c13.getDestinationTrackName());
r1l1.setPickUpAllowed(true);
r1l2.setPickUpAllowed(false);
train3.reset();
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 9", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 9", "Chelmsford Interchange 1", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 9", "", c3.getDestinationTrackName());
Assert.assertEquals("c13 destination 9", "Bedford Yard 1", c13.getDestinationTrackName());
r1l2.setPickUpAllowed(true);
// Old Chelmsford
r1l2.setDropAllowed(false);
train3.reset();
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 10", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 10", "Bedford Yard 1", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 10", "Bedford Yard 1", c3.getDestinationTrackName());
Assert.assertEquals("c13 destination 10", "Bedford Yard 1", c13.getDestinationTrackName());
// try forcing c2 to Chelmsford
train3.reset();
c2.setDestination(loc2, null);
new TrainBuilder().build(train3);
Assert.assertEquals("c2 destination Old Chelmsford", "", c2.getDestinationTrackName());
// confirm that c2 isn't part of this train
Assert.assertNull("c2 isn't assigned to a train", c2.getTrain());
Assert.assertNull("c2 destination has been set to null", c2.getDestination());
Assert.assertNull("c2 next destination should be null", c2.getFinalDestination());
Assert.assertNull("c2 next destination track should be null", c2.getFinalDestinationTrack());
// try without moves
train3.reset();
r1l2.setDropAllowed(true);
r1l2.setMaxCarMoves(0);
c2.setDestination(loc2, null);
new TrainBuilder().build(train3);
Assert.assertEquals("c2 destination Old Chelmsford, no moves", "", c2.getDestinationTrackName());
c2.setDestination(null, null);
r1l2.setMaxCarMoves(6);
// Should be able to drop off caboose
r1l3.setDropAllowed(false);
train3.reset();
new TrainBuilder().build(train3);
Assert.assertEquals("c1 destination 11", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 11", "Chelmsford Interchange 1", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 11", "", c3.getDestinationTrackName());
Assert.assertEquals("c13 destination 11", "Bedford Yard 1", c13.getDestinationTrackName());
// test to see if FRED also get delivered
train3.setRequirements(Train.FRED);
c2.setFred(true);
train3.reset();
new TrainBuilder().build(train3);
Assert.assertTrue("Train 3 built", train3.isBuilt());
Assert.assertEquals("c1 destination 12", "Chelmsford Interchange 1", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 12", "Bedford Yard 1", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 12", "", c3.getDestinationTrackName());
Assert.assertEquals("c13 destination 12", "", c13.getDestinationTrackName());
// move and terminate
train3.move();
train3.move();
train3.move();
train3.move();
Assert.assertEquals("c1 track 12", "Chelmsford Interchange 1", c1.getTrackName());
Assert.assertEquals("c2 track 12", "Bedford Yard 1", c2.getTrackName());
Assert.assertEquals("c3 track 12", "Chelmsford Interchange 1", c3.getTrackName());
Assert.assertEquals("c13 track 12", "Westford Yard 1", c13.getTrackName());
// test previous car delivered pickup interchange operation
loc2trk1.setDropOption(Track.ANY);
loc2trk1.setPickupOption(Track.TRAINS);
loc2trk2.setDropOption(Track.ANY);
loc2trk2.setPickupOption(Track.TRAINS);
// Place car with FRED back at start of route
Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c3 at start of route", Track.OKAY, c3.setLocation(loc1, loc1trk2));
train3.reset();
new TrainBuilder().build(train3);
Assert.assertTrue("train 3 should build", train3.isBuilt());
Assert.assertEquals("car BM Q1 should not be part of train", null, c1.getTrain());
Assert.assertEquals("car XP Q3 should be part of train", train3, c3.getTrain());
// put some cars at start of Route
Assert.assertEquals("Place c1 again", Track.OKAY, c1.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c3 again", Track.OKAY, c3.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c4 again", Track.OKAY, c4.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c6 again", Track.OKAY, c6.setLocation(loc2, loc2trk1));
Assert.assertEquals("Place c7 again", Track.OKAY, c7.setLocation(loc2, loc2trk2));
r1l1.setMaxCarMoves(5);
loc2trk1.setDropOption(Track.ROUTES);
loc2trk1.setPickupOption(Track.ROUTES);
loc2trk2.setDropOption(Track.ROUTES);
loc2trk2.setPickupOption(Track.ROUTES);
train3.reset();
new TrainBuilder().build(train3);
Assert.assertTrue("train 3 should build", train3.isBuilt());
Assert.assertEquals("BM Q1 in train", null, c1.getTrain());
Assert.assertEquals("UP Q2 in train", train3, c2.getTrain());
Assert.assertEquals("XP Q3 in train", train3, c3.getTrain());
Assert.assertEquals("PU Q4 in train", train3, c4.getTrain());
Assert.assertEquals("UP Q5 in train", null, c5.getTrain());
Assert.assertEquals("CP Q6 in train", null, c6.getTrain());
Assert.assertEquals("UP Q7 in train", null, c7.getTrain());
Assert.assertEquals("UP Q2 destination", "Bedford Yard 1", c2.getDestinationTrackName());
Assert.assertEquals("XP Q3 destination", "Chelmsford Yard 3", c3.getDestinationTrackName());
Assert.assertEquals("PU Q4 destination", "Chelmsford Freight 4", c4.getDestinationTrackName());
Assert.assertEquals("UP Q5 destination", "", c5.getDestinationTrackName());
// interchange testing done, now test replace car type and road
Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
// replace should modify locations and trains
ct.replaceName("Boxcar", "boxcar");
Assert.assertFalse("loc1 should not accept Boxcar", loc1.acceptsTypeName("Boxcar"));
Assert.assertFalse("loc2 should not accept Boxcar", loc2.acceptsTypeName("Boxcar"));
Assert.assertFalse("track loc1trk1 should not accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
Assert.assertFalse("track loc2trk1 should not accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
Assert.assertFalse("train 1 should not accept Boxcar", train1.acceptsTypeName("Boxcar"));
Assert.assertFalse("train 2 should not accept Boxcar", train2.acceptsTypeName("Boxcar"));
Assert.assertFalse("train 3 should not accept Boxcar", train3.acceptsTypeName("Boxcar"));
Assert.assertTrue("loc1 should accept boxcar", loc1.acceptsTypeName("boxcar"));
Assert.assertTrue("loc2 should accept boxcar", loc2.acceptsTypeName("boxcar"));
Assert.assertTrue("track loc1trk1 should accept boxcar", loc1trk1.acceptsTypeName("boxcar"));
Assert.assertTrue("track loc2trk1 should accept boxcar", loc2trk1.acceptsTypeName("boxcar"));
Assert.assertTrue("train 1 should accept boxcar", train1.acceptsTypeName("boxcar"));
Assert.assertTrue("train 2 should accept boxcar", train2.acceptsTypeName("boxcar"));
Assert.assertTrue("train 3 should accept boxcar", train3.acceptsTypeName("boxcar"));
ct.replaceName("boxcar", "Boxcar");
Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
Assert.assertTrue("track loc1trk1 should accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
Assert.assertTrue("track loc2trk1 should accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
Assert.assertTrue("train 1 should accept Boxcar", train1.acceptsTypeName("Boxcar"));
Assert.assertTrue("train 2 should accept Boxcar", train2.acceptsTypeName("Boxcar"));
Assert.assertTrue("train 3 should accept Boxcar", train3.acceptsTypeName("Boxcar"));
// now test road name replace
CarRoads cr = CarRoads.instance();
cr.addName("CP");
loc1trk1.setRoadOption(Track.INCLUDE_ROADS);
loc1trk1.addRoadName("CP");
loc1trk1.addRoadName("PC");
train1.setRoadOption(Train.INCLUDE_ROADS);
train1.addRoadName("CP");
train1.addRoadName("PC");
train1.setCabooseRoad("CP");
train1.setEngineRoad("CP");
Assert.assertTrue("track loc1trk1 should accept road CP", loc1trk1.acceptsRoadName("CP"));
Assert.assertTrue("track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
Assert.assertFalse("track loc1trk1 should Not accept road PC", loc1trk1.acceptsRoadName("UP"));
Assert.assertTrue("Train 1 should accept road CP", train1.acceptsRoadName("CP"));
Assert.assertTrue("Train 1 should accept road PC", train1.acceptsRoadName("PC"));
Assert.assertFalse("Train 1 should Not accept road UP", train1.acceptsRoadName("UP"));
Assert.assertEquals("Caboose road", "CP", train1.getCabooseRoad());
Assert.assertEquals("Engine road", "CP", train1.getEngineRoad());
cr.replaceName("CP", "UP");
Assert.assertFalse("after replace track loc1trk1 should Not accept road CP", loc1trk1.acceptsRoadName("CP"));
Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("UP"));
Assert.assertFalse("after replace Train 1 should Not accept road CP", train1.acceptsRoadName("CP"));
Assert.assertTrue("after replace Train 1 should accept road PC", train1.acceptsRoadName("PC"));
Assert.assertTrue("after replace Train 1 should accept road UP", train1.acceptsRoadName("UP"));
Assert.assertEquals("Caboose road", "UP", train1.getCabooseRoad());
Assert.assertEquals("Engine road", "UP", train1.getEngineRoad());
}
Aggregations