use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class OperationsRoutesTest method testRouteLocation.
// test route location
public void testRouteLocation() {
Route r1 = new Route("TESTROUTEID", "TESTROUTENAME");
Assert.assertEquals("Route Id", "TESTROUTEID", r1.getId());
Assert.assertEquals("Route Name", "TESTROUTENAME", r1.getName());
Location l1 = new Location("TESTLOCATIONID1", "TESTLOCATIONNAME1");
RouteLocation rl1 = new RouteLocation("TESTROUTELOCATIONID", l1);
Assert.assertEquals("Route Location Id", "TESTROUTELOCATIONID", rl1.getId());
Assert.assertEquals("Route Location Name", "TESTLOCATIONNAME1", rl1.getName());
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithSchedulesMatchMode.
/*
* Using the setup from the previous tests, use trains and schedules to move
* cars. This test creates 1 schedule in match mode with multiple items.
* Test uses car loads to activate schedule.
*/
public void testRoutingWithSchedulesMatchMode() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Car c5 = cmanager.getByRoadAndNumber("BC", "5");
Car c6 = cmanager.getByRoadAndNumber("BD", "6");
Car c7 = cmanager.getByRoadAndNumber("BA", "7");
Car c8 = cmanager.getByRoadAndNumber("BB", "8");
Car c9 = cmanager.getByRoadAndNumber("BC", "9");
Location Acton = lmanager.getLocationByName("Acton MA");
Location Clinton = lmanager.getLocationByName("Clinton MA");
Location Danbury = lmanager.getLocationByName("Danbury MA");
Location Essex = lmanager.getLocationByName("Essex MA");
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
Track DS1 = Danbury.getTrackByName("Danbury Siding 1", Track.SPUR);
Track DS2 = Danbury.getTrackByName("Danbury Siding 2", Track.SPUR);
Track ES1 = Essex.getTrackByName("Essex Siding 1", Track.SPUR);
Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SPUR);
// set the depart track Acton to service by local train only
AS1.setTrainDirections(0);
// create schedules
ScheduleManager scheduleManager = ScheduleManager.instance();
Schedule schA = scheduleManager.newSchedule("Schedule AAA");
ScheduleItem schAItem1 = schA.addItem("Boxcar");
schAItem1.setReceiveLoadName("Empty");
schAItem1.setShipLoadName("Metal");
schAItem1.setDestination(Acton);
schAItem1.setDestinationTrack(AS1);
ScheduleItem schAItem2 = schA.addItem("Flat");
schAItem2.setReceiveLoadName("Junk");
schAItem2.setShipLoadName("Metal");
schAItem2.setDestination(Danbury);
schAItem2.setDestinationTrack(DS2);
ScheduleItem schAItem3 = schA.addItem("Boxcar");
schAItem3.setReceiveLoadName("Boxes");
schAItem3.setShipLoadName("Screws");
schAItem3.setDestination(Essex);
schAItem3.setDestinationTrack(ES1);
ScheduleItem schAItem4 = schA.addItem("Boxcar");
schAItem4.setReceiveLoadName("Boxes");
schAItem4.setShipLoadName("Bolts");
schAItem4.setDestination(Danbury);
schAItem4.setDestinationTrack(DS1);
ScheduleItem schAItem5 = schA.addItem("Boxcar");
schAItem5.setReceiveLoadName("");
schAItem5.setShipLoadName("Nuts");
schAItem5.setDestination(Essex);
schAItem5.setDestinationTrack(ES2);
// Add schedule to tracks
CS1.setScheduleId("");
ES1.setScheduleId(schA.getId());
// set schedule into match mode
ES1.setScheduleMode(Track.MATCH);
// c3 (BA 3) is a Boxcar
c3.setLoadName("Boxes");
// c4 (BB 4) is a Flat
c4.setLoadName("Junk");
// c5 (BC 5) is a Boxcar
c5.setLoadName("Boxes");
// c6 (BD 6) is a Boxcar
c6.setLoadName("Boxes");
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c7.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c8.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c9.setLocation(Acton, AS1));
// build train
Train ActonTrain = tmanager.getTrainByName("Acton Local");
ActonTrain.build();
Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Interchange", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Essex MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Essex Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Essex MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Essex Siding 1", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Acton Interchange", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Essex MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "Essex Siding 1", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Essex MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "Essex Siding 1", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 7 destination", "Acton MA", c7.getDestinationName());
Assert.assertEquals("Car BD 7 destination track", "Acton Interchange", c7.getDestinationTrackName());
Assert.assertEquals("Car BD 7 final destination", "Essex MA", c7.getFinalDestinationName());
Assert.assertEquals("Car BD 7 final destination track", "Essex Siding 1", c7.getFinalDestinationTrackName());
// check car schedule ids
Assert.assertEquals("Car BA 3 schedule id", schAItem3.getId(), c3.getScheduleItemId());
Assert.assertEquals("Car BB 4 schedule id", schAItem2.getId(), c4.getScheduleItemId());
Assert.assertEquals("Car BC 5 schedule id", schAItem3.getId(), c5.getScheduleItemId());
Assert.assertEquals("Car BD 6 schedule id", schAItem4.getId(), c6.getScheduleItemId());
Assert.assertEquals("Car BA 7 schedule id", schAItem5.getId(), c7.getScheduleItemId());
Assert.assertEquals("Car BB 8 schedule id", schAItem1.getId(), c8.getScheduleItemId());
Assert.assertEquals("Car BC 9 schedule id", schAItem5.getId(), c9.getScheduleItemId());
ActonTrain.reset();
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class EngineTest method testSetLocation.
public void testSetLocation() {
Engine e1 = new Engine("TESTROAD", "TESTNUMBER1");
e1.setModel("TESTMODEL");
e1.setLength("50");
Location l1 = new Location("id1", "B");
Track l1t1 = l1.addTrack("A", Track.SPUR);
Location l2 = new Location("id2", "C");
Track l2t1 = l2.addTrack("B", Track.SPUR);
Location l3 = new Location("id3", "A");
Track l3t1 = l3.addTrack("B", Track.SPUR);
// add track lengths
l1t1.setLength(100);
l1t1.setLength(100);
l3t1.setLength(100);
l1.addTypeName("Diesel");
l2.addTypeName("Diesel");
l3.addTypeName("Diesel");
l1t1.addTypeName("Diesel");
l2t1.addTypeName("Diesel");
l3t1.addTypeName("Diesel");
EngineTypes et = EngineTypes.instance();
et.addName("Diesel");
e1.setTypeName("Diesel");
// place engines on tracks
Assert.assertEquals("place e1", Track.OKAY, e1.setLocation(l1, l1t1));
// check for failure too.
Assert.assertFalse("fail place e1", Track.OKAY == e1.setLocation(l3, l2t1));
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrainTest method testCaboose.
public void testCaboose() {
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");
// place two engines in a consist
Consist con1 = emanager.newConsist("C1");
Engine e1 = emanager.newEngine("UP", "1");
e1.setModel("GP40");
e1.setConsist(con1);
Engine e2 = emanager.newEngine("SP", "2");
e2.setModel("GP40");
e2.setConsist(con1);
// Set up three cabooses and six box cars
Car c1 = cmanager.newCar("UP", "1");
c1.setTypeName("Caboose");
c1.setLength("32");
c1.setMoves(10);
c1.setCaboose(true);
Car c2 = cmanager.newCar("SP", "2");
c2.setTypeName("Caboose");
c2.setLength("30");
c2.setMoves(5);
c2.setCaboose(true);
Car c3 = cmanager.newCar("NH", "3");
c3.setTypeName("Caboose");
c3.setLength("33");
c3.setCaboose(true);
Car c4 = cmanager.newCar("UP", "4");
c4.setTypeName("Boxcar");
c4.setLength("40");
c4.setMoves(16);
c4.setFred(true);
Car c5 = cmanager.newCar("SP", "5");
c5.setTypeName("Boxcar");
c5.setLength("40");
c5.setMoves(8);
c5.setFred(true);
Car c6 = cmanager.newCar("NH", "6");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(2);
c6.setFred(true);
Car c7 = cmanager.newCar("UP", "7");
c7.setTypeName("Flat");
c7.setLength("40");
c7.setMoves(5);
Car c8 = cmanager.newCar("SP", "8");
c8.setTypeName("Boxcar");
c8.setLength("40");
c8.setMoves(4);
Car c9 = cmanager.newCar("NH", "9");
c9.setTypeName("Boxcar");
c9.setLength("40");
c9.setMoves(3);
Car c10 = cmanager.newCar("NH", "10");
c10.setTypeName("Boxcar");
c10.setLength("40");
c10.setMoves(10);
Car c11 = cmanager.newCar("SP", "11");
c11.setTypeName("Boxcar");
c11.setLength("40");
c11.setMoves(3);
// Create 3 locations
Location loc1 = lmanager.newLocation("Harvard");
Track loc1trk1 = loc1.addTrack("Harvard Yard", Track.YARD);
loc1trk1.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);
loc3trk1.deleteTypeName("Diesel");
Track loc3trk2 = loc3.addTrack("Boston Engine Yard", Track.YARD);
loc3trk2.setLength(200);
loc3trk2.deleteTypeName("Boxcar");
loc3trk2.deleteTypeName("Flat");
loc3trk2.deleteTypeName("Caboose");
// Create route with 3 location
Route rte1 = rmanager.newRoute("Route 2 Boston");
RouteLocation rl1 = rte1.addLocation(loc1);
RouteLocation rl2 = rte1.addLocation(loc2);
// set the train icon coordinates
rl2.setTrainIconX(75);
rl2.setTrainIconY(150);
RouteLocation rl3 = rte1.addLocation(loc3);
// set the train icon coordinates
rl3.setTrainIconX(125);
rl3.setTrainIconY(150);
// Create train
Train train1 = tmanager.newTrain("HTB");
train1.setRoute(rte1);
// Place cars
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, 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));
// Place engines
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk1));
// no requirements, so no caboose or FRED or engines
train1.build();
Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 1", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 1", "", 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", "Boston Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 1", "Arlington Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 1", "Boston Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 1", "Boston Yard", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 1", "Boston Yard", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 1", "", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 1", "", e2.getDestinationTrackName());
// no engines, so the caboose with least moves should be used
train1.setRequirements(Train.CABOOSE);
// don't allow pickups at second location Arlington
rl2.setPickUpAllowed(false);
train1.build();
Assert.assertEquals("Train 1 After Build 2", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 2", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 2", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 2", "Boston Yard", 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", "Boston Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 2", "Boston Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 2", "Arlington 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());
// there's a caboose c1 that matches lead engine
train1.setNumberEngines("2");
train1.build();
Assert.assertEquals("Train 1 After Build 3", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 3", "Boston Yard", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 3", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 3", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 3", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 3", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 3", "Boston Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 3", "Boston Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 3", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 3", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 3", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 3", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 3", "Boston Engine Yard", e2.getDestinationTrackName());
// should default to the caboose with the least moves
e1.setRoadName("X");
// allow pickups at Arlington
rl2.setPickUpAllowed(true);
train1.build();
Assert.assertEquals("Train 1 After Build 4", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 4", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 4", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 4", "Boston Yard", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 4", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 4", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 4", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 4", "Boston Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 4", "Boston Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 4", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 4", "Boston Yard", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 4", "Boston Yard", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 4", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 4", "Boston Engine Yard", e2.getDestinationTrackName());
// don't allow drops at Boston, caboose and engines should still drop there
rl3.setDropAllowed(false);
// should not take NH caboose
e1.setRoadName("NH");
// now require a SP caboose
train1.setCabooseRoad("SP");
train1.build();
Assert.assertEquals("Train 1 After Build 5", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 5", "Boston 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", "Arlington Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 5", "Arlington Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 5", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 5", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 5", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 5", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 5", "Boston Engine Yard", e2.getDestinationTrackName());
// allow drops at Boston
rl3.setDropAllowed(true);
// should take car with FRED and road SP
train1.setRequirements(Train.FRED);
train1.build();
Assert.assertEquals("Train 1 After Build 6", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 6", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 6", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 6", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 6", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 6", "Boston Yard", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 6", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 6", "Boston Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 6", "Boston Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 6", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 6", "Boston Yard", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 6", "Boston Yard", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 6", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 6", "Boston Engine Yard", e2.getDestinationTrackName());
// should take car with FRED least number of moves
train1.setCabooseRoad("");
train1.build();
Assert.assertEquals("Train 1 After Build 7", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 7", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 7", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 7", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 7", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 7", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 7", "Boston Yard", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 7", "Boston Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 7", "Boston Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 7", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 7", "Boston Yard", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 7", "Boston Yard", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 7", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 7", "Boston Engine Yard", e2.getDestinationTrackName());
// now exclude road NH, engine road is NH and should be rejected
train1.addRoadName("NH");
train1.setRoadOption(Train.EXCLUDE_ROADS);
train1.build();
Assert.assertEquals("Train 1 After Build 7a", false, train1.isBuilt());
// now override by setting a road for the engine
train1.setEngineRoad("NH");
train1.build();
Assert.assertEquals("Train 1 After Build 8", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 8", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 8", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 8", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 8", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 8", "Boston Yard", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 8", "", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 8", "Boston Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 8", "Arlington Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 8", "", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 8", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 8", "Boston Yard", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 8", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 8", "Boston Engine Yard", e2.getDestinationTrackName());
// now only include NH
train1.setRoadOption(Train.INCLUDE_ROADS);
train1.build();
Assert.assertEquals("Train 1 After Build 9", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 9", "", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 9", "", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 9", "", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 9", "", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 9", "", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 9", "Boston Yard", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 9", "", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 9", "", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 9", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 9", "Boston Yard", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 9", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 9", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 9", "Boston Engine Yard", e2.getDestinationTrackName());
// don't allow boxcar, car with FRED required, build should fail
loc3.deleteTypeName("Boxcar");
train1.build();
Assert.assertEquals("Train 1 After Build 9a", false, train1.isBuilt());
loc3.addTypeName("Boxcar");
// add staging
Track loc1trk2 = loc1.addTrack("Harvard Staging", Track.STAGING);
loc1trk2.setLength(1000);
// now depart staging, must take all cars in staging
// there are nine cars departing staging
rl1.setMaxCarMoves(9);
// Place cars
Assert.assertEquals("Move c1", Track.OKAY, c1.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c2", Track.OKAY, c2.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c3", Track.OKAY, c3.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c4", Track.OKAY, c4.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
Assert.assertEquals("Move c9", Track.OKAY, c9.setLocation(loc1, loc1trk2));
// Place engines
Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk2));
// program requires only staging at any location, so we don't test with yard
loc1.deleteTrack(loc1trk1);
// All engines and cars in staging must move! Cabooses and cars with FRED to terminal
train1.setNumberEngines("0");
train1.build();
// train only accepted engine and cars with NH road therefore build should fail
Assert.assertEquals("Train 1 After Build from staging", false, train1.isBuilt());
// try again but now accept all roads
train1.setRoadOption(Train.ALL_ROADS);
train1.build();
Assert.assertEquals("Train 1 After Build 10", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 10", "Boston Yard", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 10", "Boston Yard", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 10", "Boston Yard", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 10", "Boston Yard", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 10", "Boston Yard", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 10", "Boston Yard", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 10", "Arlington Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 10", "Arlington Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 10", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 10", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 10", "Boston Yard", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 10", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 10", "Boston Engine Yard", e2.getDestinationTrackName());
// exclude road NH
train1.setRoadOption(Train.EXCLUDE_ROADS);
train1.build();
// should fail since there are NH roads in staging
Assert.assertEquals("Train 1 After Build 11", false, train1.isBuilt());
// reduce Boston moves to 6, to force non caboose and FRED cars to Arlington
rl3.setMaxCarMoves(6);
train1.setRoadOption(Train.ALL_ROADS);
train1.build();
Assert.assertEquals("Train 1 After Build 12", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 12", "Boston Yard", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 12", "Boston Yard", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 12", "Boston Yard", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 12", "Boston Yard", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 12", "Boston Yard", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 12", "Boston Yard", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 12", "Arlington Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 12", "Arlington Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 12", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 12", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 12", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 12", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 12", "Boston Engine Yard", e2.getDestinationTrackName());
// Reduce Arlington to only two moves, this should cause train build to fail
rl2.setMaxCarMoves(2);
train1.build();
Assert.assertEquals("Train 1 After Build 13", false, train1.isBuilt());
// restore number of moves
rl2.setMaxCarMoves(7);
rl3.setMaxCarMoves(7);
// don't allow drops at Boston
rl3.setDropAllowed(false);
train1.build();
Assert.assertEquals("Train 1 After Build 14", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 14", "Boston Yard", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 14", "Boston Yard", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 14", "Boston Yard", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 14", "Boston Yard", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 14", "Boston Yard", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 14", "Boston Yard", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 14", "Arlington Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 14", "Arlington Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 14", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 14", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 14", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 14", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 14", "Boston Engine Yard", e2.getDestinationTrackName());
// Reduce Arlington to only two moves, this should cause train build to fail
rl2.setMaxCarMoves(2);
train1.build();
Assert.assertEquals("Train 1 After Build 15", false, train1.isBuilt());
// Don't allow cabooses at Boston, should cause build failure
rl2.setMaxCarMoves(7);
loc3.deleteTypeName("Caboose");
train1.build();
Assert.assertEquals("Train 1 After Build 16", false, train1.isBuilt());
// Don't allow boxcars, should also cause build failure
loc3.addTypeName("Caboose");
loc3.deleteTypeName("Boxcar");
train1.setRequirements(Train.NO_CABOOSE_OR_FRED);
train1.build();
Assert.assertEquals("Train 1 After Build 17", false, train1.isBuilt());
// allow the three road names we're testing
loc3.addTypeName("Boxcar");
loc3trk1.addRoadName("NH");
loc3trk1.addRoadName("SP");
loc3trk1.addRoadName("UP");
loc3trk1.setRoadOption(Track.INCLUDE_ROADS);
loc3trk2.addRoadName("NH");
loc3trk2.addRoadName("SP");
loc3trk2.addRoadName("UP");
loc3trk2.setRoadOption(Track.INCLUDE_ROADS);
train1.build();
Assert.assertEquals("Train 1 After Build 18", true, train1.isBuilt());
// now remove type Diesel, this should cause a failure
loc3trk2.deleteTypeName("Diesel");
train1.build();
Assert.assertEquals("Train 1 After Build 19", false, train1.isBuilt());
// now restore type Diesel
loc3trk2.addTypeName("Diesel");
train1.build();
Assert.assertEquals("Train 1 After Build 20", true, train1.isBuilt());
// Set the track length too short missing one set of couplers
loc3trk2.setLength(Integer.parseInt(e1.getLength()) + Integer.parseInt(e2.getLength()) + Engine.COUPLER);
train1.build();
Assert.assertEquals("Train 1 After Build 20.1", false, train1.isBuilt());
// restore track length
loc3trk2.setLength(Integer.parseInt(e1.getLength()) + Integer.parseInt(e2.getLength()) + 2 * Engine.COUPLER);
train1.build();
Assert.assertEquals("Train 1 After Build 20.2", true, train1.isBuilt());
// change lead engine road name, should cause build failure since Boston only
// accepts NH, SP, and UP.
// reset engine road requirements, was "NH"
train1.setEngineRoad("");
// was "NH"
e1.setRoadName("X");
train1.build();
Assert.assertEquals("Train 1 After Build 21", false, train1.isBuilt());
e1.setRoadName("UP");
// this test that a caboose fails
loc3trk1.deleteRoadName("NH");
train1.build();
Assert.assertEquals("Train 1 After Build 22", false, train1.isBuilt());
loc3trk1.addRoadName("NH");
// this test that a car with FRED fails
c6.setRoadName("X");
train1.build();
Assert.assertEquals("Train 1 After Build 23", false, train1.isBuilt());
loc3trk1.addRoadName("X");
// this test that an ordinary car must move
loc2trk1.deleteTypeName("Flat");
train1.build();
Assert.assertEquals("Train 1 After Build 24", false, train1.isBuilt());
// restore
loc2trk1.addTypeName("Flat");
train1.build();
Assert.assertEquals("Train 1 After Build 25", true, train1.isBuilt());
// check destinations
Assert.assertEquals("c1 destination 25", "Boston Yard", c1.getDestinationTrackName());
Assert.assertEquals("c2 destination 25", "Boston Yard", c2.getDestinationTrackName());
Assert.assertEquals("c3 destination 25", "Boston Yard", c3.getDestinationTrackName());
Assert.assertEquals("c4 destination 25", "Boston Yard", c4.getDestinationTrackName());
Assert.assertEquals("c5 destination 25", "Boston Yard", c5.getDestinationTrackName());
Assert.assertEquals("c6 destination 25", "Boston Yard", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination 25", "Arlington Yard", c7.getDestinationTrackName());
Assert.assertEquals("c8 destination 25", "Arlington Yard", c8.getDestinationTrackName());
Assert.assertEquals("c9 destination 25", "Arlington Yard", c9.getDestinationTrackName());
Assert.assertEquals("c10 destination 25", "", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination 25", "", c11.getDestinationTrackName());
Assert.assertEquals("e1 destination 25", "Boston Engine Yard", e1.getDestinationTrackName());
Assert.assertEquals("e2 destination 25", "Boston Engine Yard", e2.getDestinationTrackName());
train1.reset();
// send caboose SP 2 from staging to track that will not service it
loc3trk2.addTypeName("Caboose");
loc3trk2.setLength(200);
c2.setDestination(loc3, loc3trk2);
loc3trk2.deleteTypeName("Caboose");
train1.build();
Assert.assertEquals("Train 1 After Build with caboose bad destination", false, train1.isBuilt());
c2.setDestination(null, null);
train1.build();
train1.move();
train1.move();
train1.move();
// check final locations
Assert.assertEquals("c1 location 24", "Boston Yard", c1.getTrackName());
Assert.assertEquals("c2 location 24", "Boston Yard", c2.getTrackName());
Assert.assertEquals("c3 location 24", "Boston Yard", c3.getTrackName());
Assert.assertEquals("c4 location 24", "Boston Yard", c4.getTrackName());
Assert.assertEquals("c5 location 24", "Boston Yard", c5.getTrackName());
Assert.assertEquals("c6 location 24", "Boston Yard", c6.getTrackName());
Assert.assertEquals("c7 location 24", "Arlington Yard", c7.getTrackName());
Assert.assertEquals("c8 location 24", "Arlington Yard", c8.getTrackName());
Assert.assertEquals("c9 location 24", "Arlington Yard", c9.getTrackName());
Assert.assertEquals("c10 location 24", "Arlington Yard", c10.getTrackName());
Assert.assertEquals("c11 location 24", "Arlington Yard", c11.getTrackName());
Assert.assertEquals("e1 location 24", "Boston Engine Yard", e1.getTrackName());
Assert.assertEquals("e2 location 24", "Boston Engine Yard", e2.getTrackName());
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrainTest method testAutoEnginesGrade.
public void testAutoEnginesGrade() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
EngineManager emanager = EngineManager.instance();
// This test uses the maximum length of a train in route
Setup.setMaxTrainLength(1000);
Setup.setMaxNumberEngines(6);
Train train = tmanager.newTrain("AutoEngineTest");
train.setNumberEngines(Train.AUTO);
Route route = rmanager.newRoute("AutoEngineTest");
train.setRoute(route);
Location A = lmanager.newLocation("A");
Location B = lmanager.newLocation("B");
Location C = lmanager.newLocation("C");
Track At = A.addTrack("track", Track.SPUR);
Track Bt = B.addTrack("track", Track.SPUR);
Track Ct = C.addTrack("track", Track.SPUR);
At.setLength(300);
Bt.setLength(300);
Ct.setLength(300);
RouteLocation rA = route.addLocation(A);
RouteLocation rB = route.addLocation(B);
RouteLocation rC = route.addLocation(C);
rA.setMaxCarMoves(12);
rB.setMaxCarMoves(12);
rC.setMaxCarMoves(12);
// 2.5% grade!
rB.setGrade(2.5);
Engine e1 = emanager.newEngine("E", "1");
e1.setModel("GP40");
Engine e2 = emanager.newEngine("E", "2");
e2.setModel("GP40");
Engine e3 = emanager.newEngine("E", "3");
e3.setModel("GP40");
Engine e4 = emanager.newEngine("E", "4");
e4.setModel("GP40");
e1.setLocation(A, At);
e2.setLocation(A, At);
e3.setLocation(A, At);
e4.setLocation(A, At);
Consist c = emanager.newConsist("c");
e1.setConsist(c);
e2.setConsist(c);
// train should require four engines
train.build();
Assert.assertFalse("Train should not build, needs four engines, only two", train.isBuilt());
e3.setConsist(c);
train.build();
Assert.assertFalse("Train should not build, needs four engines, only three", train.isBuilt());
e4.setConsist(c);
train.build();
Assert.assertTrue("Train should build, four engines available", train.isBuilt());
}
Aggregations