Search in sources :

Example 36 with LocationManager

use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.

the class TrainTest method testScheduleLoads.

public void testScheduleLoads() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    CarManager cmanager = CarManager.instance();
    ScheduleManager smanager = ScheduleManager.instance();
    CarTypes ct = CarTypes.instance();
    ct.addName("Boxcar");
    ct.addName("Gon");
    ct.addName("Coil Car");
    ct.addName("Flat Car");
    // create schedules
    Schedule sch1 = smanager.newSchedule("Schedule 1");
    ScheduleItem sch1Item1 = sch1.addItem("Boxcar");
    // request a UP Boxcar
    sch1Item1.setRoadName("UP");
    ScheduleItem sch1Item2 = sch1.addItem("Flat Car");
    // request an empty car and load it with Scrap
    sch1Item2.setReceiveLoadName("E");
    sch1Item2.setShipLoadName("Scrap");
    ScheduleItem sch1Item3 = sch1.addItem("Gon");
    // request a loaded car and load it with Tin
    sch1Item3.setReceiveLoadName("L");
    sch1Item3.setShipLoadName("Tin");
    // Allows c13 which is part of a kernel to get a new load
    CarLoads.instance().addName("Gon", "Tin");
    Schedule sch2 = smanager.newSchedule("Schedule 2");
    ScheduleItem sch2Item1 = sch2.addItem("Coil Car");
    sch2Item1.setCount(2);
    sch2.addItem("Boxcar");
    // Create locations used
    Location loc1;
    loc1 = lmanager.newLocation("New Westford");
    loc1.setTrainDirections(DIRECTION_ALL);
    //		loc1.addTypeName("Flat Car");
    Location loc2;
    loc2 = lmanager.newLocation("New Chelmsford");
    loc2.setTrainDirections(DIRECTION_ALL);
    Location loc3;
    loc3 = lmanager.newLocation("New Bedford");
    loc3.setTrainDirections(DIRECTION_ALL);
    Track loc1trk1;
    loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
    loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk1.setLength(900);
    //		loc1trk1.addTypeName("Flat Car");
    Track loc1trk2;
    loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
    loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk2.setLength(500);
    loc1trk2.deleteTypeName("Coil Car");
    Track loc1trk3;
    loc1trk3 = loc1.addTrack("Westford Express 3", Track.SPUR);
    loc1trk3.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk3.setLength(300);
    loc1trk3.deleteTypeName("Gon");
    loc1trk3.deleteTypeName("Coil Car");
    Track loc1trk4;
    loc1trk4 = loc1.addTrack("Westford Express 4", Track.SPUR);
    loc1trk4.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk4.setLength(300);
    loc1trk4.deleteTypeName("Gon");
    loc1trk4.deleteTypeName("Coil Car");
    Track loc2trk1;
    loc2trk1 = loc2.addTrack("Chelmsford Freight 1", Track.SPUR);
    loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk1.setLength(900);
    loc2trk1.deleteTypeName("Coil Car");
    loc2trk1.setScheduleId(sch1.getId());
    loc2trk1.setScheduleMode(Track.SEQUENTIAL);
    // start the schedule with 2nd item Flat Car
    loc2trk1.setScheduleItemId(sch1.getItemsBySequenceList().get(1).getId());
    Track loc2trk2;
    loc2trk2 = loc2.addTrack("Chelmsford Freight 2", Track.SPUR);
    loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk2.setLength(900);
    loc2trk2.deleteTypeName("Coil Car");
    loc2trk2.setScheduleId(sch1.getId());
    loc2trk2.setScheduleMode(Track.SEQUENTIAL);
    // start the schedule with 3rd item Gon
    loc2trk2.setScheduleItemId(sch1.getItemsBySequenceList().get(2).getId());
    Track loc2trk3;
    loc2trk3 = loc2.addTrack("Chelmsford Yard 3", Track.YARD);
    loc2trk3.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk3.setLength(900);
    loc2trk3.deleteTypeName("Gon");
    loc2trk3.deleteTypeName("Coil Car");
    Track loc2trk4;
    loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
    loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk4.setLength(900);
    loc2trk4.setScheduleId(sch2.getId());
    loc2trk4.setScheduleMode(Track.SEQUENTIAL);
    Track loc3trk1;
    loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.STAGING);
    loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc3trk1.setLength(900);
    loc3trk1.setRemoveCustomLoadsEnabled(true);
    // Create route with 2 location
    Route rte1;
    rte1 = rmanager.newRoute("Two Location Route");
    RouteLocation rl1 = rte1.addLocation(loc1);
    rl1.setTrainDirection(RouteLocation.EAST);
    rl1.setMaxCarMoves(12);
    // set the train icon coordinates
    rl1.setTrainIconX(25);
    rl1.setTrainIconY(75);
    RouteLocation rl2 = rte1.addLocation(loc2);
    rl2.setTrainDirection(RouteLocation.EAST);
    rl2.setMaxCarMoves(12);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(75);
    // Create train
    Train train1;
    train1 = tmanager.newTrain("NWNC");
    train1.setRoute(rte1);
    // Set up 13 cars
    Car c1 = new Car("BM", "S1");
    c1.setTypeName("Gon");
    c1.setLength("90");
    c1.setMoves(13);
    c1.setLoadName("L");
    cmanager.register(c1);
    Car c2 = new Car("UP", "S2");
    c2.setTypeName("Boxcar");
    c2.setLength("80");
    c2.setMoves(12);
    cmanager.register(c2);
    Car c3 = new Car("XP", "S3");
    c3.setTypeName("Flat Car");
    c3.setLength("70");
    c3.setMoves(0);
    c3.setLoadName("L");
    // force this car to Chelmsford
    c3.setDestination(loc2, null);
    cmanager.register(c3);
    Car c4 = new Car("PU", "S4");
    c4.setTypeName("Boxcar");
    c4.setLength("60");
    c4.setMoves(10);
    cmanager.register(c4);
    // place two cars in a kernel
    Kernel k1 = cmanager.newKernel("TwoCars");
    Car c5 = new Car("UP", "S5");
    c5.setTypeName("Gon");
    c5.setLength("50");
    c5.setMoves(9);
    c5.setLoadName("L");
    c5.setKernel(k1);
    cmanager.register(c5);
    Car c6 = new Car("CP", "S6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(8);
    c6.setLoadName("L");
    cmanager.register(c6);
    Car c7 = new Car("UP", "S7");
    c7.setTypeName("Boxcar");
    c7.setLength("50");
    c7.setMoves(7);
    cmanager.register(c7);
    Car c8 = new Car("XP", "S8");
    c8.setTypeName("Gon");
    c8.setLength("60");
    c8.setMoves(6);
    cmanager.register(c8);
    Car c9 = new Car("XP", "S9");
    c9.setTypeName("Flat Car");
    c9.setLength("90");
    c9.setMoves(5);
    c9.setLoadName("E");
    cmanager.register(c9);
    Car c10 = new Car("CP", "S10");
    c10.setTypeName("Coil Car");
    c10.setLength("40");
    c10.setMoves(2);
    c10.setLoadName("L");
    cmanager.register(c10);
    Car c11 = new Car("CP", "S11");
    c11.setTypeName("Coil Car");
    c11.setLength("40");
    c11.setMoves(3);
    c11.setLoadName("Coils");
    cmanager.register(c11);
    Car c12 = new Car("CP", "S12");
    c12.setTypeName("Coil Car");
    c12.setLength("40");
    c12.setMoves(4);
    cmanager.register(c12);
    // place car in kernel with c5
    Car c13 = new Car("UP", "S13");
    c13.setTypeName("Gon");
    c13.setLength("50");
    c13.setMoves(1);
    c13.setLoadName("L");
    c13.setKernel(k1);
    cmanager.register(c13);
    // place the cars in the yards
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c12", Track.OKAY, c12.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c13", Track.OKAY, c13.setLocation(loc1, loc1trk2));
    train1.build();
    // Schedule sch1 should cause c2 to be delivered to Chelmsford Freight 2
    Assert.assertEquals("c2 destination", "Chelmsford Freight 2", c2.getDestinationTrackName());
    Assert.assertEquals("c2 next load", "", c2.getNextLoadName());
    // Schedule sch1 and sch2 should reject c3, to be delivered to Chelmsford Yard 3
    Assert.assertEquals("c3 destination", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c3 next load", "", c3.getNextLoadName());
    Assert.assertEquals("c4 destination", "Chelmsford Yard 3", c4.getDestinationTrackName());
    // Schedule sch1 should cause c5 & c13 to be delivered to Chelmsford Freight 2
    Assert.assertEquals("c5 destination", "Chelmsford Freight 2", c5.getDestinationTrackName());
    Assert.assertEquals("c5 next load", "Tin", c5.getNextLoadName());
    Assert.assertEquals("c6 destination", "Chelmsford Yard 3", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination", "Chelmsford Freight 4", c7.getDestinationTrackName());
    Assert.assertEquals("c9 destination", "Chelmsford Freight 1", c9.getDestinationTrackName());
    Assert.assertEquals("c9 next load", "Scrap", c9.getNextLoadName());
    Assert.assertEquals("c10 destination", "Chelmsford Freight 4", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination", "Chelmsford Freight 4", c11.getDestinationTrackName());
    // C13 is part of kernel, load will flip between E and L
    Assert.assertEquals("c13 destination", "Chelmsford Freight 2", c13.getDestinationTrackName());
    Assert.assertEquals("c13 next load", "Tin", c13.getNextLoadName());
    // move and terminate train
    train1.move();
    train1.move();
    train1.move();
    Assert.assertEquals("c1 track", "Chelmsford Freight 1", c1.getTrackName());
    Assert.assertEquals("c1 load", "Tin", c1.getLoadName());
    Assert.assertEquals("c2 track", "Chelmsford Freight 2", c2.getTrackName());
    Assert.assertEquals("c2 load", "L", c2.getLoadName());
    Assert.assertEquals("c3 track", "Chelmsford Yard 3", c3.getTrackName());
    Assert.assertEquals("c3 load", "L", c3.getLoadName());
    Assert.assertEquals("c4 track", "Chelmsford Yard 3", c4.getTrackName());
    Assert.assertEquals("c4 load", "E", c4.getLoadName());
    Assert.assertEquals("c5 track", "Chelmsford Freight 2", c5.getTrackName());
    Assert.assertEquals("c5 load", "Tin", c5.getLoadName());
    Assert.assertEquals("c6 track", "Chelmsford Yard 3", c6.getTrackName());
    Assert.assertEquals("c6 load", "L", c6.getLoadName());
    Assert.assertEquals("c7 track", "Chelmsford Freight 4", c7.getTrackName());
    Assert.assertEquals("c7 load", "L", c7.getLoadName());
    Assert.assertEquals("c8 track", "Westford Yard 2", c8.getTrackName());
    Assert.assertEquals("c8 load", "E", c8.getLoadName());
    Assert.assertEquals("c9 track", "Chelmsford Freight 1", c9.getTrackName());
    Assert.assertEquals("c9 load", "Scrap", c9.getLoadName());
    Assert.assertEquals("c10 track", "Chelmsford Freight 4", c10.getTrackName());
    Assert.assertEquals("c10 load", "E", c10.getLoadName());
    Assert.assertEquals("c11 track", "Chelmsford Freight 4", c11.getTrackName());
    Assert.assertEquals("c11 load", "E", c11.getLoadName());
    Assert.assertEquals("c12 track", "Westford Yard 1", c12.getTrackName());
    Assert.assertEquals("c12 load", "E", c12.getLoadName());
    Assert.assertEquals("c13 track", "Chelmsford Freight 2", c13.getTrackName());
    Assert.assertEquals("c13 load", "Tin", c13.getLoadName());
    // create a route to staging to test remove schedule load
    // Create route with 2 location
    Route rte2;
    rte2 = rmanager.newRoute("Chelmsford to Staging");
    RouteLocation r2rl1 = rte2.addLocation(loc2);
    r2rl1.setTrainDirection(RouteLocation.EAST);
    r2rl1.setMaxCarMoves(12);
    // set the train icon coordinates
    r2rl1.setTrainIconX(125);
    r2rl1.setTrainIconY(75);
    RouteLocation r2rl3 = rte2.addLocation(loc3);
    r2rl3.setTrainDirection(RouteLocation.EAST);
    r2rl3.setMaxCarMoves(12);
    // set the train icon coordinates
    r2rl3.setTrainIconX(175);
    r2rl3.setTrainIconY(75);
    train1.setRoute(rte2);
    train1.setName("Chelmsford to Bedford");
    train1.build();
    // move and terminate train
    train1.move();
    train1.move();
    train1.move();
    Assert.assertEquals("c1 track to staging", "Bedford Yard 1", c1.getTrackName());
    Assert.assertEquals("c1 load to staging", "E", c1.getLoadName());
    Assert.assertEquals("c2 track to staging", "Bedford Yard 1", c2.getTrackName());
    Assert.assertEquals("c2 load to staging", "L", c2.getLoadName());
    Assert.assertEquals("c3 track to staging", "Bedford Yard 1", c3.getTrackName());
    Assert.assertEquals("c3 load to staging", "L", c3.getLoadName());
    Assert.assertEquals("c4 track to staging", "Bedford Yard 1", c4.getTrackName());
    Assert.assertEquals("c4 load to staging", "E", c4.getLoadName());
    Assert.assertEquals("c5 track to staging", "Bedford Yard 1", c5.getTrackName());
    Assert.assertEquals("c5 load to staging", "E", c5.getLoadName());
    Assert.assertEquals("c6 track to staging", "Bedford Yard 1", c6.getTrackName());
    Assert.assertEquals("c6 load to staging", "L", c6.getLoadName());
    Assert.assertEquals("c7 track to staging", "Bedford Yard 1", c7.getTrackName());
    Assert.assertEquals("c7 load to staging", "L", c7.getLoadName());
    Assert.assertEquals("c8 track to staging", "Westford Yard 2", c8.getTrackName());
    Assert.assertEquals("c8 load to staging", "E", c8.getLoadName());
    Assert.assertEquals("c9 track to staging", "Bedford Yard 1", c9.getTrackName());
    Assert.assertEquals("c9 load to staging", "E", c9.getLoadName());
    Assert.assertEquals("c10 track to staging", "Bedford Yard 1", c10.getTrackName());
    Assert.assertEquals("c10 load to staging", "E", c10.getLoadName());
    Assert.assertEquals("c11 track to staging", "Bedford Yard 1", c11.getTrackName());
    Assert.assertEquals("c11 load to staging", "E", c11.getLoadName());
    Assert.assertEquals("c12 track to staging", "Westford Yard 1", c12.getTrackName());
    Assert.assertEquals("c12 load to staging", "E", c12.getLoadName());
    Assert.assertEquals("c13 track to staging", "Bedford Yard 1", c13.getTrackName());
    Assert.assertEquals("c13 load to staging", "E", c13.getLoadName());
    // create a route from staging to test generate schedule load
    // Create route with 3 locations
    Route rte3;
    rte3 = rmanager.newRoute("Staging to Chelmsford");
    RouteLocation r3rl1 = rte3.addLocation(loc3);
    r3rl1.setTrainDirection(RouteLocation.EAST);
    // there are 11 cars departing staging
    r3rl1.setMaxCarMoves(11);
    // set the train icon coordinates
    r3rl1.setTrainIconX(25);
    r3rl1.setTrainIconY(100);
    RouteLocation r3rl2 = rte3.addLocation(loc2);
    r3rl2.setTrainDirection(RouteLocation.EAST);
    r3rl2.setMaxCarMoves(12);
    RouteLocation r3rl3 = rte3.addLocation(loc1);
    r3rl3.setTrainDirection(RouteLocation.EAST);
    r3rl3.setMaxCarMoves(12);
    // set the train icon coordinates
    r3rl3.setTrainIconX(75);
    r3rl3.setTrainIconY(100);
    loc3trk1.setRemoveCustomLoadsEnabled(false);
    // generate schedule loads
    loc3trk1.setAddCustomLoadsEnabled(true);
    // request these loads from staging
    sch1Item1.setReceiveLoadName("Metal 1");
    sch1Item2.setReceiveLoadName("Metal 2");
    sch1Item3.setReceiveLoadName("Metal 3");
    // Allows c13 which is part of a kernel to get a new load
    CarLoads.instance().addName("Gon", "Metal 3");
    train1.setRoute(rte3);
    train1.setName("BCW");
    train1.build();
    Assert.assertEquals("Train Bedford Chelmsford Westford build status", true, train1.isBuilt());
    Assert.assertEquals("c1 load from staging", "E", c1.getLoadName());
    Assert.assertEquals("c2 load from staging", "L", c2.getLoadName());
    Assert.assertEquals("c3 load from staging", "L", c3.getLoadName());
    Assert.assertEquals("c4 load from staging", "E", c4.getLoadName());
    Assert.assertEquals("c5 load from staging", "Metal 3", c5.getLoadName());
    Assert.assertEquals("c6 load from staging", "L", c6.getLoadName());
    Assert.assertEquals("c7 load from staging", "L", c7.getLoadName());
    Assert.assertEquals("c8 load from staging", "E", c8.getLoadName());
    Assert.assertEquals("c9 load from staging", "Metal 2", c9.getLoadName());
    Assert.assertEquals("c9 next load from staging", "Scrap", c9.getNextLoadName());
    Assert.assertEquals("c10 load from staging", "E", c10.getLoadName());
    Assert.assertEquals("c11 load from staging", "E", c11.getLoadName());
    Assert.assertEquals("c13 load from staging", "Metal 3", c13.getLoadName());
    // move and terminate train
    train1.move();
    train1.move();
    train1.move();
    train1.move();
    Assert.assertEquals("c1 track from staging terminated", "Westford Yard 1", c1.getTrackName());
    Assert.assertEquals("c1 load from staging terminated", "E", c1.getLoadName());
    Assert.assertEquals("c2 track from staging terminated", "Westford Yard 2", c2.getTrackName());
    Assert.assertEquals("c2 load from staging terminated", "L", c2.getLoadName());
    Assert.assertEquals("c3 track from staging terminated", "Westford Yard 1", c3.getTrackName());
    Assert.assertEquals("c3 load from staging terminated", "L", c3.getLoadName());
    Assert.assertEquals("c4 track from staging terminated", "Westford Express 4", c4.getTrackName());
    Assert.assertEquals("c4 load from staging terminated", "L", c4.getLoadName());
    Assert.assertEquals("c5 track from staging terminated", "Chelmsford Freight 2", c5.getTrackName());
    Assert.assertEquals("c5 load from staging terminated", "Tin", c5.getLoadName());
    Assert.assertEquals("c6 track from staging terminated", "Westford Express 3", c6.getTrackName());
    Assert.assertEquals("c6 load from staging terminated", "E", c6.getLoadName());
    Assert.assertEquals("c7 track from staging terminated", "Westford Yard 2", c7.getTrackName());
    Assert.assertEquals("c7 load from staging terminated", "L", c7.getLoadName());
    Assert.assertEquals("c8 track from staging terminated", "Westford Yard 2", c8.getTrackName());
    Assert.assertEquals("c8 load from staging terminated", "E", c8.getLoadName());
    Assert.assertEquals("c9 track from staging terminated", "Chelmsford Freight 2", c9.getTrackName());
    Assert.assertEquals("c9 load from staging terminated", "Scrap", c9.getLoadName());
    Assert.assertEquals("c10 track from staging terminated", "Chelmsford Freight 4", c10.getTrackName());
    Assert.assertEquals("c10 load from staging terminated", "L", c10.getLoadName());
    Assert.assertEquals("c11 track from staging terminated", "Westford Yard 1", c11.getTrackName());
    Assert.assertEquals("c11 load from staging terminated", "E", c11.getLoadName());
    Assert.assertEquals("c12 track from staging terminated", "Westford Yard 1", c12.getTrackName());
    Assert.assertEquals("c12 load from staging terminated", "E", c12.getLoadName());
    Assert.assertEquals("c13 track from staging terminated", "Chelmsford Freight 2", c13.getTrackName());
    Assert.assertEquals("c13 load from staging terminated", "Tin", c13.getLoadName());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ScheduleManager(jmri.jmrit.operations.locations.schedules.ScheduleManager) ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Schedule(jmri.jmrit.operations.locations.schedules.Schedule) Kernel(jmri.jmrit.operations.rollingstock.cars.Kernel) 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 37 with LocationManager

use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.

the class EngineSetFrameTest method loadEngines.

private void loadEngines() {
    // add Owner1 and Owner2
    CarOwners co = CarOwners.instance();
    co.addName("Owner1");
    co.addName("Owner2");
    // add road names
    CarRoads cr = CarRoads.instance();
    cr.addName("NH");
    cr.addName("UP");
    cr.addName("AA");
    cr.addName("SP");
    // add locations
    LocationManager lManager = LocationManager.instance();
    Location westford = lManager.newLocation("Westford");
    Track westfordYard = westford.addTrack("Yard", Track.YARD);
    westfordYard.setLength(300);
    Track westfordSiding = westford.addTrack("Siding", Track.SPUR);
    westfordSiding.setLength(300);
    Track westfordAble = westford.addTrack("Able", Track.SPUR);
    westfordAble.setLength(300);
    Location boxford = lManager.newLocation("Boxford");
    Track boxfordYard = boxford.addTrack("Yard", Track.YARD);
    boxfordYard.setLength(300);
    Track boxfordJacobson = boxford.addTrack("Jacobson", Track.SPUR);
    boxfordJacobson.setLength(300);
    Track boxfordHood = boxford.addTrack("Hood", Track.SPUR);
    boxfordHood.setLength(300);
    EngineManager eManager = EngineManager.instance();
    // add 5 Engines to table
    Engine e1 = eManager.newEngine("NH", "1");
    e1.setModel("RS1");
    e1.setBuilt("2009");
    e1.setMoves(55);
    e1.setOwner("Owner2");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 3");
    e1.setRfid("RFID 3");
    e1.setWeightTons("Tons of Weight");
    e1.setComment("Test Engine NH 1 Comment");
    Assert.assertEquals("e1 location", Track.OKAY, e1.setLocation(westford, westfordYard));
    Assert.assertEquals("e1 destination", Track.OKAY, e1.setDestination(boxford, boxfordJacobson));
    Engine e2 = eManager.newEngine("UP", "2");
    e2.setModel("FT");
    e2.setBuilt("2004");
    e2.setMoves(50);
    e2.setOwner("AT");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 2");
    e2.setRfid("RFID 2");
    Engine e3 = eManager.newEngine("AA", "3");
    e3.setModel("SW8");
    e3.setBuilt("2006");
    e3.setMoves(40);
    e3.setOwner("AB");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 5");
    e3.setRfid("RFID 5");
    Assert.assertEquals("e3 location", Track.OKAY, e3.setLocation(boxford, boxfordHood));
    Assert.assertEquals("e3 destination", Track.OKAY, e3.setDestination(boxford, boxfordYard));
    Engine e4 = eManager.newEngine("SP", "2");
    e4.setModel("GP35");
    e4.setBuilt("1990");
    e4.setMoves(30);
    e4.setOwner("AAA");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 4");
    e4.setRfid("RFID 4");
    Assert.assertEquals("e4 location", Track.OKAY, e4.setLocation(westford, westfordSiding));
    Assert.assertEquals("e4 destination", Track.OKAY, e4.setDestination(boxford, boxfordHood));
    Engine e5 = eManager.newEngine("NH", "5");
    e5.setModel("SW1200");
    e5.setBuilt("1956");
    e5.setMoves(25);
    e5.setOwner("DAB");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 1");
    e5.setRfid("RFID 1");
    Assert.assertEquals("e5 location", Track.OKAY, e5.setLocation(westford, westfordAble));
    Assert.assertEquals("e5 destination", Track.OKAY, e5.setDestination(westford, westfordAble));
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) CarOwners(jmri.jmrit.operations.rollingstock.cars.CarOwners) CarRoads(jmri.jmrit.operations.rollingstock.cars.CarRoads) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 38 with LocationManager

use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.

the class EnginesTableFrameTest method loadEngines.

private void loadEngines() {
    // add Owner1 and Owner2
    CarOwners co = CarOwners.instance();
    co.addName("Owner1");
    co.addName("Owner2");
    // add road names
    CarRoads cr = CarRoads.instance();
    cr.addName("NH");
    cr.addName("UP");
    cr.addName("AA");
    cr.addName("SP");
    // add locations
    LocationManager lManager = LocationManager.instance();
    Location westford = lManager.newLocation("Westford");
    Track westfordYard = westford.addTrack("Yard", Track.YARD);
    westfordYard.setLength(300);
    Track westfordSiding = westford.addTrack("Siding", Track.SPUR);
    westfordSiding.setLength(300);
    Track westfordAble = westford.addTrack("Able", Track.SPUR);
    westfordAble.setLength(300);
    Location boxford = lManager.newLocation("Boxford");
    Track boxfordYard = boxford.addTrack("Yard", Track.YARD);
    boxfordYard.setLength(300);
    Track boxfordJacobson = boxford.addTrack("Jacobson", Track.SPUR);
    boxfordJacobson.setLength(300);
    Track boxfordHood = boxford.addTrack("Hood", Track.SPUR);
    boxfordHood.setLength(300);
    EngineManager eManager = EngineManager.instance();
    // add 5 Engines to table
    Engine e1 = eManager.newEngine("NH", "1");
    e1.setModel("RS1");
    e1.setBuilt("2009");
    e1.setMoves(55);
    e1.setOwner("Owner2");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 3");
    e1.setRfid("RFID 3");
    e1.setWeightTons("Tons of Weight");
    e1.setComment("Test Engine NH 1 Comment");
    Assert.assertEquals("e1 location", Track.OKAY, e1.setLocation(westford, westfordYard));
    Assert.assertEquals("e1 destination", Track.OKAY, e1.setDestination(boxford, boxfordJacobson));
    Engine e2 = eManager.newEngine("UP", "2");
    e2.setModel("FT");
    e2.setBuilt("2004");
    e2.setMoves(50);
    e2.setOwner("AT");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 2");
    e2.setRfid("RFID 2");
    Engine e3 = eManager.newEngine("AA", "3");
    e3.setModel("SW8");
    e3.setBuilt("2006");
    e3.setMoves(40);
    e3.setOwner("AB");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 5");
    e3.setRfid("RFID 5");
    Assert.assertEquals("e3 location", Track.OKAY, e3.setLocation(boxford, boxfordHood));
    Assert.assertEquals("e3 destination", Track.OKAY, e3.setDestination(boxford, boxfordYard));
    Engine e4 = eManager.newEngine("SP", "2");
    e4.setModel("GP35");
    e4.setBuilt("1990");
    e4.setMoves(30);
    e4.setOwner("AAA");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 4");
    e4.setRfid("RFID 4");
    Assert.assertEquals("e4 location", Track.OKAY, e4.setLocation(westford, westfordSiding));
    Assert.assertEquals("e4 destination", Track.OKAY, e4.setDestination(boxford, boxfordHood));
    Engine e5 = eManager.newEngine("NH", "5");
    e5.setModel("SW1200");
    e5.setBuilt("1956");
    e5.setMoves(25);
    e5.setOwner("DAB");
    jmri.InstanceManager.getDefault(jmri.IdTagManager.class).provideIdTag("RFID 1");
    e5.setRfid("RFID 1");
    Assert.assertEquals("e5 location", Track.OKAY, e5.setLocation(westford, westfordAble));
    Assert.assertEquals("e5 destination", Track.OKAY, e5.setDestination(westford, westfordAble));
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) CarOwners(jmri.jmrit.operations.rollingstock.cars.CarOwners) CarRoads(jmri.jmrit.operations.rollingstock.cars.CarRoads) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 39 with LocationManager

use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.

the class TrainTest method testLocal.

// Test a route of one location (local train).
// Locations that don't have a train direction assigned
// can only be served by a local train.
// Creates two locations Westford and Chelmsford and 9 cars.
// Westford has 2 yards, 2 sidings, 3 interchange tracks.
// Chelmsford has 1 yard. Chelmsford is used to test that a
// train with two locations will not service certain tracks.
public void testLocal() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    // Create locations used
    Location loc1;
    loc1 = lmanager.newLocation("Westford");
    loc1.setTrainDirections(DIRECTION_ALL);
    loc1.addTypeName("Flat Car");
    Location loc2;
    loc2 = lmanager.newLocation("Chelmsford");
    loc2.setTrainDirections(DIRECTION_ALL);
    loc2.addTypeName("Flat Car");
    Track loc1trk1;
    loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
    loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk1.setLength(500);
    loc1trk1.addTypeName("Flat Car");
    Track loc1trk2;
    loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
    loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk2.setLength(500);
    loc1trk2.addTypeName("Flat Car");
    Track loc1trk3;
    loc1trk3 = loc1.addTrack("Westford Siding 3", Track.SPUR);
    // Only local moves allowed
    loc1trk3.setTrainDirections(0);
    loc1trk3.setLength(300);
    loc1trk3.addTypeName("Flat Car");
    Track loc1trk4;
    loc1trk4 = loc1.addTrack("Westford Siding 4", Track.SPUR);
    // Only local moves allowed
    loc1trk4.setTrainDirections(0);
    loc1trk4.setLength(300);
    loc1trk4.addTypeName("Flat Car");
    Track loc1trk5;
    loc1trk5 = loc1.addTrack("Westford Interchange 5", Track.INTERCHANGE);
    // Only local moves allowed
    loc1trk5.setTrainDirections(0);
    loc1trk5.setLength(300);
    loc1trk5.addTypeName("Flat Car");
    Track loc1trk6;
    loc1trk6 = loc1.addTrack("Westford Interchange 6", Track.INTERCHANGE);
    loc1trk6.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk6.setLength(300);
    loc1trk6.addTypeName("Flat Car");
    Track loc1trk7;
    loc1trk7 = loc1.addTrack("Westford Interchange 7", Track.INTERCHANGE);
    // Only local moves allowed
    loc1trk7.setTrainDirections(0);
    loc1trk7.setLength(300);
    loc1trk7.addTypeName("Flat Car");
    Track loc2trk1;
    loc2trk1 = loc2.addTrack("Chelmsford Yard 1", Track.YARD);
    loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk1.setLength(900);
    loc2trk1.addTypeName("Flat Car");
    // now bias track selection by moves
    // no yard to yard moves expected
    loc1trk1.setMoves(3);
    // no yard to yard moves expected
    loc1trk2.setMoves(4);
    // this will be the 5th location assigned
    loc1trk3.setMoves(10);
    // this will be the 6th location assigned
    loc1trk4.setMoves(10);
    // this will be the 2nd location assigned
    loc1trk5.setMoves(9);
    // this will be the 3rd location assigned
    loc1trk6.setMoves(9);
    // this will be the first and 4th location assigned
    loc1trk7.setMoves(8);
    // Create route with only one location
    Route rte1 = rmanager.newRoute("Local Route");
    // set the default moves to 7
    Setup.setCarMoves(7);
    RouteLocation rl1 = rte1.addLocation(loc1);
    // Create train
    Train train1 = tmanager.newTrain("Local Train");
    train1.setRoute(rte1);
    // Flat Car isn't registered yet so add it now
    train1.addTypeName("Flat Car");
    // Set up 7 box cars and 2 flat cars
    Car c1 = new Car("BM", "1");
    c1.setTypeName("Boxcar");
    c1.setLength("90");
    // should be the 7th car assigned to train
    c1.setMoves(17);
    cmanager.register(c1);
    Car c2 = new Car("CP", "2");
    c2.setTypeName("Boxcar");
    c2.setLength("80");
    // should be the 6th car assigned to train
    c2.setMoves(15);
    cmanager.register(c2);
    Car c3 = new Car("XP", "3");
    c3.setTypeName("Flat Car");
    c3.setLength("70");
    // default c3 moves = 0 should be the 1st car assigned
    cmanager.register(c3);
    Car c4 = new Car("UP", "4");
    c4.setTypeName("Boxcar");
    c4.setLength("60");
    // should be the 5th car assigned to train
    c4.setMoves(6);
    cmanager.register(c4);
    Car c5 = new Car("UP", "5");
    c5.setTypeName("Boxcar");
    c5.setLength("50");
    // should be the 2nd car assigned to train
    c5.setMoves(1);
    cmanager.register(c5);
    Car c6 = new Car("CP", "6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    // should be the 4th car assigned to train
    c6.setMoves(3);
    cmanager.register(c6);
    Car c7 = new Car("UP", "7");
    c7.setTypeName("Boxcar");
    c7.setLength("50");
    c7.setMoves(18);
    cmanager.register(c7);
    Car c8 = new Car("XP", "8");
    c8.setTypeName("Boxcar");
    c8.setLength("60");
    // should be the 2rd car assigned to train
    c8.setMoves(2);
    cmanager.register(c8);
    Car c9 = new Car("XP", "9");
    c9.setTypeName("Flat Car");
    c9.setLength("90");
    c9.setMoves(19);
    cmanager.register(c9);
    //		Assert.assertEquals("Westford should not accept Flat Car", false, loc1.acceptsTypeName("Flat Car"));
    // add Flat Car as a valid type so Westford will accept
    ct.addName("Flat Car");
    Assert.assertEquals("Westford should now accepts Flat Car", true, loc1.acceptsTypeName("Flat Car"));
    // place the cars in the yards
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk3));
    // 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());
    // Build train
    train1.build();
    // check train status
    Assert.assertEquals("Train 1 built", Train.CODE_BUILT, train1.getStatusCode());
    Assert.assertEquals("Train 1 After Build Departs Name", "Westford", train1.getTrainDepartsName());
    Assert.assertEquals("Train 1 After Build Terminates Name", "Westford", train1.getTrainTerminatesName());
    Assert.assertEquals("Train 1 After Build Next Location Name", "", train1.getNextLocationName());
    Assert.assertEquals("Train 1 After Build Built Status", true, train1.isBuilt());
    // are the right cars assigned to the train?
    // the default moves is 7, therefore only 7 cars should be moved based on their move counts
    Assert.assertEquals("Car c1 After Build should be assigned to Train 1", train1, c1.getTrain());
    Assert.assertEquals("Car c2 After Build should be assigned to Train 1", train1, c2.getTrain());
    Assert.assertEquals("Car c3 After Build should be assigned to Train 1", train1, c3.getTrain());
    Assert.assertEquals("Car c4 After Build should NOT be assigned to Train 1", train1, c4.getTrain());
    Assert.assertEquals("Car c5 After Build should be assigned to Train 1", train1, c5.getTrain());
    Assert.assertEquals("Car c6 After Build should be assigned to Train 1", train1, c6.getTrain());
    Assert.assertEquals("Car c7 After Build should NOT be assigned to Train 1", null, c7.getTrain());
    Assert.assertEquals("Car c8 After Build should be assigned to Train 1", train1, c8.getTrain());
    Assert.assertEquals("Car c9 After Build should NOT be assigned to Train 1", null, c9.getTrain());
    // now check to see if cars are going to be delivered to the right places?
    Assert.assertEquals("Car c1 After Build destination", "Westford Interchange 5", c1.getDestinationTrackName());
    Assert.assertEquals("Car c2 After Build destination", "Westford Siding 4", c2.getDestinationTrackName());
    Assert.assertEquals("Car c3 After Build destination", "Westford Interchange 7", c3.getDestinationTrackName());
    Assert.assertEquals("Car c4 After Build destination", "Westford Siding 3", c4.getDestinationTrackName());
    Assert.assertEquals("Car c5 After Build destination", "Westford Interchange 5", c5.getDestinationTrackName());
    Assert.assertEquals("Car c6 After Build destination", "Westford Interchange 7", c6.getDestinationTrackName());
    Assert.assertEquals("Car c8 After Build destination", "Westford Interchange 6", c8.getDestinationTrackName());
    // are the pickup and drop counts correct?
    Assert.assertEquals("Drop count for Westford", 7, loc1.getDropRS());
    Assert.assertEquals("Drop count for Westford track Westford Yard 1", 0, loc1trk1.getDropRS());
    Assert.assertEquals("Drop count for Westford track Westford Yard 2", 0, loc1trk2.getDropRS());
    Assert.assertEquals("Drop count for Westford track Westford Siding 3", 1, loc1trk3.getDropRS());
    Assert.assertEquals("Drop count for Westford track Westford Siding 4", 1, loc1trk4.getDropRS());
    Assert.assertEquals("Drop count for Westford track Westford Interchange 5", 2, loc1trk5.getDropRS());
    Assert.assertEquals("Drop count for Westford track Westford Interchange 6", 1, loc1trk6.getDropRS());
    Assert.assertEquals("Drop count for Westford track Westford Interchange 7", 2, loc1trk7.getDropRS());
    Assert.assertEquals("Pickup count for Westford", 7, loc1.getPickupRS());
    Assert.assertEquals("Pickup count for Westford track Westford Yard 1", 4, loc1trk1.getPickupRS());
    Assert.assertEquals("Pickup count for Westford track Westford Yard 2", 3, loc1trk2.getPickupRS());
    Assert.assertEquals("Pickup count for Westford track Westford Siding 3", 0, loc1trk3.getPickupRS());
    Assert.assertEquals("Pickup count for Westford track Westford Siding 4", 0, loc1trk4.getPickupRS());
    Assert.assertEquals("Pickup count for Westford track Westford Interchange 5", 0, loc1trk5.getPickupRS());
    Assert.assertEquals("Pickup count for Westford track Westford Interchange 6", 0, loc1trk6.getPickupRS());
    Assert.assertEquals("Pickup count for Westford track Westford Interchange 7", 0, loc1trk7.getPickupRS());
    train1.move();
    // Train should not be in route since there's only one location
    Assert.assertEquals("Train 1 not in route", false, train1.isTrainEnRoute());
    // check train status
    Assert.assertEquals("Train 1 not en route", Train.TERMINATED, getTrainStatus(train1));
    Assert.assertEquals("Train 1 not en route", Train.CODE_TERMINATED, train1.getStatusCode());
    // check for correct tracks
    Assert.assertEquals("Car c1 After Move location", "Westford Interchange 5", c1.getTrackName());
    Assert.assertEquals("Car c2 After Move location", "Westford Siding 4", c2.getTrackName());
    Assert.assertEquals("Car c3 After Move location", "Westford Interchange 7", c3.getTrackName());
    Assert.assertEquals("Car c4 After Move location", "Westford Siding 3", c4.getTrackName());
    Assert.assertEquals("Car c5 After Move location", "Westford Interchange 5", c5.getTrackName());
    Assert.assertEquals("Car c6 After Move location", "Westford Interchange 7", c6.getTrackName());
    Assert.assertEquals("Car c8 After Move location", "Westford Interchange 6", c8.getTrackName());
    // do cars have the right loads?
    Assert.assertEquals("Car c1 After Move load should be E", "E", c1.getLoadName());
    Assert.assertEquals("Car c2 After Move load should be L", "L", c2.getLoadName());
    Assert.assertEquals("Car c3 After Move load should be E", "E", c3.getLoadName());
    Assert.assertEquals("Car c4 After Move load should be L", "L", c4.getLoadName());
    Assert.assertEquals("Car c5 After Move load should be E", "E", c5.getLoadName());
    Assert.assertEquals("Car c6 After Move load should be E", "E", c6.getLoadName());
    Assert.assertEquals("Car c7 After Move load should be E", "E", c7.getLoadName());
    Assert.assertEquals("Car c8 After Move load should be E", "E", c8.getLoadName());
    Assert.assertEquals("Car c9 After Move load should be E", "E", c9.getLoadName());
    // are the pickup and drop counts correct?
    Assert.assertEquals("Move 1 Drop count for Westford", 0, loc1.getDropRS());
    Assert.assertEquals("Move 1 Drop count for Westford track Westford Yard 1", 0, loc1trk1.getDropRS());
    Assert.assertEquals("Move 1 Drop count for Westford track Westford Yard 2", 0, loc1trk2.getDropRS());
    Assert.assertEquals("Move 1 Drop count for Westford track Westford Siding 3", 0, loc1trk3.getDropRS());
    Assert.assertEquals("Move 1 Drop count for Westford track Westford Siding 4", 0, loc1trk4.getDropRS());
    Assert.assertEquals("Move 1 Drop count for Westford track Westford Interchange 5", 0, loc1trk5.getDropRS());
    Assert.assertEquals("Move 1 Drop count for Westford track Westford Interchange 6", 0, loc1trk6.getDropRS());
    Assert.assertEquals("Move 1 Drop count for Westford track Westford Interchange 7", 0, loc1trk7.getDropRS());
    Assert.assertEquals("Move 1 Pickup count for Westford", 0, loc1.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for Westford track Westford Yard 1", 0, loc1trk1.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for Westford track Westford Yard 2", 0, loc1trk2.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for Westford track Westford Siding 3", 0, loc1trk3.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for Westford track Westford Siding 4", 0, loc1trk4.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for Westford track Westford Interchange 5", 0, loc1trk5.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for Westford track Westford Interchange 6", 0, loc1trk6.getPickupRS());
    Assert.assertEquals("Move 1 Pickup count for Westford track Westford Interchange 7", 0, loc1trk7.getPickupRS());
    // Verify that an extra move will not change train status.
    train1.move();
    Assert.assertEquals("Train 1 After 2nd Move Status", Train.TERMINATED, getTrainStatus(train1));
    Assert.assertEquals("Train 1 After 2nd Move Status", Train.CODE_TERMINATED, train1.getStatusCode());
    // build the train again, now there are cars on all tracks
    // try and use all 9/10 of the cars
    rl1.setMaxCarMoves(10);
    train1.build();
    // c1, c3, c5, c6, c8 are at interchange tracks and should not be assigned to train1
    Assert.assertEquals("Car c1 After Build 2 should NOT be assigned to Train 1", null, c1.getTrain());
    Assert.assertEquals("Car c2 After Build 2 should be assigned to Train 1", train1, c2.getTrain());
    Assert.assertEquals("Car c3 After Build 2 should NOT be assigned to Train 1", null, c3.getTrain());
    Assert.assertEquals("Car c4 After Build 2 should be assigned to Train 1", train1, c4.getTrain());
    Assert.assertEquals("Car c5 After Build 2 should NOT be assigned to Train 1", null, c5.getTrain());
    Assert.assertEquals("Car c6 After Build 2 should NOT be assigned to Train 1", null, c6.getTrain());
    Assert.assertEquals("Car c7 After Build 2 should be assigned to Train 1", train1, c7.getTrain());
    Assert.assertEquals("Car c8 After Build 2 should NOT be assigned to Train 1", null, c8.getTrain());
    Assert.assertEquals("Car c9 After Build 2 should be assigned to Train 1", train1, c9.getTrain());
    // now check to see if cars are going to be delivered to the right places?
    Assert.assertEquals("Car c2 After Build 2 destination", "Westford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("Car c4 After Build 2 destination", "Westford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("Car c7 After Build 2 destination", "Westford Interchange 6", c7.getDestinationTrackName());
    Assert.assertEquals("Car c9 After Build 2 destination", "Westford Yard 2", c9.getDestinationTrackName());
    // move and terminate
    train1.move();
    Assert.assertEquals("Train 1 After 2nd build Status", Train.TERMINATED, getTrainStatus(train1));
    Assert.assertEquals("Train 1 After 2nd build Status", Train.CODE_TERMINATED, train1.getStatusCode());
    // are cars at the right location?
    Assert.assertEquals("Car c2 After Move 2 location", "Westford Yard 1", c2.getTrackName());
    Assert.assertEquals("Car c4 After Move 2 location", "Westford Yard 1", c4.getTrackName());
    Assert.assertEquals("Car c7 After Move 2 location", "Westford Interchange 6", c7.getTrackName());
    Assert.assertEquals("Car c9 After Move 2 location", "Westford Yard 2", c9.getTrackName());
    // do cars have the right loads?
    Assert.assertEquals("Car c1 After Move 2 load should be E", "E", c1.getLoadName());
    Assert.assertEquals("Car c2 After Move 2 load should be L", "L", c2.getLoadName());
    Assert.assertEquals("Car c3 After Move 2 load should be E", "E", c3.getLoadName());
    Assert.assertEquals("Car c4 After Move 2 load should be L", "L", c4.getLoadName());
    Assert.assertEquals("Car c5 After Move 2 load should be E", "E", c5.getLoadName());
    Assert.assertEquals("Car c6 After Move 2 load should be E", "E", c6.getLoadName());
    Assert.assertEquals("Car c7 After Move 2 load should be E", "E", c7.getLoadName());
    Assert.assertEquals("Car c8 After Move 2 load should be E", "E", c8.getLoadName());
    Assert.assertEquals("Car c9 After Move 2 load should be E", "E", c9.getLoadName());
    // try a new route, this should allow cars to move from interchange
    // Create route with only one location
    Route rte2;
    rte2 = rmanager.newRoute("Local Route 2");
    RouteLocation rl2 = rte2.addLocation(loc1);
    // move 8 of the 9 cars available
    rl2.setMaxCarMoves(8);
    // and assign the new route to train 1
    train1.setRoute(rte2);
    train1.build();
    // we should be able to pickup cars at the interchange tracks
    Assert.assertEquals("Car c1 After Build 3 should be assigned to Train 1", train1, c1.getTrain());
    Assert.assertEquals("Car c2 After Build 3 should be assigned to Train 1", train1, c2.getTrain());
    Assert.assertEquals("Car c3 After Build 3 should be assigned to Train 1", train1, c3.getTrain());
    Assert.assertEquals("Car c4 After Build 3 should be assigned to Train 1", train1, c4.getTrain());
    Assert.assertEquals("Car c5 After Build 3 should be assigned to Train 1", train1, c5.getTrain());
    Assert.assertEquals("Car c6 After Build 3 should be assigned to Train 1", train1, c6.getTrain());
    Assert.assertEquals("Car c7 After Build 3 should be assigned to Train 1", train1, c7.getTrain());
    Assert.assertEquals("Car c8 After Build 3 should be assigned to Train 1", train1, c8.getTrain());
    Assert.assertEquals("Car c9 After Build 3 should NOT be assigned to Train 1", null, c9.getTrain());
    // now check to see if cars are going to be delivered to the right places?
    Assert.assertEquals("Car c1 After Build 3 destination", "Westford Yard 1", c1.getDestinationTrackName());
    Assert.assertEquals("Car c2 After Build 3 destination", "Westford Siding 3", c2.getDestinationTrackName());
    Assert.assertEquals("Car c3 After Build 3 destination", "Westford Yard 1", c3.getDestinationTrackName());
    Assert.assertEquals("Car c4 After Build 3 destination", "Westford Interchange 7", c4.getDestinationTrackName());
    Assert.assertEquals("Car c5 After Build 3 destination", "Westford Yard 2", c5.getDestinationTrackName());
    Assert.assertEquals("Car c6 After Build 3 destination", "Westford Yard 2", c6.getDestinationTrackName());
    Assert.assertEquals("Car c7 After Build 3 destination", "Westford Yard 2", c7.getDestinationTrackName());
    Assert.assertEquals("Car c8 After Build 3 destination", "Westford Yard 1", c8.getDestinationTrackName());
    // move and terminate
    train1.move();
    Assert.assertEquals("Train 1 After 2nd build Status", Train.TERMINATED, getTrainStatus(train1));
    Assert.assertEquals("Train 1 After 2nd build Status", Train.CODE_TERMINATED, train1.getStatusCode());
    // Final check to see if cars were delivered.
    Assert.assertEquals("Car c1 After Move 3 location", "Westford Yard 1", c1.getTrackName());
    Assert.assertEquals("Car c2 After Move 3 location", "Westford Siding 3", c2.getTrackName());
    Assert.assertEquals("Car c3 After Move 3 location", "Westford Yard 1", c3.getTrackName());
    Assert.assertEquals("Car c4 After Move 3 location", "Westford Interchange 7", c4.getTrackName());
    Assert.assertEquals("Car c5 After Move 3 location", "Westford Yard 2", c5.getTrackName());
    Assert.assertEquals("Car c6 After Move 3 location", "Westford Yard 2", c6.getTrackName());
    Assert.assertEquals("Car c7 After Move 3 location", "Westford Yard 2", c7.getTrackName());
    Assert.assertEquals("Car c8 After Move 3 location", "Westford Yard 1", c8.getTrackName());
    // do cars have the right loads?
    Assert.assertEquals("Car c1 After Move 3 load should be E", "E", c1.getLoadName());
    Assert.assertEquals("Car c2 After Move 3 load should be E", "E", c2.getLoadName());
    Assert.assertEquals("Car c3 After Move 3 load should be E", "E", c3.getLoadName());
    Assert.assertEquals("Car c4 After Move 3 load should be L", "L", c4.getLoadName());
    Assert.assertEquals("Car c5 After Move 3 load should be E", "E", c5.getLoadName());
    Assert.assertEquals("Car c6 After Move 3 load should be E", "E", c6.getLoadName());
    Assert.assertEquals("Car c7 After Move 3 load should be E", "E", c7.getLoadName());
    Assert.assertEquals("Car c8 After Move 3 load should be E", "E", c8.getLoadName());
    Assert.assertEquals("Car c9 After Move 3 load should be E", "E", c9.getLoadName());
    // check car move counts
    Assert.assertEquals("Car c1 Move count", 19, c1.getMoves());
    Assert.assertEquals("Car c2 Move count", 18, c2.getMoves());
    Assert.assertEquals("Car c3 Move count", 2, c3.getMoves());
    Assert.assertEquals("Car c4 Move count", 9, c4.getMoves());
    Assert.assertEquals("Car c5 Move count", 3, c5.getMoves());
    Assert.assertEquals("Car c6 Move count", 5, c6.getMoves());
    Assert.assertEquals("Car c7 Move count", 20, c7.getMoves());
    Assert.assertEquals("Car c8 Move count", 4, c8.getMoves());
    Assert.assertEquals("Car c9 Move count", 20, c9.getMoves());
    // now try and use a train with more than one location
    // Create route with two locations
    Route rte3;
    rte3 = rmanager.newRoute("Westford to Chelmsford");
    RouteLocation rl3 = rte3.addLocation(loc1);
    rl3.setTrainDirection(RouteLocation.WEST);
    rl3.setMaxCarMoves(10);
    RouteLocation rl4 = rte3.addLocation(loc2);
    rl4.setTrainDirection(RouteLocation.WEST);
    // and assign the new route to train 1
    train1.setRoute(rte3);
    rl4.setMaxCarMoves(10);
    // set the train icon coordinates
    rl4.setTrainIconX(175);
    rl4.setTrainIconY(50);
    train1.build();
    // should not pick up cars at Westford Siding 3, Westford Siding 4, Westford Interchange 5
    // and Westford Interchange 7
    Assert.assertEquals("Car c1 After Build 4 should be assigned to Train 1", train1, c1.getTrain());
    Assert.assertEquals("Car c2 After Build 4 should NOT be assigned to Train 1", null, c2.getTrain());
    Assert.assertEquals("Car c3 After Build 4 should be assigned to Train 1", train1, c3.getTrain());
    Assert.assertEquals("Car c4 After Build 4 should NOT be assigned to Train 1", null, c4.getTrain());
    Assert.assertEquals("Car c5 After Build 4 should be assigned to Train 1", train1, c5.getTrain());
    Assert.assertEquals("Car c6 After Build 4 should be assigned to Train 1", train1, c6.getTrain());
    Assert.assertEquals("Car c7 After Build 4 should be assigned to Train 1", train1, c7.getTrain());
    Assert.assertEquals("Car c8 After Build 4 should be assigned to Train 1", train1, c8.getTrain());
    Assert.assertEquals("Car c9 After Build 4 should be assigned to Train 1", train1, c9.getTrain());
    train1.move();
    // Train in route since there's two locations
    Assert.assertEquals("Train 1 in route to Chelmsford", true, train1.isTrainEnRoute());
    Assert.assertEquals("Train 1 in route to Chelmsford", Train.CODE_TRAIN_EN_ROUTE, train1.getStatusCode());
    train1.move();
    // 7 cars should in Chelmsford, the other 2 in Westford
    Assert.assertEquals("Car c1 After Move 4 location", "Chelmsford Yard 1", c1.getTrackName());
    Assert.assertEquals("Car c2 verify location", "Westford Siding 3", c2.getTrackName());
    Assert.assertEquals("Car c3 After Move 4 location", "Chelmsford Yard 1", c3.getTrackName());
    Assert.assertEquals("Car c4 verify location", "Westford Interchange 7", c4.getTrackName());
    Assert.assertEquals("Car c5 After Move 4 location", "Chelmsford Yard 1", c5.getTrackName());
    Assert.assertEquals("Car c6 After Move 4 location", "Chelmsford Yard 1", c6.getTrackName());
    Assert.assertEquals("Car c7 After Move 4 location", "Chelmsford Yard 1", c7.getTrackName());
    Assert.assertEquals("Car c8 After Move 4 location", "Chelmsford Yard 1", c8.getTrackName());
    Assert.assertEquals("Car c9 After Move 4 location", "Chelmsford Yard 1", c9.getTrackName());
    // do cars have the right loads?
    Assert.assertEquals("Car c1 After Move 4 load should be E", "E", c1.getLoadName());
    Assert.assertEquals("Car c2 After Move 4 load should be E", "E", c2.getLoadName());
    Assert.assertEquals("Car c3 After Move 4 load should be E", "E", c3.getLoadName());
    Assert.assertEquals("Car c4 After Move 4 load should be L", "L", c4.getLoadName());
    Assert.assertEquals("Car c5 After Move 4 load should be E", "E", c5.getLoadName());
    Assert.assertEquals("Car c6 After Move 4 load should be E", "E", c6.getLoadName());
    Assert.assertEquals("Car c7 After Move 4 load should be E", "E", c7.getLoadName());
    Assert.assertEquals("Car c8 After Move 4 load should be E", "E", c8.getLoadName());
    Assert.assertEquals("Car c9 After Move 4 load should be E", "E", c9.getLoadName());
    // check car move counts
    Assert.assertEquals("Car c1 Move count", 20, c1.getMoves());
    Assert.assertEquals("Car c2 Move count", 18, c2.getMoves());
    Assert.assertEquals("Car c3 Move count", 3, c3.getMoves());
    Assert.assertEquals("Car c4 Move count", 9, c4.getMoves());
    Assert.assertEquals("Car c5 Move count", 4, c5.getMoves());
    Assert.assertEquals("Car c6 Move count", 6, c6.getMoves());
    Assert.assertEquals("Car c7 Move count", 21, c7.getMoves());
    Assert.assertEquals("Car c8 Move count", 5, c8.getMoves());
    Assert.assertEquals("Car c9 Move count", 21, c9.getMoves());
    train1.move();
    Assert.assertEquals("Train 1 After 4th build Status", Train.TERMINATED, getTrainStatus(train1));
    Assert.assertEquals("Train 1 After 4th build Status", Train.CODE_TERMINATED, train1.getStatusCode());
    // test siding to siding
    train1.setRoute(rte1);
    // bias track selection to sidings
    loc1trk3.setMoves(2);
    loc1trk4.setMoves(2);
    train1.build();
    Assert.assertTrue("local testing siding to siding", train1.isBuilt());
    Assert.assertEquals("car UP 4 at interchange, destination Westford Siding 3", loc1trk3, c4.getDestinationTrack());
    Assert.assertEquals("car CP 2 at siding, destination Westford Yard 1", loc1trk1, c2.getDestinationTrack());
    // bias track selection to interchanges
    loc1trk3.setMoves(12);
    loc1trk4.setMoves(12);
    loc1trk5.setMoves(2);
    loc1trk6.setMoves(2);
    train1.build();
    Assert.assertTrue("local testing siding to siding", train1.isBuilt());
    Assert.assertEquals("car UP 4 at interchange, destination", "Westford Yard 2", c4.getDestinationTrackName());
    Assert.assertEquals("car CP 2 at siding, destination", "Westford Interchange 5", c2.getDestinationTrackName());
    // set CP 2 destination, currently at Westford, Westford Siding 3
    // release CP2 from train so we can set the car's destination
    train1.reset();
    c2.setDestination(loc1, null);
    // bias to same track
    loc1trk3.setMoves(1);
    train1.build();
    Assert.assertTrue("local testing siding to siding", train1.isBuilt());
    Assert.assertEquals("car UP 4 at interchange, destination", "Westford Siding 3", c4.getDestinationTrackName());
    Assert.assertEquals("car CP 2 at siding, destination", "Westford Interchange 6", c2.getDestinationTrackName());
    // CP 2 is at Westford Siding 3, set destination to be the same
    train1.reset();
    c2.setDestination(loc1, loc1trk3);
    train1.build();
    Assert.assertTrue("local testing siding to siding", train1.isBuilt());
    Assert.assertEquals("car UP 4 at interchange, destination", "Westford Siding 3", c4.getDestinationTrackName());
    Assert.assertEquals("car CP 2 at siding, destination", "Westford Siding 3", c2.getDestinationTrackName());
    train1.move();
    Assert.assertEquals("Train 1 terminated", Train.TERMINATED, getTrainStatus(train1));
    Assert.assertEquals("Train 1 terminated", Train.CODE_TERMINATED, train1.getStatusCode());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) 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 40 with LocationManager

use of jmri.jmrit.operations.locations.LocationManager in project JMRI by JMRI.

the class TrainTest method testStagingtoStaging.

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

Aggregations

LocationManager (jmri.jmrit.operations.locations.LocationManager)45 Location (jmri.jmrit.operations.locations.Location)43 Track (jmri.jmrit.operations.locations.Track)33 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)28 Route (jmri.jmrit.operations.routes.Route)23 RouteManager (jmri.jmrit.operations.routes.RouteManager)21 Car (jmri.jmrit.operations.rollingstock.cars.Car)18 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)18 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)13 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)13 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)10 Train (jmri.jmrit.operations.trains.Train)9 TrainManager (jmri.jmrit.operations.trains.TrainManager)9 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)7 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)7 ScheduleManager (jmri.jmrit.operations.locations.schedules.ScheduleManager)7 Test (org.junit.Test)7 CarRoads (jmri.jmrit.operations.rollingstock.cars.CarRoads)6 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)6