Search in sources :

Example 11 with Consist

use of jmri.jmrit.operations.rollingstock.engines.Consist in project JMRI by JMRI.

the class TrainTest method testStagingtoStaging.

// test train staging to staging
public void testStagingtoStaging() {
    Setup.setSwitchTime(11);
    Setup.setTravelTime(111);
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    EngineTypes et = EngineTypes.instance();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    et.addName("Diesel");
    // Set up four engines in two consists
    Consist con1 = emanager.newConsist("C16");
    Consist con2 = emanager.newConsist("C14");
    Engine e1 = new Engine("PC", "5016");
    e1.setModel("GP40");
    e1.setConsist(con1);
    e1.setMoves(123);
    e1.setOwner("AT");
    e1.setBuilt("1990");
    Assert.assertEquals("Engine 1 Length", "59", e1.getLength());
    emanager.register(e1);
    Engine e2 = new Engine("PC", "5019");
    e2.setModel("GP40");
    e2.setConsist(con1);
    e2.setMoves(321);
    e2.setOwner("AT");
    e2.setBuilt("1990");
    Assert.assertEquals("Engine 2 Length", "59", e2.getLength());
    emanager.register(e2);
    Engine e3 = new Engine("PC", "5524");
    e3.setModel("SD45");
    e3.setConsist(con2);
    e3.setOwner("DAB");
    e3.setBuilt("1980");
    Assert.assertEquals("Engine 3 Length", "66", e3.getLength());
    emanager.register(e3);
    Engine e4 = new Engine("PC", "5559");
    e4.setModel("SD45");
    e4.setConsist(con2);
    e4.setOwner("DAB");
    e4.setBuilt("1980");
    Assert.assertEquals("Engine 4 Length", "66", e4.getLength());
    emanager.register(e4);
    // Set up two cabooses and six box cars
    Car c1 = new Car("CP", "C10099");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(23);
    c1.setOwner("AT");
    c1.setBuilt("1980");
    c1.setCaboose(true);
    Assert.assertEquals("Caboose 1 Length", "32", c1.getLength());
    cmanager.register(c1);
    Car c2 = new Car("CP", "C20099");
    c2.setTypeName("Caboose");
    c2.setLength("32");
    c2.setMoves(54);
    c2.setOwner("DAB");
    c2.setBuilt("1984");
    c2.setCaboose(true);
    Assert.assertEquals("Caboose 2 Length", "32", c2.getLength());
    cmanager.register(c2);
    Car c3 = new Car("CP", "X10001");
    c3.setTypeName("Boxcar");
    c3.setLength("40");
    c3.setOwner("DAB");
    c3.setBuilt("1984");
    Assert.assertEquals("Box Car X10001 Length", "40", c3.getLength());
    cmanager.register(c3);
    Car c4 = new Car("CP", "X10002");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setOwner("AT");
    c4.setBuilt("1-84");
    c4.setMoves(4444);
    Assert.assertEquals("Box Car X10002 Length", "40", c4.getLength());
    cmanager.register(c4);
    Car c5 = new Car("CP", "X20001");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setOwner("DAB");
    c5.setBuilt("1980");
    Assert.assertEquals("Box Car X20001 Length", "40", c5.getLength());
    cmanager.register(c5);
    Car c6 = new Car("CP", "X20002");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setOwner("DAB");
    c6.setBuilt("1978");
    Assert.assertEquals("Box Car X20002 Length", "40", c6.getLength());
    cmanager.register(c6);
    Car c7 = new Car("CP", "777");
    c7.setTypeName("Flat");
    c7.setLength("50");
    c7.setOwner("AT");
    c7.setBuilt("1990");
    c7.setMoves(6);
    Assert.assertEquals("Box Car 777 Length", "50", c7.getLength());
    cmanager.register(c7);
    Car c8 = new Car("CP", "888");
    c8.setTypeName("Boxcar");
    c8.setLength("60");
    c8.setOwner("DAB");
    c8.setBuilt("1985");
    Assert.assertEquals("Box Car 888 Length", "60", c8.getLength());
    cmanager.register(c8);
    Car c9 = new Car("CP", "99");
    c9.setTypeName("Flat");
    c9.setLength("90");
    c9.setOwner("AT");
    c9.setBuilt("6-80");
    Assert.assertEquals("Box Car 888 Length", "90", c9.getLength());
    cmanager.register(c9);
    // do cars have the right default loads?
    Assert.assertEquals("Car c1 load should be E", "E", c1.getLoadName());
    Assert.assertEquals("Car c2 load should be E", "E", c2.getLoadName());
    Assert.assertEquals("Car c3 load should be E", "E", c3.getLoadName());
    Assert.assertEquals("Car c4 load should be E", "E", c4.getLoadName());
    Assert.assertEquals("Car c5 load should be E", "E", c5.getLoadName());
    Assert.assertEquals("Car c6 load should be E", "E", c6.getLoadName());
    Assert.assertEquals("Car c7 load should be E", "E", c7.getLoadName());
    Assert.assertEquals("Car c8 load should be E", "E", c8.getLoadName());
    Assert.assertEquals("Car c9 load should be E", "E", c9.getLoadName());
    // Set up a route of 3 locations: North End Staging (2 tracks),
    // North Industries (1 track), and South End Staging (2 tracks).
    Location l1 = new Location("1", "North End");
    Assert.assertEquals("Location 1 Id", "1", l1.getId());
    Assert.assertEquals("Location 1 Name", "North End", l1.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, l1.getLength());
    l1.setLocationOps(Location.STAGING);
    l1.setTrainDirections(DIRECTION_ALL);
    l1.setSwitchListEnabled(true);
    lmanager.register(l1);
    Track l1s1 = new Track("1s1", "North End 1", Track.STAGING, l1);
    l1s1.setLength(300);
    Assert.assertEquals("Location 1s1 Id", "1s1", l1s1.getId());
    Assert.assertEquals("Location 1s1 Name", "North End 1", l1s1.getName());
    Assert.assertEquals("Location 1s1 LocType", "Staging", l1s1.getTrackType());
    Assert.assertEquals("Location 1s1 Length", 300, l1s1.getLength());
    l1s1.setTrainDirections(DIRECTION_ALL);
    l1s1.setRoadOption(Track.ALL_ROADS);
    l1s1.setDropOption(Track.ANY);
    l1s1.setPickupOption(Track.ANY);
    Track l1s2 = new Track("1s2", "North End 2", Track.STAGING, l1);
    l1s2.setLength(400);
    Assert.assertEquals("Location 1s2 Id", "1s2", l1s2.getId());
    Assert.assertEquals("Location 1s2 Name", "North End 2", l1s2.getName());
    Assert.assertEquals("Location 1s2 LocType", "Staging", l1s2.getTrackType());
    Assert.assertEquals("Location 1s2 Length", 400, l1s2.getLength());
    l1s2.setTrainDirections(DIRECTION_ALL);
    l1s2.setRoadOption(Track.ALL_ROADS);
    l1s2.setDropOption(Track.ANY);
    l1s2.setPickupOption(Track.ANY);
    l1.addTrack("North End 1", Track.STAGING);
    l1.addTrack("North End 2", Track.STAGING);
    List<Track> templist1 = l1.getTrackByNameList(null);
    for (int i = 0; i < templist1.size(); i++) {
        if (i == 0) {
            Assert.assertEquals("RL 1 Staging 1 Name", "North End 1", templist1.get(i).getName());
        }
        if (i == 1) {
            Assert.assertEquals("RL 1 Staging 2 Name", "North End 2", templist1.get(i).getName());
        }
    }
    l1.register(l1s1);
    l1.register(l1s2);
    Assert.assertEquals("Location 1 Length", 700, l1.getLength());
    Location l2 = new Location("2", "North Industries");
    Assert.assertEquals("Location 2 Id", "2", l2.getId());
    Assert.assertEquals("Location 2 Name", "North Industries", l2.getName());
    l2.setLocationOps(Location.NORMAL);
    l2.setTrainDirections(DIRECTION_ALL);
    l2.setSwitchListEnabled(true);
    lmanager.register(l2);
    Track l2s1 = new Track("2s1", "NI Yard", Track.YARD, l2);
    l2s1.setLength(432);
    Assert.assertEquals("Location 2s1 Id", "2s1", l2s1.getId());
    Assert.assertEquals("Location 2s1 Name", "NI Yard", l2s1.getName());
    Assert.assertEquals("Location 2s1 LocType", Track.YARD, l2s1.getTrackType());
    Assert.assertEquals("Location 2s1 Length", 432, l2s1.getLength());
    l2s1.setTrainDirections(DIRECTION_ALL);
    l2.register(l2s1);
    Assert.assertEquals("Location 2 Length", 432, l2.getLength());
    Location l3 = new Location("3", "South End");
    Assert.assertEquals("Location 3 Id", "3", l3.getId());
    Assert.assertEquals("Location 3 Name", "South End", l3.getName());
    Assert.assertEquals("Location 3 Initial Length", 0, l3.getLength());
    l3.setLocationOps(Location.STAGING);
    l3.setTrainDirections(DIRECTION_ALL);
    l3.setSwitchListEnabled(true);
    lmanager.register(l3);
    Track l3s1 = new Track("3s1", "South End 1", Track.STAGING, l3);
    l3s1.setLength(300);
    Assert.assertEquals("Location 3s1 Id", "3s1", l3s1.getId());
    Assert.assertEquals("Location 3s1 Name", "South End 1", l3s1.getName());
    Assert.assertEquals("Location 3s1 LocType", "Staging", l3s1.getTrackType());
    Assert.assertEquals("Location 3s1 Length", 300, l3s1.getLength());
    l3s1.setTrainDirections(DIRECTION_ALL);
    l3s1.setRoadOption(Track.ALL_ROADS);
    l3s1.setDropOption(Track.ANY);
    l3s1.setPickupOption(Track.ANY);
    Track l3s2 = new Track("3s2", "South End 2", Track.STAGING, l3);
    l3s2.setLength(401);
    Assert.assertEquals("Location 3s2 Id", "3s2", l3s2.getId());
    Assert.assertEquals("Location 3s2 Name", "South End 2", l3s2.getName());
    Assert.assertEquals("Location 3s2 LocType", "Staging", l3s2.getTrackType());
    Assert.assertEquals("Location 3s2 Length", 401, l3s2.getLength());
    l3s2.setTrainDirections(DIRECTION_ALL);
    l3s2.setRoadOption(Track.ALL_ROADS);
    l3s2.setDropOption(Track.ANY);
    l3s2.setPickupOption(Track.ANY);
    l3.addTrack("South End 1", Track.STAGING);
    l3.addTrack("South End 2", Track.STAGING);
    List<Track> templist3 = l3.getTrackByNameList(null);
    for (int i = 0; i < templist3.size(); i++) {
        if (i == 0) {
            Assert.assertEquals("RL 3 Staging 1 Name", "South End 1", templist3.get(i).getName());
        }
        if (i == 1) {
            Assert.assertEquals("RL 3 Staging 2 Name", "South End 2", templist3.get(i).getName());
        }
    }
    l3.register(l3s1);
    l3.register(l3s2);
    Assert.assertEquals("Location 3 Length", 701, l3.getLength());
    // Place 4 Boxcars on Staging tracks
    Assert.assertTrue("l1 Accepts Boxcar", l1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("l1s1 Accepts Boxcar", l1s1.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Location 1s1 Init Used Length", 0, l1s1.getUsedLength());
    Assert.assertEquals("Location 1s2 Init Used Length", 0, l1s2.getUsedLength());
    Assert.assertEquals("Location 1 Init Used Length", 0, l1s1.getUsedLength());
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(l1, l1s1));
    Assert.assertEquals("Location 1s1 c3 Used Length", 44, l1s1.getUsedLength());
    Assert.assertEquals("Location 1 c3 Used Length", 44, l1.getUsedLength());
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(l1, l1s1));
    Assert.assertEquals("Location 1s1 c4 Used Length", 88, l1s1.getUsedLength());
    Assert.assertEquals("Location 1 c4 Used Length", 88, l1.getUsedLength());
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(l1, l1s2));
    Assert.assertEquals("Location 1s2 c5 Used Length", 44, l1s2.getUsedLength());
    Assert.assertEquals("Location 1 c5 Used Length", 132, l1.getUsedLength());
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(l1, l1s2));
    Assert.assertEquals("Location 1s2 c6 Used Length", 88, l1s2.getUsedLength());
    Assert.assertEquals("Location 1 c6 Used Length", 176, l1.getUsedLength());
    // Place 2 Boxcars and Flat in yard
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l2, l2s1));
    Assert.assertEquals("Location 2s1 c7 Used Length", 54, l2s1.getUsedLength());
    Assert.assertEquals("Location 2 c7 Used Length", 54, l2.getUsedLength());
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l2, l2s1));
    Assert.assertEquals("Location 2s1 c4 Used Length", 118, l2s1.getUsedLength());
    Assert.assertEquals("Location 2 c4 Used Length", 118, l2.getUsedLength());
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(l2, l2s1));
    Assert.assertEquals("Location 2s1 c9 Used Length", 212, l2s1.getUsedLength());
    Assert.assertEquals("Location 2 c9 Used Length", 212, l2.getUsedLength());
    // Place Cabooses on Staging tracks
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(l1, l1s1));
    Assert.assertEquals("Location 1s1 c1 Used Length", 124, l1s1.getUsedLength());
    Assert.assertEquals("Location 1 c1 Used Length", 212, l1.getUsedLength());
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(l1, l1s2));
    Assert.assertEquals("Location 1s2 c2 Used Length", 124, l1s2.getUsedLength());
    Assert.assertEquals("Location 1 c2 Used Length", 248, l1.getUsedLength());
    // Define the route.
    Route route1 = new Route("1", "Southbound Main Route");
    Assert.assertEquals("Route Id", "1", route1.getId());
    Assert.assertEquals("Route Name", "Southbound Main Route", route1.getName());
    RouteLocation rl1 = new RouteLocation("1r1", l1);
    rl1.setSequenceId(1);
    rl1.setTrainDirection(RouteLocation.SOUTH);
    rl1.setMaxCarMoves(5);
    rl1.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl1.setTrainIconX(25);
    rl1.setTrainIconY(25);
    Assert.assertEquals("Route Location 1 Id", "1r1", rl1.getId());
    Assert.assertEquals("Route Location 1 Name", "North End", rl1.getName());
    RouteLocation rl2 = new RouteLocation("1r2", l2);
    rl2.setSequenceId(2);
    rl2.setTrainDirection(RouteLocation.SOUTH);
    // test for only 1 pickup and 1 drop
    rl2.setMaxCarMoves(2);
    rl2.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(25);
    Assert.assertEquals("Route Location 2 Id", "1r2", rl2.getId());
    Assert.assertEquals("Route Location 2 Name", "North Industries", rl2.getName());
    RouteLocation rl3 = new RouteLocation("1r3", l3);
    rl3.setSequenceId(3);
    rl3.setTrainDirection(RouteLocation.SOUTH);
    rl3.setMaxCarMoves(5);
    rl3.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl3.setTrainIconX(125);
    rl3.setTrainIconY(25);
    Assert.assertEquals("Route Location 3 Id", "1r3", rl3.getId());
    Assert.assertEquals("Route Location 3 Name", "South End", rl3.getName());
    route1.register(rl1);
    route1.register(rl2);
    route1.register(rl3);
    rmanager.register(route1);
    // Finally ready to define the trains.
    Train train1 = new Train("1", "STF");
    Assert.assertEquals("Train Id", "1", train1.getId());
    Assert.assertEquals("Train Name", "STF", train1.getName());
    train1.setRequirements(Train.CABOOSE);
    train1.setCabooseRoad("CP");
    train1.deleteTypeName("Flat");
    train1.setRoadOption(Train.ALL_ROADS);
    train1.setRoute(route1);
    train1.setDepartureTime("6", "5");
    tmanager.register(train1);
    Train train2 = new Train("2", "SFF");
    Assert.assertEquals("Train Id", "2", train2.getId());
    Assert.assertEquals("Train Name", "SFF", train2.getName());
    // there are boxcars waiting in staging so build should fail
    train2.deleteTypeName("Boxcar");
    train2.deleteTypeName("Flat");
    train2.setRoute(route1);
    train2.setDepartureTime("22", "45");
    tmanager.register(train2);
    // Last minute checks.
    Assert.assertEquals("Train 1 Departs Name", "North End", train1.getTrainDepartsName());
    Assert.assertEquals("Train 1 Route Departs Name", "North End", train1.getTrainDepartsRouteLocation().getName());
    Assert.assertEquals("Train 1 Terminates Name", "South End", train1.getTrainTerminatesName());
    Assert.assertEquals("Train 1 Route Terminates Name", "South End", train1.getTrainTerminatesRouteLocation().getName());
    Assert.assertEquals("Train 1 Next Location Name", "", train1.getNextLocationName());
    Assert.assertEquals("Train 1 Route Name", "Southbound Main Route", train1.getRoute().getName());
    Assert.assertEquals("Train 2 Departs Name", "North End", train2.getTrainDepartsName());
    Assert.assertEquals("Train 2 Route Departs Name", "North End", train2.getTrainDepartsRouteLocation().getName());
    Assert.assertEquals("Train 2 Terminates Name", "South End", train2.getTrainTerminatesName());
    Assert.assertEquals("Train 2 Route Terminates Name", "South End", train2.getTrainTerminatesRouteLocation().getName());
    Assert.assertEquals("Train 2 Next Location Name", "", train2.getNextLocationName());
    Assert.assertEquals("Train 2 Route Name", "Southbound Main Route", train2.getRoute().getName());
    // Try building without engines
    train1.build();
    train2.build();
    // Only train 1 should build
    Assert.assertEquals("Train 1 After 1st Build without engines", true, train1.isBuilt());
    Assert.assertEquals("Train 2 After 1st Build exclude Boxcar", false, train2.isBuilt());
    // now allow train 2 to service Boxcars
    train2.addTypeName("Boxcar");
    // Try again, but exclude road name CP
    train2.setRoadOption(Train.EXCLUDE_ROADS);
    train2.addRoadName("CP");
    Assert.assertEquals("Number of road names for train", 1, train2.getRoadNames().length);
    train2.build();
    Assert.assertEquals("Train 2 After Build but exclude road CP", false, train2.isBuilt());
    train2.setRoadOption(Train.ALL_ROADS);
    train2.build();
    Assert.assertEquals("Train 2 After Build include Boxcar", true, train2.isBuilt());
    // check train 1
    Assert.assertEquals("Car c1 After Build without engines should be assigned to Train 1", train1, c1.getTrain());
    Assert.assertEquals("Car c3 After Build without engines should be assigned to Train 1", train1, c3.getTrain());
    Assert.assertEquals("Car c4 After Build without engines should be assigned to Train 1", train1, c4.getTrain());
    Assert.assertEquals("Car c8 After Build without engines should be assigned to Train 1", train1, c8.getTrain());
    // car destinations correct?
    Assert.assertEquals("Car c1 After Build without engines destination", "South End", c1.getDestinationName());
    Assert.assertEquals("Car c3 After Build without engines destination", "North Industries", c3.getDestinationName());
    Assert.assertEquals("Car c4 After Build without engines destination", "South End", c4.getDestinationName());
    Assert.assertEquals("Car c8 After Build without engines destination", "South End", c8.getDestinationName());
    // car destination track correct?
    Assert.assertEquals("Car c1 After without engines Build track", "South End 1", c1.getDestinationTrackName());
    Assert.assertEquals("Car c3 After without engines Build track", "NI Yard", c3.getDestinationTrackName());
    Assert.assertEquals("Car c4 After without engines Build track", "South End 1", c4.getDestinationTrackName());
    Assert.assertEquals("Car c8 After without engines Build track", "South End 1", c8.getDestinationTrackName());
    // Try again building without engines on staging tracks but require them
    train1.setEngineRoad("PC");
    train1.setEngineModel("GP40");
    train1.setNumberEngines("2");
    train2.setNumberEngines("2");
    train1.build();
    train2.build();
    Assert.assertEquals("Train 1 After 2nd Build without engines", false, train1.isBuilt());
    Assert.assertEquals("Train 2 After 2nd Build without engines", false, train2.isBuilt());
    // Place Engines on Staging tracks
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
    Assert.assertEquals("Location 1s1 e1 Used Length", 187, l1s1.getUsedLength());
    Assert.assertEquals("Location 1 e1 Used Length", 311, l1.getUsedLength());
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(l1, l1s1));
    Assert.assertEquals("Location 1s1 e2 Used Length", 250, l1s1.getUsedLength());
    Assert.assertEquals("Location 1 e2 Used Length", 374, l1.getUsedLength());
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(l1, l1s2));
    Assert.assertEquals("Location 1s2 e3 Used Length", 194, l1s2.getUsedLength());
    Assert.assertEquals("Location 1 e3 Used Length", 444, l1.getUsedLength());
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(l1, l1s2));
    Assert.assertEquals("Location 1s2 e4 Used Length", 264, l1s2.getUsedLength());
    Assert.assertEquals("Location 1 e4 Used Length", 514, l1.getUsedLength());
    // Build the trains with engines
    train1.build();
    train2.build();
    // Both should build
    Assert.assertEquals("Train 1 After Build with engines", true, train1.isBuilt());
    Assert.assertEquals("Train 2 After Build with engines", true, train2.isBuilt());
    // Check train 1
    Assert.assertEquals("Train 1 After Build Departs Name", "North End", train1.getTrainDepartsName());
    Assert.assertEquals("Train 1 After Build Terminates Name", "South End", train1.getTrainTerminatesName());
    Assert.assertEquals("Train 1 After Build Next Location Name", "North Industries", train1.getNextLocationName());
    Assert.assertEquals("Train 1 After Build Built Status", true, train1.isBuilt());
    // Are the proper engines and cars assigned to train 1?
    Assert.assertEquals("Engine e1 After Build should be assigned to Train 1", train1, e1.getTrain());
    Assert.assertEquals("Engine e2 After Build should be assigned to Train 1", train1, e2.getTrain());
    Assert.assertEquals("Car c1 After Build should be assigned to Train 1", train1, c1.getTrain());
    Assert.assertEquals("Car c3 After Build should be assigned to Train 1", train1, c3.getTrain());
    Assert.assertEquals("Car c4 After Build should be assigned to Train 1", train1, c4.getTrain());
    Assert.assertEquals("Car c8 After Build should be assigned to Train 1", train1, c8.getTrain());
    // Are the proper engines and cars assigned to train 2?
    Assert.assertEquals("Engine e3 After Build should be assigned to Train 2", train2, e3.getTrain());
    Assert.assertEquals("Engine e4 After Build should be assigned to Train 2", train2, e4.getTrain());
    Assert.assertEquals("Car c2 After Build should be assigned to Train 2", train2, c2.getTrain());
    Assert.assertEquals("Car c5 After Build should be assigned to Train 2", train2, c5.getTrain());
    Assert.assertEquals("Car c7 After Build should be not be assigned", null, c7.getTrain());
    Assert.assertEquals("Car c9 After Build should be not be assigned", null, c9.getTrain());
    // Are the engine and car destinations correct?
    Assert.assertEquals("Engine e1 After Build destination", "South End", e1.getDestinationName());
    Assert.assertEquals("Engine e2 After Build destination", "South End", e2.getDestinationName());
    Assert.assertEquals("Car c1 After Build destination", "South End", c1.getDestinationName());
    Assert.assertEquals("Car c3 After Build destination", "North Industries", c3.getDestinationName());
    Assert.assertEquals("Car c4 After Build destination", "South End", c4.getDestinationName());
    Assert.assertEquals("Car c8 After Build destination", "South End", c8.getDestinationName());
    // Are the engine and car destination track correct?
    Assert.assertEquals("Engine e1 After Build track", "South End 2", e1.getDestinationTrackName());
    Assert.assertEquals("Engine e2 After Build track", "South End 2", e2.getDestinationTrackName());
    Assert.assertEquals("Car c1 After Build track", "South End 2", c1.getDestinationTrackName());
    Assert.assertEquals("Car c3 After Build track", "NI Yard", c3.getDestinationTrackName());
    Assert.assertEquals("Car c4 After Build track", "South End 2", c4.getDestinationTrackName());
    Assert.assertEquals("Car c8 After Build track", "South End 2", c8.getDestinationTrackName());
    // Are the location pickup and drop counts correct?
    Assert.assertEquals("Drop count for North End", 0, l1.getDropRS());
    // Each train has one drop at North Industries
    Assert.assertEquals("Drop count for North Industries", 2, l2.getDropRS());
    // Train1 has 5 drops and Train2 has 4 drops for South End
    Assert.assertEquals("Drop count for South End", 9, l3.getDropRS());
    // Each train has 5 pickups
    Assert.assertEquals("Pickup count for North End", 10, l1.getPickupRS());
    Assert.assertEquals("Pickup count for North Industries", 1, l2.getPickupRS());
    Assert.assertEquals("Pickup count for South End", 0, l3.getPickupRS());
    // Are the track pickup and drop counts correct?
    Assert.assertEquals("Drop count for North End, track North End 1", 0, l1s1.getDropRS());
    Assert.assertEquals("Drop count for North End, track North End 2", 0, l1s2.getDropRS());
    Assert.assertEquals("Pickup count for North End, track North End 1", 5, l1s1.getPickupRS());
    Assert.assertEquals("Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
    // Each train has one drop at NI Yard
    Assert.assertEquals("Drop count for North Industries, track NI Yard", 2, l2s1.getDropRS());
    Assert.assertEquals("Pickup count for North Industries, track NI Yard", 1, l2s1.getPickupRS());
    Assert.assertEquals("Drop count for South End, track South End 1", 4, l3s1.getDropRS());
    Assert.assertEquals("Drop count for South End, track South End 2", 5, l3s2.getDropRS());
    Assert.assertEquals("Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
    Assert.assertEquals("Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
    // Are the other engines and cars assigned correctly?
    Assert.assertEquals("Engine e3 After Build should NOT be assigned to Train 1", train2, e3.getTrain());
    Assert.assertEquals("Engine e4 After Build should NOT be assigned to Train 1", train2, e4.getTrain());
    Assert.assertEquals("Car c2 After Build should NOT be assigned to Train 1", train2, c2.getTrain());
    Assert.assertEquals("Car c5 After Build should NOT be assigned to Train 1", train2, c5.getTrain());
    Assert.assertEquals("Car c6 After Build should NOT be assigned to Train 1", train2, c6.getTrain());
    Assert.assertEquals("Car c7 After Build should NOT be assigned to Train 1", null, c7.getTrain());
    Assert.assertEquals("Car c9 After Build should NOT be assigned to Train 1", null, c9.getTrain());
    // Check expected arrival times
    Assert.assertEquals("Train 1 expected departure time", "06:05", train1.getExpectedArrivalTime(rl1));
    // Check time for car moves and train travel times
    Assert.assertEquals("Per Car move time", 11, Setup.getSwitchTime());
    Assert.assertEquals("Train travel time", 111, Setup.getTravelTime());
    Assert.assertEquals("Train 1 expected North End", "07:56", train1.getExpectedArrivalTime(rl2));
    // one car dropped and one is picked up at North End, so travel time + two car moves
    Assert.assertEquals("Train 1 expected North Industries", "10:09", train1.getExpectedArrivalTime(rl3));
    // Reset the train!
    Assert.assertEquals("Train 1 Reset should be true", true, train1.reset());
    Assert.assertEquals("Train 1 After Reset Departs Name", "North End", train1.getTrainDepartsName());
    Assert.assertEquals("Train 1 After Reset Terminates Name", "South End", train1.getTrainTerminatesName());
    Assert.assertEquals("Train 1 After Reset Next Location Name", "", train1.getNextLocationName());
    Assert.assertEquals("Train 1 After Reset Built Status", false, train1.isBuilt());
    // Are the engines and cars released from train 1?
    Assert.assertEquals("Engine e1 After Reset should NOT be assigned to Train 1", null, e1.getTrain());
    Assert.assertEquals("Engine e2 After Reset should NOT be assigned to Train 1", null, e2.getTrain());
    Assert.assertEquals("Car c1 After Reset should NOT be assigned to Train 1", null, c1.getTrain());
    Assert.assertEquals("Car c3 After Reset should NOT be assigned to Train 1", null, c3.getTrain());
    Assert.assertEquals("Car c4 After Reset should NOT be assigned to Train 1", null, c4.getTrain());
    Assert.assertEquals("Car c8 After Reset should NOT be assigned to Train 1", null, c8.getTrain());
    // Are the location pickup and drop counts correct?
    Assert.assertEquals("Reset Drop count for North End", 0, l1.getDropRS());
    Assert.assertEquals("Reset Drop count for North Industries", 1, l2.getDropRS());
    Assert.assertEquals("Reset Drop count for South End", 4, l3.getDropRS());
    Assert.assertEquals("Reset Pickup count for North End", 5, l1.getPickupRS());
    Assert.assertEquals("Reset Pickup count for North Industries", 0, l2.getPickupRS());
    Assert.assertEquals("Reset Pickup count for South End", 0, l3.getPickupRS());
    // Are the track pickup and drop counts correct?
    Assert.assertEquals("Reset Drop count for North End, track North End 1", 0, l1s1.getDropRS());
    Assert.assertEquals("Reset Drop count for North End, track North End 2", 0, l1s2.getDropRS());
    Assert.assertEquals("Reset Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
    Assert.assertEquals("Reset Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
    Assert.assertEquals("Reset Drop count for North Industries, track NI Yard", 1, l2s1.getDropRS());
    Assert.assertEquals("Reset Pickup count for North Industries, track NI Yard", 1, l2s1.getDropRS());
    Assert.assertEquals("Reset Drop count for South End, track South End 1", 4, l3s1.getDropRS());
    Assert.assertEquals("Reset Drop count for South End, track South End 2", 0, l3s2.getDropRS());
    Assert.assertEquals("Reset Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
    Assert.assertEquals("Reset Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
    // Try again, but exclude caboose
    // there are cabooses waiting in staging so build should fail
    train1.deleteTypeName("Caboose");
    train1.build();
    Assert.assertEquals("Train 1 After Build with engines but exclude Caboose", false, train1.isBuilt());
    train1.addTypeName("Caboose");
    // Try again, but exclude road name CP
    train1.setRoadOption(Train.EXCLUDE_ROADS);
    train1.addRoadName("CP");
    Assert.assertEquals("Number of road names for train", 1, train1.getRoadNames().length);
    train1.build();
    Assert.assertEquals("Train 1 After Build with engines but exclude road CP", false, train1.isBuilt());
    train1.setRoadOption(Train.ALL_ROADS);
    // try again, but set the caboose destination to NI yard
    c1.setDestination(l2, null);
    train1.build();
    Assert.assertEquals("Train 1 build should fail, caboose destination isn't terminal", false, train1.isBuilt());
    // send caboose to last location which is staging
    c1.setDestination(l3, null);
    train1.build();
    Assert.assertEquals("Train 1 build, caboose destination is terminal", true, train1.isBuilt());
    // don't allow cabooses road
    l3.deleteTypeName("Caboose");
    train1.build();
    Assert.assertEquals("Train 1 build, caboose destination is terminal", false, train1.isBuilt());
    l3.addTypeName("Caboose");
    // Try again, but only allow rolling stock built before 1985
    train2.reset();
    train1.setBuiltEndYear("1985");
    train1.build();
    // should fail, required engines have built dates after 1985
    Assert.assertEquals("Train 1 After Build with rs built before 1985", false, train1.isBuilt());
    // change the engine built date
    e1.setBuilt("7-84");
    e2.setBuilt("1984");
    train1.build();
    Assert.assertEquals("Train 1 After 2nd Build with rs built before 1985", true, train1.isBuilt());
    // change one of the car's built date to after 1985
    c4.setBuilt("1-85");
    train1.build();
    // should fail
    Assert.assertEquals("Train 1 After 3rd Build with rs built before 1985", false, train1.isBuilt());
    train1.setBuiltEndYear("");
    train1.build();
    Assert.assertEquals("Train 1 After 4th Build with rs built before 1985", true, train1.isBuilt());
    // Try again, but now exclude engine type Diesel
    train1.deleteTypeName("Diesel");
    train1.build();
    Assert.assertEquals("Train 1 After 1st Build type Diesel not serviced", false, train1.isBuilt());
    train1.addTypeName("Diesel");
    train1.build();
    Assert.assertEquals("Train 1 After 2nd Build type Diesel serviced", true, train1.isBuilt());
    // Try again, but now restrict owner
    train1.addOwnerName("DAB");
    train1.setOwnerOption(Train.INCLUDE_OWNERS);
    train1.build();
    Assert.assertEquals("Train 1 After 1st Build owner DAB", false, train1.isBuilt());
    train1.addOwnerName("AT");
    train1.build();
    Assert.assertEquals("Train 1 After 2nd Build owners DAB and AT", true, train1.isBuilt());
    train1.setOwnerOption(Train.EXCLUDE_OWNERS);
    train1.build();
    Assert.assertEquals("Train 1 After 3rd Build exclude owners DAB and AT", false, train1.isBuilt());
    train1.deleteOwnerName("AT");
    train1.build();
    Assert.assertEquals("Train 1 After 4th Build exclude owner DAB", false, train1.isBuilt());
    train1.setOwnerOption(Train.ALL_OWNERS);
    train1.build();
    Assert.assertEquals("Train 1 After 5th Build all owners", true, train1.isBuilt());
    // Try again, but now restrict load
    train1.addLoadName("L");
    train1.setLoadOption(Train.INCLUDE_LOADS);
    train1.build();
    // build should fail, cars in staging have E loads
    Assert.assertEquals("Train 1 After include load L", false, train1.isBuilt());
    train1.deleteLoadName("L");
    // this car shouldn't be picked up.
    c8.setLoadName("L");
    train1.addLoadName("E");
    train1.build();
    Assert.assertEquals("Train 1 After include load E", true, train1.isBuilt());
    Assert.assertEquals("car C10099 in staging should be assigned to train", train1, c1.getTrain());
    Assert.assertEquals("car X1001 in staging should be assigned to train", train1, c3.getTrain());
    Assert.assertEquals("car X1002 in staging should be assigned to train", train1, c4.getTrain());
    Assert.assertEquals("car 888 at siding has load L, excluded", null, c8.getTrain());
    train1.addLoadName("L");
    train1.build();
    Assert.assertEquals("Train 1 After include load L", true, train1.isBuilt());
    Assert.assertEquals("car C10099 in staging should be assigned to train", train1, c1.getTrain());
    Assert.assertEquals("car X1001 in staging should be assigned to train", train1, c3.getTrain());
    Assert.assertEquals("car X1002 in staging should be assigned to train", train1, c4.getTrain());
    Assert.assertEquals("car 888 at siding has load L, now included", train1, c8.getTrain());
    train1.setLoadOption(Train.EXCLUDE_LOADS);
    // cars in staging have E loads, so build should fail
    train1.build();
    Assert.assertEquals("Train 1 After exclude loads", false, train1.isBuilt());
    // allow train to carry E loads
    train1.deleteLoadName("E");
    train1.build();
    Assert.assertEquals("Train 1 After exclude loads L", true, train1.isBuilt());
    Assert.assertEquals("car C10099 in staging should be assigned to train", train1, c1.getTrain());
    Assert.assertEquals("car X1001 in staging should be assigned to train", train1, c3.getTrain());
    Assert.assertEquals("car X1002 in staging should be assigned to train", train1, c4.getTrain());
    Assert.assertEquals("car 888 at siding has load L, now excluded", null, c8.getTrain());
    // done
    train1.setLoadOption(Train.ALL_LOADS);
    // Try again, but now set staging track service direction NORTH, train departs to the south
    l1s1.setTrainDirections(Location.NORTH);
    l1s2.setTrainDirections(Location.NORTH);
    train1.build();
    Assert.assertEquals("Train 1 After 1st Build staging set to North", false, train1.isBuilt());
    l1s1.setTrainDirections(Location.SOUTH);
    l1s2.setTrainDirections(Location.SOUTH);
    train1.build();
    Assert.assertEquals("Train 1 After 2nd Build staging set to South", true, train1.isBuilt());
    // need to reset train to release cars
    train1.reset();
    // Try again, but now have a car with a destination not serviced by train
    Location nowhere = lmanager.newLocation("nowhere");
    c4.setDestination(nowhere, null);
    train1.build();
    Assert.assertEquals("Train 1 After Build car to nowhere", false, train1.isBuilt());
    c4.setDestination(null, null);
    // Build the trains again!!
    train1.build();
    train2.build();
    Assert.assertEquals("Train 1 After Build with engines include all roads", true, train1.isBuilt());
    Assert.assertEquals("Train 1 After Build Departs Name", "North End", train1.getTrainDepartsName());
    Assert.assertEquals("Train 1 After Build Terminates Name", "South End", train1.getTrainTerminatesName());
    Assert.assertEquals("Train 1 After Build Next Location Name", "North Industries", train1.getNextLocationName());
    // now trying limiting the number of cars that can depart staging
    // there are three cars in staging
    rl1.setMaxCarMoves(2);
    train1.build();
    Assert.assertEquals("Train 1 After Build limit train to 2 cars out of staging", false, train1.isBuilt());
    // try again but now the train can have three cars departing staging
    // there are three cars in staging
    rl1.setMaxCarMoves(3);
    train1.build();
    Assert.assertEquals("Train 1 After Build limit train to 3 cars out of staging", true, train1.isBuilt());
    // Move the train #1
    train1.move();
    Assert.assertEquals("Train 1 After 1st Move Current Name", "North Industries", train1.getCurrentLocationName());
    Assert.assertEquals("Train 1 After 1st Move Next Location Name", "South End", train1.getNextLocationName());
    // Is the train in route?
    Assert.assertEquals("Train 1 in route after 1st", true, train1.isTrainEnRoute());
    // Try and reset the train
    Assert.assertEquals("Train 1 Reset should be false", false, train1.reset());
    // Are the engine and car locations correct?
    Assert.assertEquals("Engine e1 After After 1st Move", "North Industries", e1.getLocationName());
    Assert.assertEquals("Engine e2 After After 1st Move", "North Industries", e2.getLocationName());
    Assert.assertEquals("Car c1 After After 1st Move", "North Industries", c1.getLocationName());
    Assert.assertEquals("Car c3 After After 1st Move", "North Industries", c3.getLocationName());
    Assert.assertEquals("Car c4 After After 1st Move", "North Industries", c4.getLocationName());
    Assert.assertEquals("Car c8 After After 1st Move", "North Industries", c8.getLocationName());
    // Are the location pickup and drop counts correct?
    Assert.assertEquals("Move 1 Drop count for North End", 0, l1.getDropRS());
    Assert.assertEquals("Move 1 Drop count for North Industries", 2, l2.getDropRS());
    Assert.assertEquals("Move 1 Drop count for South End", 9, l3.getDropRS());
    Assert.assertEquals("Move 1 Pickup count for North End", 5, l1.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for North Industries", 1, l2.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for South End", 0, l3.getPickupRS());
    // Are the track pickup and drop counts correct?
    Assert.assertEquals("Move 1 Drop count for North End, track North End 1", 0, l1s1.getDropRS());
    Assert.assertEquals("Move 1 Drop count for North End, track North End 2", 0, l1s2.getDropRS());
    Assert.assertEquals("Move 1 Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
    Assert.assertEquals("Move 1 Drop count for North Industries, track NI Yard", 2, l2s1.getDropRS());
    Assert.assertEquals("Move 1 Pickup count for North Industries, track NI Yard", 1, l2s1.getPickupRS());
    Assert.assertEquals("Move 1 Drop count for South End, track South End 1", 4, l3s1.getDropRS());
    Assert.assertEquals("Move 1 Drop count for South End, track South End 2", 5, l3s2.getDropRS());
    Assert.assertEquals("Move 1 Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
    // Move the train #2
    train1.move();
    Assert.assertEquals("Train 1 After 2nd Move Current Name", "South End", train1.getCurrentLocationName());
    Assert.assertEquals("Train 1 After 2nd Move Next Location Name", "", train1.getNextLocationName());
    // Is the train in route?
    Assert.assertEquals("Train 1 in route after 2nd", true, train1.isTrainEnRoute());
    // Are the engine and car locations correct?
    Assert.assertEquals("Engine e1 After After 2nd Move", "South End", e1.getLocationName());
    Assert.assertEquals("Engine e2 After After 2nd Move", "South End", e2.getLocationName());
    Assert.assertEquals("Car c1 After After 2nd Move", "South End", c1.getLocationName());
    Assert.assertEquals("Car c3 After After 2nd Move", "North Industries", c3.getLocationName());
    Assert.assertEquals("Car c4 After After 2nd Move", "South End", c4.getLocationName());
    Assert.assertEquals("Car c8 After After 2nd Move", "South End", c8.getLocationName());
    // was c3 released from train?
    Assert.assertEquals("Car c3 After drop should NOT be assigned to Train 1", null, c3.getTrain());
    Assert.assertEquals("Car c3 destination After 2nd Move", "", c3.getDestinationTrackName());
    Assert.assertEquals("Car c3 After 2nd Move location", "North Industries", c3.getLocationName());
    Assert.assertEquals("Car c3 After 2nd Move", "NI Yard", c3.getTrackName());
    Assert.assertEquals("Car c3 Moves after drop should be 14", 14, c3.getMoves());
    // Are the location pickup and drop counts correct?
    Assert.assertEquals("Move 2 Drop count for North End", 0, l1.getDropRS());
    Assert.assertEquals("Move 2 Drop count for North Industries", 1, l2.getDropRS());
    Assert.assertEquals("Move 2 Drop count for South End", 9, l3.getDropRS());
    Assert.assertEquals("Move 2 Pickup count for North End", 5, l1.getPickupRS());
    Assert.assertEquals("Move 2 Pickup count for North Industries", 0, l2.getPickupRS());
    Assert.assertEquals("Move 2 Pickup count for South End", 0, l3.getPickupRS());
    // Are the track pickup and drop counts correct?
    Assert.assertEquals("Move 2 Drop count for North End, track North End 1", 0, l1s1.getDropRS());
    Assert.assertEquals("Move 2 Drop count for North End, track North End 2", 0, l1s2.getDropRS());
    Assert.assertEquals("Move 2 Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
    Assert.assertEquals("Move 2 Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
    Assert.assertEquals("Move 2 Drop count for North Industries, track NI Yard", 1, l2s1.getDropRS());
    Assert.assertEquals("Move 2 Pickup count for North Industries, track NI Yard", 0, l2s1.getPickupRS());
    Assert.assertEquals("Move 2 Drop count for South End, track South End 1", 4, l3s1.getDropRS());
    Assert.assertEquals("Move 2 Drop count for South End, track South End 2", 5, l3s2.getDropRS());
    Assert.assertEquals("Move 2 Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
    Assert.assertEquals("Move 2 Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
    // Move the train #3 (Terminate)
    train1.move();
    Assert.assertEquals("Train 1 After 3rd Move Current Name", "", train1.getCurrentLocationName());
    Assert.assertEquals("Train 1 After 3rd Move Next Location Name", "", train1.getNextLocationName());
    Assert.assertEquals("Train 1 After 3rd Move Status", Train.TERMINATED, getTrainStatus(train1));
    // Is the train in route?
    Assert.assertEquals("Train 1 in route after 3rd", false, train1.isTrainEnRoute());
    // Are the engine and car destinations correct?
    Assert.assertEquals("Engine e1 After 3rd Move", "", e1.getDestinationTrackName());
    Assert.assertEquals("Engine e2 After 3rd Move", "", e2.getDestinationTrackName());
    Assert.assertEquals("Car c1 After 3rd Move", "", c1.getDestinationTrackName());
    Assert.assertEquals("Car c4 After 3rd Move", "", c4.getDestinationTrackName());
    Assert.assertEquals("Car c8 After 3rd Move", "", c8.getDestinationTrackName());
    // Are the engine and car final locations correct?
    Assert.assertEquals("Engine e1 After Terminate location", "South End", e1.getLocationName());
    Assert.assertEquals("Engine e2 After Terminate location", "South End", e2.getLocationName());
    Assert.assertEquals("Car c1 After Terminate location", "South End", c1.getLocationName());
    Assert.assertEquals("Car c4 After Terminate location", "South End", c4.getLocationName());
    Assert.assertEquals("Car c8 After Terminate location", "South End", c8.getLocationName());
    // Are the engine and car final staging track correct?
    Assert.assertEquals("Engine e1 After Terminate track", "South End 2", e1.getTrackName());
    Assert.assertEquals("Engine e2 After Terminate track", "South End 2", e2.getTrackName());
    Assert.assertEquals("Car c1 After Terminate track", "South End 2", c1.getTrackName());
    Assert.assertEquals("Car c4 After Terminate track", "South End 2", c4.getTrackName());
    Assert.assertEquals("Car c8 After Terminate track", "South End 2", c8.getTrackName());
    // Are the engine and car moves correct
    Assert.assertEquals("Engine e1 Moves after Terminate should be 137", 137, e1.getMoves());
    Assert.assertEquals("Engine e2 Moves after Terminate should be 335", 335, e2.getMoves());
    Assert.assertEquals("Car c1 Moves after Terminate should be 37", 37, c1.getMoves());
    Assert.assertEquals("Car c4 Moves after Terminate should be 4458", 4458, c4.getMoves());
    Assert.assertEquals("Car c8 Moves after Terminate should be 11", 11, c8.getMoves());
    // Are the location pickup and drop counts correct?
    Assert.assertEquals("Move 3 Drop count for North End", 0, l1.getDropRS());
    Assert.assertEquals("Move 3 Drop count for North Industries", 1, l2.getDropRS());
    Assert.assertEquals("Move 3 Drop count for South End", 4, l3.getDropRS());
    Assert.assertEquals("Move 3 Pickup count for North End", 5, l1.getPickupRS());
    Assert.assertEquals("Move 3 Pickup count for North Industries", 0, l2.getPickupRS());
    Assert.assertEquals("Move 3 Pickup count for South End", 0, l3.getPickupRS());
    // Are the track pickup and drop counts correct?
    Assert.assertEquals("Move 3 Drop count for North End, track North End 1", 0, l1s1.getDropRS());
    Assert.assertEquals("Move 3 Drop count for North End, track North End 2", 0, l1s2.getDropRS());
    Assert.assertEquals("Move 3 Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
    Assert.assertEquals("Move 3 Pickup count for North End, track North End 2", 5, l1s2.getPickupRS());
    Assert.assertEquals("Move 3 Drop count for North Industries, track NI Yard", 1, l2s1.getDropRS());
    Assert.assertEquals("Move 3 Pickup count for North Industries, track NI Yard", 0, l2s1.getPickupRS());
    Assert.assertEquals("Move 3 Drop count for South End, track South End 1", 4, l3s1.getDropRS());
    Assert.assertEquals("Move 3 Drop count for South End, track South End 2", 0, l3s2.getDropRS());
    Assert.assertEquals("Move 3 Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
    Assert.assertEquals("Move 3 Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
    // Move the train 1 for the forth time, this shouldn't change anything
    train1.move();
    Assert.assertEquals("Train 1 After 4th Move Current Name", "", train1.getCurrentLocationName());
    Assert.assertEquals("Train 1 After 4th Move Next Location Name", "", train1.getNextLocationName());
    Assert.assertEquals("Train 1 After 4th Move Status", Train.TERMINATED, getTrainStatus(train1));
    // Is the train in route?
    Assert.assertEquals("Train 1 sould not be in route", false, train1.isTrainEnRoute());
    // Are the engines and cars released from train 1?
    Assert.assertEquals("Engine e1 After Terminate should NOT be assigned to Train 1", null, e1.getTrain());
    Assert.assertEquals("Engine e2 After Terminate should NOT be assigned to Train 1", null, e2.getTrain());
    Assert.assertEquals("Car c1 After Terminate should NOT be assigned to Train 1", null, c1.getTrain());
    Assert.assertEquals("Car c4 After Terminate should NOT be assigned to Train 1", null, c4.getTrain());
    // do cars have the right loads?
    Assert.assertEquals("Car c1 load after Terminate", "E", c1.getLoadName());
    Assert.assertEquals("Car c2 load after Terminate", "E", c2.getLoadName());
    Assert.assertEquals("Car c3 load after Terminate", "E", c3.getLoadName());
    Assert.assertEquals("Car c4 load after Terminate", "E", c4.getLoadName());
    Assert.assertEquals("Car c5 load after Terminate", "E", c5.getLoadName());
    Assert.assertEquals("Car c6 load after Terminate", "E", c6.getLoadName());
    Assert.assertEquals("Car c7 load after Terminate", "E", c7.getLoadName());
    Assert.assertEquals("Car c8 load after Terminate", "L", c8.getLoadName());
    Assert.assertEquals("Car c9 load after Terminate", "E", c9.getLoadName());
    // reset train 2
    Assert.assertTrue("reset train2", train2.reset());
    // Are the location pickup and drop counts correct?
    Assert.assertEquals("Terminated Drop count for North End", 0, l1.getDropRS());
    Assert.assertEquals("Terminated Drop count for North Industries", 0, l2.getDropRS());
    Assert.assertEquals("Terminated Drop count for South End", 0, l3.getDropRS());
    Assert.assertEquals("Terminated Pickup count for North End", 0, l1.getPickupRS());
    Assert.assertEquals("Terminated Pickup count for North Industries", 0, l2.getPickupRS());
    Assert.assertEquals("Terminated Pickup count for South End", 0, l3.getPickupRS());
    // Are the track pickup and drop counts correct?
    Assert.assertEquals("Terminated Drop count for North End, track North End 1", 0, l1s1.getDropRS());
    Assert.assertEquals("Terminated Drop count for North End, track North End 2", 0, l1s2.getDropRS());
    Assert.assertEquals("Terminated Pickup count for North End, track North End 1", 0, l1s1.getPickupRS());
    Assert.assertEquals("Terminated Pickup count for North End, track North End 2", 0, l1s2.getPickupRS());
    Assert.assertEquals("Terminated Drop count for North Industries, track NI Yard", 0, l2s1.getDropRS());
    Assert.assertEquals("Terminated Pickup count for North Industries, track NI Yard", 0, l2s1.getDropRS());
    Assert.assertEquals("Terminated Drop count for South End, track South End 1", 0, l3s1.getDropRS());
    Assert.assertEquals("Terminated Drop count for South End, track South End 2", 0, l3s2.getDropRS());
    Assert.assertEquals("Terminated Pickup count for South End, track South End 1", 0, l3s1.getPickupRS());
    Assert.assertEquals("Terminated Pickup count for South End, track South End 2", 0, l3s2.getPickupRS());
    // this should fail, there are two engines in staging
    train2.setNumberEngines("1");
    // now build train 2 testing failure modes
    train2.build();
    // build required 1 engine and there were two
    Assert.assertEquals("Train 2 After Build require 1 engine", false, train2.isBuilt());
    // take one engine out of the consist
    e4.setConsist(null);
    train2.build();
    Assert.assertEquals("Train 2 After Build require 1 engine, but 2 engines on staging track", false, train2.isBuilt());
    // remove engine from staging
    e4.setLocation(null, null);
    train2.build();
    Assert.assertEquals("Train 2 After Build require 1 engine, 1 consisted engine on staging track", true, train2.isBuilt());
    // take lead engine out of consist
    e3.setConsist(null);
    train2.build();
    Assert.assertEquals("Train 2 After Build require 1 engine, single engine on staging track", true, train2.isBuilt());
    // restore engines and place back on staging tracks
    e3.setConsist(con2);
    e4.setConsist(con2);
    e3.setLocation(l1, l1s2);
    e4.setLocation(l1, l1s2);
    // should work for 0
    train2.setNumberEngines("0");
    train2.build();
    Assert.assertEquals("Train 2 After Build require 0 engine", true, train2.isBuilt());
    train2.setNumberEngines("3");
    train2.build();
    Assert.assertEquals("Train 2 After Build require 3 engines", false, train2.isBuilt());
    train2.setNumberEngines("2");
    train2.build();
    Assert.assertEquals("Train 2 After Build require 2 engine", true, train2.isBuilt());
    // take engine out of service
    e3.setOutOfService(true);
    train2.build();
    Assert.assertEquals("Train 2 After Build engine out of service", false, train2.isBuilt());
    // put back into service
    e3.setOutOfService(false);
    train2.build();
    Assert.assertEquals("Train 2 After Build engine in service", true, train2.isBuilt());
    // try different road
    train2.setEngineRoad("CP");
    train2.build();
    Assert.assertEquals("Train 2 After Build require road CP", false, train2.isBuilt());
    train2.setEngineRoad("PC");
    // try requiring FRED, should fail
    train2.setRequirements(Train.FRED);
    train2.build();
    Assert.assertEquals("Train 2 After Build requires FRED", false, train2.isBuilt());
    // Add FRED to boxcar
    c5.setFred(true);
    train2.build();
    Assert.assertEquals("Train 2 After Build 2 requires FRED", true, train2.isBuilt());
    // try engine wrong model
    train2.setEngineModel("DS45");
    train2.build();
    Assert.assertEquals("Train 2 After Build 2 requires model DS45", false, train2.isBuilt());
    // try engine correct model
    train2.setEngineModel("SD45");
    train2.build();
    Assert.assertEquals("Train 2 After Build 2 requires model SD45", true, train2.isBuilt());
    // Are the engines and cars assigned to train 2?
    Assert.assertEquals("Engine e3 After Build should be assigned to Train 2", train2, e3.getTrain());
    Assert.assertEquals("Engine e4 After Build should be assigned to Train 2", train2, e4.getTrain());
    Assert.assertEquals("Car c2 After Build should be assigned to Train 2", train2, c2.getTrain());
    Assert.assertEquals("Car c3 After Build should be assigned to Train 2", train2, c3.getTrain());
    Assert.assertEquals("Car c5 After Build should be assigned to Train 2", train2, c5.getTrain());
    Assert.assertEquals("Car c6 After Build should be assigned to Train 2", train2, c6.getTrain());
    // train 2 does not accept Flat
    Assert.assertEquals("Car c7 After Build should NOT be assigned to Train 2", null, c7.getTrain());
    Assert.assertEquals("Car c9 After Build should NOT be assigned to Train 2", null, c9.getTrain());
    // now allow Flat
    train2.addTypeName("Flat");
    c9.setLength("200");
    train2.build();
    // c9 and c7 have less moves than c3, but there's not enough room for c9 at destination
    Assert.assertEquals("Car c3 After Build 3 should be assigned to Train 2", null, c3.getTrain());
    Assert.assertEquals("Car c7 After Build 3 should be assigned to Train 2", train2, c7.getTrain());
    Assert.assertEquals("Car c9 After Build 3 should NOT be assigned to Train 2", null, c9.getTrain());
    // c7 is assigned to Staging Track South End 1 its load will swap
    Assert.assertEquals("Car c7 After Build 3 destination", "South End 1", c7.getDestinationTrackName());
    Assert.assertEquals("Car c7 load After Build 3", "E", c7.getLoadName());
    // increase the size of staging
    l3s2.setLength(500);
    // allow default load swaps
    // South End 2
    l3s2.setLoadSwapEnabled(true);
    train2.build();
    // Check expected arrival times
    Assert.assertEquals("Train 2 expected departure time", "22:45", train2.getExpectedArrivalTime(rl1));
    Assert.assertEquals("Train 2 expected North End", "1:00:36", train2.getExpectedArrivalTime(rl2));
    // one car dropped and one is picked up at North End, so travel time + two car moves
    Assert.assertEquals("Train 2 expected North Industries", "1:02:49", train2.getExpectedArrivalTime(rl3));
    // the build first resets which removes cars from the train, c3 load should NOT swap
    Assert.assertEquals("Car c3 load After Build 4", "E", c3.getLoadName());
    // c9 has less moves than c3 and c7, and now there's enough room for c9
    Assert.assertEquals("Car c3 After Build 4 should NOT be assigned to Train 2", null, c3.getTrain());
    Assert.assertEquals("Car c7 After Build 4 should be assigned to Train 2", train2, c7.getTrain());
    Assert.assertEquals("Car c9 After Build 4 should NOT be assigned to Train 2", null, c9.getTrain());
    // move the train #1
    train2.move();
    // Is the train in route?
    Assert.assertEquals("Train 2 in route after 1st", true, train2.isTrainEnRoute());
    // #2
    train2.move();
    // Is the train in route?
    Assert.assertEquals("Train 2 in route after 2nd", true, train2.isTrainEnRoute());
    // #3
    train2.move();
    // Is the train in route?
    Assert.assertEquals("Train 2 in route after 3rd", false, train2.isTrainEnRoute());
    // Are the engine and car final tracks correct?
    Assert.assertEquals("Engine e1 After Terminate track", "South End 2", e1.getTrackName());
    Assert.assertEquals("Engine e2 After Terminate track", "South End 2", e2.getTrackName());
    Assert.assertEquals("Engine e3 After Terminate track", "South End 1", e3.getTrackName());
    Assert.assertEquals("Engine e4 After Terminate track", "South End 1", e4.getTrackName());
    Assert.assertEquals("Car c1 After Terminate track", "South End 2", c1.getTrackName());
    Assert.assertEquals("Car c2 After Terminate track", "South End 1", c2.getTrackName());
    Assert.assertEquals("Car c3 After Terminate track", "NI Yard", c3.getTrackName());
    Assert.assertEquals("Car c4 After Terminate track", "South End 2", c4.getTrackName());
    Assert.assertEquals("Car c5 After Terminate track", "South End 1", c5.getTrackName());
    Assert.assertEquals("Car c6 After Terminate track", "NI Yard", c6.getTrackName());
    Assert.assertEquals("Car c7 After Terminate track", "South End 1", c7.getTrackName());
    Assert.assertEquals("Car c8 After Terminate track", "South End 2", c8.getTrackName());
    Assert.assertEquals("Car c9 After Terminate track", "NI Yard", c9.getTrackName());
    // do cars have the right loads?
    Assert.assertEquals("Car c1 load after Terminate Train 2", "E", c1.getLoadName());
    Assert.assertEquals("Car c2 load after Terminate Train 2", "E", c2.getLoadName());
    Assert.assertEquals("Car c3 load after Terminate Train 2", "E", c3.getLoadName());
    Assert.assertEquals("Car c4 load after Terminate Train 2", "E", c4.getLoadName());
    Assert.assertEquals("Car c5 load after Terminate Train 2", "E", c5.getLoadName());
    Assert.assertEquals("Car c6 load after Terminate Train 2", "E", c6.getLoadName());
    Assert.assertEquals("Car c7 load after Terminate Train 2", "E", c7.getLoadName());
    Assert.assertEquals("Car c8 load after Terminate Train 2", "L", c8.getLoadName());
    Assert.assertEquals("Car c9 load after Terminate Train 2", "E", c9.getLoadName());
    // try building again
    // Place caboose on Staging tracks
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(l1, l1s1));
    train2.setRequirements(Train.CABOOSE);
    train2.setNumberEngines("0");
    train2.build();
    // Should fail both staging tracks are full
    Assert.assertFalse("Train 2 not built", train2.isBuilt());
    // add a new staging track
    Track l3s3 = l3.addTrack("South End 3", Track.STAGING);
    l3s3.setLength(200);
    train2.build();
    // Should build
    Assert.assertTrue("Train 2 built", train2.isBuilt());
    // make staging track too small for caboose
    l3s3.setLength(20);
    train2.build();
    // Should not build
    Assert.assertFalse("Train 2 built", train2.isBuilt());
    // restore
    l3s3.setLength(200);
    // Car X10001 is a location North Industries, NI Yard, send boxcar X10001 to staging
    Assert.assertEquals("set destination", Track.OKAY, c3.setDestination(l3, null));
    train2.build();
    // Should build
    Assert.assertTrue("Train 2 built", train2.isBuilt());
    Assert.assertEquals("Car X10001 to staging track", l3s3, c3.getDestinationTrack());
    Assert.assertEquals("Car X10001 assigned to train 2", train2, c3.getTrain());
    // Send car X10001 to staging and track that isn't being used
    train2.reset();
    Assert.assertEquals("set destination", Track.OKAY, c3.setDestination(l3, l3s2));
    train2.build();
    // Should build
    Assert.assertTrue("Train 2 built", train2.isBuilt());
    Assert.assertEquals("Car X10001 not assigned to train 2", train2, c3.getTrain());
    // Send car X10001 to staging and the only track available
    train2.reset();
    // this removes track, it is now reserved
    c3.setDestination(l3, l3s3);
    train2.build();
    // Should not build
    Assert.assertFalse("Train 2 built", train2.isBuilt());
    Assert.assertEquals("Car X10001 assigned to train 2", null, c3.getTrain());
    train2.setRequirements(Train.NO_CABOOSE_OR_FRED);
    train2.reset();
    ct.addName("BOXCAR");
    train2.addTypeName("BOXCAR");
    c3.setTypeName("BOXCAR");
    l3.addTypeName("BOXCAR");
    c3.setDestination(l3, null);
    train2.build();
    // Should Not build, staging track South End 3 doesn't service type BOXCAR
    Assert.assertFalse("Train 2 will not build due to BOXCAR", train2.isBuilt());
    Assert.assertEquals("Car X10001 NOT assigned to train 2", null, c3.getTrain());
    // turn off staging check
    Setup.setTrainIntoStagingCheckEnabled(false);
    train2.build();
    Assert.assertTrue("Train 2 will now build ignoring BOXCAR", train2.isBuilt());
    Assert.assertEquals("Car X10001 NOT assigned to train 2", null, c3.getTrain());
    Setup.setTrainIntoStagingCheckEnabled(true);
    train2.deleteTypeName("BOXCAR");
    c3.setTypeName("Boxcar");
    // control which road will go into staging
    l3s3.setRoadOption(Track.INCLUDE_ROADS);
    train2.build();
    Assert.assertFalse("Train 2 will NOT build road restriction", train2.isBuilt());
    train2.setRoadOption(Train.INCLUDE_ROADS);
    Assert.assertEquals("Number of road names for train", 1, train2.getRoadNames().length);
    train2.build();
    Assert.assertFalse("Train 2 will NOT build road restriction CP", train2.isBuilt());
    l3s3.addRoadName("CP");
    Assert.assertEquals("Number of road names", 1, l3s3.getRoadNames().length);
    train2.build();
    Assert.assertTrue("Train 2 will build road restriction CP removed", train2.isBuilt());
    train2.setRoadOption(Train.EXCLUDE_ROADS);
    train2.deleteRoadName("CP");
    Assert.assertEquals("Number of road names for train", 0, train2.getRoadNames().length);
    train2.build();
    Assert.assertFalse("Train 2 will NOT build road restriction exclude road CP", train2.isBuilt());
    // now allow road into staging
    l3s3.setRoadOption(Track.EXCLUDE_ROADS);
    l3s3.deleteRoadName("CP");
    Assert.assertEquals("Number of road names", 0, l3s3.getRoadNames().length);
    train2.build();
    Assert.assertTrue("Train 2 will build no road restrictions", train2.isBuilt());
    l3s3.addRoadName("BM");
    Assert.assertEquals("Number of road names", 1, l3s3.getRoadNames().length);
    train2.build();
    Assert.assertFalse("Train 2 will Not build, staging track will not accept road BM", train2.isBuilt());
// end staging to staging 1
}
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 12 with Consist

use of jmri.jmrit.operations.rollingstock.engines.Consist in project JMRI by JMRI.

the class TrainTest method testMaxEngines.

public void testMaxEngines() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Train train = tmanager.newTrain("AutoEngineTest");
    train.setNumberEngines(Train.AUTO);
    Route route = rmanager.newRoute("AutoEngineTest");
    train.setRoute(route);
    Location A = lmanager.newLocation("A");
    Location B = lmanager.newLocation("B");
    Location C = lmanager.newLocation("C");
    Track At = A.addTrack("track", Track.SPUR);
    Track Bt = B.addTrack("track", Track.SPUR);
    Track Ct = C.addTrack("track", Track.SPUR);
    At.setLength(300);
    Bt.setLength(300);
    Ct.setLength(300);
    RouteLocation rA = route.addLocation(A);
    RouteLocation rB = route.addLocation(B);
    RouteLocation rC = route.addLocation(C);
    rA.setMaxCarMoves(12);
    rB.setMaxCarMoves(12);
    rC.setMaxCarMoves(12);
    // 2.5% grade!
    rB.setGrade(2.5);
    Engine e1 = emanager.newEngine("E", "1");
    e1.setModel("GP40");
    Engine e2 = emanager.newEngine("E", "2");
    e2.setModel("GP40");
    Engine e3 = emanager.newEngine("E", "3");
    e3.setModel("GP40");
    Engine e4 = emanager.newEngine("E", "4");
    e4.setModel("GP40");
    e1.setLocation(A, At);
    e2.setLocation(A, At);
    e3.setLocation(A, At);
    e4.setLocation(A, At);
    Consist c = emanager.newConsist("c");
    e1.setConsist(c);
    e2.setConsist(c);
    e3.setConsist(c);
    e4.setConsist(c);
    // limit the maximum to three engines
    Setup.setMaxNumberEngines(3);
    train.build();
    Assert.assertFalse("Train should not build, needs four engines, three is the maximum allowed", train.isBuilt());
    // remove one engine from consist, train should build
    c.delete(e4);
    train.build();
    Assert.assertTrue("Train should build, three engines available", train.isBuilt());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 13 with Consist

use of jmri.jmrit.operations.rollingstock.engines.Consist in project JMRI by JMRI.

the class TrainBuilderTest method testCaboose.

public void testCaboose() {
    // 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("TestCaboose");
    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
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 1", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 1", "", 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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 2", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 2", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 2", "", 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.reset();
    new TrainBuilder().build(train1);
    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());
    // now try to find a caboose with "similar" (hyphen feature) road name to engine
    c1.setRoadName("UP-1");
    train1.reset();
    new TrainBuilder().build(train1);
    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());
    // done
    c1.setRoadName("UP");
    // should default to the caboose with the least moves
    e1.setRoadName("X");
    // allow pickups at Arlington
    rl2.setPickUpAllowed(true);
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 5", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 5", "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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 7a", false, train1.isBuilt());
    // now override by setting a road for the engine
    train1.setEngineRoad("NH");
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    // 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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    // 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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 18", true, train1.isBuilt());
    // now remove type Diesel, this should cause a failure
    loc3trk2.deleteTypeName("Diesel");
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 19", false, train1.isBuilt());
    // now restore type Diesel
    loc3trk2.addTypeName("Diesel");
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 21", false, train1.isBuilt());
    e1.setRoadName("UP");
    // this test that a caboose fails
    loc3trk1.deleteRoadName("NH");
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 24", false, train1.isBuilt());
    // restore
    loc2trk1.addTypeName("Flat");
    train1.reset();
    new TrainBuilder().build(train1);
    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");
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build with caboose bad destination", false, train1.isBuilt());
    c2.setDestination(null, null);
    train1.reset();
    new TrainBuilder().build(train1);
    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 : Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 14 with Consist

use of jmri.jmrit.operations.rollingstock.engines.Consist in project JMRI by JMRI.

the class TrainBuilderTest method testTrainBuildOptions.

public void testTrainBuildOptions() {
    EngineTypes et = new EngineTypes();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    et.addName("Diesel");
    // create 2 consists and a single engine for testing
    Consist con1 = emanager.newConsist("C1");
    Engine e1 = emanager.newEngine("UP", "1");
    e1.setModel("GP30");
    e1.setOwner("AT");
    e1.setBuilt("1957");
    e1.setConsist(con1);
    e1.setMoves(5);
    Engine e2 = emanager.newEngine("SP", "2");
    e2.setModel("GP30");
    e2.setOwner("AT");
    e2.setBuilt("1957");
    e2.setConsist(con1);
    e2.setMoves(5);
    // one engine
    Engine e3 = emanager.newEngine("SP", "3");
    e3.setModel("GP40");
    e3.setOwner("DAB");
    e3.setBuilt("1957");
    Consist con2 = emanager.newConsist("C2");
    Engine e4 = emanager.newEngine("UP", "10");
    e4.setModel("GP40");
    e4.setOwner("DAB");
    e4.setBuilt("1944");
    e4.setConsist(con2);
    e4.setMoves(20);
    Engine e5 = emanager.newEngine("SP", "20");
    e5.setModel("GP40");
    e5.setOwner("DAB");
    e5.setBuilt("1944");
    e5.setConsist(con2);
    e5.setMoves(20);
    // 3 engine consist
    Consist con3 = emanager.newConsist("C3");
    Engine e6 = emanager.newEngine("UP", "100");
    e6.setModel("GP40");
    e6.setOwner("DAB");
    e6.setBuilt("1944");
    e6.setConsist(con3);
    e6.setMoves(2);
    Engine e7 = emanager.newEngine("SP", "200");
    e7.setModel("GP40");
    e7.setOwner("DAB");
    e7.setBuilt("1944");
    e7.setConsist(con3);
    e7.setMoves(2);
    Engine e8 = emanager.newEngine("SP", "300");
    e8.setModel("GP40");
    e8.setOwner("DAB");
    e8.setBuilt("1944");
    e8.setConsist(con3);
    e8.setMoves(2);
    // Set up three cabooses and six box cars
    Car c1 = cmanager.newCar("PU", "1");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(10);
    c1.setOwner("AT");
    c1.setBuilt("1943");
    c1.setCaboose(true);
    Car c2 = cmanager.newCar("SP", "2");
    c2.setTypeName("Caboose");
    c2.setLength("30");
    c2.setMoves(5);
    c2.setOwner("DAB");
    c2.setBuilt("1957");
    c2.setCaboose(true);
    Car c3 = cmanager.newCar("UP", "3");
    c3.setTypeName("Caboose");
    c3.setLength("33");
    c3.setMoves(0);
    c3.setOwner("DAB");
    c3.setBuilt("1944");
    c3.setCaboose(true);
    Car c4 = cmanager.newCar("UP", "4");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setMoves(16);
    c4.setOwner("DAB");
    c4.setBuilt("1958");
    c4.setFred(true);
    Car c5 = cmanager.newCar("SP", "5");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setMoves(8);
    c5.setOwner("DAB");
    c5.setBuilt("1958");
    c5.setFred(true);
    Car c6 = cmanager.newCar("NH", "6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(2);
    c6.setOwner("DAB");
    c6.setBuilt("1958");
    c6.setFred(true);
    Car c7 = cmanager.newCar("UP", "7");
    c7.setTypeName("Flat");
    c7.setLength("40");
    c7.setMoves(5);
    c7.setOwner("DAB");
    c7.setBuilt("1958");
    Car c8 = cmanager.newCar("SP", "8");
    c8.setTypeName("Boxcar");
    c8.setLength("40");
    c8.setMoves(4);
    c8.setOwner("DAB");
    c8.setBuilt("1958");
    Car c9 = cmanager.newCar("NH", "9");
    c9.setTypeName("Boxcar");
    c9.setLength("40");
    c9.setMoves(3);
    c9.setOwner("DAB");
    c9.setBuilt("1944");
    Car c10 = cmanager.newCar("NH", "10");
    c10.setTypeName("Boxcar");
    c10.setLength("40");
    c10.setMoves(10);
    c10.setOwner("DAB");
    c10.setBuilt("1958");
    Car c11 = cmanager.newCar("SP", "11");
    c11.setTypeName("Boxcar");
    c11.setLength("40");
    c11.setMoves(3);
    c11.setOwner("DAB");
    c11.setBuilt("1958");
    // Create 5 locations
    Location loc1 = lmanager.newLocation("Harvard");
    Track loc1trk1 = loc1.addTrack("Harvard Yard", Track.YARD);
    loc1trk1.setLength(1000);
    Track loc1trk2 = loc1.addTrack("Harvard Yard 2", Track.YARD);
    loc1trk2.setLength(1000);
    Location loc2 = lmanager.newLocation("Arlington");
    Track loc2trk1 = loc2.addTrack("Arlington Yard", Track.YARD);
    loc2trk1.setLength(1000);
    Location loc3 = lmanager.newLocation("Boston");
    Track loc3trk1 = loc3.addTrack("Boston Yard", Track.YARD);
    loc3trk1.setLength(1000);
    Track loc3trk2 = loc3.addTrack("Boston Yard 2", Track.YARD);
    loc3trk2.setLength(1000);
    Location loc4 = lmanager.newLocation("Chelmsford");
    Track loc4trk1 = loc4.addTrack("Chelmsford Yard", Track.YARD);
    loc4trk1.setLength(1000);
    Track loc4trk2 = loc4.addTrack("Chelmsford Yard 2", Track.YARD);
    loc4trk2.setLength(1000);
    Location loc5 = lmanager.newLocation("Westford");
    Track loc5trk1 = loc5.addTrack("Westford Yard", Track.YARD);
    loc5trk1.setLength(1000);
    Track loc5trk2 = loc5.addTrack("Westford Yard 2", Track.YARD);
    loc5trk2.setLength(1000);
    // Create route with 4 location
    Route rte1 = rmanager.newRoute("Route 2 Westford");
    rte1.addLocation(loc1);
    RouteLocation rl2 = rte1.addLocation(loc2);
    // set the train icon coordinates
    rl2.setTrainIconX(175);
    rl2.setTrainIconY(150);
    RouteLocation rl3 = rte1.addLocation(loc3);
    // set the train icon coordinates
    rl3.setTrainIconX(25);
    rl3.setTrainIconY(175);
    RouteLocation rl4 = rte1.addLocation(loc4);
    // set the train icon coordinates
    rl4.setTrainIconX(75);
    rl4.setTrainIconY(175);
    // don't allow pickup or drops at Arlington
    rl2.setDropAllowed(false);
    rl2.setPickUpAllowed(false);
    // Create train
    Train train1 = tmanager.newTrain("TestTrainBuildOptions");
    train1.setRoute(rte1);
    // train skips Boston
    train1.addTrainSkipsLocation(rl3.getId());
    // Place cars
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc5, loc5trk1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc2, loc2trk1));
    // set c9 destination not part of train's route
    Assert.assertEquals("Destination c9", Track.OKAY, c9.setDestination(loc5, loc5trk1));
    // Place engines
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e6", Track.OKAY, e6.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e7", Track.OKAY, e7.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(loc1, loc1trk1));
    train1.setRequirements(Train.CABOOSE);
    train1.setNumberEngines("2");
    train1.setOwnerOption(Train.ALL_OWNERS);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 1", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 1", "Chelmsford Yard 2", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 1", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 1", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 1", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 1", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 1", "Chelmsford Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 1", "Chelmsford Yard 2", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 1", "Westford Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 1", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 1", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 1", "Chelmsford Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 1", "Chelmsford Yard", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 1", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 1", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 1", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 1", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 1", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 1", "", e8.getDestinationTrackName());
    // Allow c9 to be used
    // set c9 destination Chelmsford
    Assert.assertEquals("Destination c9", Track.OKAY, c9.setDestination(loc4, null));
    // check that train direction and track direction feature works properly
    loc1trk2.setTrainDirections(Location.SOUTH);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build test track direction", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 1a", "Chelmsford Yard", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 1a", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 1a", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 1a", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 1a", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 1a", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 1a", "Chelmsford Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 1a", "Chelmsford Yard 2", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 1a", "Chelmsford Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 1a", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 1a", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 1a", "Chelmsford Yard 2", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 1a", "Chelmsford Yard 2", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 1a", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 1a", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 1a", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 1a", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 1a", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 1a", "", e8.getDestinationTrackName());
    loc1trk2.setTrainDirections(Location.NORTH);
    train1.addOwnerName("DAB");
    train1.setOwnerOption(Train.INCLUDE_OWNERS);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 2", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 2", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 2", "Chelmsford Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 2", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 2", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 2", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 2", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 2", "Chelmsford Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 2", "Chelmsford Yard 2", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 2", "Chelmsford Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 2", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 2", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 2", "", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 2", "", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 2", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 2", "Chelmsford Yard 2", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 2", "Chelmsford Yard 2", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 2", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 2", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 2", "", e8.getDestinationTrackName());
    // test that build fails if Diesel type is not allowed
    train1.deleteTypeName("Diesel");
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 3", false, train1.isBuilt());
    // restore type Diesel and allow all owners
    train1.addTypeName("Diesel");
    train1.setOwnerOption(Train.ALL_OWNERS);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 4", true, train1.isBuilt());
    // Only allow rolling stock built after 1956
    train1.setBuiltStartYear("1956");
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build 5", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 5", "Chelmsford Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 5", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 5", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 5", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 5", "Chelmsford Yard 2", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 5", "Chelmsford Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 5", "", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 5", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 5", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 5", "Chelmsford Yard 2", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 5", "Chelmsford Yard 2", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 5", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 5", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 5", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 5", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 5", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 5", "", e8.getDestinationTrackName());
    train1.reset();
}
Also used : EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 15 with Consist

use of jmri.jmrit.operations.rollingstock.engines.Consist in project JMRI by JMRI.

the class TrainBuilderTest method testEngineChanges.

/**
     * The program allows up to two engine changes in a train's route.
     */
public void testEngineChanges() {
    EngineTypes et = new EngineTypes();
    et.addName("Diesel");
    // create 5 locations with tracks        
    Location harvard = lmanager.newLocation("Harvard");
    Track loc1trk1 = harvard.addTrack("Harvard Yard 1", Track.YARD);
    loc1trk1.setLength(1000);
    Track loc1trk2 = harvard.addTrack("Harvard Yard 2", Track.YARD);
    loc1trk2.setLength(1000);
    Location arlington = lmanager.newLocation("Arlington");
    Track loc2trk1 = arlington.addTrack("Arlington Siding", Track.YARD);
    loc2trk1.setLength(1000);
    Location boston = lmanager.newLocation("Boston");
    Track loc3trk1 = boston.addTrack("Boston Yard 1", Track.YARD);
    loc3trk1.setLength(1000);
    Track loc3trk2 = boston.addTrack("Boston Yard 2", Track.YARD);
    loc3trk2.setLength(1000);
    Location chelmsford = lmanager.newLocation("Chelmsford");
    Track loc4trk1 = chelmsford.addTrack("Chelmsford Yard 1", Track.YARD);
    loc4trk1.setLength(1000);
    Track loc4trk2 = chelmsford.addTrack("Chelmsford Yard 2", Track.YARD);
    loc4trk2.setLength(1000);
    Location westford = lmanager.newLocation("Westford");
    Track loc5trk1 = westford.addTrack("Westford Yard", Track.YARD);
    loc5trk1.setLength(1000);
    // create a 2 engine consist for departure
    Consist con1 = emanager.newConsist("C1");
    Engine e1 = emanager.newEngine("UP", "1");
    e1.setModel("GP30");
    e1.setOwner("AT");
    e1.setBuilt("1957");
    e1.setConsist(con1);
    e1.setMoves(5);
    Engine e2 = emanager.newEngine("SP", "2");
    e2.setModel("GP30");
    e2.setOwner("AT");
    e2.setBuilt("1957");
    e2.setConsist(con1);
    e2.setMoves(5);
    // one engine
    Engine e3 = emanager.newEngine("SP", "3");
    e3.setModel("GP40");
    e3.setBuilt("1957");
    Engine e4 = emanager.newEngine("UP", "10");
    e4.setModel("GP40");
    e4.setBuilt("1944");
    e4.setMoves(20);
    Engine e5 = emanager.newEngine("SP", "20");
    e5.setModel("GP40");
    e5.setBuilt("1944");
    e5.setMoves(20);
    Engine e6 = emanager.newEngine("UP", "100");
    e6.setModel("GP40");
    e6.setBuilt("1944");
    e6.setMoves(2);
    Engine e7 = emanager.newEngine("SP", "200");
    e7.setModel("GP40");
    e7.setBuilt("1944");
    e7.setMoves(2);
    Engine e8 = emanager.newEngine("SP", "300");
    e8.setModel("GP40");
    e8.setBuilt("1944");
    e8.setMoves(20);
    Engine e9 = emanager.newEngine("SP", "400");
    e9.setModel("GP30");
    e9.setBuilt("1944");
    e9.setMoves(2);
    // Place engines
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(harvard, loc1trk1));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(harvard, loc1trk1));
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(arlington, loc2trk1));
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(arlington, loc2trk1));
    Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(chelmsford, loc4trk1));
    Assert.assertEquals("Place e6", Track.OKAY, e6.setLocation(chelmsford, loc4trk1));
    Assert.assertEquals("Place e7", Track.OKAY, e7.setLocation(chelmsford, loc4trk1));
    Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(chelmsford, loc4trk1));
    Assert.assertEquals("Place e9", Track.OKAY, e9.setLocation(chelmsford, loc4trk1));
    Route rte1 = rmanager.newRoute("Route Harvard to Westford");
    rte1.addLocation(harvard);
    RouteLocation rlArlington = rte1.addLocation(arlington);
    rte1.addLocation(boston);
    RouteLocation rlChelmsford = rte1.addLocation(chelmsford);
    rte1.addLocation(westford);
    // Create train
    Train train1 = tmanager.newTrain("TestEngineChanges");
    train1.setRoute(rte1);
    // depart with 2 engines
    train1.setBuildConsistEnabled(true);
    train1.setNumberEngines("2");
    // change out 2 engines with 1 engine at Arlington
    train1.setSecondLegOptions(Train.CHANGE_ENGINES);
    train1.setSecondLegNumberEngines("1");
    train1.setSecondLegStartLocation(rlArlington);
    train1.setSecondLegEngineRoad("UP");
    train1.setSecondLegEngineModel("GP40");
    // change out 1 engine with 3 "SP" engines at Chelmsford       
    train1.setThirdLegOptions(Train.CHANGE_ENGINES);
    train1.setThirdLegNumberEngines("3");
    train1.setThirdLegStartLocation(rlChelmsford);
    train1.setThirdLegEngineRoad("SP");
    train1.setThirdLegEngineModel("GP40");
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm that the specified engines were assigned to the train
    Assert.assertEquals("e1 assigned to train", arlington, e1.getDestination());
    Assert.assertEquals("e2 assigned to train", arlington, e2.getDestination());
    Assert.assertEquals("e3 not assigned to train due to road name", null, e3.getDestination());
    Assert.assertEquals("e4 assigned to train", chelmsford, e4.getDestination());
    Assert.assertEquals("e5 assigned to train", westford, e5.getDestination());
    Assert.assertEquals("e6 not assigned to train due to road name", null, e6.getDestination());
    Assert.assertEquals("e7 assigned to train", westford, e7.getDestination());
    Assert.assertEquals("e8 assigned to train", westford, e8.getDestination());
    Assert.assertEquals("e9 not assigned to train due to model type", null, e9.getDestination());
    // remove needed engine at Arlington
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(null, null));
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should not build", false, train1.isBuilt());
    // restore engine
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(arlington, loc2trk1));
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // remove needed engine at Chelmsford
    Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(null, null));
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should not build", false, train1.isBuilt());
    // restore engine
    Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(chelmsford, loc4trk1));
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
}
Also used : EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Aggregations

Location (jmri.jmrit.operations.locations.Location)19 Track (jmri.jmrit.operations.locations.Track)19 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)19 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)19 Route (jmri.jmrit.operations.routes.Route)19 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)19 Car (jmri.jmrit.operations.rollingstock.cars.Car)11 LocationManager (jmri.jmrit.operations.locations.LocationManager)10 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)10 RouteManager (jmri.jmrit.operations.routes.RouteManager)10 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)9 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)6 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)6 Kernel (jmri.jmrit.operations.rollingstock.cars.Kernel)2 Train (jmri.jmrit.operations.trains.Train)1 TrainManager (jmri.jmrit.operations.trains.TrainManager)1 JmriJFrame (jmri.util.JmriJFrame)1 Test (org.junit.Test)1