Search in sources :

Example 1 with CarTypes

use of jmri.jmrit.operations.rollingstock.cars.CarTypes 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());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 2 with CarTypes

use of jmri.jmrit.operations.rollingstock.cars.CarTypes in project JMRI by JMRI.

the class TrainTest method testTrainBuildOptions.

public void testTrainBuildOptions() {
    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");
    // 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
    // set default to 7 moves per location
    Setup.setCarMoves(7);
    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("Harvard to Chelmsford");
    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.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", "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.build();
    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.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", "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.build();
    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.build();
    Assert.assertEquals("Train 1 After Build 4", true, train1.isBuilt());
    // Only allow rolling stock built after 1956
    train1.setBuiltStartYear("1956");
    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", "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();
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 3 with CarTypes

use of jmri.jmrit.operations.rollingstock.cars.CarTypes in project JMRI by JMRI.

the class TrainTest method testAggressiveBuildOption.

public void testAggressiveBuildOption() {
    Setup.setBuildAggressive(true);
    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");
    // 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("Harvard to Westford Aggressive");
    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.build();
    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.build();
    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.build();
    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.build();
    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
    Setup.setStagingTrackImmediatelyAvail(false);
    rte1.addLocation(loc1);
    train1.build();
    // should fail, can't return to staging track
    Assert.assertEquals("Train 1 deaprting and returning to staging", false, train1.isBuilt());
    // change mode
    Setup.setStagingTrackImmediatelyAvail(true);
    train1.build();
    Assert.assertEquals("Train 1 deaprting 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());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 4 with CarTypes

use of jmri.jmrit.operations.rollingstock.cars.CarTypes in project JMRI by JMRI.

the class OperationsCarRouterTest method testCarRouting.

/**
     * Test car routing. First set of tests confirm proper operation of just one
     * location. The next set of tests confirms operation using one train and
     * two locations. When this test was written, routing up to 5 trains and 6
     * locations was supported.
     *
     */
public void testCarRouting() {
    // now load up the managers
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    Router router = Router.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    // create 6 locations and tracks
    Location Acton = lmanager.newLocation("Acton MA");
    Assert.assertEquals("Location 1 Name", "Acton MA", Acton.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, Acton.getLength());
    Track AS1 = Acton.addTrack("Acton Siding 1", Track.SPUR);
    AS1.setLength(300);
    Assert.assertEquals("Location AS1 Name", "Acton Siding 1", AS1.getName());
    Assert.assertEquals("Location AS1 Length", 300, AS1.getLength());
    Track AS2 = Acton.addTrack("Acton Siding 2", Track.SPUR);
    AS2.setLength(300);
    Assert.assertEquals("Location AS2 Name", "Acton Siding 2", AS2.getName());
    Assert.assertEquals("Location AS2 Length", 300, AS2.getLength());
    Track AY = Acton.addTrack("Acton Yard", Track.YARD);
    AY.setLength(400);
    Assert.assertEquals("Location AY Name", "Acton Yard", AY.getName());
    Assert.assertEquals("Location AY Length", 400, AY.getLength());
    Track AI = Acton.addTrack("Acton Interchange", Track.INTERCHANGE);
    AI.setLength(500);
    Assert.assertEquals("Track AI Name", "Acton Interchange", AI.getName());
    Assert.assertEquals("Track AI Length", 500, AI.getLength());
    Assert.assertEquals("Track AI Train Directions", DIRECTION_ALL, AI.getTrainDirections());
    // add a second interchange track
    Track AI2 = Acton.addTrack("Acton Interchange 2", Track.INTERCHANGE);
    AI2.setLength(500);
    // bias tracks
    AI2.setMoves(100);
    Assert.assertEquals("Track AI2 Name", "Acton Interchange 2", AI2.getName());
    Assert.assertEquals("Track AI2 Length", 500, AI2.getLength());
    Assert.assertEquals("Track AI2 Train Directions", DIRECTION_ALL, AI2.getTrainDirections());
    Location Bedford = lmanager.newLocation("Bedford MA");
    Assert.assertEquals("Location 1 Name", "Bedford MA", Bedford.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, Bedford.getLength());
    Track BS1 = Bedford.addTrack("Bedford Siding 1", Track.SPUR);
    BS1.setLength(300);
    Assert.assertEquals("Location BS1 Name", "Bedford Siding 1", BS1.getName());
    Assert.assertEquals("Location BS1 Length", 300, BS1.getLength());
    Track BS2 = Bedford.addTrack("Bedford Siding 2", Track.SPUR);
    BS2.setLength(300);
    Assert.assertEquals("Location BS2 Name", "Bedford Siding 2", BS2.getName());
    Assert.assertEquals("Location BS2 Length", 300, BS2.getLength());
    Track BY = Bedford.addTrack("Bedford Yard", Track.YARD);
    BY.setLength(400);
    Assert.assertEquals("Location BY Name", "Bedford Yard", BY.getName());
    Assert.assertEquals("Location BY Length", 400, BY.getLength());
    Track BI = Bedford.addTrack("Bedford Interchange", Track.INTERCHANGE);
    BI.setLength(500);
    Assert.assertEquals("Track BI Name", "Bedford Interchange", BI.getName());
    Assert.assertEquals("Track BI Length", 500, BI.getLength());
    Location Clinton = lmanager.newLocation("Clinton MA");
    Assert.assertEquals("Location 1 Name", "Clinton MA", Clinton.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, Clinton.getLength());
    Track CS1 = Clinton.addTrack("Clinton Siding 1", Track.SPUR);
    CS1.setLength(300);
    Assert.assertEquals("Location CS1 Name", "Clinton Siding 1", CS1.getName());
    Assert.assertEquals("Location CS1 Length", 300, CS1.getLength());
    Track CS2 = Clinton.addTrack("Clinton Siding 2", Track.SPUR);
    CS2.setLength(300);
    Assert.assertEquals("Location CS2 Name", "Clinton Siding 2", CS2.getName());
    Assert.assertEquals("Location CS2 Length", 300, BS2.getLength());
    Track CY = Clinton.addTrack("Clinton Yard", Track.YARD);
    CY.setLength(400);
    Assert.assertEquals("Location CY Name", "Clinton Yard", CY.getName());
    Assert.assertEquals("Location CY Length", 400, CY.getLength());
    Track CI = Clinton.addTrack("Clinton Interchange", Track.INTERCHANGE);
    CI.setLength(500);
    Assert.assertEquals("Track CI Name", "Clinton Interchange", CI.getName());
    Assert.assertEquals("Track CI Length", 500, CI.getLength());
    Location Danbury = lmanager.newLocation("Danbury MA");
    Track DS1 = Danbury.addTrack("Danbury Siding 1", Track.SPUR);
    DS1.setLength(300);
    Track DS2 = Danbury.addTrack("Danbury Siding 2", Track.SPUR);
    DS2.setLength(300);
    Track DY = Danbury.addTrack("Danbury Yard", Track.YARD);
    DY.setLength(400);
    Track DI = Danbury.addTrack("Danbury Interchange", Track.INTERCHANGE);
    DI.setLength(500);
    Location Essex = lmanager.newLocation("Essex MA");
    Track ES1 = Essex.addTrack("Essex Siding 1", Track.SPUR);
    ES1.setLength(300);
    Track ES2 = Essex.addTrack("Essex Siding 2", Track.SPUR);
    ES2.setLength(300);
    Track EY = Essex.addTrack("Essex Yard", Track.YARD);
    EY.setLength(400);
    Track EI = Essex.addTrack("Essex Interchange", Track.INTERCHANGE);
    EI.setLength(500);
    Location Foxboro = lmanager.newLocation("Foxboro MA");
    Track FS1 = Foxboro.addTrack("Foxboro Siding 1", Track.SPUR);
    FS1.setLength(300);
    Track FS2 = Foxboro.addTrack("Foxboro Siding 2", Track.SPUR);
    FS2.setLength(300);
    Track FY = Foxboro.addTrack("Foxboro Yard", Track.YARD);
    FY.setLength(400);
    Track FI = Foxboro.addTrack("Foxboro Interchange", Track.INTERCHANGE);
    FI.setLength(500);
    // create 2 cars
    Car c3 = cmanager.newCar("BA", "3");
    c3.setTypeName("Boxcar");
    c3.setLength("40");
    c3.setOwner("DAB");
    c3.setBuilt("1984");
    Assert.assertEquals("Box Car 3 Length", "40", c3.getLength());
    Car c4 = cmanager.newCar("BB", "4");
    c4.setTypeName("Flat");
    c4.setLength("40");
    c4.setOwner("AT");
    c4.setBuilt("1-86");
    Assert.assertEquals("Box Car 4 Length", "40", c4.getLength());
    Assert.assertEquals("place car at BI", Track.OKAY, c3.setLocation(Acton, AS1));
    Assert.assertFalse("Try routing no final destination", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("place car at Acton", Track.OKAY, c4.setLocation(Acton, AS1));
    Assert.assertFalse("Try routing no final destination", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "", c4.getDestinationName());
    // test disable routing
    Setup.setCarRoutingEnabled(false);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Test router disabled", router.setDestination(c3, null, null));
    Assert.assertEquals("Router status", Router.STATUS_ROUTER_DISABLED, router.getStatus());
    Setup.setCarRoutingEnabled(true);
    // first try car routing with just one location
    c3.setFinalDestination(Acton);
    Assert.assertFalse("Try routing final destination equal to current", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_CAR_AT_DESINATION, router.getStatus());
    // now try with next track not equal to current
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing final track not equal to current", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    // now try with next track equal to current
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS1);
    Assert.assertFalse("Try routing final track equal to current", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_CAR_AT_DESINATION, router.getStatus());
    // create a local train servicing Acton
    Train ActonTrain = tmanager.newTrain("Acton Local");
    Route routeA = rmanager.newRoute("A");
    RouteLocation rlA = routeA.addLocation(Acton);
    // set train icon coordinates
    rlA.setTrainIconX(25);
    rlA.setTrainIconY(250);
    ActonTrain.setRoute(routeA);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Siding 2", c3.getDestinationTrackName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // specify the Acton train
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, ActonTrain, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Siding 2", c3.getDestinationTrackName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // Set the track length to be less the length of c3
    AS2.setLength(c3.getTotalLength() - 1);
    // clear previous destination
    c3.setDestination(null, null);
    // local move, alternate or yard track option should be ignored
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, ActonTrain, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    Assert.assertTrue("Should report that the issue was track length", router.getStatus().startsWith(Track.CAPACITY));
    // restore track length
    AS2.setLength(300);
    // don't allow train to service boxcars
    ActonTrain.deleteTypeName("Boxcar");
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing with train that doesn't service Boxcar", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    // try the car type Flat
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Acton);
    c4.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with train that service Flat", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // now allow Boxcar again
    ActonTrain.addTypeName("Boxcar");
    Assert.assertTrue("Try routing with train that does service Boxcar", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // don't allow train to service boxcars with road name BA
    ActonTrain.addRoadName("BA");
    ActonTrain.setRoadOption(Train.EXCLUDE_ROADS);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing with train that doesn't service road name BA", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    // try the car road name BB
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Acton);
    c4.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with train that services road BB", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // now try again but allow road name
    ActonTrain.setRoadOption(Train.ALL_ROADS);
    Assert.assertTrue("Try routing with train that does service road name BA", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // don't service cars built before 1985
    ActonTrain.setBuiltStartYear("1985");
    ActonTrain.setBuiltEndYear("2010");
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing with train that doesn't service car built before 1985", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    // try the car built after 1985
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Acton);
    c4.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with train that services car built after 1985", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // car was built in 1984 should work
    ActonTrain.setBuiltStartYear("1983");
    Assert.assertTrue("Try routing with train that doesn't service car built before 1983", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // try car loads
    c3.setLoadName("Tools");
    ActonTrain.addLoadName("Tools");
    ActonTrain.setLoadOption(Train.EXCLUDE_LOADS);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing with train that doesn't service load Tools", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    // try the car load "E"
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Acton);
    c4.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with train that services load E", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
    ActonTrain.setLoadOption(Train.ALL_LOADS);
    Assert.assertTrue("Try routing with train that that does service load Tools", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    // now test by modifying the route
    rlA.setPickUpAllowed(false);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing with train that doesn't pickup cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    rlA.setPickUpAllowed(true);
    Assert.assertTrue("Try routing with train that that can pickup cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    rlA.setDropAllowed(false);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing with train that doesn't drop cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    rlA.setDropAllowed(true);
    Assert.assertTrue("Try routing with train that that can drop cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    rlA.setMaxCarMoves(0);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertFalse("Try routing with train that doesn't service location", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    rlA.setMaxCarMoves(10);
    Assert.assertTrue("Try routing with train that does service location", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    // test train depart direction
    Assert.assertEquals("check default direction", Track.NORTH, rlA.getTrainDirection());
    // set the depart location Acton to service by South bound trains only
    Acton.setTrainDirections(Track.SOUTH);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with local train that departs north, location south", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Acton.setTrainDirections(Track.NORTH);
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with local train that departs north, location north", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    // set the depart track Acton to service by local train only
    AS1.setTrainDirections(0);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with local only", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    AS1.setTrainDirections(Track.NORTH);
    Assert.assertTrue("Try routing with local train that departs north, track north", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    // test arrival directions
    // set the arrival track Acton to service by local trains only
    AS2.setTrainDirections(0);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    // now specify the actual track
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with local train", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    AS2.setTrainDirections(Track.NORTH);
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    // now specify the actual track
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing with train that departs north, track north", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    // add a second local train
    // create a local train servicing Acton
    Route routeA2 = rmanager.newRoute("A2");
    RouteLocation rlA2 = routeA2.addLocation(Acton);
    // set train icon coordinates
    rlA2.setTrainIconX(25);
    rlA2.setTrainIconY(250);
    Train ActonTrain2 = tmanager.newTrain("Acton Local 2");
    ActonTrain2.setRoute(routeA2);
    // try routing with this train
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Siding 2", c3.getDestinationTrackName());
    // don't allow Acton Local 2 to service boxcars
    ActonTrain2.deleteTypeName("Boxcar");
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Acton);
    c3.setFinalDestinationTrack(AS2);
    // Should be able to route using Acton Local, but destination should not be set
    Assert.assertTrue("Try routing with train that doesn't service Boxcar", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_THIS_TRAIN, router.getStatus());
    // Two locations one train testing begins
    // set next destination Bedford
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(null);
    // should fail no train!
    Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
    // create a train with a route from Acton to Bedford
    Train ActonToBedfordTrain = tmanager.newTrain("Acton to Bedford");
    Route routeAB = rmanager.newRoute("AB");
    RouteLocation rlActon = routeAB.addLocation(Acton);
    RouteLocation rlBedford = routeAB.addLocation(Bedford);
    // set train icon coordinates
    rlBedford.setTrainIconX(100);
    rlBedford.setTrainIconY(250);
    ActonToBedfordTrain.setRoute(routeAB);
    // should work
    Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // try specific train
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(null);
    Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, ActonToBedfordTrain, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // don't allow train to service boxcars
    ActonToBedfordTrain.deleteTypeName("Boxcar");
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't service Boxcar", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    // try the car type Flat
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Bedford);
    c4.setFinalDestinationTrack(null);
    Assert.assertTrue("Try routing with train that service Flat", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
    // now allow Boxcar again
    ActonToBedfordTrain.addTypeName("Boxcar");
    Assert.assertTrue("Try routing with train that does service Boxcar", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // don't allow train to service boxcars with road name BA
    ActonToBedfordTrain.addRoadName("BA");
    ActonToBedfordTrain.setRoadOption(Train.EXCLUDE_ROADS);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't service road name BA", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    // try the car road name BB
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Bedford);
    Assert.assertTrue("Try routing with train that services road BB", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
    // now try again but allow road name
    ActonToBedfordTrain.setRoadOption(Train.ALL_ROADS);
    Assert.assertTrue("Try routing with train that does service road name BA", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // don't service cars built before 1985
    ActonToBedfordTrain.setBuiltStartYear("1985");
    ActonToBedfordTrain.setBuiltEndYear("2010");
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't service car built before 1985", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    // try the car built after 1985
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Bedford);
    Assert.assertTrue("Try routing with train that services car built after 1985", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
    // car was built in 1984 should work
    ActonToBedfordTrain.setBuiltStartYear("1983");
    Assert.assertTrue("Try routing with train that doesn't service car built before 1983", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // try car loads
    c3.setLoadName("Tools");
    ActonToBedfordTrain.addLoadName("Tools");
    ActonToBedfordTrain.setLoadOption(Train.EXCLUDE_LOADS);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't service load Tools", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    // try the car load "E"
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Bedford);
    Assert.assertTrue("Try routing with train that services load E", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
    ActonToBedfordTrain.setLoadOption(Train.ALL_LOADS);
    Assert.assertTrue("Try routing with train that that does service load Tools", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // don't allow Bedford to service Flat
    // clear previous destination
    c4.setDestination(null, null);
    c4.setFinalDestination(Bedford);
    Bedford.deleteTypeName("Flat");
    Assert.assertFalse("Try routing with Bedford that does not service Flat", router.setDestination(c4, null, null));
    Assert.assertEquals("Check car's destination", "", c4.getDestinationName());
    Assert.assertTrue("Router status", router.getStatus().startsWith(Track.TYPE));
    // restore Bedford can service Flat
    Bedford.addTypeName("Flat");
    // now test by modifying the route
    rlActon.setPickUpAllowed(false);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't pickup cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    rlActon.setPickUpAllowed(true);
    Assert.assertTrue("Try routing with train that that can pickup cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    rlBedford.setDropAllowed(false);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't drop cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    rlBedford.setDropAllowed(true);
    Assert.assertTrue("Try routing with train that that can drop cars", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    rlBedford.setMaxCarMoves(0);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't service destination", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    rlBedford.setMaxCarMoves(5);
    Assert.assertTrue("Try routing with train that does service destination", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    rlActon.setMaxCarMoves(0);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that doesn't service location", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    rlActon.setMaxCarMoves(5);
    Assert.assertTrue("Try routing with train that does service location", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // test train depart direction
    Assert.assertEquals("check default direction", Track.NORTH, rlActon.getTrainDirection());
    // set the depart location Acton to service by South bound trains only
    Acton.setTrainDirections(Track.SOUTH);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    // remove the Action local by not allowing train to service boxcars
    ActonTrain.deleteTypeName("Boxcar");
    Assert.assertFalse("Try routing with train that departs north, location south", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Acton.setTrainDirections(Track.NORTH);
    Assert.assertTrue("Try routing with train that departs north, location north", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // set the depart track Acton to service by South bound trains only
    AS1.setTrainDirections(Track.SOUTH);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that departs north, track south", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    AS1.setTrainDirections(Track.NORTH);
    Assert.assertTrue("Try routing with train that departs north, track north", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // test arrival directions
    // set the arrival location Bedford to service by South bound trains only
    Bedford.setTrainDirections(Track.SOUTH);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing with train that arrives north, destination south", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Bedford.setTrainDirections(Track.NORTH);
    Assert.assertTrue("Try routing with train that arrives north, destination north", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // set the depart track Acton to service by South bound trains only
    BS1.setTrainDirections(Track.SOUTH);
    // and the next destination for the car
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertTrue("Try routing with train that arrives north, but no final track", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    // now specify the actual track
    c3.setFinalDestinationTrack(BS1);
    Assert.assertFalse("Try routing with train that arrives north, now with track", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    BS1.setTrainDirections(Track.NORTH);
    Assert.assertTrue("Try routing with train that departs north, track north", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    Setup.setOnlyActiveTrainsEnabled(true);
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertTrue("Try routing only active trains", router.setDestination(c3, null, null));
    // now deselect the Action to Bedford train
    ActonToBedfordTrain.setBuildEnabled(false);
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertFalse("Try routing only active trains, Action to Beford deselected", router.setDestination(c3, null, null));
    Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
    Setup.setOnlyActiveTrainsEnabled(false);
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    Assert.assertTrue("Try routing, only active trains deselected", router.setDestination(c3, null, null));
    // test yard and alternate track options
    BS1.setLength(c3.getTotalLength());
    // c4 is the same length as c3, so the track is now full
    Assert.assertEquals("Use up all of the space for BS1", Track.OKAY, c4.setLocation(Bedford, BS1));
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Test search for yard", router.setDestination(c3, null, null));
    Assert.assertEquals("Destination", "Bedford MA", c3.getDestinationName());
    Assert.assertEquals("Destination track should be yard", "Bedford Yard", c3.getDestinationTrackName());
    // the car was sent to a yard track because the spur was full
    Assert.assertTrue("Should be reporting length issue", router.getStatus().startsWith(Track.LENGTH));
    // remove yard type
    BY.setTrackType(Track.SPUR);
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Test search for yard that doesn't exist", router.setDestination(c3, null, null));
    Assert.assertEquals("Destination", "", c3.getDestinationName());
    Assert.assertTrue("Should be reporting length issue", router.getStatus().startsWith(Track.LENGTH));
    // restore yard type
    BY.setTrackType(Track.YARD);
    // test alternate track option
    BS1.setAlternateTrack(BS2);
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Test use alternate", router.setDestination(c3, null, null));
    Assert.assertEquals("Destination", "Bedford MA", c3.getDestinationName());
    Assert.assertEquals("Destination track should be siding", "Bedford Siding 2", c3.getDestinationTrackName());
    // the car was sent to the alternate track because the spur was full
    Assert.assertTrue("Should be reporting length issue", router.getStatus().startsWith(Track.LENGTH));
    // restore track length and remove alternate
    BS1.setLength(300);
    BS1.setAlternateTrack(null);
    // One train tests complete. Start two train testing.
    // Force first move to be by local train
    AS1.setTrainDirections(0);
    // restore the local
    ActonTrain.addTypeName("Boxcar");
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    // now specify the actual track
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Try routing two trains via interchange", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // don't allow use of interchange track
    AI.setDropOption(Track.TRAINS);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    // now specify the actual track
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Try routing two trains via interchange", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange 2", c3.getDestinationTrackName());
    AI2.setDropOption(Track.TRAINS);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    // now specify the actual track
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Try routing two trains via yard", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Yard", c3.getDestinationTrackName());
    // allow use of interchange track
    AI.setDropOption(Track.ANY);
    AI2.setDropOption(Track.ANY);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    // allow Boxcars
    ActonTrain2.addTypeName("Boxcar");
    Assert.assertTrue("Try routing two trains", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // test to see if second interchange track used if first is full
    AI.setLength(c3.getTotalLength() - 1);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Try routing two trains to interchange track 2", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange 2", c3.getDestinationTrackName());
    Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
    // use yard track if interchange tracks are full
    AI2.setLength(c3.getTotalLength() - 1);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    Assert.assertTrue("Try routing two trains to yard track", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Yard", c3.getDestinationTrackName());
    // disable using yard tracks for routing
    Setup.setCarRoutingViaYardsEnabled(false);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    router.setDestination(c3, ActonTrain2, null);
    Assert.assertFalse("Try routing two trains to yard track", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    // restore track length
    AI.setLength(500);
    AI2.setLength(500);
    Setup.setCarRoutingViaYardsEnabled(true);
    // don't allow train 2 to service boxcars with road name BA
    ActonTrain2.addRoadName("BA");
    ActonTrain2.setRoadOption(Train.EXCLUDE_ROADS);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Bedford);
    c3.setFinalDestinationTrack(BS1);
    // routing should work using train 1, destination and track should not be set
    Assert.assertTrue("Try routing two trains via yard", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    // two train testing done!
    // now try up to 5 trains to route car
    // set final destination Clinton
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Clinton);
    c3.setFinalDestinationTrack(null);
    // should fail no train!
    Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
    // create a train with a route from Bedford to Clinton
    Train BedfordToClintonTrain = tmanager.newTrain("Bedford to Clinton");
    Route routeBC = rmanager.newRoute("BC");
    routeBC.addLocation(Bedford);
    RouteLocation rlchelmsford = routeBC.addLocation(Clinton);
    // set train icon coordinates
    rlchelmsford.setTrainIconX(175);
    rlchelmsford.setTrainIconY(250);
    BedfordToClintonTrain.setRoute(routeBC);
    // should work
    Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // allow train 2 to service boxcars with road name BA
    ActonTrain2.setRoadOption(Train.ALL_ROADS);
    // try with train 2
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Clinton);
    // routing should work using train 2
    Assert.assertTrue("Try routing three trains", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Clinton);
    // test to see if second interchange track used if first is full
    AI.setLength(c3.getTotalLength() - 1);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Clinton);
    Assert.assertTrue("Try routing three trains to interchange track 2", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange 2", c3.getDestinationTrackName());
    // use yard track if interchange tracks are full
    AI2.setLength(c3.getTotalLength() - 1);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Clinton);
    Assert.assertTrue("Try routing three trains to yard track", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Yard", c3.getDestinationTrackName());
    // disable the use of yard tracks for routing
    Setup.setCarRoutingViaYardsEnabled(false);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Clinton);
    // both interchange tracks are too short, so there isn't a route
    Assert.assertFalse("Try routing three trains to yard track, option disabled", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    // Try again with an interchange track that is long enough for car c3.
    AI.setLength(c3.getTotalLength());
    Assert.assertEquals("c4 consumes all of the interchange track", Track.OKAY, c4.setLocation(AI.getLocation(), AI));
    // Track AI is long enough, but c4 is consuming all of the track, but there is a route!
    Assert.assertTrue("Try routing three trains to yard track, option disabled", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    // restore track length
    AI.setLength(500);
    AI2.setLength(500);
    Setup.setCarRoutingViaYardsEnabled(true);
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Clinton);
    // don't allow train 2 to service cars built before 1985
    ActonTrain2.setBuiltStartYear("1985");
    ActonTrain2.setBuiltEndYear("2010");
    // routing should work using train 1, but destinations and track should not be set
    Assert.assertTrue("Try routing three trains", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    // allow car to be serviced
    // car was built in 1984 should work
    ActonTrain2.setBuiltStartYear("1983");
    // set final destination Danbury
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Danbury);
    // should fail no train!
    Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
    // create a train with a route from Clinton to Danbury
    Train ClintonToDanburyTrain = tmanager.newTrain("Clinton to Danbury");
    Route routeCD = rmanager.newRoute("CD");
    routeCD.addLocation(Clinton);
    RouteLocation rlDanbury = routeCD.addLocation(Danbury);
    // set train icon coordinates
    rlDanbury.setTrainIconX(250);
    rlDanbury.setTrainIconY(250);
    ClintonToDanburyTrain.setRoute(routeCD);
    // should work
    Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Danbury);
    // routing should work using train 2
    Assert.assertTrue("Try routing four trains", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // clear previous destination
    c3.setDestination(null, null);
    // the final destination for the car
    c3.setFinalDestination(Danbury);
    // don't allow train 2 to service cars with load Tools
    ActonTrain2.addLoadName("Tools");
    ActonTrain2.setLoadOption(Train.EXCLUDE_LOADS);
    // routing should work using train 1, but destinations and track should not be set
    Assert.assertTrue("Try routing four trains", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    // restore train 2
    ActonTrain2.setLoadOption(Train.ALL_LOADS);
    // set final destination Essex
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Essex);
    // should fail no train!
    Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
    // create a train with a route from Danbury to Essex
    Train DanburyToEssexTrain = tmanager.newTrain("Danbury to Essex");
    Route routeDE = rmanager.newRoute("DE");
    RouteLocation rlDanbury2 = routeDE.addLocation(Danbury);
    RouteLocation rlEssex = routeDE.addLocation(Essex);
    // set the number of car moves to 8 for a later test
    rlDanbury2.setMaxCarMoves(8);
    rlEssex.setMaxCarMoves(8);
    // set train icon coordinates
    rlEssex.setTrainIconX(25);
    rlEssex.setTrainIconY(275);
    DanburyToEssexTrain.setRoute(routeDE);
    // should work
    Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // routing should work using train 2
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Essex);
    Assert.assertTrue("Try routing five trains", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Essex);
    // don't allow train 2 to pickup
    rlA2.setPickUpAllowed(false);
    // routing should work using train 1, but destinations and track should not be set
    Assert.assertTrue("Try routing five trains", router.setDestination(c3, ActonTrain2, null));
    Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
    Assert.assertEquals("Check status", Router.STATUS_NOT_THIS_TRAIN, router.getStatus());
    // set final destination Foxboro
    // clear previous destination
    c3.setDestination(null, null);
    c3.setFinalDestination(Foxboro);
    // should fail no train!
    Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
    // create a train with a route from Essex to Foxboro
    Train EssexToFoxboroTrain = tmanager.newTrain("Essex to Foxboro");
    Route routeEF = rmanager.newRoute("EF");
    routeEF.addLocation(Essex);
    RouteLocation rlFoxboro = routeEF.addLocation(Foxboro);
    // set train icon coordinates
    rlFoxboro.setTrainIconX(100);
    rlFoxboro.setTrainIconY(275);
    EssexToFoxboroTrain.setRoute(routeEF);
    // 6th train should fail!  Only 5 trains supported
    Assert.assertFalse("Try routing with final destination and train", router.setDestination(c3, null, null));
    Assert.assertFalse("Try routing with final destination and train", router.setDestination(c3, ActonTrain, null));
    Assert.assertFalse("Try routing with final destination and train", router.setDestination(c3, ActonTrain2, null));
    // get rid of the local train
    AS1.setTrainDirections(Track.NORTH);
    // now should work!
    Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
    Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
    Assert.assertEquals("Check car's destination track", "Bedford Interchange", c3.getDestinationTrackName());
    // require local train for next test
    AS1.setTrainDirections(0);
//TODO test restrict location by car type
//TODO test restrict tracks by type road, load
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) TrainManager(jmri.jmrit.operations.trains.TrainManager) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 5 with CarTypes

use of jmri.jmrit.operations.rollingstock.cars.CarTypes in project JMRI by JMRI.

the class OperationsCarRouterTest method loadLocationsTrainsAndCars.

private void loadLocationsTrainsAndCars() {
    LocationManager lmanager = LocationManager.instance();
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    // create 6 locations and tracks
    Location Acton = lmanager.newLocation("Acton MA");
    Assert.assertEquals("Location 1 Name", "Acton MA", Acton.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, Acton.getLength());
    Track AS1 = Acton.addTrack("Acton Siding 1", Track.SPUR);
    AS1.setLength(300);
    Assert.assertEquals("Location AS1 Name", "Acton Siding 1", AS1.getName());
    Assert.assertEquals("Location AS1 Length", 300, AS1.getLength());
    Track AS2 = Acton.addTrack("Acton Siding 2", Track.SPUR);
    AS2.setLength(300);
    Assert.assertEquals("Location AS2 Name", "Acton Siding 2", AS2.getName());
    Assert.assertEquals("Location AS2 Length", 300, AS2.getLength());
    Track AY = Acton.addTrack("Acton Yard", Track.YARD);
    AY.setLength(400);
    Assert.assertEquals("Location AY Name", "Acton Yard", AY.getName());
    Assert.assertEquals("Location AY Length", 400, AY.getLength());
    Track AI = Acton.addTrack("Acton Interchange", Track.INTERCHANGE);
    AI.setLength(500);
    Assert.assertEquals("Track AI Name", "Acton Interchange", AI.getName());
    Assert.assertEquals("Track AI Length", 500, AI.getLength());
    Assert.assertEquals("Track AI Train Directions", DIRECTION_ALL, AI.getTrainDirections());
    Location Bedford = lmanager.newLocation("Bedford MA");
    Assert.assertEquals("Location 1 Name", "Bedford MA", Bedford.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, Bedford.getLength());
    Track BS1 = Bedford.addTrack("Bedford Siding 1", Track.SPUR);
    BS1.setLength(300);
    Assert.assertEquals("Location BS1 Name", "Bedford Siding 1", BS1.getName());
    Assert.assertEquals("Location BS1 Length", 300, BS1.getLength());
    Track BS2 = Bedford.addTrack("Bedford Siding 2", Track.SPUR);
    BS2.setLength(300);
    Assert.assertEquals("Location BS2 Name", "Bedford Siding 2", BS2.getName());
    Assert.assertEquals("Location BS2 Length", 300, BS2.getLength());
    Track BY = Bedford.addTrack("Bedford Yard", Track.YARD);
    BY.setLength(400);
    Assert.assertEquals("Location BY Name", "Bedford Yard", BY.getName());
    Assert.assertEquals("Location BY Length", 400, BY.getLength());
    Track BI = Bedford.addTrack("Bedford Interchange", Track.INTERCHANGE);
    BI.setLength(500);
    Assert.assertEquals("Track BI Name", "Bedford Interchange", BI.getName());
    Assert.assertEquals("Track BI Length", 500, BI.getLength());
    Location Clinton = lmanager.newLocation("Clinton MA");
    Assert.assertEquals("Location 1 Name", "Clinton MA", Clinton.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, Clinton.getLength());
    Track CS1 = Clinton.addTrack("Clinton Siding 1", Track.SPUR);
    CS1.setLength(300);
    Assert.assertEquals("Location CS1 Name", "Clinton Siding 1", CS1.getName());
    Assert.assertEquals("Location CS1 Length", 300, CS1.getLength());
    Track CS2 = Clinton.addTrack("Clinton Siding 2", Track.SPUR);
    CS2.setLength(300);
    Assert.assertEquals("Location CS2 Name", "Clinton Siding 2", CS2.getName());
    Assert.assertEquals("Location CS2 Length", 300, BS2.getLength());
    Track CY = Clinton.addTrack("Clinton Yard", Track.YARD);
    CY.setLength(400);
    Assert.assertEquals("Location CY Name", "Clinton Yard", CY.getName());
    Assert.assertEquals("Location CY Length", 400, CY.getLength());
    Track CI = Clinton.addTrack("Clinton Interchange", Track.INTERCHANGE);
    CI.setLength(500);
    Assert.assertEquals("Track CI Name", "Clinton Interchange", CI.getName());
    Assert.assertEquals("Track CI Length", 500, CI.getLength());
    Location Danbury = lmanager.newLocation("Danbury MA");
    Track DS1 = Danbury.addTrack("Danbury Siding 1", Track.SPUR);
    DS1.setLength(300);
    Track DS2 = Danbury.addTrack("Danbury Siding 2", Track.SPUR);
    DS2.setLength(300);
    Track DY = Danbury.addTrack("Danbury Yard", Track.YARD);
    DY.setLength(400);
    Track DI = Danbury.addTrack("Danbury Interchange", Track.INTERCHANGE);
    DI.setLength(500);
    Location Essex = lmanager.newLocation("Essex MA");
    Track ES1 = Essex.addTrack("Essex Siding 1", Track.SPUR);
    ES1.setLength(300);
    Track ES2 = Essex.addTrack("Essex Siding 2", Track.SPUR);
    ES2.setLength(300);
    Track EY = Essex.addTrack("Essex Yard", Track.YARD);
    EY.setLength(400);
    Track EI = Essex.addTrack("Essex Interchange", Track.INTERCHANGE);
    EI.setLength(500);
    Location Foxboro = lmanager.newLocation("Foxboro MA");
    Track FS1 = Foxboro.addTrack("Foxboro Siding 1", Track.SPUR);
    FS1.setLength(300);
    Track FS2 = Foxboro.addTrack("Foxboro Siding 2", Track.SPUR);
    FS2.setLength(300);
    Track FY = Foxboro.addTrack("Foxboro Yard", Track.YARD);
    FY.setLength(400);
    Track FI = Foxboro.addTrack("Foxboro Interchange", Track.INTERCHANGE);
    FI.setLength(500);
    // create a local train servicing Acton
    Train ActonTrain = tmanager.newTrain("Acton Local");
    Route routeA = rmanager.newRoute("A");
    RouteLocation rlA = routeA.addLocation(Acton);
    rlA.setMaxCarMoves(10);
    // set train icon coordinates
    rlA.setTrainIconX(25);
    rlA.setTrainIconY(250);
    ActonTrain.setRoute(routeA);
    // create a train with a route from Acton to Bedford
    Train ActonToBedfordTrain = tmanager.newTrain("Acton to Bedford");
    Route routeAB = rmanager.newRoute("AB");
    routeAB.addLocation(Acton);
    RouteLocation rlBedford = routeAB.addLocation(Bedford);
    // set train icon coordinates
    rlBedford.setTrainIconX(100);
    rlBedford.setTrainIconY(250);
    ActonToBedfordTrain.setRoute(routeAB);
    // create a train with a route from Bedford to Clinton
    Train BedfordToClintonTrain = tmanager.newTrain("Bedford to Clinton");
    Route routeBC = rmanager.newRoute("BC");
    routeBC.addLocation(Bedford);
    RouteLocation rlchelmsford = routeBC.addLocation(Clinton);
    // set train icon coordinates
    rlchelmsford.setTrainIconX(175);
    rlchelmsford.setTrainIconY(250);
    BedfordToClintonTrain.setRoute(routeBC);
    // create a train with a route from Clinton to Danbury
    Train ClintonToDanburyTrain = tmanager.newTrain("Clinton to Danbury");
    Route routeCD = rmanager.newRoute("CD");
    routeCD.addLocation(Clinton);
    RouteLocation rlDanbury = routeCD.addLocation(Danbury);
    // set train icon coordinates
    rlDanbury.setTrainIconX(250);
    rlDanbury.setTrainIconY(250);
    ClintonToDanburyTrain.setRoute(routeCD);
    // create a train with a route from Danbury to Essex
    Train DanburyToEssexTrain = tmanager.newTrain("Danbury to Essex");
    Route routeDE = rmanager.newRoute("DE");
    RouteLocation rlDanbury2 = routeDE.addLocation(Danbury);
    RouteLocation rlEssex = routeDE.addLocation(Essex);
    // set the number of car moves to 8 for a later test
    rlDanbury2.setMaxCarMoves(8);
    rlEssex.setMaxCarMoves(8);
    // set train icon coordinates
    rlEssex.setTrainIconX(25);
    rlEssex.setTrainIconY(275);
    DanburyToEssexTrain.setRoute(routeDE);
    // create a train with a route from Essex to Foxboro
    Train EssexToFoxboroTrain = tmanager.newTrain("Essex to Foxboro");
    Route routeEF = rmanager.newRoute("EF");
    routeEF.addLocation(Essex);
    RouteLocation rlFoxboro = routeEF.addLocation(Foxboro);
    // set train icon coordinates
    rlFoxboro.setTrainIconX(100);
    rlFoxboro.setTrainIconY(275);
    EssexToFoxboroTrain.setRoute(routeEF);
    Train BedfordToActonTrain = tmanager.newTrain("BedfordToActonToBedford");
    Route BedfordToActon = RouteManager.instance().newRoute("BedfordToActonToBedford");
    RouteLocation rlB2 = BedfordToActon.addLocation(Bedford);
    RouteLocation rlA3 = BedfordToActon.addLocation(Acton);
    RouteLocation rlB3 = BedfordToActon.addLocation(Bedford);
    // increase the number of moves so all cars are used
    rlB2.setMaxCarMoves(10);
    rlA3.setMaxCarMoves(10);
    rlB3.setMaxCarMoves(10);
    BedfordToActonTrain.setRoute(BedfordToActon);
    // add cars
    Car c3 = cmanager.newCar("BA", "3");
    c3.setTypeName("Boxcar");
    c3.setLength("40");
    c3.setOwner("DAB");
    c3.setBuilt("1984");
    Car c4 = cmanager.newCar("BB", "4");
    c4.setTypeName("Flat");
    c4.setLength("40");
    c4.setOwner("AT");
    c4.setBuilt("1-86");
    c4.setMoves(2);
    Car c5 = cmanager.newCar("BC", "5");
    c5.setTypeName("Boxcar");
    c5.setLoadName("Boxes");
    c5.setLength("40");
    c5.setBuilt("2000");
    c5.setMoves(3);
    Car c6 = cmanager.newCar("BD", "6");
    c6.setTypeName("Boxcar");
    c6.setLoadName("Empty");
    c6.setLength("40");
    c6.setBuilt("2000");
    c6.setMoves(4);
    Car c7 = cmanager.newCar("BA", "7");
    c7.setTypeName("Boxcar");
    c7.setLoadName("Boxes");
    c7.setLength("4");
    c7.setBuilt("2000");
    c7.setMoves(5);
    Car c8 = cmanager.newCar("BB", "8");
    c8.setTypeName("Boxcar");
    c8.setLoadName("Empty");
    c8.setLength("4");
    c8.setBuilt("2000");
    c8.setMoves(6);
    Car c9 = cmanager.newCar("BC", "9");
    c9.setTypeName("Boxcar");
    c9.setLoadName("Empty");
    c9.setLength("4");
    c9.setBuilt("2000");
    c9.setMoves(7);
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) TrainManager(jmri.jmrit.operations.trains.TrainManager) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Aggregations

CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)15 Location (jmri.jmrit.operations.locations.Location)12 LocationManager (jmri.jmrit.operations.locations.LocationManager)12 Track (jmri.jmrit.operations.locations.Track)12 Car (jmri.jmrit.operations.rollingstock.cars.Car)12 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)12 Route (jmri.jmrit.operations.routes.Route)12 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)12 RouteManager (jmri.jmrit.operations.routes.RouteManager)12 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)7 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)7 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)6 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)5 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)3 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)3 ScheduleManager (jmri.jmrit.operations.locations.schedules.ScheduleManager)3 Train (jmri.jmrit.operations.trains.Train)3 TrainManager (jmri.jmrit.operations.trains.TrainManager)3 CarRoads (jmri.jmrit.operations.rollingstock.cars.CarRoads)2 Kernel (jmri.jmrit.operations.rollingstock.cars.Kernel)2