use of jmri.jmrit.operations.rollingstock.engines.EngineTypes in project JMRI by JMRI.
the class TrainBuilderTest method testTrainBuildOptions.
public void testTrainBuildOptions() {
EngineTypes et = new EngineTypes();
// register the car and engine types used
ct.addName("Boxcar");
ct.addName("Caboose");
ct.addName("Flat");
et.addName("Diesel");
// create 2 consists and a single engine for testing
Consist con1 = emanager.newConsist("C1");
Engine e1 = emanager.newEngine("UP", "1");
e1.setModel("GP30");
e1.setOwner("AT");
e1.setBuilt("1957");
e1.setConsist(con1);
e1.setMoves(5);
Engine e2 = emanager.newEngine("SP", "2");
e2.setModel("GP30");
e2.setOwner("AT");
e2.setBuilt("1957");
e2.setConsist(con1);
e2.setMoves(5);
// one engine
Engine e3 = emanager.newEngine("SP", "3");
e3.setModel("GP40");
e3.setOwner("DAB");
e3.setBuilt("1957");
Consist con2 = emanager.newConsist("C2");
Engine e4 = emanager.newEngine("UP", "10");
e4.setModel("GP40");
e4.setOwner("DAB");
e4.setBuilt("1944");
e4.setConsist(con2);
e4.setMoves(20);
Engine e5 = emanager.newEngine("SP", "20");
e5.setModel("GP40");
e5.setOwner("DAB");
e5.setBuilt("1944");
e5.setConsist(con2);
e5.setMoves(20);
// 3 engine consist
Consist con3 = emanager.newConsist("C3");
Engine e6 = emanager.newEngine("UP", "100");
e6.setModel("GP40");
e6.setOwner("DAB");
e6.setBuilt("1944");
e6.setConsist(con3);
e6.setMoves(2);
Engine e7 = emanager.newEngine("SP", "200");
e7.setModel("GP40");
e7.setOwner("DAB");
e7.setBuilt("1944");
e7.setConsist(con3);
e7.setMoves(2);
Engine e8 = emanager.newEngine("SP", "300");
e8.setModel("GP40");
e8.setOwner("DAB");
e8.setBuilt("1944");
e8.setConsist(con3);
e8.setMoves(2);
// Set up three cabooses and six box cars
Car c1 = cmanager.newCar("PU", "1");
c1.setTypeName("Caboose");
c1.setLength("32");
c1.setMoves(10);
c1.setOwner("AT");
c1.setBuilt("1943");
c1.setCaboose(true);
Car c2 = cmanager.newCar("SP", "2");
c2.setTypeName("Caboose");
c2.setLength("30");
c2.setMoves(5);
c2.setOwner("DAB");
c2.setBuilt("1957");
c2.setCaboose(true);
Car c3 = cmanager.newCar("UP", "3");
c3.setTypeName("Caboose");
c3.setLength("33");
c3.setMoves(0);
c3.setOwner("DAB");
c3.setBuilt("1944");
c3.setCaboose(true);
Car c4 = cmanager.newCar("UP", "4");
c4.setTypeName("Boxcar");
c4.setLength("40");
c4.setMoves(16);
c4.setOwner("DAB");
c4.setBuilt("1958");
c4.setFred(true);
Car c5 = cmanager.newCar("SP", "5");
c5.setTypeName("Boxcar");
c5.setLength("40");
c5.setMoves(8);
c5.setOwner("DAB");
c5.setBuilt("1958");
c5.setFred(true);
Car c6 = cmanager.newCar("NH", "6");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(2);
c6.setOwner("DAB");
c6.setBuilt("1958");
c6.setFred(true);
Car c7 = cmanager.newCar("UP", "7");
c7.setTypeName("Flat");
c7.setLength("40");
c7.setMoves(5);
c7.setOwner("DAB");
c7.setBuilt("1958");
Car c8 = cmanager.newCar("SP", "8");
c8.setTypeName("Boxcar");
c8.setLength("40");
c8.setMoves(4);
c8.setOwner("DAB");
c8.setBuilt("1958");
Car c9 = cmanager.newCar("NH", "9");
c9.setTypeName("Boxcar");
c9.setLength("40");
c9.setMoves(3);
c9.setOwner("DAB");
c9.setBuilt("1944");
Car c10 = cmanager.newCar("NH", "10");
c10.setTypeName("Boxcar");
c10.setLength("40");
c10.setMoves(10);
c10.setOwner("DAB");
c10.setBuilt("1958");
Car c11 = cmanager.newCar("SP", "11");
c11.setTypeName("Boxcar");
c11.setLength("40");
c11.setMoves(3);
c11.setOwner("DAB");
c11.setBuilt("1958");
// Create 5 locations
Location loc1 = lmanager.newLocation("Harvard");
Track loc1trk1 = loc1.addTrack("Harvard Yard", Track.YARD);
loc1trk1.setLength(1000);
Track loc1trk2 = loc1.addTrack("Harvard Yard 2", Track.YARD);
loc1trk2.setLength(1000);
Location loc2 = lmanager.newLocation("Arlington");
Track loc2trk1 = loc2.addTrack("Arlington Yard", Track.YARD);
loc2trk1.setLength(1000);
Location loc3 = lmanager.newLocation("Boston");
Track loc3trk1 = loc3.addTrack("Boston Yard", Track.YARD);
loc3trk1.setLength(1000);
Track loc3trk2 = loc3.addTrack("Boston Yard 2", Track.YARD);
loc3trk2.setLength(1000);
Location loc4 = lmanager.newLocation("Chelmsford");
Track loc4trk1 = loc4.addTrack("Chelmsford Yard", Track.YARD);
loc4trk1.setLength(1000);
Track loc4trk2 = loc4.addTrack("Chelmsford Yard 2", Track.YARD);
loc4trk2.setLength(1000);
Location loc5 = lmanager.newLocation("Westford");
Track loc5trk1 = loc5.addTrack("Westford Yard", Track.YARD);
loc5trk1.setLength(1000);
Track loc5trk2 = loc5.addTrack("Westford Yard 2", Track.YARD);
loc5trk2.setLength(1000);
// Create route with 4 location
Route rte1 = rmanager.newRoute("Route 2 Westford");
rte1.addLocation(loc1);
RouteLocation rl2 = rte1.addLocation(loc2);
// set the train icon coordinates
rl2.setTrainIconX(175);
rl2.setTrainIconY(150);
RouteLocation rl3 = rte1.addLocation(loc3);
// set the train icon coordinates
rl3.setTrainIconX(25);
rl3.setTrainIconY(175);
RouteLocation rl4 = rte1.addLocation(loc4);
// set the train icon coordinates
rl4.setTrainIconX(75);
rl4.setTrainIconY(175);
// don't allow pickup or drops at Arlington
rl2.setDropAllowed(false);
rl2.setPickUpAllowed(false);
// Create train
Train train1 = tmanager.newTrain("TestTrainBuildOptions");
train1.setRoute(rte1);
// train skips Boston
train1.addTrainSkipsLocation(rl3.getId());
// Place cars
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc2, loc2trk1));
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc5, loc5trk1));
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc2, loc2trk1));
Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc2, loc2trk1));
// set c9 destination not part of train's route
Assert.assertEquals("Destination c9", Track.OKAY, c9.setDestination(loc5, loc5trk1));
// Place engines
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e6", Track.OKAY, e6.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e7", Track.OKAY, e7.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(loc1, loc1trk1));
train1.setRequirements(Train.CABOOSE);
train1.setNumberEngines("2");
train1.setOwnerOption(Train.ALL_OWNERS);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 1", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 1", "Chelmsford Yard 2", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 1", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 1", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 1", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 1", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 1", "Chelmsford Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 1", "Chelmsford Yard 2", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 1", "Westford Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 1", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 1", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 1", "Chelmsford Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 1", "Chelmsford Yard", e2.getDestinationTrackName());
Assert.assertEquals("e3 destination 1", "", e3.getDestinationTrackName());
Assert.assertEquals("e4 destination 1", "", e4.getDestinationTrackName());
Assert.assertEquals("e5 destination 1", "", e5.getDestinationTrackName());
Assert.assertEquals("e6 destination 1", "", e6.getDestinationTrackName());
Assert.assertEquals("e7 destination 1", "", e7.getDestinationTrackName());
Assert.assertEquals("e8 destination 1", "", e8.getDestinationTrackName());
// Allow c9 to be used
// set c9 destination Chelmsford
Assert.assertEquals("Destination c9", Track.OKAY, c9.setDestination(loc4, null));
// check that train direction and track direction feature works properly
loc1trk2.setTrainDirections(Location.SOUTH);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build test track direction", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 1a", "Chelmsford Yard", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 1a", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 1a", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 1a", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 1a", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 1a", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 1a", "Chelmsford Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 1a", "Chelmsford Yard 2", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 1a", "Chelmsford Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 1a", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 1a", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 1a", "Chelmsford Yard 2", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 1a", "Chelmsford Yard 2", e2.getDestinationTrackName());
Assert.assertEquals("e3 destination 1a", "", e3.getDestinationTrackName());
Assert.assertEquals("e4 destination 1a", "", e4.getDestinationTrackName());
Assert.assertEquals("e5 destination 1a", "", e5.getDestinationTrackName());
Assert.assertEquals("e6 destination 1a", "", e6.getDestinationTrackName());
Assert.assertEquals("e7 destination 1a", "", e7.getDestinationTrackName());
Assert.assertEquals("e8 destination 1a", "", e8.getDestinationTrackName());
loc1trk2.setTrainDirections(Location.NORTH);
train1.addOwnerName("DAB");
train1.setOwnerOption(Train.INCLUDE_OWNERS);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build 2", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 2", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 2", "Chelmsford Yard", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 2", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 2", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 2", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 2", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 2", "Chelmsford Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 2", "Chelmsford Yard 2", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 2", "Chelmsford Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 2", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 2", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 2", "", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 2", "", e2.getDestinationTrackName());
Assert.assertEquals("e3 destination 2", "", e3.getDestinationTrackName());
Assert.assertEquals("e4 destination 2", "Chelmsford Yard 2", e4.getDestinationTrackName());
Assert.assertEquals("e5 destination 2", "Chelmsford Yard 2", e5.getDestinationTrackName());
Assert.assertEquals("e6 destination 2", "", e6.getDestinationTrackName());
Assert.assertEquals("e7 destination 2", "", e7.getDestinationTrackName());
Assert.assertEquals("e8 destination 2", "", e8.getDestinationTrackName());
// test that build fails if Diesel type is not allowed
train1.deleteTypeName("Diesel");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build 3", false, train1.isBuilt());
// restore type Diesel and allow all owners
train1.addTypeName("Diesel");
train1.setOwnerOption(Train.ALL_OWNERS);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build 4", true, train1.isBuilt());
// Only allow rolling stock built after 1956
train1.setBuiltStartYear("1956");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build 5", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 5", "Chelmsford Yard", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 5", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 5", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 5", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 5", "Chelmsford Yard 2", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 5", "Chelmsford Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 5", "", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 5", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 5", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 5", "Chelmsford Yard 2", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 5", "Chelmsford Yard 2", e2.getDestinationTrackName());
Assert.assertEquals("e3 destination 5", "", e3.getDestinationTrackName());
Assert.assertEquals("e4 destination 5", "", e4.getDestinationTrackName());
Assert.assertEquals("e5 destination 5", "", e5.getDestinationTrackName());
Assert.assertEquals("e6 destination 5", "", e6.getDestinationTrackName());
Assert.assertEquals("e7 destination 5", "", e7.getDestinationTrackName());
Assert.assertEquals("e8 destination 5", "", e8.getDestinationTrackName());
train1.reset();
}
use of jmri.jmrit.operations.rollingstock.engines.EngineTypes in project JMRI by JMRI.
the class TrainBuilderTest method testEngineChanges.
/**
* The program allows up to two engine changes in a train's route.
*/
public void testEngineChanges() {
EngineTypes et = new EngineTypes();
et.addName("Diesel");
// 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);
Location westford = lmanager.newLocation("Westford");
Track loc5trk1 = westford.addTrack("Westford Yard", Track.YARD);
loc5trk1.setLength(1000);
// create a 2 engine consist for departure
Consist con1 = emanager.newConsist("C1");
Engine e1 = emanager.newEngine("UP", "1");
e1.setModel("GP30");
e1.setOwner("AT");
e1.setBuilt("1957");
e1.setConsist(con1);
e1.setMoves(5);
Engine e2 = emanager.newEngine("SP", "2");
e2.setModel("GP30");
e2.setOwner("AT");
e2.setBuilt("1957");
e2.setConsist(con1);
e2.setMoves(5);
// one engine
Engine e3 = emanager.newEngine("SP", "3");
e3.setModel("GP40");
e3.setBuilt("1957");
Engine e4 = emanager.newEngine("UP", "10");
e4.setModel("GP40");
e4.setBuilt("1944");
e4.setMoves(20);
Engine e5 = emanager.newEngine("SP", "20");
e5.setModel("GP40");
e5.setBuilt("1944");
e5.setMoves(20);
Engine e6 = emanager.newEngine("UP", "100");
e6.setModel("GP40");
e6.setBuilt("1944");
e6.setMoves(2);
Engine e7 = emanager.newEngine("SP", "200");
e7.setModel("GP40");
e7.setBuilt("1944");
e7.setMoves(2);
Engine e8 = emanager.newEngine("SP", "300");
e8.setModel("GP40");
e8.setBuilt("1944");
e8.setMoves(20);
Engine e9 = emanager.newEngine("SP", "400");
e9.setModel("GP30");
e9.setBuilt("1944");
e9.setMoves(2);
// Place engines
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(harvard, loc1trk1));
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(harvard, loc1trk1));
Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(arlington, loc2trk1));
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(arlington, loc2trk1));
Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(chelmsford, loc4trk1));
Assert.assertEquals("Place e6", Track.OKAY, e6.setLocation(chelmsford, loc4trk1));
Assert.assertEquals("Place e7", Track.OKAY, e7.setLocation(chelmsford, loc4trk1));
Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(chelmsford, loc4trk1));
Assert.assertEquals("Place e9", Track.OKAY, e9.setLocation(chelmsford, loc4trk1));
Route rte1 = rmanager.newRoute("Route Harvard to Westford");
rte1.addLocation(harvard);
RouteLocation rlArlington = rte1.addLocation(arlington);
rte1.addLocation(boston);
RouteLocation rlChelmsford = rte1.addLocation(chelmsford);
rte1.addLocation(westford);
// Create train
Train train1 = tmanager.newTrain("TestEngineChanges");
train1.setRoute(rte1);
// depart with 2 engines
train1.setBuildConsistEnabled(true);
train1.setNumberEngines("2");
// change out 2 engines with 1 engine at Arlington
train1.setSecondLegOptions(Train.CHANGE_ENGINES);
train1.setSecondLegNumberEngines("1");
train1.setSecondLegStartLocation(rlArlington);
train1.setSecondLegEngineRoad("UP");
train1.setSecondLegEngineModel("GP40");
// change out 1 engine with 3 "SP" engines at Chelmsford
train1.setThirdLegOptions(Train.CHANGE_ENGINES);
train1.setThirdLegNumberEngines("3");
train1.setThirdLegStartLocation(rlChelmsford);
train1.setThirdLegEngineRoad("SP");
train1.setThirdLegEngineModel("GP40");
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// confirm that the specified engines were assigned to the train
Assert.assertEquals("e1 assigned to train", arlington, e1.getDestination());
Assert.assertEquals("e2 assigned to train", arlington, e2.getDestination());
Assert.assertEquals("e3 not assigned to train due to road name", null, e3.getDestination());
Assert.assertEquals("e4 assigned to train", chelmsford, e4.getDestination());
Assert.assertEquals("e5 assigned to train", westford, e5.getDestination());
Assert.assertEquals("e6 not assigned to train due to road name", null, e6.getDestination());
Assert.assertEquals("e7 assigned to train", westford, e7.getDestination());
Assert.assertEquals("e8 assigned to train", westford, e8.getDestination());
Assert.assertEquals("e9 not assigned to train due to model type", null, e9.getDestination());
// remove needed engine at Arlington
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(null, null));
new TrainBuilder().build(train1);
Assert.assertEquals("Train should not build", false, train1.isBuilt());
// restore engine
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(arlington, loc2trk1));
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// remove needed engine at Chelmsford
Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(null, null));
new TrainBuilder().build(train1);
Assert.assertEquals("Train should not build", false, train1.isBuilt());
// restore engine
Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(chelmsford, loc4trk1));
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
}
use of jmri.jmrit.operations.rollingstock.engines.EngineTypes in project JMRI by JMRI.
the class TrainBuilderTest method testAggressiveBuildOption.
public void testAggressiveBuildOption() {
Setup.setBuildAggressive(true);
Setup.setStagingTrackImmediatelyAvail(false);
EngineTypes et = EngineTypes.instance();
// register the car and engine types used
ct.addName("Boxcar");
ct.addName("Caboose");
ct.addName("Flat");
et.addName("Diesel");
// create 2 consists and a single engine for testing
Consist con1 = emanager.newConsist("C1");
Engine e1 = emanager.newEngine("UP", "1");
e1.setModel("GP30");
e1.setOwner("AT");
e1.setBuilt("1957");
e1.setConsist(con1);
e1.setMoves(5);
Engine e2 = emanager.newEngine("SP", "2");
e2.setModel("GP30");
e2.setOwner("AT");
e2.setBuilt("1957");
e2.setConsist(con1);
e2.setMoves(5);
// one engine
Engine e3 = emanager.newEngine("SP", "3");
e3.setModel("GP40");
e3.setOwner("DAB");
e3.setBuilt("1957");
Consist con2 = emanager.newConsist("C2");
Engine e4 = emanager.newEngine("UP", "10");
e4.setModel("GP40");
e4.setOwner("DAB");
e4.setBuilt("1944");
e4.setConsist(con2);
e4.setMoves(20);
Engine e5 = emanager.newEngine("SP", "20");
e5.setModel("GP40");
e5.setOwner("DAB");
e5.setBuilt("1944");
e5.setConsist(con2);
e5.setMoves(20);
// 3 engine consist
Consist con3 = emanager.newConsist("C3");
Engine e6 = emanager.newEngine("UP", "100");
e6.setModel("GP40");
e6.setOwner("DAB");
e6.setBuilt("1944");
e6.setConsist(con3);
e6.setMoves(2);
Engine e7 = emanager.newEngine("SP", "200");
e7.setModel("GP40");
e7.setOwner("DAB");
e7.setBuilt("1944");
e7.setConsist(con3);
e7.setMoves(2);
Engine e8 = emanager.newEngine("SP", "300");
e8.setModel("GP40");
e8.setOwner("DAB");
e8.setBuilt("1944");
e8.setConsist(con3);
e8.setMoves(2);
// Set up cars
Car c1 = cmanager.newCar("PU", "13");
c1.setTypeName("Caboose");
c1.setLength("32");
c1.setMoves(10);
c1.setOwner("AT");
c1.setBuilt("1943");
c1.setCaboose(true);
Car c2 = cmanager.newCar("SP", "23");
c2.setTypeName("Boxcar");
c2.setLength("30");
c2.setMoves(5);
c2.setOwner("DAB");
c2.setBuilt("1957");
Car c3 = cmanager.newCar("UP", "33");
c3.setTypeName("Boxcar");
c3.setLength("33");
c3.setMoves(0);
c3.setOwner("DAB");
c3.setBuilt("1944");
Car c4 = cmanager.newCar("UP", "43");
c4.setTypeName("Boxcar");
c4.setLength("40");
c4.setMoves(16);
c4.setOwner("DAB");
c4.setBuilt("1958");
Car c5 = cmanager.newCar("SP", "53");
c5.setTypeName("Boxcar");
c5.setLength("40");
c5.setMoves(8);
c5.setOwner("DAB");
c5.setBuilt("1958");
Car c6 = cmanager.newCar("NH", "63");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(2);
c6.setOwner("DAB");
c6.setBuilt("1958");
Car c7 = cmanager.newCar("UP", "73");
c7.setTypeName("Flat");
c7.setLength("40");
c7.setMoves(5);
c7.setOwner("DAB");
c7.setBuilt("1958");
Car c8 = cmanager.newCar("SP", "83");
c8.setTypeName("Boxcar");
c8.setLength("40");
c8.setMoves(4);
c8.setOwner("DAB");
c8.setBuilt("1958");
Car c9 = cmanager.newCar("NH", "93");
c9.setTypeName("Boxcar");
c9.setLength("40");
c9.setMoves(3);
c9.setOwner("DAB");
c9.setBuilt("1944");
Car c10 = cmanager.newCar("NH", "103");
c10.setTypeName("Boxcar");
c10.setLength("40");
c10.setMoves(10);
c10.setOwner("DAB");
c10.setBuilt("1958");
Car c11 = cmanager.newCar("SP", "113");
c11.setTypeName("Boxcar");
c11.setLength("40");
c11.setMoves(3);
c11.setOwner("DAB");
c11.setBuilt("1958");
// Create 5 locations
Location loc1 = lmanager.newLocation("New Harvard");
Track loc1trk1 = loc1.addTrack("Harvard Yard 1", Track.YARD);
loc1trk1.setLength(1000);
Track loc1trk2 = loc1.addTrack("Harvard Yard 2", Track.YARD);
loc1trk2.setLength(1000);
Location loc2 = lmanager.newLocation("New Arlington");
Track loc2trk1 = loc2.addTrack("Arlington Siding", Track.SPUR);
loc2trk1.setLength(50);
Location loc3 = lmanager.newLocation("New Boston");
Track loc3trk1 = loc3.addTrack("Boston Yard 1", Track.YARD);
loc3trk1.setLength(50);
Track loc3trk2 = loc3.addTrack("Boston Yard 2", Track.YARD);
loc3trk2.setLength(50);
Location loc4 = lmanager.newLocation("New Chelmsford");
Track loc4trk1 = loc4.addTrack("Chelmsford Yard 1", Track.YARD);
loc4trk1.setLength(50);
Track loc4trk2 = loc4.addTrack("Chelmsford Yard 2", Track.YARD);
loc4trk2.setLength(50);
Location loc5 = lmanager.newLocation("New Westford");
Track loc5trk1 = loc5.addTrack("Westford Yard 1", Track.YARD);
loc5trk1.setLength(1000);
Track loc5trk2 = loc5.addTrack("Westford Yard 2", Track.YARD);
loc5trk2.setLength(1000);
// Create route with 5 location
Route rte1 = rmanager.newRoute("Route 3 Westford");
rte1.addLocation(loc1);
rte1.addLocation(loc2);
rte1.addLocation(loc3);
rte1.addLocation(loc4);
rte1.addLocation(loc5);
// Create train
Train train1 = tmanager.newTrain("TestAggressiveBuildOption");
train1.setRoute(rte1);
// Place cars
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc2, loc2trk1));
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, loc1trk1));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc3, loc3trk1));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc3, loc3trk2));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc4, loc4trk1));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc4, loc4trk2));
Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1));
// Place engines
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e6", Track.OKAY, e6.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e7", Track.OKAY, e7.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(loc1, loc1trk1));
train1.setRequirements(Train.CABOOSE);
train1.setNumberEngines("3");
train1.setOwnerOption(Train.ALL_OWNERS);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 1", "Westford Yard 2", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 1", "Westford Yard 1", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 1", "Westford Yard 2", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 1", "Boston Yard 1", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 1", "Arlington Siding", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 1", "Westford Yard 2", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 1", "Westford Yard 2", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 1", "Westford Yard 1", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 1", "", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 1", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 1", "Westford Yard 2", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 1", "", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 1", "", e2.getDestinationTrackName());
Assert.assertEquals("e3 destination 1", "", e3.getDestinationTrackName());
Assert.assertEquals("e4 destination 1", "", e4.getDestinationTrackName());
Assert.assertEquals("e5 destination 1", "", e5.getDestinationTrackName());
Assert.assertEquals("e6 destination 1", "Westford Yard 1", e6.getDestinationTrackName());
Assert.assertEquals("e7 destination 1", "Westford Yard 1", e7.getDestinationTrackName());
Assert.assertEquals("e8 destination 1", "Westford Yard 1", e8.getDestinationTrackName());
// test departing from staging in aggressive mode
Assert.assertTrue(train1.reset());
loc1trk1.setTrackType(Track.STAGING);
loc1trk2.setTrackType(Track.STAGING);
loc1.setLocationOps(Location.STAGING);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertFalse("Train 1 After Build from staging, eight loco on departure track", train1.isBuilt());
// move locos to other departure track
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(loc1, loc1trk2));
train1.reset();
new TrainBuilder().build(train1);
Assert.assertTrue("Train 1 After Build from staging, three loco on departure track", train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 2", "Westford Yard 2", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 2", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 2", "Westford Yard 2", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 2", "Boston Yard 2", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 2", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 2", "Arlington Siding", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 2", "Westford Yard 1", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 2", "Westford Yard 2", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 2", "Westford Yard 2", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 2", "Westford Yard 1", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 2", "Chelmsford Yard 1", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 2", "", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 2", "", e2.getDestinationTrackName());
Assert.assertEquals("e3 destination 2", "", e3.getDestinationTrackName());
Assert.assertEquals("e4 destination 2", "", e4.getDestinationTrackName());
Assert.assertEquals("e5 destination 2", "", e5.getDestinationTrackName());
Assert.assertEquals("e6 destination 2", "Westford Yard 1", e6.getDestinationTrackName());
Assert.assertEquals("e7 destination 2", "Westford Yard 1", e7.getDestinationTrackName());
Assert.assertEquals("e8 destination 2", "Westford Yard 1", e8.getDestinationTrackName());
// test train move to a specific location
Assert.assertFalse("Old Harvard is not part of this trains route", train1.move("Old Harvard"));
Assert.assertFalse("Train departs New Harvard already there", train1.move("New Harvard"));
Assert.assertTrue("Next location in train's route is New Arlington", train1.move("New Arlington"));
Assert.assertFalse("Train is at New Arlington", train1.move("New Arlington"));
// next location is New Boston, skip it and go directly to New Chelmsford
Assert.assertTrue("New Chelmsford is in train's route", train1.move("New Chelmsford"));
Assert.assertTrue("Next location in train's route is New Westford", train1.move("New Westford"));
Assert.assertFalse("Train is at New Westford last location in train's route", train1.move("New Westford"));
// terminate train
train1.move();
// now try with a train returning to staging, test alternate track feature
// Create train
Train train2 = tmanager.newTrain("Westford to Harvard Aggressive");
Route rte2 = rmanager.copyRoute(rte1, "Route 4 Harvard", true);
train2.setRoute(rte2);
train2.setRequirements(Train.CABOOSE);
train2.setNumberEngines("3");
// add 2 yard tracks to siding at Arlington
Track loc2trk2 = loc2.addTrack("Arlington Yard 1", Track.YARD);
// only enough room for one car
loc2trk2.setLength(50);
Track loc2trk3 = loc2.addTrack("Arlington Alternate Track", Track.SPUR);
// only enough room for two cars
loc2trk3.setLength(100);
// set the alternate for Arlington siding
loc2trk1.setAlternateTrack(loc2trk3);
// send cars to Arlington siding
c3.setFinalDestination(loc2);
c3.setFinalDestinationTrack(loc2trk1);
c8.setFinalDestination(loc2);
c8.setFinalDestinationTrack(loc2trk1);
c9.setFinalDestination(loc2);
c9.setFinalDestinationTrack(loc2trk1);
c11.setFinalDestination(loc2);
c11.setFinalDestinationTrack(loc2trk1);
train2.reset();
new TrainBuilder().build(train2);
Assert.assertTrue("Train 2 returns to staging", train2.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 3", "Harvard Yard 1", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 3", "Arlington Alternate Track", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 3", "Harvard Yard 1", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 3", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 3", "Harvard Yard 1", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 3", "Chelmsford Yard 2", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 3", "Arlington Yard 1", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 3", "Arlington Alternate Track", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 3", "Boston Yard 1", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 3", "Arlington Siding", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 3", "", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 3", "", e2.getDestinationTrackName());
Assert.assertEquals("e3 destination 3", "", e3.getDestinationTrackName());
Assert.assertEquals("e4 destination 3", "", e4.getDestinationTrackName());
Assert.assertEquals("e5 destination 3", "", e5.getDestinationTrackName());
Assert.assertEquals("e6 destination 3", "Harvard Yard 1", e6.getDestinationTrackName());
Assert.assertEquals("e7 destination 3", "Harvard Yard 1", e7.getDestinationTrackName());
Assert.assertEquals("e8 destination 3", "Harvard Yard 1", e8.getDestinationTrackName());
// check that cars on alternate track are sent to Arlington Siding
Assert.assertEquals("next dest Arlingtion", loc2, c3.getFinalDestination());
Assert.assertEquals("next dest track Arlingtion Siding", loc2trk1, c3.getFinalDestinationTrack());
Assert.assertEquals("next dest Arlingtion", loc2, c8.getFinalDestination());
Assert.assertEquals("next dest track Arlingtion Siding", loc2trk1, c8.getFinalDestinationTrack());
Assert.assertEquals("next dest Arlingtion", loc2, c9.getFinalDestination());
Assert.assertEquals("next dest track Arlingtion Siding", loc2trk1, c9.getFinalDestinationTrack());
Assert.assertEquals("next dest null", null, c11.getFinalDestination());
Assert.assertEquals("next dest track null", null, c11.getFinalDestinationTrack());
// test train move to a an exact location
Assert.assertFalse("Old Harvard is not part of this trains route", train2.moveToNextLocation("Old Harvard"));
Assert.assertFalse("New Harvard is the last location in this trains route", train2.moveToNextLocation("New Harvard"));
Assert.assertFalse("New Boston is the 3rd to last location in this trains route", train2.moveToNextLocation("New Boston"));
Assert.assertFalse("New Westford is the current location in this trains route", train2.moveToNextLocation("New Westford"));
Assert.assertFalse("New Arlington is the 2nd to last location in this trains route", train2.moveToNextLocation("New Arlington"));
Assert.assertTrue("New Chelmsford is the next location in this trains route", train2.moveToNextLocation("New Chelmsford"));
Assert.assertTrue("New Boston is the next location in this trains route", train2.moveToNextLocation("New Boston"));
Assert.assertTrue("New Arlington is the next location in this trains route", train2.moveToNextLocation("New Arlington"));
Assert.assertTrue("New Harvard is the next location in this trains route", train2.moveToNextLocation("New Harvard"));
Assert.assertFalse("Train is at New Harvard", train2.moveToNextLocation("New Harvard"));
// terminate train
train2.move();
// now test train returning to staging
rte1.addLocation(loc1);
train1.reset();
new TrainBuilder().build(train1);
// should fail, can't return to staging track
Assert.assertEquals("Train 1 departing and returning to staging", false, train1.isBuilt());
// change mode
Setup.setStagingTrackImmediatelyAvail(true);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train 1 departing and returning to staging", true, train1.isBuilt());
train1.terminate();
// check car locations
Assert.assertEquals("c1 location", "Harvard Yard 1", c1.getTrackName());
Assert.assertEquals("c2 location", "Harvard Yard 2", c2.getTrackName());
Assert.assertEquals("c3 location", "Arlington Alternate Track", c3.getTrackName());
Assert.assertEquals("c4 location", "Boston Yard 2", c4.getTrackName());
Assert.assertEquals("c5 location", "Harvard Yard 2", c5.getTrackName());
Assert.assertEquals("c6 location", "Westford Yard 1", c6.getTrackName());
Assert.assertEquals("c7 location", "Harvard Yard 1", c7.getTrackName());
Assert.assertEquals("c8 location", "Arlington Siding", c8.getTrackName());
Assert.assertEquals("c9 location", "Arlington Alternate Track", c9.getTrackName());
Assert.assertEquals("c10 location", "Chelmsford Yard 1", c10.getTrackName());
Assert.assertEquals("c11 location", "Westford Yard 2", c11.getTrackName());
Assert.assertEquals("e1 location", "Harvard Yard 2", e1.getTrackName());
Assert.assertEquals("e2 location", "Harvard Yard 2", e2.getTrackName());
Assert.assertEquals("e3 location", "Harvard Yard 2", e3.getTrackName());
Assert.assertEquals("e4 location", "Harvard Yard 2", e4.getTrackName());
Assert.assertEquals("e5 location", "Harvard Yard 2", e5.getTrackName());
Assert.assertEquals("e6 location", "Harvard Yard 1", e6.getTrackName());
Assert.assertEquals("e7 location", "Harvard Yard 1", e7.getTrackName());
Assert.assertEquals("e8 location", "Harvard Yard 1", e8.getTrackName());
}
use of jmri.jmrit.operations.rollingstock.engines.EngineTypes in project JMRI by JMRI.
the class JUnitOperationsUtil method initOperationsData.
/**
* Populate the Operations Managers with a common set of data for tests.
*/
public static void initOperationsData() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
EngineManager emanager = EngineManager.instance();
CarManager cmanager = CarManager.instance();
CarTypes ct = CarTypes.instance();
EngineTypes et = EngineTypes.instance();
// 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");
emanager.register(e1);
Engine e2 = new Engine("PC", "5019");
e2.setModel("GP40");
e2.setConsist(con1);
e2.setMoves(321);
e2.setOwner("AT");
e2.setBuilt("1990");
emanager.register(e2);
Engine e3 = new Engine("PC", "5524");
e3.setModel("SD45");
e3.setConsist(con2);
e3.setOwner("DAB");
e3.setBuilt("1980");
emanager.register(e3);
Engine e4 = new Engine("PC", "5559");
e4.setModel("SD45");
e4.setConsist(con2);
e4.setOwner("DAB");
e4.setBuilt("1980");
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);
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);
cmanager.register(c2);
Car c3 = new Car("CP", "X10001");
c3.setTypeName("Boxcar");
c3.setLength("40");
c3.setOwner("DAB");
c3.setBuilt("1984");
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);
cmanager.register(c4);
Car c5 = new Car("CP", "X20001");
c5.setTypeName("Boxcar");
c5.setLength("40");
c5.setOwner("DAB");
c5.setBuilt("1980");
cmanager.register(c5);
Car c6 = new Car("CP", "X20002");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setOwner("DAB");
c6.setBuilt("1978");
cmanager.register(c6);
Car c7 = new Car("CP", "777");
c7.setTypeName("Flat");
c7.setLength("50");
c7.setOwner("AT");
c7.setBuilt("1990");
c7.setMoves(6);
cmanager.register(c7);
Car c8 = new Car("CP", "888");
c8.setTypeName("Boxcar");
c8.setLength("60");
c8.setOwner("DAB");
c8.setBuilt("1985");
cmanager.register(c8);
Car c9 = new Car("CP", "99");
c9.setTypeName("Flat");
c9.setLength("90");
c9.setOwner("AT");
c9.setBuilt("6-80");
cmanager.register(c9);
// 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");
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);
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);
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);
l1.register(l1s1);
l1.register(l1s2);
Location l2 = new Location("2", "North Industries");
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);
l2s1.setTrainDirections(DIRECTION_ALL);
l2.register(l2s1);
Location l3 = new Location("3", "South End");
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);
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);
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);
l3.register(l3s1);
l3.register(l3s2);
// Place 4 Boxcars on Staging tracks
c3.setLocation(l1, l1s1);
c4.setLocation(l1, l1s1);
c5.setLocation(l1, l1s2);
c6.setLocation(l1, l1s2);
// Place 2 Boxcars and Flat in yard
c7.setLocation(l2, l2s1);
c8.setLocation(l2, l2s1);
c9.setLocation(l2, l2s1);
// Place Cabooses on Staging tracks
c1.setLocation(l1, l1s1);
// Define the route.
Route route1 = new Route("1", "Southbound Main Route");
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);
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);
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);
route1.register(rl1);
route1.register(rl2);
route1.register(rl3);
rmanager.register(route1);
// Finally ready to define the trains.
Train train1 = new Train("1", "STF");
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");
// 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);
}
use of jmri.jmrit.operations.rollingstock.engines.EngineTypes 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();
}
Aggregations