use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class OperationsTrainsGuiTest method testTrainEditFrameBuildOptionFrame.
@Test
public void testTrainEditFrameBuildOptionFrame() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// test build options
TrainManager tmanager = TrainManager.instance();
Train t = tmanager.newTrain("Test Train New Name");
// Add a route to this train
Route route = RouteManager.instance().newRoute("Test Train Route");
route.addLocation(LocationManager.instance().newLocation("Test Train Location A"));
route.addLocation(LocationManager.instance().newLocation("Test Train Location B"));
route.addLocation(LocationManager.instance().newLocation("Test Train Location C"));
t.setRoute(route);
TrainEditFrame trainEditFrame = new TrainEditFrame(t);
// entire panel must be visible for tests to work properly
trainEditFrame.setLocation(0, 0);
trainEditFrame.setTitle("Test Build Options Train Frame");
TrainEditBuildOptionsFrame f = new TrainEditBuildOptionsFrame();
// entire panel must be visible for tests to work properly
f.setLocation(0, 0);
f.initComponents(trainEditFrame);
f.setTitle("Test Train Build Options");
// confirm defaults
Assert.assertEquals("Build normal", false, t.isBuildTrainNormalEnabled());
Assert.assertEquals("send to terminal", false, t.isSendCarsToTerminalEnabled());
Assert.assertEquals("return to staging", false, t.isAllowReturnToStagingEnabled());
Assert.assertEquals("allow local moves", true, t.isAllowLocalMovesEnabled());
Assert.assertEquals("allow through cars", true, t.isAllowThroughCarsEnabled());
// test options
enterClickAndLeave(f.buildNormalCheckBox);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("Build normal", true, t.isBuildTrainNormalEnabled());
Assert.assertEquals("send to terminal", false, t.isSendCarsToTerminalEnabled());
Assert.assertEquals("return to staging", false, t.isAllowReturnToStagingEnabled());
Assert.assertEquals("allow local moves", true, t.isAllowLocalMovesEnabled());
Assert.assertEquals("allow through cars", true, t.isAllowThroughCarsEnabled());
enterClickAndLeave(f.sendToTerminalCheckBox);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("Build normal", true, t.isBuildTrainNormalEnabled());
Assert.assertEquals("send to terminal", true, t.isSendCarsToTerminalEnabled());
Assert.assertEquals("return to staging", false, t.isAllowReturnToStagingEnabled());
Assert.assertEquals("allow local moves", true, t.isAllowLocalMovesEnabled());
Assert.assertEquals("allow through cars", true, t.isAllowThroughCarsEnabled());
enterClickAndLeave(f.returnStagingCheckBox);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("Build normal", true, t.isBuildTrainNormalEnabled());
Assert.assertEquals("send to terminal", true, t.isSendCarsToTerminalEnabled());
// the return to staging checkbox should be disabled
Assert.assertEquals("return to staging", false, t.isAllowReturnToStagingEnabled());
Assert.assertEquals("allow local moves", true, t.isAllowLocalMovesEnabled());
Assert.assertEquals("allow through cars", true, t.isAllowThroughCarsEnabled());
enterClickAndLeave(f.allowLocalMovesCheckBox);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("Build normal", true, t.isBuildTrainNormalEnabled());
Assert.assertEquals("send to terminal", true, t.isSendCarsToTerminalEnabled());
Assert.assertEquals("return to staging", false, t.isAllowReturnToStagingEnabled());
Assert.assertEquals("allow local moves", false, t.isAllowLocalMovesEnabled());
Assert.assertEquals("allow through cars", true, t.isAllowThroughCarsEnabled());
enterClickAndLeave(f.allowThroughCarsCheckBox);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("Build normal", true, t.isBuildTrainNormalEnabled());
Assert.assertEquals("send to terminal", true, t.isSendCarsToTerminalEnabled());
Assert.assertEquals("return to staging", false, t.isAllowReturnToStagingEnabled());
Assert.assertEquals("allow local moves", false, t.isAllowLocalMovesEnabled());
Assert.assertEquals("allow through cars", false, t.isAllowThroughCarsEnabled());
// test car owner options
enterClickAndLeave(f.ownerNameExclude);
Assert.assertEquals("train car owner exclude", Train.EXCLUDE_OWNERS, t.getOwnerOption());
enterClickAndLeave(f.ownerNameInclude);
Assert.assertEquals("train car owner include", Train.INCLUDE_OWNERS, t.getOwnerOption());
enterClickAndLeave(f.ownerNameAll);
Assert.assertEquals("train car owner all", Train.ALL_OWNERS, t.getOwnerOption());
// test car date options
enterClickAndLeave(f.builtDateAfter);
f.builtAfterTextField.setText("1956");
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("train car built after", "1956", t.getBuiltStartYear());
enterClickAndLeave(f.builtDateBefore);
f.builtBeforeTextField.setText("2010");
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("train car built before", "2010", t.getBuiltEndYear());
enterClickAndLeave(f.builtDateRange);
f.builtAfterTextField.setText("1888");
f.builtBeforeTextField.setText("2000");
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("train car built after range", "1888", t.getBuiltStartYear());
Assert.assertEquals("train car built before range", "2000", t.getBuiltEndYear());
enterClickAndLeave(f.builtDateAll);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("train car built after all", "", t.getBuiltStartYear());
Assert.assertEquals("train car built before all", "", t.getBuiltEndYear());
// test optional loco and caboose changes
enterClickAndLeave(f.change1Engine);
enterClickAndLeave(f.saveTrainButton);
// clear dialogue box
pressDialogButton(f, Bundle.getMessage("CanNotSave"), "OK");
Assert.assertEquals("loco 1 change", Train.CHANGE_ENGINES, t.getSecondLegOptions());
Assert.assertEquals("loco 1 departure name", "", t.getSecondLegStartLocationName());
// should be "Test Train Location A"
f.routePickup1Box.setSelectedIndex(1);
// should be 3 locos
f.numEngines1Box.setSelectedIndex(3);
f.modelEngine1Box.setSelectedItem("FT");
f.roadEngine1Box.setSelectedItem("UP");
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("loco 1 change", Train.CHANGE_ENGINES, t.getSecondLegOptions());
Assert.assertEquals("loco 1 departure name", "Test Train Location A", t.getSecondLegStartLocationName());
Assert.assertEquals("loco 1 number of engines", "3", t.getSecondLegNumberEngines());
Assert.assertEquals("loco 1 model", "FT", t.getSecondLegEngineModel());
Assert.assertEquals("loco 1 road", "UP", t.getSecondLegEngineRoad());
enterClickAndLeave(f.modify1Caboose);
f.routePickup1Box.setSelectedIndex(0);
f.roadCaboose1Box.setSelectedItem("NH");
enterClickAndLeave(f.saveTrainButton);
// clear dialogue box
pressDialogButton(f, Bundle.getMessage("CanNotSave"), "OK");
Assert.assertEquals("caboose 1 change", Train.ADD_CABOOSE, t.getSecondLegOptions());
f.routePickup1Box.setSelectedIndex(2);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("caboose 1 road", "NH", t.getSecondLegCabooseRoad());
enterClickAndLeave(f.helper1Service);
f.routePickup1Box.setSelectedIndex(0);
enterClickAndLeave(f.saveTrainButton);
// clear dialogue box
pressDialogButton(f, Bundle.getMessage("CanNotSave"), "OK");
Assert.assertEquals("helper 1 change", Train.HELPER_ENGINES, t.getSecondLegOptions());
// Should be "Test Train Location B"
f.routePickup1Box.setSelectedIndex(2);
// Should be "Test Train Location C"
f.routeDrop1Box.setSelectedIndex(3);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("Helper 1 start location name", "Test Train Location B", t.getSecondLegStartLocationName());
Assert.assertEquals("Helper 1 end location name", "Test Train Location C", t.getSecondLegEndLocationName());
enterClickAndLeave(f.none1);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("none 1", 0, t.getSecondLegOptions());
// now do the second set of locos and cabooses
enterClickAndLeave(f.change2Engine);
enterClickAndLeave(f.saveTrainButton);
// clear dialogue box
pressDialogButton(f, Bundle.getMessage("CanNotSave"), "OK");
Assert.assertEquals("loco 2 change", Train.CHANGE_ENGINES, t.getThirdLegOptions());
Assert.assertEquals("loco 2 departure name", "", t.getThirdLegStartLocationName());
// should be "Test Train Location A"
f.routePickup2Box.setSelectedIndex(1);
// should be 3 locos
f.numEngines2Box.setSelectedIndex(3);
f.modelEngine2Box.setSelectedItem("FT");
f.roadEngine2Box.setSelectedItem("UP");
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("loco 2 change", Train.CHANGE_ENGINES, t.getThirdLegOptions());
Assert.assertEquals("loco 2 departure name", "Test Train Location A", t.getThirdLegStartLocationName());
Assert.assertEquals("loco 2 number of engines", "3", t.getThirdLegNumberEngines());
Assert.assertEquals("loco 2 model", "FT", t.getThirdLegEngineModel());
Assert.assertEquals("loco 2 road", "UP", t.getThirdLegEngineRoad());
enterClickAndLeave(f.modify2Caboose);
f.routePickup2Box.setSelectedIndex(0);
f.roadCaboose2Box.setSelectedItem("NH");
enterClickAndLeave(f.saveTrainButton);
// clear dialogue box
pressDialogButton(f, Bundle.getMessage("CanNotSave"), "OK");
Assert.assertEquals("caboose 2 change", Train.ADD_CABOOSE, t.getThirdLegOptions());
f.routePickup2Box.setSelectedIndex(2);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("caboose 2 road", "NH", t.getThirdLegCabooseRoad());
enterClickAndLeave(f.helper2Service);
f.routePickup2Box.setSelectedIndex(0);
enterClickAndLeave(f.saveTrainButton);
// clear dialogue box
pressDialogButton(f, Bundle.getMessage("CanNotSave"), "OK");
Assert.assertEquals("helper 2 change", Train.HELPER_ENGINES, t.getThirdLegOptions());
// Should be "Test Train Location B"
f.routePickup2Box.setSelectedIndex(2);
// Should be "Test Train Location C"
f.routeDrop2Box.setSelectedIndex(3);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("Helper 2 start location name", "Test Train Location B", t.getThirdLegStartLocationName());
Assert.assertEquals("Helper 2 end location name", "Test Train Location C", t.getThirdLegEndLocationName());
enterClickAndLeave(f.none2);
enterClickAndLeave(f.saveTrainButton);
Assert.assertEquals("none 2", 0, t.getThirdLegOptions());
trainEditFrame.dispose();
f.dispose();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class OperationsCarRouterTest method loadLocationsTrainsAndCars.
private void loadLocationsTrainsAndCars() {
LocationManager lmanager = LocationManager.instance();
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
CarManager cmanager = CarManager.instance();
CarTypes ct = CarTypes.instance();
// register the car and engine types used
ct.addName("Boxcar");
ct.addName("Caboose");
ct.addName("Flat");
// create 6 locations and tracks
Location Acton = lmanager.newLocation("Acton MA");
Assert.assertEquals("Location 1 Name", "Acton MA", Acton.getName());
Assert.assertEquals("Location 1 Initial Length", 0, Acton.getLength());
Track AS1 = Acton.addTrack("Acton Siding 1", Track.SPUR);
AS1.setLength(300);
Assert.assertEquals("Location AS1 Name", "Acton Siding 1", AS1.getName());
Assert.assertEquals("Location AS1 Length", 300, AS1.getLength());
Track AS2 = Acton.addTrack("Acton Siding 2", Track.SPUR);
AS2.setLength(300);
Assert.assertEquals("Location AS2 Name", "Acton Siding 2", AS2.getName());
Assert.assertEquals("Location AS2 Length", 300, AS2.getLength());
Track AY = Acton.addTrack("Acton Yard", Track.YARD);
AY.setLength(400);
Assert.assertEquals("Location AY Name", "Acton Yard", AY.getName());
Assert.assertEquals("Location AY Length", 400, AY.getLength());
Track AI = Acton.addTrack("Acton Interchange", Track.INTERCHANGE);
AI.setLength(500);
Assert.assertEquals("Track AI Name", "Acton Interchange", AI.getName());
Assert.assertEquals("Track AI Length", 500, AI.getLength());
Assert.assertEquals("Track AI Train Directions", DIRECTION_ALL, AI.getTrainDirections());
Location Bedford = lmanager.newLocation("Bedford MA");
Assert.assertEquals("Location 1 Name", "Bedford MA", Bedford.getName());
Assert.assertEquals("Location 1 Initial Length", 0, Bedford.getLength());
Track BS1 = Bedford.addTrack("Bedford Siding 1", Track.SPUR);
BS1.setLength(300);
Assert.assertEquals("Location BS1 Name", "Bedford Siding 1", BS1.getName());
Assert.assertEquals("Location BS1 Length", 300, BS1.getLength());
Track BS2 = Bedford.addTrack("Bedford Siding 2", Track.SPUR);
BS2.setLength(300);
Assert.assertEquals("Location BS2 Name", "Bedford Siding 2", BS2.getName());
Assert.assertEquals("Location BS2 Length", 300, BS2.getLength());
Track BY = Bedford.addTrack("Bedford Yard", Track.YARD);
BY.setLength(400);
Assert.assertEquals("Location BY Name", "Bedford Yard", BY.getName());
Assert.assertEquals("Location BY Length", 400, BY.getLength());
Track BI = Bedford.addTrack("Bedford Interchange", Track.INTERCHANGE);
BI.setLength(500);
Assert.assertEquals("Track BI Name", "Bedford Interchange", BI.getName());
Assert.assertEquals("Track BI Length", 500, BI.getLength());
Location Clinton = lmanager.newLocation("Clinton MA");
Assert.assertEquals("Location 1 Name", "Clinton MA", Clinton.getName());
Assert.assertEquals("Location 1 Initial Length", 0, Clinton.getLength());
Track CS1 = Clinton.addTrack("Clinton Siding 1", Track.SPUR);
CS1.setLength(300);
Assert.assertEquals("Location CS1 Name", "Clinton Siding 1", CS1.getName());
Assert.assertEquals("Location CS1 Length", 300, CS1.getLength());
Track CS2 = Clinton.addTrack("Clinton Siding 2", Track.SPUR);
CS2.setLength(300);
Assert.assertEquals("Location CS2 Name", "Clinton Siding 2", CS2.getName());
Assert.assertEquals("Location CS2 Length", 300, BS2.getLength());
Track CY = Clinton.addTrack("Clinton Yard", Track.YARD);
CY.setLength(400);
Assert.assertEquals("Location CY Name", "Clinton Yard", CY.getName());
Assert.assertEquals("Location CY Length", 400, CY.getLength());
Track CI = Clinton.addTrack("Clinton Interchange", Track.INTERCHANGE);
CI.setLength(500);
Assert.assertEquals("Track CI Name", "Clinton Interchange", CI.getName());
Assert.assertEquals("Track CI Length", 500, CI.getLength());
Location Danbury = lmanager.newLocation("Danbury MA");
Track DS1 = Danbury.addTrack("Danbury Siding 1", Track.SPUR);
DS1.setLength(300);
Track DS2 = Danbury.addTrack("Danbury Siding 2", Track.SPUR);
DS2.setLength(300);
Track DY = Danbury.addTrack("Danbury Yard", Track.YARD);
DY.setLength(400);
Track DI = Danbury.addTrack("Danbury Interchange", Track.INTERCHANGE);
DI.setLength(500);
Location Essex = lmanager.newLocation("Essex MA");
Track ES1 = Essex.addTrack("Essex Siding 1", Track.SPUR);
ES1.setLength(300);
Track ES2 = Essex.addTrack("Essex Siding 2", Track.SPUR);
ES2.setLength(300);
Track EY = Essex.addTrack("Essex Yard", Track.YARD);
EY.setLength(400);
Track EI = Essex.addTrack("Essex Interchange", Track.INTERCHANGE);
EI.setLength(500);
Location Foxboro = lmanager.newLocation("Foxboro MA");
Track FS1 = Foxboro.addTrack("Foxboro Siding 1", Track.SPUR);
FS1.setLength(300);
Track FS2 = Foxboro.addTrack("Foxboro Siding 2", Track.SPUR);
FS2.setLength(300);
Track FY = Foxboro.addTrack("Foxboro Yard", Track.YARD);
FY.setLength(400);
Track FI = Foxboro.addTrack("Foxboro Interchange", Track.INTERCHANGE);
FI.setLength(500);
// create a local train servicing Acton
Train ActonTrain = tmanager.newTrain("Acton Local");
Route routeA = rmanager.newRoute("A");
RouteLocation rlA = routeA.addLocation(Acton);
rlA.setMaxCarMoves(10);
// set train icon coordinates
rlA.setTrainIconX(25);
rlA.setTrainIconY(250);
ActonTrain.setRoute(routeA);
// create a train with a route from Acton to Bedford
Train ActonToBedfordTrain = tmanager.newTrain("Acton to Bedford");
Route routeAB = rmanager.newRoute("AB");
routeAB.addLocation(Acton);
RouteLocation rlBedford = routeAB.addLocation(Bedford);
// set train icon coordinates
rlBedford.setTrainIconX(100);
rlBedford.setTrainIconY(250);
ActonToBedfordTrain.setRoute(routeAB);
// create a train with a route from Bedford to Clinton
Train BedfordToClintonTrain = tmanager.newTrain("Bedford to Clinton");
Route routeBC = rmanager.newRoute("BC");
routeBC.addLocation(Bedford);
RouteLocation rlchelmsford = routeBC.addLocation(Clinton);
// set train icon coordinates
rlchelmsford.setTrainIconX(175);
rlchelmsford.setTrainIconY(250);
BedfordToClintonTrain.setRoute(routeBC);
// create a train with a route from Clinton to Danbury
Train ClintonToDanburyTrain = tmanager.newTrain("Clinton to Danbury");
Route routeCD = rmanager.newRoute("CD");
routeCD.addLocation(Clinton);
RouteLocation rlDanbury = routeCD.addLocation(Danbury);
// set train icon coordinates
rlDanbury.setTrainIconX(250);
rlDanbury.setTrainIconY(250);
ClintonToDanburyTrain.setRoute(routeCD);
// create a train with a route from Danbury to Essex
Train DanburyToEssexTrain = tmanager.newTrain("Danbury to Essex");
Route routeDE = rmanager.newRoute("DE");
RouteLocation rlDanbury2 = routeDE.addLocation(Danbury);
RouteLocation rlEssex = routeDE.addLocation(Essex);
// set the number of car moves to 8 for a later test
rlDanbury2.setMaxCarMoves(8);
rlEssex.setMaxCarMoves(8);
// set train icon coordinates
rlEssex.setTrainIconX(25);
rlEssex.setTrainIconY(275);
DanburyToEssexTrain.setRoute(routeDE);
// create a train with a route from Essex to Foxboro
Train EssexToFoxboroTrain = tmanager.newTrain("Essex to Foxboro");
Route routeEF = rmanager.newRoute("EF");
routeEF.addLocation(Essex);
RouteLocation rlFoxboro = routeEF.addLocation(Foxboro);
// set train icon coordinates
rlFoxboro.setTrainIconX(100);
rlFoxboro.setTrainIconY(275);
EssexToFoxboroTrain.setRoute(routeEF);
Train BedfordToActonTrain = tmanager.newTrain("BedfordToActonToBedford");
Route BedfordToActon = RouteManager.instance().newRoute("BedfordToActonToBedford");
RouteLocation rlB2 = BedfordToActon.addLocation(Bedford);
RouteLocation rlA3 = BedfordToActon.addLocation(Acton);
RouteLocation rlB3 = BedfordToActon.addLocation(Bedford);
// increase the number of moves so all cars are used
rlB2.setMaxCarMoves(10);
rlA3.setMaxCarMoves(10);
rlB3.setMaxCarMoves(10);
BedfordToActonTrain.setRoute(BedfordToActon);
// add cars
Car c3 = cmanager.newCar("BA", "3");
c3.setTypeName("Boxcar");
c3.setLength("40");
c3.setOwner("DAB");
c3.setBuilt("1984");
Car c4 = cmanager.newCar("BB", "4");
c4.setTypeName("Flat");
c4.setLength("40");
c4.setOwner("AT");
c4.setBuilt("1-86");
c4.setMoves(2);
Car c5 = cmanager.newCar("BC", "5");
c5.setTypeName("Boxcar");
c5.setLoadName("Boxes");
c5.setLength("40");
c5.setBuilt("2000");
c5.setMoves(3);
Car c6 = cmanager.newCar("BD", "6");
c6.setTypeName("Boxcar");
c6.setLoadName("Empty");
c6.setLength("40");
c6.setBuilt("2000");
c6.setMoves(4);
Car c7 = cmanager.newCar("BA", "7");
c7.setTypeName("Boxcar");
c7.setLoadName("Boxes");
c7.setLength("4");
c7.setBuilt("2000");
c7.setMoves(5);
Car c8 = cmanager.newCar("BB", "8");
c8.setTypeName("Boxcar");
c8.setLoadName("Empty");
c8.setLength("4");
c8.setBuilt("2000");
c8.setMoves(6);
Car c9 = cmanager.newCar("BC", "9");
c9.setTypeName("Boxcar");
c9.setLoadName("Empty");
c9.setLength("4");
c9.setBuilt("2000");
c9.setMoves(7);
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class OperationsTrainsGuiTest method testTrainIcon.
@Test
public void testTrainIcon() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
EngineManager emanager = EngineManager.instance();
EngineTypes et = EngineTypes.instance();
// create and register a panel
jmri.jmrit.display.panelEditor.PanelEditor editor = new jmri.jmrit.display.panelEditor.PanelEditor("Train Test Panel");
PanelMenu.instance().addEditorPanel(editor);
// confirm panel creation
JmriJFrame f = JmriJFrame.getFrame("Train Test Panel");
Assert.assertNotNull(f);
// Place train icons on panel
Setup.setPanelName("Train Test Panel");
// Set terminate color to yellow
Setup.setTrainIconColorTerminate(TrainIcon.YELLOW);
// add engine number
Setup.setTrainIconAppendEnabled(true);
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 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 Engines on Staging tracks
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(l1, l1s1));
Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(l1, l1s2));
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(l1, l1s2));
// Define the route.
Route r1 = new Route("1", "Southbound Main Route");
Assert.assertEquals("Route Id", "1", r1.getId());
Assert.assertEquals("Route Name", "Southbound Main Route", r1.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(35);
Assert.assertEquals("Route Location 3 Id", "1r3", rl3.getId());
Assert.assertEquals("Route Location 3 Name", "South End", rl3.getName());
r1.register(rl1);
r1.register(rl2);
r1.register(rl3);
rmanager.register(r1);
// 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.setRoute(r1);
tmanager.register(train1);
Train train2 = new Train("2", "SFF");
Assert.assertEquals("Train Id", "2", train2.getId());
Assert.assertEquals("Train Name", "SFF", train2.getName());
train2.setRoute(r1);
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());
// disable build messages
tmanager.setBuildMessagesEnabled(false);
// disable build reports
tmanager.setBuildReportEnabled(false);
train1.build();
train2.build();
Assert.assertEquals("Train 1 after build", true, train1.isBuilt());
Assert.assertEquals("Train 2 after build", true, train2.isBuilt());
// check train icon location and name
TrainIcon ti1 = train1.getTrainIcon();
Assert.assertNotNull("Train 1 icon exists", ti1);
Assert.assertEquals("Train 1 icon text", "STF 5016", ti1.getText());
TrainIcon ti2 = train2.getTrainIcon();
Assert.assertNotNull("Train 2 icon exists", ti2);
Assert.assertEquals("Train 2 icon text", "SFF 5524", ti2.getText());
// icon uses TrainIconAnimation 2 pixels every 3 mSec
// X=0 to X=25 25/2 * 3 = 38 mSec
// Y=0 to Y=25 25/2 * 3 = 38 mSec
// need to wait for icon to finish moving
jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 25 && ti2.getY() == 25), "Train 2 Move 0");
Assert.assertEquals("Train 1 icon X", 25, ti1.getX());
Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
Assert.assertEquals("Train 2 icon X", 25, ti2.getX());
Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
// move the trains
train1.move();
// icon uses TrainIconAnimation 2 pixels every 3 mSec
// need to wait for icon to finish moving
jmri.util.JUnitUtil.waitFor(() -> (ti1.getX() == 75 && ti1.getY() == 25), "Train 1 Move");
Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
// train 2 shouldn't move
Assert.assertEquals("Train 2 icon X", 25, ti2.getX());
Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
train2.move();
// need to wait for icon to finish moving
jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 75 && ti2.getY() == 25), "Train 2 Move");
Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
Assert.assertEquals("Train 2 icon X", 75, ti2.getX());
Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
train2.move();
// need to wait for icon to finish moving
jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 125 && ti2.getY() == 35), "Train 2 Move 2");
Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
Assert.assertEquals("Train 2 icon X", 125, ti2.getX());
Assert.assertEquals("Train 2 icon Y", 35, ti2.getY());
editor.getTargetFrame().dispose();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class TrainTest method testSidingsYards.
// test siding and yard moves
// tests manual setting of destinations and trains for engines, cars, and cabooses.
// tests consists and kernels
public void testSidingsYards() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
EngineManager emanager = EngineManager.instance();
CarManager cmanager = CarManager.instance();
CarTypes ct = CarTypes.instance();
// register the car and engine types used
ct.addName("Boxcar");
ct.addName("Caboose");
ct.addName("Flat");
// Set up two cabooses and six box cars
Car c1 = cmanager.newCar("CP", "10");
c1.setTypeName("Caboose");
c1.setLength("32");
c1.setMoves(10);
c1.setCaboose(true);
Car c2 = cmanager.newCar("CP", "200");
c2.setTypeName("Caboose");
c2.setLength("32");
c2.setMoves(11);
c2.setCaboose(true);
Car c3 = cmanager.newCar("CP", "30");
c3.setTypeName("Boxcar");
c3.setLength("40");
c2.setMoves(12);
Car c4 = cmanager.newCar("CP", "4000");
c4.setTypeName("Boxcar");
c4.setLength("40");
c4.setMoves(13);
Car c5 = cmanager.newCar("CP", "5");
c5.setTypeName("Boxcar");
c5.setLength("40");
c5.setMoves(14);
Car c6 = cmanager.newCar("CP", "60");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(15);
Car c7 = cmanager.newCar("CP", "700");
c7.setTypeName("Flat");
c7.setLength("50");
c7.setMoves(16);
Car c8 = cmanager.newCar("CP", "8000");
c8.setTypeName("Boxcar");
c8.setLength("60");
c8.setMoves(17);
Car c9 = cmanager.newCar("CP", "9");
c9.setTypeName("Flat");
c9.setLength("40");
c9.setMoves(18);
Car c10 = cmanager.newCar("CP", "1000");
c10.setTypeName("Flat");
c10.setLength("40");
c10.setMoves(19);
// place two engines in a consist
Consist con1 = emanager.newConsist("CP");
Engine e1 = emanager.newEngine("CP", "10");
e1.setModel("GP30");
e1.setConsist(con1);
Engine e2 = emanager.newEngine("CP", "20");
e2.setModel("GP30");
e2.setConsist(con1);
// Set up a route of 3 locations: Foxboro (2 tracks, yard and siding),
// Acton (2 tracks, sidings), and Nashua (2 tracks, yards).
Location l1 = lmanager.newLocation("Foxboro");
Assert.assertEquals("Location 1 Name", "Foxboro", l1.getName());
Assert.assertEquals("Location 1 Initial Length", 0, l1.getLength());
Track l1s1 = l1.addTrack("Foxboro Siding", Track.SPUR);
l1s1.setLength(600);
Assert.assertEquals("Location 1s1 Name", "Foxboro Siding", l1s1.getName());
Assert.assertEquals("Location 1s1 LocType", "Siding", l1s1.getTrackType());
Assert.assertEquals("Location 1s1 Length", 600, l1s1.getLength());
Assert.assertEquals("Default directions", DIRECTION_ALL, l1s1.getTrainDirections());
Track l1s2 = l1.addTrack("Foxboro Yard", Track.YARD);
l1s2.setLength(400);
Assert.assertEquals("Location 1s2 Name", "Foxboro Yard", l1s2.getName());
Assert.assertEquals("Location 1s2 LocType", "Yard", l1s2.getTrackType());
Assert.assertEquals("Location 1s2 Length", 400, l1s2.getLength());
Assert.assertEquals("Location 1 Length", 1000, l1.getLength());
Location l2 = lmanager.newLocation("Acton");
Assert.assertEquals("Location 2 Name", "Acton", l2.getName());
Track l2s1 = l2.addTrack("Acton Siding 1", Track.SPUR);
l2s1.setLength(543);
l2s1.setMoves(1);
Assert.assertEquals("Location 2s1 Name", "Acton Siding 1", l2s1.getName());
Assert.assertEquals("Location 2s1 LocType", Track.SPUR, l2s1.getTrackType());
Assert.assertEquals("Location 2s1 Length", 543, l2s1.getLength());
Track l2s2 = l2.addTrack("Acton Siding 2", Track.SPUR);
l2s2.setLength(345);
Assert.assertEquals("Acton Length", 888, l2.getLength());
Location l3 = lmanager.newLocation("Nashua");
Track l3s1 = l3.addTrack("Nashua Yard 1", Track.YARD);
l3s1.setLength(301);
Track l3s2 = l3.addTrack("Nashua Yard 2", Track.YARD);
l3s2.setLength(402);
Assert.assertEquals("Location 3 Length", 703, l3.getLength());
// define the route
// set default to 6 moves per location
Setup.setCarMoves(6);
Route r1 = rmanager.newRoute("Foxboro-Acton-Nashua-Acton-Foxboro");
RouteLocation rl1 = r1.addLocation(l1);
// set the train icon coordinates
rl1.setTrainIconX(25);
rl1.setTrainIconY(225);
RouteLocation rl2 = r1.addLocation(l2);
// set the train icon coordinates
rl2.setTrainIconX(75);
rl2.setTrainIconY(225);
RouteLocation rl3 = r1.addLocation(l3);
// set the train icon coordinates
rl3.setTrainIconX(125);
rl3.setTrainIconY(225);
RouteLocation rl4 = r1.addLocation(l2);
// set the train icon coordinates
rl4.setTrainIconX(175);
rl4.setTrainIconY(225);
RouteLocation rl5 = r1.addLocation(l1);
// set the train icon coordinates
rl5.setTrainIconX(225);
rl5.setTrainIconY(225);
// don't include cars at destination
rl5.setPickUpAllowed(false);
// define the train
Train t1 = tmanager.newTrain("FF");
t1.setRoute(r1);
t1.build();
Assert.assertTrue("train built 1", t1.isBuilt());
Assert.assertEquals("should be 0 cars", 0, t1.getNumberCarsWorked());
// place the cars on the tracks
// Place cars
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(l1, l1s1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(l1, l1s1));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(l1, l1s1));
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(l1, l1s1));
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(l1, l1s1));
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(l1, l1s1));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l1, l1s1));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l1, l1s1));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(l1, l1s1));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(l1, l1s1));
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
t1.build();
Assert.assertTrue("train built 2", t1.isBuilt());
Assert.assertEquals("should be 6 cars", 6, t1.getNumberCarsWorked());
// check car destinations
Assert.assertEquals("Destination c1", "", c1.getDestinationName());
Assert.assertEquals("Destination c2", "", c2.getDestinationName());
Assert.assertEquals("Destination c3", "Acton", c3.getDestinationName());
Assert.assertEquals("Destination c4", "Nashua", c4.getDestinationName());
Assert.assertEquals("Destination c5", "Acton", c5.getDestinationName());
Assert.assertEquals("Destination c6", "Nashua", c6.getDestinationName());
Assert.assertEquals("Destination c7", "Acton", c7.getDestinationName());
Assert.assertEquals("Destination c8", "Nashua", c8.getDestinationName());
Assert.assertEquals("Destination c9", "", c9.getDestinationName());
Assert.assertEquals("Destination c10", "", c10.getDestinationName());
Assert.assertEquals("Destination e1", "", e1.getDestinationName());
// release cars from train
Assert.assertTrue("reset train", t1.reset());
Assert.assertEquals("Train reset", Train.CODE_TRAIN_RESET, t1.getStatusCode());
// set c3, c5, c6, c8, c10 destination to be Nashua
c3.setDestination(l3, l3s1);
c5.setDestination(l3, l3s1);
c6.setDestination(l3, l3s1);
c8.setDestination(l3, l3s1);
c10.setDestination(l3, l3s1);
// set c5 and c9 to be serviced by train TT
Train t2 = tmanager.newTrain("TT");
c5.setTrain(t2);
c9.setTrain(t2);
// set c6 to be serviced by train FF
c6.setTrain(t1);
// require a caboose
t1.setRequirements(Train.CABOOSE);
t1.build();
Assert.assertTrue("train built 3", t1.isBuilt());
// check car destinations
Assert.assertEquals("2 Destination c1", "Foxboro", c1.getDestinationName());
Assert.assertEquals("2 Destination c2", "", c2.getDestinationName());
Assert.assertEquals("2 Destination c3", "Nashua", c3.getDestinationName());
Assert.assertEquals("2 Destination c4", "Acton", c4.getDestinationName());
Assert.assertEquals("2 Destination c5", "Nashua", c5.getDestinationName());
Assert.assertEquals("2 Destination c6", "Nashua", c6.getDestinationName());
Assert.assertEquals("2 Destination c7", "Acton", c7.getDestinationName());
Assert.assertEquals("2 Destination c8", "Nashua", c8.getDestinationName());
Assert.assertEquals("2 Destination c9", "", c9.getDestinationName());
Assert.assertEquals("2 Destination c10", "Nashua", c10.getDestinationName());
// move and terminate the train
// to Acton
t1.move();
// to Nashua
t1.move();
// to Acton
t1.move();
// to Foxboro
t1.move();
// terminate
t1.move();
// check car destinations
Assert.assertEquals("3 Destination c1", "", c1.getDestinationName());
Assert.assertEquals("3 Destination c2", "", c2.getDestinationName());
Assert.assertEquals("3 Destination c3", "", c3.getDestinationName());
Assert.assertEquals("3 Destination c4", "", c4.getDestinationName());
Assert.assertEquals("3 Destination c5", "Nashua", c5.getDestinationName());
Assert.assertEquals("3 Destination c6", "", c6.getDestinationName());
Assert.assertEquals("3 Destination c7", "", c7.getDestinationName());
Assert.assertEquals("3 Destination c8", "", c8.getDestinationName());
Assert.assertEquals("3 Destination c9", "", c9.getDestinationName());
Assert.assertEquals("3 Destination c10", "Nashua", c10.getDestinationName());
// check car locations
Assert.assertEquals("Location c1", "Foxboro", c1.getLocationName());
Assert.assertEquals("Location c2", "Foxboro", c2.getLocationName());
Assert.assertEquals("Location c3", "Nashua", c3.getLocationName());
Assert.assertEquals("Location c4", "Acton", c4.getLocationName());
Assert.assertEquals("Location c5", "Foxboro", c5.getLocationName());
Assert.assertEquals("Location c6", "Nashua", c6.getLocationName());
Assert.assertEquals("Location c7", "Acton", c7.getLocationName());
Assert.assertEquals("Location c8", "Nashua", c8.getLocationName());
Assert.assertEquals("Location c9", "Foxboro", c9.getLocationName());
Assert.assertEquals("Location c10", "Foxboro", c10.getLocationName());
// now set caboose destinations that aren't the terminal
Assert.assertEquals("set destination c1", Track.OKAY, c1.setDestination(l2, l2s1));
Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l3, l3s1));
// train requires a caboose, should fail
t1.build();
Assert.assertFalse("train built 4", t1.isBuilt());
// Set caboose destination to be the terminal
Assert.assertEquals("set caboose destination", Track.OKAY, c2.setDestination(l1, l1s2));
t1.build();
Assert.assertTrue("train built 5", t1.isBuilt());
Assert.assertTrue("train reset 5", t1.reset());
// set the cabooses to train FF
c1.setTrain(t2);
c2.setTrain(t2);
// build should fail
t1.build();
Assert.assertFalse("train built 6", t1.isBuilt());
// set caboose to train TT
c1.setTrain(t1);
t1.build();
Assert.assertTrue("train built 7", t1.isBuilt());
// check car destinations
Assert.assertEquals("4 Destination c1", "Foxboro", c1.getDestinationName());
Assert.assertEquals("4 Destination c2", "", c2.getDestinationName());
Assert.assertEquals("4 Destination c3", "Acton", c3.getDestinationName());
Assert.assertEquals("4 Destination c4", "Nashua", c4.getDestinationName());
Assert.assertEquals("4 Destination c5", "Nashua", c5.getDestinationName());
Assert.assertEquals("4 Destination c6", "Foxboro", c6.getDestinationName());
Assert.assertEquals("4 Destination c7", "Foxboro", c7.getDestinationName());
Assert.assertEquals("4 Destination c8", "Foxboro", c8.getDestinationName());
Assert.assertEquals("4 Destination c9", "", c9.getDestinationName());
Assert.assertEquals("4 Destination c10", "Acton", c10.getDestinationName());
// add an engine
t1.setNumberEngines("2");
t1.build();
Assert.assertTrue("train built 8", t1.isBuilt());
Assert.assertEquals("5 Destination e1", "Foxboro", e1.getDestinationName());
Assert.assertEquals("5 Destination e2", "Foxboro", e2.getDestinationName());
t1.reset();
// assign lead engine to train TT
e1.setTrain(t2);
// should fail
t1.build();
Assert.assertFalse("train built 9", t1.isBuilt());
// assign one of the consist engine to train TT
e1.setTrain(t1);
// shouldn't pay attention to the other engine
e2.setTrain(t2);
// should build
t1.build();
Assert.assertTrue("train built 10", t1.isBuilt());
t1.reset();
// both engines should release
Assert.assertEquals("6 Destination e1", "", e1.getDestinationName());
Assert.assertEquals("6 Train e1", "", e1.getTrainName());
Assert.assertEquals("6 Destination e2", "", e2.getDestinationName());
Assert.assertEquals("6 Train e2", "", e2.getTrainName());
// now try setting engine destination that isn't the terminal
Assert.assertEquals("set destination e1", Track.OKAY, e1.setDestination(l2, l2s1));
// should fail
t1.build();
Assert.assertFalse("train built 11", t1.isBuilt());
e1.setDestination(l1, l1s2);
// program should ignore
e2.setDestination(l2, l2s1);
// should build
t1.build();
Assert.assertTrue("train built 12", t1.isBuilt());
// set lead engine's track to null
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, null));
// should not build
t1.build();
Assert.assertFalse("train will not build engine track is null", t1.isBuilt());
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
// should now build
t1.build();
// move and terminate the train
// to Acton
t1.move();
// to Nashua
t1.move();
// to Acton
t1.move();
// to Foxboro
t1.move();
// terminate
t1.move();
// check engine final locations
Assert.assertEquals("Location e1", "Foxboro", e1.getLocationName());
Assert.assertEquals("Location e2", "Foxboro", e2.getLocationName());
// move c7 & c8 to Foxboro to help test kernels
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l1, l1s1));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l1, l1s1));
// now test kernels
Kernel k1 = cmanager.newKernel("group of cars");
// lead car
c8.setKernel(k1);
c7.setKernel(k1);
// program should ignore
c7.setTrain(t2);
c3.setLocation(l1, l1s1);
c3.setKernel(k1);
// program should ignore (produces debug warning)
c3.setDestination(l1, l1s1);
// should build
t1.build();
Assert.assertTrue("train built 12", t1.isBuilt());
// Confirm partial build
Assert.assertEquals("Train built", Train.CODE_PARTIAL_BUILT, t1.getStatusCode());
Assert.assertEquals("12 Location c3", "Foxboro", c3.getLocationName());
Assert.assertEquals("12 Location c7", "Foxboro", c7.getLocationName());
Assert.assertEquals("12 Location c8", "Foxboro", c8.getLocationName());
Assert.assertEquals("12 Destination c3", "Nashua", c3.getDestinationName());
Assert.assertEquals("12 Destination c7", "Nashua", c7.getDestinationName());
Assert.assertEquals("12 Destination c8", "Nashua", c8.getDestinationName());
// move and terminate the train
// to Acton
t1.move();
Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
// to Nashua
t1.move();
Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
// to Acton
t1.move();
Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
// to Foxboro
t1.move();
Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
// terminate
t1.move();
Assert.assertEquals("Train Terminated", Train.CODE_TERMINATED, t1.getStatusCode());
Assert.assertEquals("13 Location c3", "Nashua", c3.getLocationName());
Assert.assertEquals("13 Location c7", "Nashua", c7.getLocationName());
Assert.assertEquals("13 Location c8", "Nashua", c8.getLocationName());
Assert.assertEquals("13 Destination c3", "", c3.getDestinationName());
Assert.assertEquals("13 Destination c7", "", c7.getDestinationName());
Assert.assertEquals("13 Destination c8", "", c8.getDestinationName());
Assert.assertEquals("13 Train c3", "", c3.getTrainName());
Assert.assertEquals("13 Train c7", "", c7.getTrainName());
Assert.assertEquals("13 Train c8", "", c8.getTrainName());
// now test car with FRED
c1.setCaboose(false);
c2.setCaboose(false);
c1.setFred(true);
c2.setFred(true);
// change the type, now Boxcar with FRED
c1.setTypeName("Boxcar");
c2.setTypeName("Boxcar");
c2.setTrain(null);
// train requires a caboose, there are none, should fail
t1.build();
Assert.assertFalse("train built 14", t1.isBuilt());
// change requirement to car with FRED
t1.setRequirements(Train.FRED);
// train requires a car with FRED, should pass
t1.build();
Assert.assertTrue("train built 15", t1.isBuilt());
// release cars
Assert.assertTrue("train reset 15", t1.reset());
// now set FRED destinations that aren't the terminal
Assert.assertEquals("set destination c1", Track.OKAY, c1.setDestination(l2, l2s1));
Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l3, l3s1));
// train requires a car with FRED, should fail
t1.build();
Assert.assertFalse("train built 16", t1.isBuilt());
// Set FRED destination to be the terminal
Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l1, l1s2));
t1.build();
Assert.assertTrue("train built 17", t1.isBuilt());
Assert.assertTrue("train reset 17", t1.reset());
// set the cars with FRED to train FF
c1.setTrain(t2);
c2.setTrain(t2);
// build should fail
t1.build();
Assert.assertFalse("train built 18", t1.isBuilt());
// set car with FRED to train TT
c2.setTrain(t1);
t1.build();
Assert.assertTrue("train built 19", t1.isBuilt());
// test car out of service
c2.setOutOfService(true);
t1.build();
Assert.assertFalse("required car is out of service", t1.isBuilt());
// test location unknown
c2.setOutOfService(false);
c2.setLocationUnknown(true);
t1.build();
Assert.assertFalse("required car location is unknown", t1.isBuilt());
c2.setLocationUnknown(false);
t1.build();
Assert.assertTrue("need car is available", t1.isBuilt());
c2.setWait(1);
t1.build();
Assert.assertFalse("required car will wait for next train", t1.isBuilt());
t1.build();
Assert.assertTrue("next train!", t1.isBuilt());
Assert.assertEquals("CP 4000 destination", "Nashua", c4.getDestinationName());
// test train and location direction controls
// place led car of kernel in Action Siding 1
c8.setLocation(l2, l2s1);
// train is north bound
l2.setTrainDirections(Location.EAST + Location.SOUTH + Location.WEST);
t1.build();
// build should fail, cars c3 and c7 which is part of c8 kernel are on the wrong track
Assert.assertFalse("Train direction test", t1.isBuilt());
// place c3 Action Siding 1
c3.setLocation(l2, l2s1);
// place c7 Action Siding 1
c7.setLocation(l2, l2s1);
t1.build();
Assert.assertTrue("Train direction test", t1.isBuilt());
Assert.assertEquals("CP 1000 destination is now Nashua", "Nashua", c10.getDestinationName());
Assert.assertEquals("CP 30 at Acton, not serviced", null, c3.getTrain());
Assert.assertEquals("CP 700 at Acton, not serviced", null, c7.getTrain());
Assert.assertEquals("CP 8000 at Acton, not serviced", null, c8.getTrain());
// restore Acton
// train is north bound
l2.setTrainDirections(Location.NORTH);
t1.build();
Assert.assertEquals("CP 1000 destination is now", "Acton", c10.getDestinationName());
Assert.assertEquals("CP 30 at Acton", t1, c3.getTrain());
Assert.assertEquals("CP 700 at Acton", t1, c7.getTrain());
Assert.assertEquals("CP 8000 at Acton", t1, c8.getTrain());
// restrict train direction at the track level
l2s2.setTrainDirections(Track.EAST + Track.SOUTH + Track.WEST);
// take one car out of kernel
c3.setKernel(null);
// place car in Action Siding 1
c3.setLocation(l2, l2s1);
// place lead car in Action Yard
c8.setLocation(l2, l2s2);
// place c7 in Action Yard
c7.setLocation(l2, l2s2);
t1.build();
Assert.assertEquals("CP 1000 destination track", "Acton Siding 1", c1.getDestinationTrackName());
Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
Assert.assertEquals("CP 30 destination track", "Nashua Yard 2", c3.getDestinationTrackName());
Assert.assertEquals("CP 4000 at Foxboro Siding", t1, c4.getTrain());
Assert.assertEquals("CP 4000 destination", "Foxboro", c4.getDestinationName());
Assert.assertEquals("CP 4000 destination track", "Foxboro Yard", c4.getDestinationTrackName());
Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
Assert.assertEquals("CP 700 at Acton, not serviced, part of kernel CP 8000", null, c7.getTrain());
Assert.assertEquals("CP 8000 at Acton, Acton Siding 2 not serviced", null, c8.getTrain());
// test train length restrictions
// only enough for the two engines, train needs a car with FRED
rl1.setMaxTrainLength(155);
t1.build();
Assert.assertFalse("Train length test, can't service car with FRED", t1.isBuilt());
// build failed after engines were assigned to train 1
Assert.assertEquals("Engine assignment ignores train length restrictions", t1, e1.getTrain());
Assert.assertEquals("Engine assignment ignores train length restrictions", t1, e2.getTrain());
Assert.assertEquals("Engine destination ignores train length restrictions", "Foxboro", e1.getDestinationName());
Assert.assertEquals("Engine destination ignores train length restrictions", "Foxboro", e2.getDestinationName());
Assert.assertEquals("Check CP30 engine length", "56", e1.getLength());
Assert.assertEquals("Check CP 200 length", "32", c2.getLength());
// enough for the two engines and a car with FRED 56 + 56 + 32 + 12(couplers) = 156
rl1.setMaxTrainLength(156);
t1.build();
Assert.assertTrue("Train length test, just enough length for engines and car with FRED", t1.isBuilt());
Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
Assert.assertEquals("CP 200 destination track", "Foxboro Siding", c2.getDestinationTrackName());
Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
Assert.assertEquals("CP 30 destination track", "Nashua Yard 1", c3.getDestinationTrackName());
Assert.assertEquals("CP 4000 at Foxboro Siding", t1, c4.getTrain());
Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
Assert.assertEquals("CP 700 at Acton, not serviced, part of kernel CP 8000", null, c7.getTrain());
Assert.assertEquals("CP 8000 at Acton, Acton Siding 2 not serviced", null, c8.getTrain());
Assert.assertEquals("CP 1000 not part of train", null, c10.getTrain());
// Increase the train length from the departure location
rl1.setMaxTrainLength(1000);
// restrict train length from Acton
rl2.setMaxTrainLength(156);
t1.build();
Assert.assertTrue("Train length test, just enough length for engines and car with FRED", t1.isBuilt());
Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
Assert.assertEquals("CP 200 destination track", "Foxboro Yard", c2.getDestinationTrackName());
Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
Assert.assertEquals("CP 30 destination track", "Foxboro Yard", c3.getDestinationTrackName());
Assert.assertEquals("CP 4000 at Foxboro Yard", t1, c4.getTrain());
Assert.assertEquals("CP 4000 destination track", "Foxboro Siding", c4.getDestinationTrackName());
Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
Assert.assertEquals("CP 1000 part of train", t1, c10.getTrain());
Assert.assertEquals("CP 1000 destination track", "Acton Siding 1", c10.getDestinationTrackName());
// test setting car's destination to Foxboro Siding
c2.setDestination(l1, l1s1);
t1.build();
Assert.assertTrue("car with FRED has destination", t1.isBuilt());
t1.reset();
// again, but now change car type serviced by Foxboro Yard
c2.setDestination(l1, l1s1);
l1s1.deleteTypeName("Boxcar");
t1.build();
Assert.assertFalse("car with FRED has destination that won't accept it", t1.isBuilt());
l1s1.addTypeName("Boxcar");
// destination Action Siding 2
c6.setDestination(l2, l2s2);
// don't allow Boxcar to drop
l2s2.deleteTypeName("Boxcar");
t1.build();
Assert.assertTrue("car with FRED has destination that will now accept it", t1.isBuilt());
Assert.assertEquals("CP 60 can't be delivered", null, c6.getTrain());
c2.setLocation(l1, null);
t1.build();
Assert.assertFalse("need car doesn't have a track assignment", t1.isBuilt());
// end testSidingsYards
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class TrainTest method testInterchange.
public void testInterchange() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
CarManager cmanager = CarManager.instance();
CarTypes ct = CarTypes.instance();
Setup.setMaxTrainLength(500);
ct.addName("Boxcar");
ct.addName("Gon");
ct.addName("Coil Car");
ct.addName("Flat Car");
ct.addName("XCaboose");
// 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("TT1OWOB");
train1.setRoute(rte1);
Train train2;
train2 = tmanager.newTrain("TT2OWOB");
train2.setRoute(rte1);
Train train3;
train3 = tmanager.newTrain("TT3OWOB");
train3.setRoute(rte1);
// Set up 7 box cars and 2 flat cars
Car c1 = new Car("BM", "Q1");
c1.setTypeName("Gon");
c1.setLength("90");
c1.setMoves(20);
c1.setLoadName("L");
c1.setWeightTons("10");
cmanager.register(c1);
Car c2 = new Car("UP", "Q2");
c2.setTypeName("Boxcar");
c2.setLength("80");
c2.setMoves(18);
c2.setWeightTons("20");
cmanager.register(c2);
Car c3 = new Car("XP", "Q3");
c3.setTypeName("Flat Car");
c3.setLength("70");
c3.setMoves(17);
c3.setWeightTons("30");
cmanager.register(c3);
Car c4 = new Car("PU", "Q4");
c4.setTypeName("Boxcar");
c4.setLength("60");
c4.setMoves(16);
c4.setWeightTons("40");
cmanager.register(c4);
Car c5 = new Car("UP", "Q5");
c5.setTypeName("Gon");
c5.setLength("50");
c5.setMoves(15);
c5.setLoadName("L");
c5.setWeightTons("50");
cmanager.register(c5);
Car c6 = new Car("CP", "Q6");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(14);
c6.setLoadName("L");
c6.setWeightTons("60");
cmanager.register(c6);
Car c7 = new Car("UP", "Q7");
c7.setTypeName("Boxcar");
c7.setLength("50");
c7.setMoves(13);
c7.setWeightTons("70");
cmanager.register(c7);
Car c8 = new Car("XP", "Q8");
c8.setTypeName("Gon");
c8.setLength("60");
c8.setMoves(12);
c8.setWeightTons("80");
cmanager.register(c8);
Car c9 = new Car("XP", "Q9");
c9.setTypeName("Flat Car");
c9.setLength("90");
c9.setMoves(11);
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.build();
train2.build();
// 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.build();
train2.build();
// 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("c5 destination", "", c5.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("c4 destination 2", "Chelmsford Interchange 2", c4.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("c4 train", train2, c4.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);
// note that train3 uses rte1, should not pickup cars at interchange
train3.build();
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", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 3", "Bedford Yard 1", 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);
// confirm that c2 and c3 have the same move counts
Assert.assertEquals("c2 move count", 18, c2.getMoves());
Assert.assertEquals("c3 move count", 18, c3.getMoves());
Assert.assertEquals("c4 move count", 17, c4.getMoves());
// bias c2
c2.setMoves(19);
train3.build();
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());
// bias c3
c3.setMoves(20);
// 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());
train3.build();
Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 5", "Chelmsford Freight 4", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 5", "", 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());
// check car move counts
Assert.assertEquals("c1 move count", 20, c1.getMoves());
Assert.assertEquals("c2 move count", 19, c2.getMoves());
Assert.assertEquals("c3 move count", 21, c3.getMoves());
Assert.assertEquals("c4 move count", 18, c4.getMoves());
Assert.assertEquals("c5 move count", 18, c5.getMoves());
Assert.assertEquals("c6 move count", 16, c6.getMoves());
Assert.assertEquals("c7 move count", 16, c7.getMoves());
Assert.assertEquals("c8 move count", 14, c8.getMoves());
Assert.assertEquals("c9 move count", 14, c9.getMoves());
Assert.assertEquals("c12 move count", 14, c12.getMoves());
c1.setMoves(19);
// 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());
train3.build();
Assert.assertEquals("c1 destination 6", "Bedford Yard 1", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 6", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 6", "", 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());
c5.setMoves(19);
c2.setMoves(20);
c1.setMoves(21);
train3.build();
Assert.assertEquals("c1 destination 7", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 7", "Chelmsford Interchange 1", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 7", "", 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", "Chelmsford Interchange 1", c2.getTrackName());
Assert.assertEquals("c3 track", "Westford Yard 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, c2 E and c5 L car weight 20/3 + 50 = 56
Assert.assertEquals("Depart Old Westford tonnage", 56, 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);
c1.setMoves(10);
c3.setMoves(21);
train3.build();
Assert.assertEquals("c1 destination 8", "", c1.getDestinationTrackName());
Assert.assertEquals("c5 destination 8", "", c5.getDestinationTrackName());
Assert.assertEquals("c3 destination 8", "", c3.getDestinationTrackName());
Assert.assertEquals("c13 destination 8", "Bedford Yard 1", c13.getDestinationTrackName());
r1l1.setPickUpAllowed(true);
r1l2.setPickUpAllowed(false);
train3.build();
Assert.assertEquals("c1 destination 9", "Chelmsford Interchange 1", c1.getDestinationTrackName());
Assert.assertEquals("c5 destination 9", "", c5.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.build();
Assert.assertEquals("c1 destination 10", "Bedford Yard 1", c1.getDestinationTrackName());
Assert.assertEquals("c5 destination 10", "", c5.getDestinationTrackName());
Assert.assertEquals("c3 destination 10", "", c3.getDestinationTrackName());
Assert.assertEquals("c13 destination 10", "Bedford Yard 1", c13.getDestinationTrackName());
train3.reset();
// try forcing c1 to Chelmsford
c1.setDestination(loc2, null);
train3.build();
Assert.assertEquals("c1 destination Old Chelmsford", "", c1.getDestinationTrackName());
// confirm that c1 isn't part of this train
Assert.assertNull("c1 isn't assigned to a train", c1.getTrain());
Assert.assertNull("c1 destination has been set to null", c1.getDestination());
Assert.assertNull("c1 next destination should be null", c1.getFinalDestination());
Assert.assertNull("c1 next destination track should be null", c1.getFinalDestinationTrack());
// try without moves
r1l2.setDropAllowed(true);
r1l2.setMaxCarMoves(0);
c1.setDestination(loc2, null);
train3.build();
Assert.assertEquals("c1 destination Old Chelmsford, no moves", "", c1.getDestinationTrackName());
c1.setDestination(null, null);
r1l2.setMaxCarMoves(6);
// Should be able to drop off caboose
r1l3.setDropAllowed(false);
train3.build();
Assert.assertEquals("c1 destination 11", "Chelmsford Interchange 1", c1.getDestinationTrackName());
Assert.assertEquals("c5 destination 11", "", c5.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);
Assert.assertEquals("Place c2 at start of route", Track.OKAY, c2.setLocation(loc1, loc1trk2));
c2.setFred(true);
train3.build();
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", "Westford Yard 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));
train3.build();
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.build();
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 Freight 4", c3.getDestinationTrackName());
Assert.assertEquals("PU Q4 destination", "Chelmsford Yard 3", 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