Search in sources :

Example 6 with Consist

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

the class TrainBuilderTest method testAutoEnginesTwoEngines.

public void testAutoEnginesTwoEngines() {
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Train train = tmanager.newTrain("TestAutoEnginesTwoEngines");
    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(5);
    rB.setMaxCarMoves(5);
    rC.setMaxCarMoves(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);
    // change requirements
    rA.setMaxCarMoves(12);
    rB.setMaxCarMoves(12);
    rC.setMaxCarMoves(12);
    train.reset();
    new TrainBuilder().build(train);
    Assert.assertFalse("Train should not build, only single engines", train.isBuilt());
    Consist c = emanager.newConsist("c");
    e1.setConsist(c);
    e2.setConsist(c);
    // train should require two engines
    train.reset();
    new TrainBuilder().build(train);
    Assert.assertTrue("Train should build", train.isBuilt());
    Assert.assertEquals("e1 should be assigned to train", train, e1.getTrain());
    Assert.assertEquals("e2 should be assigned to train", train, e2.getTrain());
}
Also used : 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) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 7 with Consist

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

the class TrainBuilderTest method testMaxEngines.

public void testMaxEngines() {
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Train train = tmanager.newTrain("TestMaxEngines");
    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.reset();
    new TrainBuilder().build(train);
    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.reset();
    new TrainBuilder().build(train);
    Assert.assertTrue("Train should build, three engines available", train.isBuilt());
}
Also used : 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) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 8 with Consist

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

the class OperationsTrainsGuiTest method testTrainIcon.

@Test
public void testTrainIcon() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    EngineTypes et = EngineTypes.instance();
    // create and register a panel
    jmri.jmrit.display.panelEditor.PanelEditor editor = new jmri.jmrit.display.panelEditor.PanelEditor("Train Test Panel");
    PanelMenu.instance().addEditorPanel(editor);
    // confirm panel creation
    JmriJFrame f = JmriJFrame.getFrame("Train Test Panel");
    Assert.assertNotNull(f);
    // Place train icons on panel
    Setup.setPanelName("Train Test Panel");
    // Set terminate color to yellow
    Setup.setTrainIconColorTerminate(TrainIcon.YELLOW);
    // add engine number
    Setup.setTrainIconAppendEnabled(true);
    et.addName("Diesel");
    // Set up four engines in two consists
    Consist con1 = emanager.newConsist("C16");
    Consist con2 = emanager.newConsist("C14");
    Engine e1 = new Engine("PC", "5016");
    e1.setModel("GP40");
    e1.setConsist(con1);
    e1.setMoves(123);
    e1.setOwner("AT");
    e1.setBuilt("1990");
    Assert.assertEquals("Engine 1 Length", "59", e1.getLength());
    emanager.register(e1);
    Engine e2 = new Engine("PC", "5019");
    e2.setModel("GP40");
    e2.setConsist(con1);
    e2.setMoves(321);
    e2.setOwner("AT");
    e2.setBuilt("1990");
    Assert.assertEquals("Engine 2 Length", "59", e2.getLength());
    emanager.register(e2);
    Engine e3 = new Engine("PC", "5524");
    e3.setModel("SD45");
    e3.setConsist(con2);
    e3.setOwner("DAB");
    e3.setBuilt("1980");
    Assert.assertEquals("Engine 3 Length", "66", e3.getLength());
    emanager.register(e3);
    Engine e4 = new Engine("PC", "5559");
    e4.setModel("SD45");
    e4.setConsist(con2);
    e4.setOwner("DAB");
    e4.setBuilt("1980");
    Assert.assertEquals("Engine 4 Length", "66", e4.getLength());
    emanager.register(e4);
    // Set up a route of 3 locations: North End Staging (2 tracks),
    // North Industries (1 track), and South End Staging (2 tracks).
    Location l1 = new Location("1", "North End");
    Assert.assertEquals("Location 1 Id", "1", l1.getId());
    Assert.assertEquals("Location 1 Name", "North End", l1.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, l1.getLength());
    l1.setLocationOps(Location.STAGING);
    l1.setTrainDirections(DIRECTION_ALL);
    l1.setSwitchListEnabled(true);
    lmanager.register(l1);
    Track l1s1 = new Track("1s1", "North End 1", Track.STAGING, l1);
    l1s1.setLength(300);
    Assert.assertEquals("Location 1s1 Id", "1s1", l1s1.getId());
    Assert.assertEquals("Location 1s1 Name", "North End 1", l1s1.getName());
    Assert.assertEquals("Location 1s1 LocType", "Staging", l1s1.getTrackType());
    Assert.assertEquals("Location 1s1 Length", 300, l1s1.getLength());
    l1s1.setTrainDirections(DIRECTION_ALL);
    l1s1.setRoadOption(Track.ALL_ROADS);
    l1s1.setDropOption(Track.ANY);
    l1s1.setPickupOption(Track.ANY);
    Track l1s2 = new Track("1s2", "North End 2", Track.STAGING, l1);
    l1s2.setLength(400);
    Assert.assertEquals("Location 1s2 Id", "1s2", l1s2.getId());
    Assert.assertEquals("Location 1s2 Name", "North End 2", l1s2.getName());
    Assert.assertEquals("Location 1s2 LocType", "Staging", l1s2.getTrackType());
    Assert.assertEquals("Location 1s2 Length", 400, l1s2.getLength());
    l1s2.setTrainDirections(DIRECTION_ALL);
    l1s2.setRoadOption(Track.ALL_ROADS);
    l1s2.setDropOption(Track.ANY);
    l1s2.setPickupOption(Track.ANY);
    l1.addTrack("North End 1", Track.STAGING);
    l1.addTrack("North End 2", Track.STAGING);
    List<Track> templist1 = l1.getTrackByNameList(null);
    for (int i = 0; i < templist1.size(); i++) {
        if (i == 0) {
            Assert.assertEquals("RL 1 Staging 1 Name", "North End 1", templist1.get(i).getName());
        }
        if (i == 1) {
            Assert.assertEquals("RL 1 Staging 2 Name", "North End 2", templist1.get(i).getName());
        }
    }
    l1.register(l1s1);
    l1.register(l1s2);
    Assert.assertEquals("Location 1 Length", 700, l1.getLength());
    Location l2 = new Location("2", "North Industries");
    Assert.assertEquals("Location 2 Id", "2", l2.getId());
    Assert.assertEquals("Location 2 Name", "North Industries", l2.getName());
    l2.setLocationOps(Location.NORMAL);
    l2.setTrainDirections(DIRECTION_ALL);
    l2.setSwitchListEnabled(true);
    lmanager.register(l2);
    Track l2s1 = new Track("2s1", "NI Yard", Track.YARD, l2);
    l2s1.setLength(432);
    Assert.assertEquals("Location 2s1 Id", "2s1", l2s1.getId());
    Assert.assertEquals("Location 2s1 Name", "NI Yard", l2s1.getName());
    Assert.assertEquals("Location 2s1 LocType", Track.YARD, l2s1.getTrackType());
    Assert.assertEquals("Location 2s1 Length", 432, l2s1.getLength());
    l2s1.setTrainDirections(DIRECTION_ALL);
    l2.register(l2s1);
    Assert.assertEquals("Location 2 Length", 432, l2.getLength());
    Location l3 = new Location("3", "South End");
    Assert.assertEquals("Location 3 Id", "3", l3.getId());
    Assert.assertEquals("Location 3 Name", "South End", l3.getName());
    Assert.assertEquals("Location 3 Initial Length", 0, l3.getLength());
    l3.setLocationOps(Location.STAGING);
    l3.setTrainDirections(DIRECTION_ALL);
    l3.setSwitchListEnabled(true);
    lmanager.register(l3);
    Track l3s1 = new Track("3s1", "South End 1", Track.STAGING, l3);
    l3s1.setLength(300);
    Assert.assertEquals("Location 3s1 Id", "3s1", l3s1.getId());
    Assert.assertEquals("Location 3s1 Name", "South End 1", l3s1.getName());
    Assert.assertEquals("Location 3s1 LocType", "Staging", l3s1.getTrackType());
    Assert.assertEquals("Location 3s1 Length", 300, l3s1.getLength());
    l3s1.setTrainDirections(DIRECTION_ALL);
    l3s1.setRoadOption(Track.ALL_ROADS);
    l3s1.setDropOption(Track.ANY);
    l3s1.setPickupOption(Track.ANY);
    Track l3s2 = new Track("3s2", "South End 2", Track.STAGING, l3);
    l3s2.setLength(401);
    Assert.assertEquals("Location 3s2 Id", "3s2", l3s2.getId());
    Assert.assertEquals("Location 3s2 Name", "South End 2", l3s2.getName());
    Assert.assertEquals("Location 3s2 LocType", "Staging", l3s2.getTrackType());
    Assert.assertEquals("Location 3s2 Length", 401, l3s2.getLength());
    l3s2.setTrainDirections(DIRECTION_ALL);
    l3s2.setRoadOption(Track.ALL_ROADS);
    l3s2.setDropOption(Track.ANY);
    l3s2.setPickupOption(Track.ANY);
    l3.addTrack("South End 1", Track.STAGING);
    l3.addTrack("South End 2", Track.STAGING);
    List<Track> templist3 = l3.getTrackByNameList(null);
    for (int i = 0; i < templist3.size(); i++) {
        if (i == 0) {
            Assert.assertEquals("RL 3 Staging 1 Name", "South End 1", templist3.get(i).getName());
        }
        if (i == 1) {
            Assert.assertEquals("RL 3 Staging 2 Name", "South End 2", templist3.get(i).getName());
        }
    }
    l3.register(l3s1);
    l3.register(l3s2);
    Assert.assertEquals("Location 3 Length", 701, l3.getLength());
    // Place Engines on Staging tracks
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(l1, l1s1));
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(l1, l1s2));
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(l1, l1s2));
    // Define the route.
    Route r1 = new Route("1", "Southbound Main Route");
    Assert.assertEquals("Route Id", "1", r1.getId());
    Assert.assertEquals("Route Name", "Southbound Main Route", r1.getName());
    RouteLocation rl1 = new RouteLocation("1r1", l1);
    rl1.setSequenceId(1);
    rl1.setTrainDirection(RouteLocation.SOUTH);
    rl1.setMaxCarMoves(5);
    rl1.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl1.setTrainIconX(25);
    rl1.setTrainIconY(25);
    Assert.assertEquals("Route Location 1 Id", "1r1", rl1.getId());
    Assert.assertEquals("Route Location 1 Name", "North End", rl1.getName());
    RouteLocation rl2 = new RouteLocation("1r2", l2);
    rl2.setSequenceId(2);
    rl2.setTrainDirection(RouteLocation.SOUTH);
    // test for only 1 pickup and 1 drop
    rl2.setMaxCarMoves(2);
    rl2.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(25);
    Assert.assertEquals("Route Location 2 Id", "1r2", rl2.getId());
    Assert.assertEquals("Route Location 2 Name", "North Industries", rl2.getName());
    RouteLocation rl3 = new RouteLocation("1r3", l3);
    rl3.setSequenceId(3);
    rl3.setTrainDirection(RouteLocation.SOUTH);
    rl3.setMaxCarMoves(5);
    rl3.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl3.setTrainIconX(125);
    rl3.setTrainIconY(35);
    Assert.assertEquals("Route Location 3 Id", "1r3", rl3.getId());
    Assert.assertEquals("Route Location 3 Name", "South End", rl3.getName());
    r1.register(rl1);
    r1.register(rl2);
    r1.register(rl3);
    rmanager.register(r1);
    // Finally ready to define the trains.
    Train train1 = new Train("1", "STF");
    Assert.assertEquals("Train Id", "1", train1.getId());
    Assert.assertEquals("Train Name", "STF", train1.getName());
    train1.setRoute(r1);
    tmanager.register(train1);
    Train train2 = new Train("2", "SFF");
    Assert.assertEquals("Train Id", "2", train2.getId());
    Assert.assertEquals("Train Name", "SFF", train2.getName());
    train2.setRoute(r1);
    tmanager.register(train2);
    // Last minute checks.
    Assert.assertEquals("Train 1 Departs Name", "North End", train1.getTrainDepartsName());
    Assert.assertEquals("Train 1 Route Departs Name", "North End", train1.getTrainDepartsRouteLocation().getName());
    Assert.assertEquals("Train 1 Terminates Name", "South End", train1.getTrainTerminatesName());
    Assert.assertEquals("Train 1 Route Terminates Name", "South End", train1.getTrainTerminatesRouteLocation().getName());
    Assert.assertEquals("Train 1 Next Location Name", "", train1.getNextLocationName());
    Assert.assertEquals("Train 1 Route Name", "Southbound Main Route", train1.getRoute().getName());
    Assert.assertEquals("Train 2 Departs Name", "North End", train2.getTrainDepartsName());
    Assert.assertEquals("Train 2 Route Departs Name", "North End", train2.getTrainDepartsRouteLocation().getName());
    Assert.assertEquals("Train 2 Terminates Name", "South End", train2.getTrainTerminatesName());
    Assert.assertEquals("Train 2 Route Terminates Name", "South End", train2.getTrainTerminatesRouteLocation().getName());
    Assert.assertEquals("Train 2 Next Location Name", "", train2.getNextLocationName());
    Assert.assertEquals("Train 2 Route Name", "Southbound Main Route", train2.getRoute().getName());
    // disable build messages
    tmanager.setBuildMessagesEnabled(false);
    // disable build reports
    tmanager.setBuildReportEnabled(false);
    train1.build();
    train2.build();
    Assert.assertEquals("Train 1 after build", true, train1.isBuilt());
    Assert.assertEquals("Train 2 after build", true, train2.isBuilt());
    // check train icon location and name
    TrainIcon ti1 = train1.getTrainIcon();
    Assert.assertNotNull("Train 1 icon exists", ti1);
    Assert.assertEquals("Train 1 icon text", "STF 5016", ti1.getText());
    TrainIcon ti2 = train2.getTrainIcon();
    Assert.assertNotNull("Train 2 icon exists", ti2);
    Assert.assertEquals("Train 2 icon text", "SFF 5524", ti2.getText());
    // icon uses TrainIconAnimation 2 pixels every 3 mSec
    // X=0 to X=25 25/2 * 3 = 38 mSec
    // Y=0 to Y=25 25/2 * 3 = 38 mSec
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 25 && ti2.getY() == 25), "Train 2 Move 0");
    Assert.assertEquals("Train 1 icon X", 25, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    Assert.assertEquals("Train 2 icon X", 25, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
    // move the trains
    train1.move();
    // icon uses TrainIconAnimation 2 pixels every 3 mSec
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti1.getX() == 75 && ti1.getY() == 25), "Train 1 Move");
    Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    // train 2 shouldn't move
    Assert.assertEquals("Train 2 icon X", 25, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
    train2.move();
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 75 && ti2.getY() == 25), "Train 2 Move");
    Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    Assert.assertEquals("Train 2 icon X", 75, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
    train2.move();
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 125 && ti2.getY() == 35), "Train 2 Move 2");
    Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    Assert.assertEquals("Train 2 icon X", 125, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 35, ti2.getY());
    editor.getTargetFrame().dispose();
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) JmriJFrame(jmri.util.JmriJFrame) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) 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) Test(org.junit.Test)

Example 9 with Consist

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

the class TrainTest method testSidingsYards.

// test siding and yard moves
// tests manual setting of destinations and trains for engines, cars, and cabooses.
// tests consists and kernels
public void testSidingsYards() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    // Set up two cabooses and six box cars
    Car c1 = cmanager.newCar("CP", "10");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(10);
    c1.setCaboose(true);
    Car c2 = cmanager.newCar("CP", "200");
    c2.setTypeName("Caboose");
    c2.setLength("32");
    c2.setMoves(11);
    c2.setCaboose(true);
    Car c3 = cmanager.newCar("CP", "30");
    c3.setTypeName("Boxcar");
    c3.setLength("40");
    c2.setMoves(12);
    Car c4 = cmanager.newCar("CP", "4000");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setMoves(13);
    Car c5 = cmanager.newCar("CP", "5");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setMoves(14);
    Car c6 = cmanager.newCar("CP", "60");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(15);
    Car c7 = cmanager.newCar("CP", "700");
    c7.setTypeName("Flat");
    c7.setLength("50");
    c7.setMoves(16);
    Car c8 = cmanager.newCar("CP", "8000");
    c8.setTypeName("Boxcar");
    c8.setLength("60");
    c8.setMoves(17);
    Car c9 = cmanager.newCar("CP", "9");
    c9.setTypeName("Flat");
    c9.setLength("40");
    c9.setMoves(18);
    Car c10 = cmanager.newCar("CP", "1000");
    c10.setTypeName("Flat");
    c10.setLength("40");
    c10.setMoves(19);
    // place two engines in a consist
    Consist con1 = emanager.newConsist("CP");
    Engine e1 = emanager.newEngine("CP", "10");
    e1.setModel("GP30");
    e1.setConsist(con1);
    Engine e2 = emanager.newEngine("CP", "20");
    e2.setModel("GP30");
    e2.setConsist(con1);
    // Set up a route of 3 locations: Foxboro (2 tracks, yard and siding),
    // Acton (2 tracks, sidings), and Nashua (2 tracks, yards).
    Location l1 = lmanager.newLocation("Foxboro");
    Assert.assertEquals("Location 1 Name", "Foxboro", l1.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, l1.getLength());
    Track l1s1 = l1.addTrack("Foxboro Siding", Track.SPUR);
    l1s1.setLength(600);
    Assert.assertEquals("Location 1s1 Name", "Foxboro Siding", l1s1.getName());
    Assert.assertEquals("Location 1s1 LocType", "Siding", l1s1.getTrackType());
    Assert.assertEquals("Location 1s1 Length", 600, l1s1.getLength());
    Assert.assertEquals("Default directions", DIRECTION_ALL, l1s1.getTrainDirections());
    Track l1s2 = l1.addTrack("Foxboro Yard", Track.YARD);
    l1s2.setLength(400);
    Assert.assertEquals("Location 1s2 Name", "Foxboro Yard", l1s2.getName());
    Assert.assertEquals("Location 1s2 LocType", "Yard", l1s2.getTrackType());
    Assert.assertEquals("Location 1s2 Length", 400, l1s2.getLength());
    Assert.assertEquals("Location 1 Length", 1000, l1.getLength());
    Location l2 = lmanager.newLocation("Acton");
    Assert.assertEquals("Location 2 Name", "Acton", l2.getName());
    Track l2s1 = l2.addTrack("Acton Siding 1", Track.SPUR);
    l2s1.setLength(543);
    l2s1.setMoves(1);
    Assert.assertEquals("Location 2s1 Name", "Acton Siding 1", l2s1.getName());
    Assert.assertEquals("Location 2s1 LocType", Track.SPUR, l2s1.getTrackType());
    Assert.assertEquals("Location 2s1 Length", 543, l2s1.getLength());
    Track l2s2 = l2.addTrack("Acton Siding 2", Track.SPUR);
    l2s2.setLength(345);
    Assert.assertEquals("Acton Length", 888, l2.getLength());
    Location l3 = lmanager.newLocation("Nashua");
    Track l3s1 = l3.addTrack("Nashua Yard 1", Track.YARD);
    l3s1.setLength(301);
    Track l3s2 = l3.addTrack("Nashua Yard 2", Track.YARD);
    l3s2.setLength(402);
    Assert.assertEquals("Location 3 Length", 703, l3.getLength());
    // define the route
    // set default to 6 moves per location
    Setup.setCarMoves(6);
    Route r1 = rmanager.newRoute("Foxboro-Acton-Nashua-Acton-Foxboro");
    RouteLocation rl1 = r1.addLocation(l1);
    // set the train icon coordinates
    rl1.setTrainIconX(25);
    rl1.setTrainIconY(225);
    RouteLocation rl2 = r1.addLocation(l2);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(225);
    RouteLocation rl3 = r1.addLocation(l3);
    // set the train icon coordinates
    rl3.setTrainIconX(125);
    rl3.setTrainIconY(225);
    RouteLocation rl4 = r1.addLocation(l2);
    // set the train icon coordinates
    rl4.setTrainIconX(175);
    rl4.setTrainIconY(225);
    RouteLocation rl5 = r1.addLocation(l1);
    // set the train icon coordinates
    rl5.setTrainIconX(225);
    rl5.setTrainIconY(225);
    // don't include cars at destination
    rl5.setPickUpAllowed(false);
    // define the train
    Train t1 = tmanager.newTrain("FF");
    t1.setRoute(r1);
    t1.build();
    Assert.assertTrue("train built 1", t1.isBuilt());
    Assert.assertEquals("should be 0 cars", 0, t1.getNumberCarsWorked());
    // place the cars on the tracks
    // Place cars
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(l1, l1s1));
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(l1, l1s1));
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(l1, l1s1));
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(l1, l1s1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(l1, l1s1));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(l1, l1s1));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l1, l1s1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l1, l1s1));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(l1, l1s1));
    Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(l1, l1s1));
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
    t1.build();
    Assert.assertTrue("train built 2", t1.isBuilt());
    Assert.assertEquals("should be 6 cars", 6, t1.getNumberCarsWorked());
    // check car destinations
    Assert.assertEquals("Destination c1", "", c1.getDestinationName());
    Assert.assertEquals("Destination c2", "", c2.getDestinationName());
    Assert.assertEquals("Destination c3", "Acton", c3.getDestinationName());
    Assert.assertEquals("Destination c4", "Nashua", c4.getDestinationName());
    Assert.assertEquals("Destination c5", "Acton", c5.getDestinationName());
    Assert.assertEquals("Destination c6", "Nashua", c6.getDestinationName());
    Assert.assertEquals("Destination c7", "Acton", c7.getDestinationName());
    Assert.assertEquals("Destination c8", "Nashua", c8.getDestinationName());
    Assert.assertEquals("Destination c9", "", c9.getDestinationName());
    Assert.assertEquals("Destination c10", "", c10.getDestinationName());
    Assert.assertEquals("Destination e1", "", e1.getDestinationName());
    // release cars from train
    Assert.assertTrue("reset train", t1.reset());
    Assert.assertEquals("Train reset", Train.CODE_TRAIN_RESET, t1.getStatusCode());
    // set c3, c5, c6, c8, c10 destination to be Nashua
    c3.setDestination(l3, l3s1);
    c5.setDestination(l3, l3s1);
    c6.setDestination(l3, l3s1);
    c8.setDestination(l3, l3s1);
    c10.setDestination(l3, l3s1);
    // set c5 and c9 to be serviced by train TT
    Train t2 = tmanager.newTrain("TT");
    c5.setTrain(t2);
    c9.setTrain(t2);
    // set c6 to be serviced by train FF
    c6.setTrain(t1);
    // require a caboose
    t1.setRequirements(Train.CABOOSE);
    t1.build();
    Assert.assertTrue("train built 3", t1.isBuilt());
    // check car destinations
    Assert.assertEquals("2 Destination  c1", "Foxboro", c1.getDestinationName());
    Assert.assertEquals("2 Destination  c2", "", c2.getDestinationName());
    Assert.assertEquals("2 Destination  c3", "Nashua", c3.getDestinationName());
    Assert.assertEquals("2 Destination  c4", "Acton", c4.getDestinationName());
    Assert.assertEquals("2 Destination  c5", "Nashua", c5.getDestinationName());
    Assert.assertEquals("2 Destination  c6", "Nashua", c6.getDestinationName());
    Assert.assertEquals("2 Destination  c7", "Acton", c7.getDestinationName());
    Assert.assertEquals("2 Destination  c8", "Nashua", c8.getDestinationName());
    Assert.assertEquals("2 Destination  c9", "", c9.getDestinationName());
    Assert.assertEquals("2 Destination  c10", "Nashua", c10.getDestinationName());
    // move and terminate the train
    // to Acton
    t1.move();
    // to Nashua
    t1.move();
    // to Acton
    t1.move();
    // to Foxboro
    t1.move();
    // terminate
    t1.move();
    // check car destinations
    Assert.assertEquals("3 Destination c1", "", c1.getDestinationName());
    Assert.assertEquals("3 Destination c2", "", c2.getDestinationName());
    Assert.assertEquals("3 Destination c3", "", c3.getDestinationName());
    Assert.assertEquals("3 Destination c4", "", c4.getDestinationName());
    Assert.assertEquals("3 Destination c5", "Nashua", c5.getDestinationName());
    Assert.assertEquals("3 Destination c6", "", c6.getDestinationName());
    Assert.assertEquals("3 Destination c7", "", c7.getDestinationName());
    Assert.assertEquals("3 Destination c8", "", c8.getDestinationName());
    Assert.assertEquals("3 Destination c9", "", c9.getDestinationName());
    Assert.assertEquals("3 Destination c10", "Nashua", c10.getDestinationName());
    // check car locations
    Assert.assertEquals("Location c1", "Foxboro", c1.getLocationName());
    Assert.assertEquals("Location c2", "Foxboro", c2.getLocationName());
    Assert.assertEquals("Location c3", "Nashua", c3.getLocationName());
    Assert.assertEquals("Location c4", "Acton", c4.getLocationName());
    Assert.assertEquals("Location c5", "Foxboro", c5.getLocationName());
    Assert.assertEquals("Location c6", "Nashua", c6.getLocationName());
    Assert.assertEquals("Location c7", "Acton", c7.getLocationName());
    Assert.assertEquals("Location c8", "Nashua", c8.getLocationName());
    Assert.assertEquals("Location c9", "Foxboro", c9.getLocationName());
    Assert.assertEquals("Location c10", "Foxboro", c10.getLocationName());
    // now set caboose destinations that aren't the terminal
    Assert.assertEquals("set destination c1", Track.OKAY, c1.setDestination(l2, l2s1));
    Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l3, l3s1));
    // train requires a caboose, should fail
    t1.build();
    Assert.assertFalse("train built 4", t1.isBuilt());
    // Set caboose destination to be the terminal
    Assert.assertEquals("set caboose destination", Track.OKAY, c2.setDestination(l1, l1s2));
    t1.build();
    Assert.assertTrue("train built 5", t1.isBuilt());
    Assert.assertTrue("train reset 5", t1.reset());
    // set the cabooses to train FF
    c1.setTrain(t2);
    c2.setTrain(t2);
    // build should fail
    t1.build();
    Assert.assertFalse("train built 6", t1.isBuilt());
    // set caboose to train TT
    c1.setTrain(t1);
    t1.build();
    Assert.assertTrue("train built 7", t1.isBuilt());
    // check car destinations
    Assert.assertEquals("4 Destination c1", "Foxboro", c1.getDestinationName());
    Assert.assertEquals("4 Destination c2", "", c2.getDestinationName());
    Assert.assertEquals("4 Destination c3", "Acton", c3.getDestinationName());
    Assert.assertEquals("4 Destination c4", "Nashua", c4.getDestinationName());
    Assert.assertEquals("4 Destination c5", "Nashua", c5.getDestinationName());
    Assert.assertEquals("4 Destination c6", "Foxboro", c6.getDestinationName());
    Assert.assertEquals("4 Destination c7", "Foxboro", c7.getDestinationName());
    Assert.assertEquals("4 Destination c8", "Foxboro", c8.getDestinationName());
    Assert.assertEquals("4 Destination c9", "", c9.getDestinationName());
    Assert.assertEquals("4 Destination c10", "Acton", c10.getDestinationName());
    // add an engine
    t1.setNumberEngines("2");
    t1.build();
    Assert.assertTrue("train built 8", t1.isBuilt());
    Assert.assertEquals("5 Destination e1", "Foxboro", e1.getDestinationName());
    Assert.assertEquals("5 Destination e2", "Foxboro", e2.getDestinationName());
    t1.reset();
    // assign lead engine to train TT
    e1.setTrain(t2);
    // should fail
    t1.build();
    Assert.assertFalse("train built 9", t1.isBuilt());
    // assign one of the consist engine to train TT
    e1.setTrain(t1);
    // shouldn't pay attention to the other engine
    e2.setTrain(t2);
    // should build
    t1.build();
    Assert.assertTrue("train built 10", t1.isBuilt());
    t1.reset();
    // both engines should release
    Assert.assertEquals("6 Destination e1", "", e1.getDestinationName());
    Assert.assertEquals("6 Train e1", "", e1.getTrainName());
    Assert.assertEquals("6 Destination e2", "", e2.getDestinationName());
    Assert.assertEquals("6 Train e2", "", e2.getTrainName());
    // now try setting engine destination that isn't the terminal
    Assert.assertEquals("set destination e1", Track.OKAY, e1.setDestination(l2, l2s1));
    // should fail
    t1.build();
    Assert.assertFalse("train built 11", t1.isBuilt());
    e1.setDestination(l1, l1s2);
    // program should ignore
    e2.setDestination(l2, l2s1);
    // should build
    t1.build();
    Assert.assertTrue("train built 12", t1.isBuilt());
    // set lead engine's track to null
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, null));
    // should not build
    t1.build();
    Assert.assertFalse("train will not build engine track is null", t1.isBuilt());
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
    // should now build
    t1.build();
    // move and terminate the train
    // to Acton
    t1.move();
    // to Nashua
    t1.move();
    // to Acton
    t1.move();
    // to Foxboro
    t1.move();
    // terminate
    t1.move();
    // check engine final locations
    Assert.assertEquals("Location e1", "Foxboro", e1.getLocationName());
    Assert.assertEquals("Location e2", "Foxboro", e2.getLocationName());
    // move c7 & c8 to Foxboro to help test kernels
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l1, l1s1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l1, l1s1));
    // now test kernels
    Kernel k1 = cmanager.newKernel("group of cars");
    // lead car
    c8.setKernel(k1);
    c7.setKernel(k1);
    // program should ignore
    c7.setTrain(t2);
    c3.setLocation(l1, l1s1);
    c3.setKernel(k1);
    // program should ignore (produces debug warning)
    c3.setDestination(l1, l1s1);
    // should build
    t1.build();
    Assert.assertTrue("train built 12", t1.isBuilt());
    // Confirm partial build
    Assert.assertEquals("Train built", Train.CODE_PARTIAL_BUILT, t1.getStatusCode());
    Assert.assertEquals("12 Location c3", "Foxboro", c3.getLocationName());
    Assert.assertEquals("12 Location c7", "Foxboro", c7.getLocationName());
    Assert.assertEquals("12 Location c8", "Foxboro", c8.getLocationName());
    Assert.assertEquals("12 Destination c3", "Nashua", c3.getDestinationName());
    Assert.assertEquals("12 Destination c7", "Nashua", c7.getDestinationName());
    Assert.assertEquals("12 Destination c8", "Nashua", c8.getDestinationName());
    // move and terminate the train
    // to Acton
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // to Nashua
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // to Acton
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // to Foxboro
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // terminate
    t1.move();
    Assert.assertEquals("Train Terminated", Train.CODE_TERMINATED, t1.getStatusCode());
    Assert.assertEquals("13 Location c3", "Nashua", c3.getLocationName());
    Assert.assertEquals("13 Location c7", "Nashua", c7.getLocationName());
    Assert.assertEquals("13 Location c8", "Nashua", c8.getLocationName());
    Assert.assertEquals("13 Destination c3", "", c3.getDestinationName());
    Assert.assertEquals("13 Destination c7", "", c7.getDestinationName());
    Assert.assertEquals("13 Destination c8", "", c8.getDestinationName());
    Assert.assertEquals("13 Train c3", "", c3.getTrainName());
    Assert.assertEquals("13 Train c7", "", c7.getTrainName());
    Assert.assertEquals("13 Train c8", "", c8.getTrainName());
    // now test car with FRED
    c1.setCaboose(false);
    c2.setCaboose(false);
    c1.setFred(true);
    c2.setFred(true);
    // change the type, now Boxcar with FRED
    c1.setTypeName("Boxcar");
    c2.setTypeName("Boxcar");
    c2.setTrain(null);
    // train requires a caboose, there are none, should fail
    t1.build();
    Assert.assertFalse("train built 14", t1.isBuilt());
    // change requirement to car with FRED
    t1.setRequirements(Train.FRED);
    // train requires a car with FRED, should pass
    t1.build();
    Assert.assertTrue("train built 15", t1.isBuilt());
    // release cars
    Assert.assertTrue("train reset 15", t1.reset());
    // now set FRED destinations that aren't the terminal
    Assert.assertEquals("set destination c1", Track.OKAY, c1.setDestination(l2, l2s1));
    Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l3, l3s1));
    // train requires a car with FRED, should fail
    t1.build();
    Assert.assertFalse("train built 16", t1.isBuilt());
    // Set FRED destination to be the terminal
    Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l1, l1s2));
    t1.build();
    Assert.assertTrue("train built 17", t1.isBuilt());
    Assert.assertTrue("train reset 17", t1.reset());
    // set the cars with FRED to train FF
    c1.setTrain(t2);
    c2.setTrain(t2);
    // build should fail
    t1.build();
    Assert.assertFalse("train built 18", t1.isBuilt());
    // set car with FRED to train TT
    c2.setTrain(t1);
    t1.build();
    Assert.assertTrue("train built 19", t1.isBuilt());
    // test car out of service
    c2.setOutOfService(true);
    t1.build();
    Assert.assertFalse("required car is out of service", t1.isBuilt());
    // test location unknown
    c2.setOutOfService(false);
    c2.setLocationUnknown(true);
    t1.build();
    Assert.assertFalse("required car location is unknown", t1.isBuilt());
    c2.setLocationUnknown(false);
    t1.build();
    Assert.assertTrue("need car is available", t1.isBuilt());
    c2.setWait(1);
    t1.build();
    Assert.assertFalse("required car will wait for next train", t1.isBuilt());
    t1.build();
    Assert.assertTrue("next train!", t1.isBuilt());
    Assert.assertEquals("CP 4000 destination", "Nashua", c4.getDestinationName());
    // test train and location direction controls
    // place led car of kernel in Action Siding 1
    c8.setLocation(l2, l2s1);
    // train is north bound
    l2.setTrainDirections(Location.EAST + Location.SOUTH + Location.WEST);
    t1.build();
    // build should fail, cars c3 and c7 which is part of c8 kernel are on the wrong track
    Assert.assertFalse("Train direction test", t1.isBuilt());
    // place c3 Action Siding 1
    c3.setLocation(l2, l2s1);
    // place c7 Action Siding 1
    c7.setLocation(l2, l2s1);
    t1.build();
    Assert.assertTrue("Train direction test", t1.isBuilt());
    Assert.assertEquals("CP 1000 destination is now Nashua", "Nashua", c10.getDestinationName());
    Assert.assertEquals("CP 30 at Acton, not serviced", null, c3.getTrain());
    Assert.assertEquals("CP 700 at Acton, not serviced", null, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton, not serviced", null, c8.getTrain());
    // restore Acton
    // train is north bound
    l2.setTrainDirections(Location.NORTH);
    t1.build();
    Assert.assertEquals("CP 1000 destination is now", "Acton", c10.getDestinationName());
    Assert.assertEquals("CP 30 at Acton", t1, c3.getTrain());
    Assert.assertEquals("CP 700 at Acton", t1, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton", t1, c8.getTrain());
    // restrict train direction at the track level
    l2s2.setTrainDirections(Track.EAST + Track.SOUTH + Track.WEST);
    // take one car out of kernel
    c3.setKernel(null);
    // place car in Action Siding 1
    c3.setLocation(l2, l2s1);
    // place lead car in Action Yard
    c8.setLocation(l2, l2s2);
    // place c7 in Action Yard
    c7.setLocation(l2, l2s2);
    t1.build();
    Assert.assertEquals("CP 1000 destination track", "Acton Siding 1", c1.getDestinationTrackName());
    Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
    Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
    Assert.assertEquals("CP 30 destination track", "Nashua Yard 2", c3.getDestinationTrackName());
    Assert.assertEquals("CP 4000 at Foxboro Siding", t1, c4.getTrain());
    Assert.assertEquals("CP 4000 destination", "Foxboro", c4.getDestinationName());
    Assert.assertEquals("CP 4000 destination track", "Foxboro Yard", c4.getDestinationTrackName());
    Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
    Assert.assertEquals("CP 700 at Acton, not serviced, part of kernel CP 8000", null, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton, Acton Siding 2 not serviced", null, c8.getTrain());
    // test train length restrictions
    // only enough for the two engines, train needs a car with FRED
    rl1.setMaxTrainLength(155);
    t1.build();
    Assert.assertFalse("Train length test, can't service car with FRED", t1.isBuilt());
    // build failed after engines were assigned to train 1
    Assert.assertEquals("Engine assignment ignores train length restrictions", t1, e1.getTrain());
    Assert.assertEquals("Engine assignment ignores train length restrictions", t1, e2.getTrain());
    Assert.assertEquals("Engine destination ignores train length restrictions", "Foxboro", e1.getDestinationName());
    Assert.assertEquals("Engine destination ignores train length restrictions", "Foxboro", e2.getDestinationName());
    Assert.assertEquals("Check CP30 engine length", "56", e1.getLength());
    Assert.assertEquals("Check CP 200 length", "32", c2.getLength());
    // enough for the two engines and a car with FRED 56 + 56 + 32 + 12(couplers) = 156
    rl1.setMaxTrainLength(156);
    t1.build();
    Assert.assertTrue("Train length test, just enough length for engines and car with FRED", t1.isBuilt());
    Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
    Assert.assertEquals("CP 200 destination track", "Foxboro Siding", c2.getDestinationTrackName());
    Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
    Assert.assertEquals("CP 30 destination track", "Nashua Yard 1", c3.getDestinationTrackName());
    Assert.assertEquals("CP 4000 at Foxboro Siding", t1, c4.getTrain());
    Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
    Assert.assertEquals("CP 700 at Acton, not serviced, part of kernel CP 8000", null, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton, Acton Siding 2 not serviced", null, c8.getTrain());
    Assert.assertEquals("CP 1000 not part of train", null, c10.getTrain());
    // Increase the train length from the departure location
    rl1.setMaxTrainLength(1000);
    // restrict train length from Acton
    rl2.setMaxTrainLength(156);
    t1.build();
    Assert.assertTrue("Train length test, just enough length for engines and car with FRED", t1.isBuilt());
    Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
    Assert.assertEquals("CP 200 destination track", "Foxboro Yard", c2.getDestinationTrackName());
    Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
    Assert.assertEquals("CP 30 destination track", "Foxboro Yard", c3.getDestinationTrackName());
    Assert.assertEquals("CP 4000 at Foxboro Yard", t1, c4.getTrain());
    Assert.assertEquals("CP 4000 destination track", "Foxboro Siding", c4.getDestinationTrackName());
    Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
    Assert.assertEquals("CP 1000 part of train", t1, c10.getTrain());
    Assert.assertEquals("CP 1000 destination track", "Acton Siding 1", c10.getDestinationTrackName());
    // test setting car's destination to Foxboro Siding
    c2.setDestination(l1, l1s1);
    t1.build();
    Assert.assertTrue("car with FRED has destination", t1.isBuilt());
    t1.reset();
    // again, but now change car type serviced by Foxboro Yard
    c2.setDestination(l1, l1s1);
    l1s1.deleteTypeName("Boxcar");
    t1.build();
    Assert.assertFalse("car with FRED has destination that won't accept it", t1.isBuilt());
    l1s1.addTypeName("Boxcar");
    // destination Action Siding 2
    c6.setDestination(l2, l2s2);
    // don't allow Boxcar to drop
    l2s2.deleteTypeName("Boxcar");
    t1.build();
    Assert.assertTrue("car with FRED has destination that will now accept it", t1.isBuilt());
    Assert.assertEquals("CP 60 can't be delivered", null, c6.getTrain());
    c2.setLocation(l1, null);
    t1.build();
    Assert.assertFalse("need car doesn't have a track assignment", t1.isBuilt());
// end testSidingsYards
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) 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) Kernel(jmri.jmrit.operations.rollingstock.cars.Kernel) 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 10 with Consist

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

the class TrainBuilderTest method testStagingtoStaging.

// testStagingtoStaging tests the build procedure
// through the train's build method.
// test train staging to staging
public void testStagingtoStaging() {
    Setup.setSwitchTime(11);
    Setup.setTravelTime(111);
    // 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.reset();
    new TrainBuilder().build(train1);
    train2.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build but exclude road CP", false, train2.isBuilt());
    train2.setRoadOption(Train.ALL_ROADS);
    train2.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train1);
    train2.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train1);
    train2.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 build, caboose destination is terminal", true, train1.isBuilt());
    // don't allow cabooses road
    l3.deleteTypeName("Caboose");
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    // 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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    // should fail
    Assert.assertEquals("Train 1 After 3rd Build with rs built before 1985", false, train1.isBuilt());
    train1.setBuiltEndYear("");
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After 1st Build type Diesel not serviced", false, train1.isBuilt());
    train1.addTypeName("Diesel");
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After 1st Build owner DAB", false, train1.isBuilt());
    train1.addOwnerName("AT");
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After 2nd Build owners DAB and AT", true, train1.isBuilt());
    train1.setOwnerOption(Train.EXCLUDE_OWNERS);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After 3rd Build exclude owners DAB and AT", false, train1.isBuilt());
    train1.deleteOwnerName("AT");
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After 4th Build exclude owner DAB", false, train1.isBuilt());
    train1.setOwnerOption(Train.ALL_OWNERS);
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    // 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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After exclude loads", false, train1.isBuilt());
    // allow train to carry E loads
    train1.deleteLoadName("E");
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After 1st Build staging set to North", false, train1.isBuilt());
    l1s1.setTrainDirections(Location.SOUTH);
    l1s2.setTrainDirections(Location.SOUTH);
    train1.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train 1 After Build car to nowhere", false, train1.isBuilt());
    c4.setDestination(null, null);
    // Build the trains again!!
    train1.reset();
    new TrainBuilder().build(train1);
    train2.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train1);
    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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build require 0 engine", true, train2.isBuilt());
    train2.setNumberEngines("3");
    train2.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build require 3 engines", false, train2.isBuilt());
    train2.setNumberEngines("2");
    train2.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build require 2 engine", true, train2.isBuilt());
    // take engine out of service
    e3.setOutOfService(true);
    train2.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build engine out of service", false, train2.isBuilt());
    // put back into service
    e3.setOutOfService(false);
    train2.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build engine in service", true, train2.isBuilt());
    // try different road
    train2.setEngineRoad("CP");
    train2.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build requires FRED", false, train2.isBuilt());
    // Add FRED to boxcar
    c5.setFred(true);
    train2.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build 2 requires FRED", true, train2.isBuilt());
    // try engine wrong model
    train2.setEngineModel("DS45");
    train2.reset();
    new TrainBuilder().build(train2);
    Assert.assertEquals("Train 2 After Build 2 requires model DS45", false, train2.isBuilt());
    // try engine correct model
    train2.setEngineModel("SD45");
    train2.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    // Should build
    Assert.assertTrue("Train 2 built", train2.isBuilt());
    // make staging track too small for caboose
    l3s3.setLength(20);
    train2.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    // 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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    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.reset();
    new TrainBuilder().build(train2);
    Assert.assertFalse("Train 2 will Not build, staging track will not accept road BM", train2.isBuilt());
// end staging to staging 1
}
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)

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