Search in sources :

Example 6 with CarRoads

use of jmri.jmrit.operations.rollingstock.cars.CarRoads 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 7 with CarRoads

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

the class TrainBuilderTest method testInterchange.

public void testInterchange() {
    Setup.setMaxTrainLength(500);
    ct.addName("Gon");
    ct.addName("Coil Car");
    ct.addName("Flat Car");
    ct.addName("XCaboose");
    ct.addName("Boxcar");
    // confirm no locations
    Assert.assertEquals("number of locations", 0, lmanager.getNumberOfLocations());
    // Create locations used
    Location loc1;
    loc1 = lmanager.newLocation("Old Westford");
    loc1.setTrainDirections(DIRECTION_ALL);
    Location loc2;
    loc2 = lmanager.newLocation("Old Chelmsford");
    loc2.setTrainDirections(DIRECTION_ALL);
    Location loc3;
    loc3 = lmanager.newLocation("Old Bedford");
    loc3.setTrainDirections(DIRECTION_ALL);
    Track loc1trk1;
    loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
    loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk1.setLength(900);
    Track loc1trk2;
    loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
    loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk2.setLength(500);
    loc1trk2.deleteTypeName("Coil Car");
    loc1trk2.deleteTypeName("XCaboose");
    Track loc2trk1;
    loc2trk1 = loc2.addTrack("Chelmsford Interchange 1", Track.INTERCHANGE);
    loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk1.setLength(900);
    loc2trk1.deleteTypeName("Coil Car");
    loc2trk1.deleteTypeName("XCaboose");
    Track loc2trk2;
    loc2trk2 = loc2.addTrack("Chelmsford Interchange 2", Track.INTERCHANGE);
    loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk2.setLength(900);
    loc2trk2.deleteTypeName("XCaboose");
    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");
    loc2trk3.deleteTypeName("XCaboose");
    Track loc2trk4;
    loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
    loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk4.setLength(900);
    loc2trk4.deleteTypeName("Gon");
    loc2trk4.deleteTypeName("XCaboose");
    // bias interchange tracks
    loc2trk3.setMoves(20);
    loc2trk4.setMoves(20);
    Track loc3trk1;
    loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.YARD);
    loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc3trk1.setLength(900);
    // Create route with 3 location
    Route rte1;
    rte1 = rmanager.newRoute("Route 1 East");
    RouteLocation r1l1 = rte1.addLocation(loc1);
    r1l1.setTrainDirection(RouteLocation.EAST);
    r1l1.setMaxCarMoves(4);
    // set the train icon coordinates
    r1l1.setTrainIconX(125);
    r1l1.setTrainIconY(100);
    RouteLocation r1l2 = rte1.addLocation(loc2);
    r1l2.setTrainDirection(RouteLocation.EAST);
    r1l2.setMaxCarMoves(3);
    // set the train icon coordinates
    r1l2.setTrainIconX(25);
    r1l2.setTrainIconY(125);
    RouteLocation r1l3 = rte1.addLocation(loc3);
    r1l3.setTrainDirection(RouteLocation.EAST);
    r1l3.setMaxCarMoves(3);
    // set the train icon coordinates
    r1l3.setTrainIconX(75);
    r1l3.setTrainIconY(125);
    // Create route with 3 location
    Route rte2;
    rte2 = rmanager.newRoute("Route 2 East");
    RouteLocation r2l1 = rte2.addLocation(loc1);
    r2l1.setTrainDirection(RouteLocation.EAST);
    r2l1.setMaxCarMoves(2);
    // set the train icon coordinates
    r2l1.setTrainIconX(125);
    r2l1.setTrainIconY(125);
    RouteLocation r2l2 = rte2.addLocation(loc2);
    r2l2.setTrainDirection(RouteLocation.EAST);
    r2l2.setMaxCarMoves(6);
    // set the train icon coordinates
    r2l2.setTrainIconX(175);
    r2l2.setTrainIconY(125);
    RouteLocation r2l3 = rte2.addLocation(loc3);
    r2l3.setTrainDirection(RouteLocation.EAST);
    r2l3.setMaxCarMoves(6);
    // set the train icon coordinates
    r2l3.setTrainIconX(25);
    r2l3.setTrainIconY(150);
    // Create trains
    Train train1;
    train1 = tmanager.newTrain("T1OWOB");
    train1.setRoute(rte1);
    Train train2;
    train2 = tmanager.newTrain("T2OWOB");
    train2.setRoute(rte1);
    Train train3;
    train3 = tmanager.newTrain("T3OWOB");
    train3.setRoute(rte1);
    // Set up 7 box cars and 2 flat cars
    Car c1 = new Car("BM", "Q1");
    c1.setTypeName("Gon");
    c1.setLength("100");
    c1.setMoves(100);
    c1.setLoadName("L");
    c1.setWeightTons("10");
    cmanager.register(c1);
    Car c2 = new Car("UP", "Q2");
    c2.setTypeName("Boxcar");
    c2.setLength("80");
    c2.setMoves(90);
    c2.setWeightTons("20");
    cmanager.register(c2);
    Car c3 = new Car("XP", "Q3");
    c3.setTypeName("Flat Car");
    c3.setLength("70");
    c3.setMoves(70);
    c3.setWeightTons("30");
    cmanager.register(c3);
    Car c4 = new Car("PU", "Q4");
    c4.setTypeName("Boxcar");
    c4.setLength("60");
    c4.setMoves(60);
    c4.setWeightTons("40");
    cmanager.register(c4);
    Car c5 = new Car("UP", "Q5");
    c5.setTypeName("Gon");
    c5.setLength("50");
    c5.setMoves(50);
    c5.setLoadName("L");
    c5.setWeightTons("50");
    cmanager.register(c5);
    Car c6 = new Car("CP", "Q6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(40);
    c6.setLoadName("L");
    c6.setWeightTons("60");
    cmanager.register(c6);
    Car c7 = new Car("UP", "Q7");
    c7.setTypeName("Boxcar");
    c7.setLength("50");
    c7.setMoves(30);
    c7.setWeightTons("70");
    cmanager.register(c7);
    Car c8 = new Car("XP", "Q8");
    c8.setTypeName("Gon");
    c8.setLength("60");
    c8.setMoves(20);
    c8.setWeightTons("80");
    cmanager.register(c8);
    Car c9 = new Car("XP", "Q9");
    c9.setTypeName("Flat Car");
    c9.setLength("90");
    c9.setMoves(10);
    c9.setLoadName("L");
    c9.setWeightTons("90");
    cmanager.register(c9);
    Car c10 = new Car("CP", "Q10");
    c10.setTypeName("Coil Car");
    c10.setLength("40");
    c10.setMoves(8);
    c10.setLoadName("L");
    c10.setWeightTons("100");
    cmanager.register(c10);
    Car c11 = new Car("CP", "Q11");
    c11.setTypeName("Coil Car");
    c11.setLength("40");
    c11.setMoves(9);
    c11.setLoadName("Coils");
    c11.setWeightTons("110");
    cmanager.register(c11);
    Car c12 = new Car("CP", "Q12");
    c12.setTypeName("Coil Car");
    c12.setLength("40");
    c12.setMoves(10);
    c12.setWeightTons("120");
    cmanager.register(c12);
    Car c13 = new Car("CP", "Q13");
    c13.setTypeName("XCaboose");
    c13.setCaboose(true);
    c13.setLength("40");
    c13.setMoves(7);
    c13.setWeightTons("130");
    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, loc1trk1));
    train1.reset();
    new TrainBuilder().build(train1);
    train2.reset();
    new TrainBuilder().build(train2);
    // now check to where cars are going to be delivered
    Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination", "", c4.getDestinationTrackName());
    Assert.assertEquals("c9 destination", "Chelmsford Interchange 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination", "Bedford Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination", "Chelmsford Interchange 2", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination", "Bedford Yard 1", c12.getDestinationTrackName());
    Assert.assertEquals("c5 destination", "Chelmsford Interchange 2", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination", "Bedford Yard 1", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination", "Chelmsford Interchange 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination", "Bedford Yard 1", c8.getDestinationTrackName());
    // now check which trains
    Assert.assertEquals("c9 train", train1, c9.getTrain());
    Assert.assertEquals("c10 train", train1, c10.getTrain());
    Assert.assertEquals("c11 train", train1, c11.getTrain());
    Assert.assertEquals("c12 train", train1, c12.getTrain());
    Assert.assertEquals("c5 train", train2, c5.getTrain());
    Assert.assertEquals("c6 train", train2, c6.getTrain());
    Assert.assertEquals("c7 train", train2, c7.getTrain());
    Assert.assertEquals("c8 train", train2, c8.getTrain());
    // try restricting interchange 1 to train1 and interchange 2 to train2
    loc2trk1.setDropOption(Track.TRAINS);
    loc2trk1.addDropId(train1.getId());
    loc2trk2.setDropOption(Track.TRAINS);
    loc2trk2.addDropId(train2.getId());
    train1.reset();
    new TrainBuilder().build(train1);
    train2.reset();
    new TrainBuilder().build(train2);
    // now check to where cars are going to be delivered
    Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination", "", c4.getDestinationTrackName());
    Assert.assertEquals("c9 destination 2", "Chelmsford Interchange 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 2", "Bedford Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 2", "Bedford Yard 1", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination 2", "Chelmsford Freight 4", c12.getDestinationTrackName());
    Assert.assertEquals("c5 destination 2", "Chelmsford Interchange 2", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 2", "Bedford Yard 1", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 2", "Chelmsford Interchange 2", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 2", "Bedford Yard 1", c8.getDestinationTrackName());
    // now check which trains
    Assert.assertEquals("c9 train", train1, c9.getTrain());
    Assert.assertEquals("c10 train", train1, c10.getTrain());
    Assert.assertEquals("c11 train", train1, c11.getTrain());
    Assert.assertEquals("c12 train", train1, c12.getTrain());
    Assert.assertEquals("c5 train", train2, c5.getTrain());
    Assert.assertEquals("c6 train", train2, c6.getTrain());
    Assert.assertEquals("c7 train", train2, c7.getTrain());
    Assert.assertEquals("c8 train", train2, c8.getTrain());
    // move and terminate
    Assert.assertEquals("Check train 1 departure location name", "Old Westford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 departure location", r1l1, train1.getCurrentLocation());
    // #1
    train1.move();
    Assert.assertEquals("Check train 1 location name", "Old Chelmsford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", r1l2, train1.getCurrentLocation());
    // #2
    train1.move();
    Assert.assertEquals("Check train 1 location name", "Old Bedford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", r1l3, train1.getCurrentLocation());
    // #3 terminate
    train1.move();
    Assert.assertEquals("Check train 1 location name", "", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", null, train1.getCurrentLocation());
    Assert.assertEquals("Check train 2 departure location name", "Old Westford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 departure location", r1l1, train2.getCurrentLocation());
    // #1
    train2.move();
    Assert.assertEquals("Check train 2 location name", "Old Chelmsford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", r1l2, train2.getCurrentLocation());
    // #2
    train2.move();
    Assert.assertEquals("Check train 2 location name", "Old Bedford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", r1l3, train2.getCurrentLocation());
    // #3 terminate
    train2.move();
    Assert.assertEquals("Check train 2 location name", "", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", null, train2.getCurrentLocation());
    r1l1.setMaxCarMoves(2);
    r1l2.setMaxCarMoves(6);
    r1l3.setMaxCarMoves(6);
    train3.reset();
    // note that train3 uses rte1, should not pickup cars at interchange
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 3", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 3", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 3", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 3", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 3", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 3", "", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 3", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 3", "", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 3", "Bedford Yard 1", c12.getDestinationTrackName());
    // Change the route to 2, should be able to pickup c4, c7, c9
    train3.reset();
    train3.setRoute(rte2);
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 4", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 4", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 4", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 4", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 4", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 4", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 4", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 4", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 4", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 4", "Bedford Yard 1", c12.getDestinationTrackName());
    // Change back to route to 1, should be able to pickup c4, c7
    train3.reset();
    train3.setRoute(rte1);
    loc2trk2.setPickupOption(Track.TRAINS);
    loc2trk2.addPickupId(train3.getId());
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 5", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 5", "Chelmsford Freight 4", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 5", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 5", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 5", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 5", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 5", "", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 5", "Bedford Yard 1", c12.getDestinationTrackName());
    // Change back to route to 1, should be able to pickup c4, c7, and c9
    train3.reset();
    train3.setRoute(rte1);
    loc2trk1.setPickupOption(Track.ROUTES);
    loc2trk1.addPickupId(rte1.getId());
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 6", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 6", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 6", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 6", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 6", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 6", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 6", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 6", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 6", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 6", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 6", "", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination 6", "Bedford Yard 1", c12.getDestinationTrackName());
    // now allow train 3 to drop
    train3.reset();
    loc2trk1.setDropOption(Track.ROUTES);
    loc2trk1.addDropId(rte1.getId());
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 7", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 7", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 7", "Chelmsford Interchange 1", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 7", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 7", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 7", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 7", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 7", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 7", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 7", "Bedford Yard 1", c12.getDestinationTrackName());
    // move and terminate
    train3.move();
    train3.move();
    train3.move();
    train3.move();
    // check tracks
    Assert.assertEquals("c1 track", "Westford Yard 1", c1.getTrackName());
    Assert.assertEquals("c2 track", "Westford Yard 1", c2.getTrackName());
    Assert.assertEquals("c3 track", "Chelmsford Interchange 1", c3.getTrackName());
    Assert.assertEquals("c4 track", "Bedford Yard 1", c4.getTrackName());
    Assert.assertEquals("c5 track", "Bedford Yard 1", c5.getTrackName());
    Assert.assertEquals("c6 track", "Bedford Yard 1", c6.getTrackName());
    Assert.assertEquals("c7 track", "Bedford Yard 1", c7.getTrackName());
    Assert.assertEquals("c8 track", "Bedford Yard 1", c8.getTrackName());
    Assert.assertEquals("c9 track", "Bedford Yard 1", c9.getTrackName());
    Assert.assertEquals("c10 track", "Bedford Yard 1", c10.getTrackName());
    Assert.assertEquals("c11 track", "Bedford Yard 1", c11.getTrackName());
    Assert.assertEquals("c12 track", "Bedford Yard 1", c12.getTrackName());
    // check train length and tonnage
    Assert.assertEquals("Depart Westford length", 138, r1l1.getTrainLength());
    Assert.assertEquals("Depart Old Chelmsford length", 310, r1l2.getTrainLength());
    // In train 2 cars, c3 E and c4 E car weight 20/3 + 50/3 = 23
    Assert.assertEquals("Depart Old Westford tonnage", 23, r1l1.getTrainWeight());
    // In train 5 cars, c4 E, c5 L, c7 E, c9 L, c12 L = 40/3 + 50 + 70/3 + 90 + 120 = 296
    Assert.assertEquals("Depart Old Chelmsford tonnage", 296, r1l2.getTrainWeight());
    // test route pickup and drop controls
    train3.setRequirements(Train.CABOOSE);
    r1l1.setPickUpAllowed(false);
    train3.reset();
    // c1, c2, and c13 at start of train's route
    // c3 at Old Chelmsford, second stop
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 8", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 8", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 8", "Bedford Yard 1", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 8", "Bedford Yard 1", c13.getDestinationTrackName());
    r1l1.setPickUpAllowed(true);
    r1l2.setPickUpAllowed(false);
    train3.reset();
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 9", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 9", "Chelmsford Interchange 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 9", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 9", "Bedford Yard 1", c13.getDestinationTrackName());
    r1l2.setPickUpAllowed(true);
    // Old Chelmsford
    r1l2.setDropAllowed(false);
    train3.reset();
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 10", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 10", "Bedford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 10", "Bedford Yard 1", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 10", "Bedford Yard 1", c13.getDestinationTrackName());
    // try forcing c2 to Chelmsford
    train3.reset();
    c2.setDestination(loc2, null);
    new TrainBuilder().build(train3);
    Assert.assertEquals("c2 destination Old Chelmsford", "", c2.getDestinationTrackName());
    // confirm that c2 isn't part of this train
    Assert.assertNull("c2 isn't assigned to a train", c2.getTrain());
    Assert.assertNull("c2 destination has been set to null", c2.getDestination());
    Assert.assertNull("c2 next destination should be null", c2.getFinalDestination());
    Assert.assertNull("c2 next destination track should be null", c2.getFinalDestinationTrack());
    // try without moves
    train3.reset();
    r1l2.setDropAllowed(true);
    r1l2.setMaxCarMoves(0);
    c2.setDestination(loc2, null);
    new TrainBuilder().build(train3);
    Assert.assertEquals("c2 destination Old Chelmsford, no moves", "", c2.getDestinationTrackName());
    c2.setDestination(null, null);
    r1l2.setMaxCarMoves(6);
    // Should be able to drop off caboose
    r1l3.setDropAllowed(false);
    train3.reset();
    new TrainBuilder().build(train3);
    Assert.assertEquals("c1 destination 11", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 11", "Chelmsford Interchange 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 11", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 11", "Bedford Yard 1", c13.getDestinationTrackName());
    // test to see if FRED also get delivered
    train3.setRequirements(Train.FRED);
    c2.setFred(true);
    train3.reset();
    new TrainBuilder().build(train3);
    Assert.assertTrue("Train 3 built", train3.isBuilt());
    Assert.assertEquals("c1 destination 12", "Chelmsford Interchange 1", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 12", "Bedford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 12", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 12", "", c13.getDestinationTrackName());
    // move and terminate
    train3.move();
    train3.move();
    train3.move();
    train3.move();
    Assert.assertEquals("c1 track 12", "Chelmsford Interchange 1", c1.getTrackName());
    Assert.assertEquals("c2 track 12", "Bedford Yard 1", c2.getTrackName());
    Assert.assertEquals("c3 track 12", "Chelmsford Interchange 1", c3.getTrackName());
    Assert.assertEquals("c13 track 12", "Westford Yard 1", c13.getTrackName());
    // test previous car delivered pickup interchange operation
    loc2trk1.setDropOption(Track.ANY);
    loc2trk1.setPickupOption(Track.TRAINS);
    loc2trk2.setDropOption(Track.ANY);
    loc2trk2.setPickupOption(Track.TRAINS);
    // Place car with FRED back at start of route
    Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c3 at start of route", Track.OKAY, c3.setLocation(loc1, loc1trk2));
    train3.reset();
    new TrainBuilder().build(train3);
    Assert.assertTrue("train 3 should build", train3.isBuilt());
    Assert.assertEquals("car BM Q1 should not be part of train", null, c1.getTrain());
    Assert.assertEquals("car XP Q3 should be part of train", train3, c3.getTrain());
    // put some cars at start of Route
    Assert.assertEquals("Place c1 again", Track.OKAY, c1.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c3 again", Track.OKAY, c3.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c4 again", Track.OKAY, c4.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c6 again", Track.OKAY, c6.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c7 again", Track.OKAY, c7.setLocation(loc2, loc2trk2));
    r1l1.setMaxCarMoves(5);
    loc2trk1.setDropOption(Track.ROUTES);
    loc2trk1.setPickupOption(Track.ROUTES);
    loc2trk2.setDropOption(Track.ROUTES);
    loc2trk2.setPickupOption(Track.ROUTES);
    train3.reset();
    new TrainBuilder().build(train3);
    Assert.assertTrue("train 3 should build", train3.isBuilt());
    Assert.assertEquals("BM Q1 in train", null, c1.getTrain());
    Assert.assertEquals("UP Q2 in train", train3, c2.getTrain());
    Assert.assertEquals("XP Q3 in train", train3, c3.getTrain());
    Assert.assertEquals("PU Q4 in train", train3, c4.getTrain());
    Assert.assertEquals("UP Q5 in train", null, c5.getTrain());
    Assert.assertEquals("CP Q6 in train", null, c6.getTrain());
    Assert.assertEquals("UP Q7 in train", null, c7.getTrain());
    Assert.assertEquals("UP Q2 destination", "Bedford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("XP Q3 destination", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("PU Q4 destination", "Chelmsford Freight 4", c4.getDestinationTrackName());
    Assert.assertEquals("UP Q5 destination", "", c5.getDestinationTrackName());
    // interchange testing done, now test replace car type and road
    Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    // replace should modify locations and trains
    ct.replaceName("Boxcar", "boxcar");
    Assert.assertFalse("loc1 should not accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("loc2 should not accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    Assert.assertFalse("track loc1trk1 should not accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("track loc2trk1 should not accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 1 should not accept Boxcar", train1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 2 should not accept Boxcar", train2.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 3 should not accept Boxcar", train3.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc1 should accept boxcar", loc1.acceptsTypeName("boxcar"));
    Assert.assertTrue("loc2 should accept boxcar", loc2.acceptsTypeName("boxcar"));
    Assert.assertTrue("track loc1trk1 should accept boxcar", loc1trk1.acceptsTypeName("boxcar"));
    Assert.assertTrue("track loc2trk1 should accept boxcar", loc2trk1.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 1 should accept boxcar", train1.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 2 should accept boxcar", train2.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 3 should accept boxcar", train3.acceptsTypeName("boxcar"));
    ct.replaceName("boxcar", "Boxcar");
    Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    Assert.assertTrue("track loc1trk1 should accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("track loc2trk1 should accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 1 should accept Boxcar", train1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 2 should accept Boxcar", train2.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 3 should accept Boxcar", train3.acceptsTypeName("Boxcar"));
    // now test road name replace
    CarRoads cr = CarRoads.instance();
    cr.addName("CP");
    loc1trk1.setRoadOption(Track.INCLUDE_ROADS);
    loc1trk1.addRoadName("CP");
    loc1trk1.addRoadName("PC");
    train1.setRoadOption(Train.INCLUDE_ROADS);
    train1.addRoadName("CP");
    train1.addRoadName("PC");
    train1.setCabooseRoad("CP");
    train1.setEngineRoad("CP");
    Assert.assertTrue("track loc1trk1 should accept road CP", loc1trk1.acceptsRoadName("CP"));
    Assert.assertTrue("track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
    Assert.assertFalse("track loc1trk1 should Not accept road PC", loc1trk1.acceptsRoadName("UP"));
    Assert.assertTrue("Train 1 should accept road CP", train1.acceptsRoadName("CP"));
    Assert.assertTrue("Train 1 should accept road PC", train1.acceptsRoadName("PC"));
    Assert.assertFalse("Train 1 should Not accept road UP", train1.acceptsRoadName("UP"));
    Assert.assertEquals("Caboose road", "CP", train1.getCabooseRoad());
    Assert.assertEquals("Engine road", "CP", train1.getEngineRoad());
    cr.replaceName("CP", "UP");
    Assert.assertFalse("after replace track loc1trk1 should Not accept road CP", loc1trk1.acceptsRoadName("CP"));
    Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
    Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("UP"));
    Assert.assertFalse("after replace Train 1 should Not accept road CP", train1.acceptsRoadName("CP"));
    Assert.assertTrue("after replace Train 1 should accept road PC", train1.acceptsRoadName("PC"));
    Assert.assertTrue("after replace Train 1 should accept road UP", train1.acceptsRoadName("UP"));
    Assert.assertEquals("Caboose road", "UP", train1.getCabooseRoad());
    Assert.assertEquals("Engine road", "UP", train1.getEngineRoad());
}
Also used : CarRoads(jmri.jmrit.operations.rollingstock.cars.CarRoads) Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 8 with CarRoads

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

the class TrainTest method testStagingtoStaging2.

// test train staging to staging
public void testStagingtoStaging2() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    CarManager cmanager = CarManager.instance();
    CarColors cc = CarColors.instance();
    CarLengths cl = CarLengths.instance();
    CarOwners co = CarOwners.instance();
    CarRoads cr = CarRoads.instance();
    CarLoads cld = CarLoads.instance();
    CarTypes ct = CarTypes.instance();
    EngineModels em = EngineModels.instance();
    // Clear out the global lists
    // Clear out the CarColors
    cc.dispose();
    // Clear out the CarLengths
    cl.dispose();
    // Clear out the CarOwners
    co.dispose();
    // Clear out the CarRoads
    cr.dispose();
    // Clear out the CarTypes
    ct.dispose();
    // Clear out the CarLoads
    cld.dispose();
    // Clear out the EngineModels
    em.dispose();
    // register the car colors used
    Assert.assertEquals("Bob Test CarColor Silver false", false, cc.containsName("Silver"));
    Assert.assertEquals("Bob Test CarColor Black false", false, cc.containsName("Black"));
    Assert.assertEquals("Bob Test CarColor Red false", false, cc.containsName("Red"));
    cc.addName("Silver");
    Assert.assertEquals("Bob Test CarColor Silver true", true, cc.containsName("Silver"));
    cc.addName("Black");
    Assert.assertEquals("Bob Test CarColor Black true", true, cc.containsName("Black"));
    cc.addName("Red");
    Assert.assertEquals("Bob Test CarColor Red true", true, cc.containsName("Red"));
    // register the car lengths used
    Assert.assertEquals("Bob Test CarLength 32 false", false, cl.containsName("32"));
    Assert.assertEquals("Bob Test CarLength 38 false", false, cl.containsName("38"));
    Assert.assertEquals("Bob Test CarLength 40 false", false, cl.containsName("40"));
    cl.addName("32");
    Assert.assertEquals("Bob Test CarLength 32 true", true, cl.containsName("32"));
    cl.addName("38");
    Assert.assertEquals("Bob Test CarLength 38 true", true, cl.containsName("38"));
    cl.addName("40");
    Assert.assertEquals("Bob Test CarLength 40 true", true, cl.containsName("40"));
    // register the car owners used
    Assert.assertEquals("Bob Test CarOwner Owner1 false", false, co.containsName("Owner1"));
    Assert.assertEquals("Bob Test CarOwner Owner2 false", false, co.containsName("Owner2"));
    Assert.assertEquals("Bob Test CarOwner Owner3 false", false, co.containsName("Owner3"));
    co.addName("Owner1");
    Assert.assertEquals("Bob Test CarOwner Owner1 true", true, co.containsName("Owner1"));
    co.addName("Owner2");
    Assert.assertEquals("Bob Test CarOwner Owner2 true", true, co.containsName("Owner2"));
    co.addName("Owner3");
    Assert.assertEquals("Bob Test CarOwner Owner3 true", true, co.containsName("Owner3"));
    // register the car roads used
    Assert.assertEquals("Bob Test CarRoads CP false", false, cr.containsName("CP"));
    Assert.assertEquals("Bob Test CarRoads Road2 false", false, cr.containsName("Road2"));
    Assert.assertEquals("Bob Test CarRoads Road3 false", false, cr.containsName("Road3"));
    cr.addName("CP");
    Assert.assertEquals("Bob Test CarRoads CP true", true, cr.containsName("CP"));
    cr.addName("Road2");
    Assert.assertEquals("Bob Test CarRoads Road2 true", true, cr.containsName("Road2"));
    cr.addName("Road3");
    Assert.assertEquals("Bob Test CarRoads Road3 true", true, cr.containsName("Road3"));
    // register the car types used
    Assert.assertEquals("Bob Test CarType Caboose false", false, ct.containsName("Caboose"));
    Assert.assertEquals("Bob Test CarType Tanker false", false, ct.containsName("Tanker"));
    Assert.assertEquals("Bob Test CarType Boxcar false", false, ct.containsName("Boxcar"));
    ct.addName("Caboose");
    Assert.assertEquals("Bob Test CarType Caboose true", true, ct.containsName("Caboose"));
    ct.addName("Tanker");
    Assert.assertEquals("Bob Test CarType Tanker true", true, ct.containsName("Tanker"));
    ct.addName("Boxcar");
    Assert.assertEquals("Bob Test CarType Boxcar true", true, ct.containsName("Boxcar"));
    // register the car loads used
    cld.addType("Boxcar");
    Assert.assertEquals("Bob Test CarLoad Boxcar Flour false", false, cld.containsName("Boxcar", "Flour"));
    Assert.assertEquals("Bob Test CarLoad Boxcar Bags false", false, cld.containsName("Boxcar", "Bags"));
    cld.addName("Boxcar", "Flour");
    Assert.assertEquals("Bob Test CarLoad Boxcar Flour true", true, cld.containsName("Boxcar", "Flour"));
    cld.addName("Boxcar", "Bags");
    Assert.assertEquals("Bob Test CarLoad Boxcar Bags true", true, cld.containsName("Boxcar", "Bags"));
    // register the engine models used
    Assert.assertEquals("Bob Test EngineModel GP40 false", false, em.containsName("GP40"));
    Assert.assertEquals("Bob Test EngineModel GP30 false", false, em.containsName("GP30"));
    em.addName("GP40");
    Assert.assertEquals("Bob Test EngineModel GP40 true", true, em.containsName("GP40"));
    em.addName("GP30");
    Assert.assertEquals("Bob Test EngineModel GP30 true", true, em.containsName("GP30"));
    // Create locations used
    Location loc1;
    loc1 = lmanager.newLocation("Westend");
    loc1.setTrainDirections(Location.WEST + Location.EAST);
    Assert.assertEquals("Bob Test Location Westend Name", "Westend", loc1.getName());
    Assert.assertEquals("Bob Test Location Westend Directions", 3, loc1.getTrainDirections());
    Assert.assertEquals("Bob Test Location Westend Type Diesel", true, loc1.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Location Westend Type Boxcar", true, loc1.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Location Westend Type Caboose", true, loc1.acceptsTypeName("Caboose"));
    Location loc2;
    loc2 = lmanager.newLocation("Midtown");
    loc2.setTrainDirections(Location.WEST + Location.EAST);
    Assert.assertEquals("Bob Test Location Midtown Name", "Midtown", loc2.getName());
    Assert.assertEquals("Bob Test Location Midtown Directions", 3, loc2.getTrainDirections());
    Assert.assertEquals("Bob Test Location Midtown Type Diesel", true, loc2.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Location Midtown Type Boxcar", true, loc2.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Location Midtown Type Caboose", true, loc2.acceptsTypeName("Caboose"));
    Location loc3;
    loc3 = lmanager.newLocation("Eastend");
    loc3.setTrainDirections(Location.WEST + Location.EAST);
    Assert.assertEquals("Bob Test Location Eastend Name", "Eastend", loc3.getName());
    Assert.assertEquals("Bob Test Location Eastend Directions", 3, loc3.getTrainDirections());
    Assert.assertEquals("Bob Test Location Eastend Type Diesel", true, loc3.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Location Eastend Type Boxcar", true, loc3.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Location Eastend Type Caboose", true, loc3.acceptsTypeName("Caboose"));
    Track loc1trk1;
    loc1trk1 = loc1.addTrack("Westend Staging 1", Track.YARD);
    loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk1.setLength(500);
    Assert.assertEquals("Bob Test Track Westend Staging 1 Name", "Westend Staging 1", loc1trk1.getName());
    Assert.assertEquals("Bob Test Track Westend Staging 1 Directions", 3, loc1trk1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Westend Staging 1 Length", 500, loc1trk1.getLength());
    Assert.assertEquals("Bob Test Track Westend Staging 1 Type Diesel", true, loc1trk1.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Track Westend Staging 1 Type Boxcar", true, loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Track Westend Staging 1 Type Caboose", true, loc1trk1.acceptsTypeName("Caboose"));
    Track loc2trk1;
    loc2trk1 = loc2.addTrack("Midtown Inbound from West", Track.YARD);
    loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk1.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown West Inbound Name", "Midtown Inbound from West", loc2trk1.getName());
    Assert.assertEquals("Bob Test Track Midtown West Inbound Directions", 3, loc2trk1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown West Inbound Length", 500, loc2trk1.getLength());
    Track loc2trk2;
    loc2trk2 = loc2.addTrack("Midtown Inbound from East", Track.YARD);
    loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk2.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown East Inbound Name", "Midtown Inbound from East", loc2trk2.getName());
    Assert.assertEquals("Bob Test Track Midtown East Inbound Directions", 3, loc2trk2.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Inbound Length", 500, loc2trk2.getLength());
    Track loc2trk3;
    loc2trk3 = loc2.addTrack("Midtown Outbound to West", Track.YARD);
    loc2trk3.setTrainDirections(Track.WEST);
    loc2trk3.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown West Outbound Name", "Midtown Outbound to West", loc2trk3.getName());
    Assert.assertEquals("Bob Test Track Midtown West Outbound Directions", 2, loc2trk3.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown West Outbound Length", 500, loc2trk3.getLength());
    Track loc2trk4;
    loc2trk4 = loc2.addTrack("Midtown Outbound to East", Track.YARD);
    loc2trk4.setTrainDirections(Track.EAST);
    loc2trk4.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown East Outbound Name", "Midtown Outbound to East", loc2trk4.getName());
    Assert.assertEquals("Bob Test Track Midtown East Outbound Directions", 1, loc2trk4.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Outbound Length", 500, loc2trk4.getLength());
    Track loc2trkc1;
    loc2trkc1 = loc2.addTrack("Midtown Caboose to East", Track.YARD);
    loc2trkc1.setTrainDirections(Track.EAST);
    loc2trkc1.setLength(100);
    Assert.assertEquals("Bob Test Track Midtown East Caboose Name", "Midtown Caboose to East", loc2trkc1.getName());
    Assert.assertEquals("Bob Test Track Midtown East Caboose Directions", 1, loc2trkc1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Caboose Length", 100, loc2trkc1.getLength());
    Track loc2trkc2;
    loc2trkc2 = loc2.addTrack("Midtown Caboose to West", Track.YARD);
    loc2trkc2.setTrainDirections(Track.WEST);
    loc2trkc2.setLength(100);
    Assert.assertEquals("Bob Test Track Midtown West Caboose Name", "Midtown Caboose to West", loc2trkc2.getName());
    Assert.assertEquals("Bob Test Track Midtown West Caboose Directions", 2, loc2trkc2.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown west Caboose Length", 100, loc2trkc2.getLength());
    Track loc2trke1;
    loc2trke1 = loc2.addTrack("Midtown Engine to East", Track.YARD);
    loc2trke1.setTrainDirections(Track.EAST);
    loc2trke1.setLength(200);
    Assert.assertEquals("Bob Test Track Midtown East Engine Name", "Midtown Engine to East", loc2trke1.getName());
    Assert.assertEquals("Bob Test Track Midtown East Engine Directions", 1, loc2trke1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Engine Length", 200, loc2trke1.getLength());
    Track loc2trke2;
    loc2trke2 = loc2.addTrack("Midtown Engine to West", Track.YARD);
    loc2trke2.setTrainDirections(Track.WEST);
    loc2trke2.setLength(200);
    Assert.assertEquals("Bob Test Track Midtown West Engine Name", "Midtown Engine to West", loc2trke2.getName());
    Assert.assertEquals("Bob Test Track Midtown West Engine Directions", 2, loc2trke2.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown west Engine Length", 200, loc2trke2.getLength());
    Track loc3trk1;
    loc3trk1 = loc3.addTrack("Eastend Staging 1", Track.YARD);
    loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc3trk1.setLength(500);
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Name", "Eastend Staging 1", loc3trk1.getName());
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Directions", 3, loc3trk1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Length", 500, loc3trk1.getLength());
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Type Diesel", true, loc3trk1.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Type Boxcar", true, loc3trk1.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Type Caboose", true, loc3trk1.acceptsTypeName("Caboose"));
    Assert.assertEquals("Bob Test Location Westend Length", 500, loc1.getLength());
    Assert.assertEquals("Bob Test Location Midtown Length", 2600, loc2.getLength());
    Assert.assertEquals("Bob Test Location Eastend Length", 500, loc3.getLength());
    // Create engines used
    Engine e1;
    e1 = emanager.newEngine("CP", "5501");
    e1.setModel("GP30");
    e1.setMoves(5);
    Assert.assertEquals("Bob Test Engine CP1801 Type", "Diesel", e1.getTypeName());
    Assert.assertEquals("Bob Test Engine CP1801 Length", "56", e1.getLength());
    Assert.assertEquals("Bob Test Engine CP1801 Hp", "2250", e1.getHp());
    // Test that first "Diesel" is an acceptable type at all locations and tracks
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 1s1", "okay", e1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s1", "okay", e1.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s2", "okay", e1.setLocation(loc2, loc2trk2));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s3", "okay", e1.setLocation(loc2, loc2trk3));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s4", "okay", e1.setLocation(loc2, loc2trk4));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 3s1", "okay", e1.setLocation(loc3, loc3trk1));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s4 for real", "okay", e1.setLocation(loc2, loc2trke1));
    Engine e2;
    e2 = emanager.newEngine("CP", "5888");
    e2.setModel("GP40");
    Assert.assertEquals("Bob Test Engine CP5801 Type", "Diesel", e2.getTypeName());
    Assert.assertEquals("Bob Test Engine CP5801 Length", "59", e2.getLength());
    Assert.assertEquals("Bob Test Engine CP5801 Hp", "3000", e2.getHp());
    Assert.assertEquals("Bob Test Engine CP5801 SetLocation 2s4", "okay", e2.setLocation(loc2, loc2trke2));
    // Create cars used
    Car b1;
    b1 = cmanager.newCar("CP", "81234567");
    b1.setTypeName("Boxcar");
    b1.setLength("40");
    b1.setLoadName("L");
    b1.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234567 Length", "40", b1.getLength());
    Assert.assertEquals("Bob Test Car CP81234567 Load", "L", b1.getLoadName());
    // Test that first "Boxcar" is an acceptable type at all locations and tracks
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 1s1", "okay", b1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s1", "okay", b1.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s2", "okay", b1.setLocation(loc2, loc2trk2));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s3", "okay", b1.setLocation(loc2, loc2trk3));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s4", "okay", b1.setLocation(loc2, loc2trk4));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 3s1", "okay", b1.setLocation(loc3, loc3trk1));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s4 for real", "okay", b1.setLocation(loc2, loc2trk4));
    Car b2;
    b2 = cmanager.newCar("CP", "81234568");
    b2.setTypeName("Boxcar");
    b2.setLength("40");
    // b2.setLoad("E");
    b2.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234568 Length", "40", b2.getLength());
    Assert.assertEquals("Bob Test Car CP81234568 Load", "E", b2.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP81234568 SetLocation 2s4", "okay", b2.setLocation(loc2, loc2trk4));
    Car b3;
    b3 = cmanager.newCar("CP", "81234569");
    b3.setTypeName("Boxcar");
    b3.setLength("40");
    b3.setLoadName("Flour");
    b3.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234569 Length", "40", b3.getLength());
    Assert.assertEquals("Bob Test Car CP81234569 Load", "Flour", b3.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP81234569 SetLocation 2s4", "okay", b3.setLocation(loc2, loc2trk4));
    Car b4;
    b4 = cmanager.newCar("CP", "81234566");
    b4.setTypeName("Boxcar");
    b4.setLength("40");
    b4.setLoadName("Bags");
    b4.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234566 Length", "40", b4.getLength());
    Assert.assertEquals("Bob Test Car CP81234566 Load", "Bags", b4.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP81234566 SetLocation 2s4", "okay", b4.setLocation(loc2, loc2trk4));
    Car b5;
    b5 = cmanager.newCar("CP", "71234567");
    b5.setTypeName("Boxcar");
    b5.setLength("40");
    // b5.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234567 Length", "40", b5.getLength());
    Assert.assertEquals("Bob Test Car CP71234567 Load", "E", b5.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234567 SetLocation 2s4", "okay", b5.setLocation(loc2, loc2trk3));
    Car b6;
    b6 = cmanager.newCar("CP", "71234568");
    b6.setTypeName("Boxcar");
    b6.setLength("40");
    // b6.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234568 Length", "40", b6.getLength());
    Assert.assertEquals("Bob Test Car CP71234568 Load", "E", b6.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234568 SetLocation 2s4", "okay", b6.setLocation(loc2, loc2trk3));
    Car b7;
    b7 = cmanager.newCar("CP", "71234569");
    b7.setTypeName("Boxcar");
    b7.setLength("40");
    // b7.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234569 Length", "40", b7.getLength());
    Assert.assertEquals("Bob Test Car CP71234569 Load", "E", b7.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234569 SetLocation 2s4", "okay", b7.setLocation(loc2, loc2trk3));
    Car b8;
    b8 = cmanager.newCar("CP", "71234566");
    b8.setTypeName("Boxcar");
    b8.setLength("40");
    // b2.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234566 Length", "40", b8.getLength());
    Assert.assertEquals("Bob Test Car CP71234566 Load", "E", b8.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234566 SetLocation 2s4", "okay", b8.setLocation(loc2, loc2trk3));
    // Create cars used
    Car c1;
    c1 = cmanager.newCar("CP", "12345678");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setCaboose(true);
    c1.setMoves(5);
    Assert.assertEquals("Bob Test Caboose CP12345678 Length", "32", c1.getLength());
    Assert.assertEquals("Bob Test Caboose CP12345678 Load", "E", c1.getLoadName());
    // Test that first "Caboose" is an acceptable type at all locations and tracks
    Assert.assertEquals("Bob Test Test Caboose CP12345678 SetLocation 1s1", "okay", c1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Bob Test Test Caboose CP12345678 SetLocation 3s1", "okay", c1.setLocation(loc3, loc3trk1));
    Assert.assertEquals("Bob Test Test Caboose CP12345678 SetLocation 2s5 for real", "okay", c1.setLocation(loc2, loc2trkc1));
    Car c2;
    c2 = cmanager.newCar("CP", "12345679");
    c2.setTypeName("Caboose");
    c2.setLength("32");
    c2.setCaboose(true);
    Assert.assertEquals("Bob Test Caboose CP12345679 Length", "32", c2.getLength());
    Assert.assertEquals("Bob Test Caboose CP12345679 Load", "E", c2.getLoadName());
    Assert.assertEquals("Bob Test Test Caboose CP12345679 SetLocation 2s5 for real", "okay", c2.setLocation(loc2, loc2trkc2));
    Assert.assertEquals("Bob Test Location Westend Used Length", 0, loc1.getUsedLength());
    // 56+4 + 59+4 + 2*(4*(40+4) + 32+4) = 123 + 2*(176 + 36) = 547
    Assert.assertEquals("Bob Test Location Midtown Used Length", 547, loc2.getUsedLength());
    Assert.assertEquals("Bob Test Location Eastend Used Length", 0, loc3.getUsedLength());
    // Create routes used
    Route rte1;
    rte1 = rmanager.newRoute("Midtown to Eastend Through");
    Assert.assertEquals("Bob Test Route rte1 Name", "Midtown to Eastend Through", rte1.getName());
    RouteLocation rte1rln1;
    rte1rln1 = rte1.addLocation(loc2);
    rte1rln1.setTrainDirection(RouteLocation.EAST);
    // set the train icon coordinates
    rte1rln1.setTrainIconX(175);
    rte1rln1.setTrainIconY(25);
    Assert.assertEquals("Bob Test Route Location rte1rln1 Name", "Midtown", rte1rln1.getName());
    Assert.assertEquals("Bob Test Route Location rte1rln1 Seq", 1, rte1rln1.getSequenceId());
    RouteLocation rte1rln2;
    rte1rln2 = rte1.addLocation(loc3);
    rte1rln2.setTrainDirection(RouteLocation.EAST);
    // set the train icon coordinates
    rte1rln2.setTrainIconX(25);
    rte1rln2.setTrainIconY(50);
    Assert.assertEquals("Bob Test Route Location rte1rln2 Name", "Eastend", rte1rln2.getName());
    Assert.assertEquals("Bob Test Route Location rte1rln2 Seq", 2, rte1rln2.getSequenceId());
    Route rte2;
    rte2 = rmanager.newRoute("Midtown to Westend Through");
    Assert.assertEquals("Bob Test Route rte2 Name", "Midtown to Westend Through", rte2.getName());
    RouteLocation rte2rln1;
    rte2rln1 = rte2.addLocation(loc2);
    rte2rln1.setTrainDirection(RouteLocation.WEST);
    // set the train icon coordinates
    rte2rln1.setTrainIconX(75);
    rte2rln1.setTrainIconY(50);
    Assert.assertEquals("Bob Test Route Location rte2rln1 Name", "Midtown", rte2rln1.getName());
    Assert.assertEquals("Bob Test Route Location rte2rln1 Seq", 1, rte2rln1.getSequenceId());
    RouteLocation rte2rln2;
    rte2rln2 = rte2.addLocation(loc1);
    rte2rln2.setTrainDirection(RouteLocation.WEST);
    // set the train icon coordinates
    rte2rln2.setTrainIconX(125);
    rte2rln2.setTrainIconY(50);
    Assert.assertEquals("Bob Test Route Location rte2rln2 Name", "Westend", rte2rln2.getName());
    Assert.assertEquals("Bob Test Route Location rte2rln2 Seq", 2, rte2rln2.getSequenceId());
    // Create trains used
    Train train1;
    train1 = tmanager.newTrain("MET");
    train1.setRoute(rte1);
    train1.setNumberEngines("1");
    train1.setRequirements(Train.CABOOSE);
    // train1.addTypeName("Diesel");
    // train1.addTypeName("Boxcar");
    // train1.addTypeName("Caboose");
    Assert.assertEquals("Bob Test Train train1 Name", "MET", train1.getName());
    Assert.assertEquals("Bob Test Train train1 Departs Name", "Midtown", train1.getTrainDepartsName());
    Assert.assertEquals("Bob Test Train train1 Terminates Name", "Eastend", train1.getTrainTerminatesName());
    Train train2;
    train2 = tmanager.newTrain("MWT");
    train2.setRoute(rte2);
    train2.setNumberEngines("1");
    train2.setRequirements(Train.CABOOSE);
    // train2.addTypeName("Diesel");
    // train2.addTypeName("Boxcar");
    // train2.addTypeName("Caboose");
    Assert.assertEquals("Bob Test Train train2 Name", "MWT", train2.getName());
    Assert.assertEquals("Bob Test Train train2 Departs Name", "Midtown", train2.getTrainDepartsName());
    Assert.assertEquals("Bob Test Train train2 Terminates Name", "Westend", train2.getTrainTerminatesName());
    // Build trains
    train1.build();
    train2.build();
    Assert.assertTrue("Bob test train1 built", train1.isBuilt());
    Assert.assertTrue("Bob test train2 built", train2.isBuilt());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) CarColors(jmri.jmrit.operations.rollingstock.cars.CarColors) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarOwners(jmri.jmrit.operations.rollingstock.cars.CarOwners) CarLengths(jmri.jmrit.operations.rollingstock.cars.CarLengths) EngineModels(jmri.jmrit.operations.rollingstock.engines.EngineModels) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) CarLoads(jmri.jmrit.operations.rollingstock.cars.CarLoads) CarRoads(jmri.jmrit.operations.rollingstock.cars.CarRoads) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) 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 9 with CarRoads

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

the class TrainTest method testInterchange.

public void testInterchange() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    Setup.setMaxTrainLength(500);
    ct.addName("Boxcar");
    ct.addName("Gon");
    ct.addName("Coil Car");
    ct.addName("Flat Car");
    ct.addName("XCaboose");
    // confirm no locations
    Assert.assertEquals("number of locations", 0, lmanager.getNumberOfLocations());
    // Create locations used
    Location loc1;
    loc1 = lmanager.newLocation("Old Westford");
    loc1.setTrainDirections(DIRECTION_ALL);
    Location loc2;
    loc2 = lmanager.newLocation("Old Chelmsford");
    loc2.setTrainDirections(DIRECTION_ALL);
    Location loc3;
    loc3 = lmanager.newLocation("Old Bedford");
    loc3.setTrainDirections(DIRECTION_ALL);
    Track loc1trk1;
    loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
    loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk1.setLength(900);
    Track loc1trk2;
    loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
    loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk2.setLength(500);
    loc1trk2.deleteTypeName("Coil Car");
    loc1trk2.deleteTypeName("XCaboose");
    Track loc2trk1;
    loc2trk1 = loc2.addTrack("Chelmsford Interchange 1", Track.INTERCHANGE);
    loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk1.setLength(900);
    loc2trk1.deleteTypeName("Coil Car");
    loc2trk1.deleteTypeName("XCaboose");
    Track loc2trk2;
    loc2trk2 = loc2.addTrack("Chelmsford Interchange 2", Track.INTERCHANGE);
    loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk2.setLength(900);
    loc2trk2.deleteTypeName("XCaboose");
    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");
    loc2trk3.deleteTypeName("XCaboose");
    Track loc2trk4;
    loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
    loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk4.setLength(900);
    loc2trk4.deleteTypeName("Gon");
    loc2trk4.deleteTypeName("XCaboose");
    // bias interchange tracks
    loc2trk3.setMoves(20);
    loc2trk4.setMoves(20);
    Track loc3trk1;
    loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.YARD);
    loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc3trk1.setLength(900);
    // Create route with 3 location
    Route rte1;
    rte1 = rmanager.newRoute("Route 1 East");
    RouteLocation r1l1 = rte1.addLocation(loc1);
    r1l1.setTrainDirection(RouteLocation.EAST);
    r1l1.setMaxCarMoves(4);
    // set the train icon coordinates
    r1l1.setTrainIconX(125);
    r1l1.setTrainIconY(100);
    RouteLocation r1l2 = rte1.addLocation(loc2);
    r1l2.setTrainDirection(RouteLocation.EAST);
    r1l2.setMaxCarMoves(3);
    // set the train icon coordinates
    r1l2.setTrainIconX(25);
    r1l2.setTrainIconY(125);
    RouteLocation r1l3 = rte1.addLocation(loc3);
    r1l3.setTrainDirection(RouteLocation.EAST);
    r1l3.setMaxCarMoves(3);
    // set the train icon coordinates
    r1l3.setTrainIconX(75);
    r1l3.setTrainIconY(125);
    // Create route with 3 location
    Route rte2;
    rte2 = rmanager.newRoute("Route 2 East");
    RouteLocation r2l1 = rte2.addLocation(loc1);
    r2l1.setTrainDirection(RouteLocation.EAST);
    r2l1.setMaxCarMoves(2);
    // set the train icon coordinates
    r2l1.setTrainIconX(125);
    r2l1.setTrainIconY(125);
    RouteLocation r2l2 = rte2.addLocation(loc2);
    r2l2.setTrainDirection(RouteLocation.EAST);
    r2l2.setMaxCarMoves(6);
    // set the train icon coordinates
    r2l2.setTrainIconX(175);
    r2l2.setTrainIconY(125);
    RouteLocation r2l3 = rte2.addLocation(loc3);
    r2l3.setTrainDirection(RouteLocation.EAST);
    r2l3.setMaxCarMoves(6);
    // set the train icon coordinates
    r2l3.setTrainIconX(25);
    r2l3.setTrainIconY(150);
    // Create trains
    Train train1;
    train1 = tmanager.newTrain("TT1OWOB");
    train1.setRoute(rte1);
    Train train2;
    train2 = tmanager.newTrain("TT2OWOB");
    train2.setRoute(rte1);
    Train train3;
    train3 = tmanager.newTrain("TT3OWOB");
    train3.setRoute(rte1);
    // Set up 7 box cars and 2 flat cars
    Car c1 = new Car("BM", "Q1");
    c1.setTypeName("Gon");
    c1.setLength("90");
    c1.setMoves(20);
    c1.setLoadName("L");
    c1.setWeightTons("10");
    cmanager.register(c1);
    Car c2 = new Car("UP", "Q2");
    c2.setTypeName("Boxcar");
    c2.setLength("80");
    c2.setMoves(18);
    c2.setWeightTons("20");
    cmanager.register(c2);
    Car c3 = new Car("XP", "Q3");
    c3.setTypeName("Flat Car");
    c3.setLength("70");
    c3.setMoves(17);
    c3.setWeightTons("30");
    cmanager.register(c3);
    Car c4 = new Car("PU", "Q4");
    c4.setTypeName("Boxcar");
    c4.setLength("60");
    c4.setMoves(16);
    c4.setWeightTons("40");
    cmanager.register(c4);
    Car c5 = new Car("UP", "Q5");
    c5.setTypeName("Gon");
    c5.setLength("50");
    c5.setMoves(15);
    c5.setLoadName("L");
    c5.setWeightTons("50");
    cmanager.register(c5);
    Car c6 = new Car("CP", "Q6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(14);
    c6.setLoadName("L");
    c6.setWeightTons("60");
    cmanager.register(c6);
    Car c7 = new Car("UP", "Q7");
    c7.setTypeName("Boxcar");
    c7.setLength("50");
    c7.setMoves(13);
    c7.setWeightTons("70");
    cmanager.register(c7);
    Car c8 = new Car("XP", "Q8");
    c8.setTypeName("Gon");
    c8.setLength("60");
    c8.setMoves(12);
    c8.setWeightTons("80");
    cmanager.register(c8);
    Car c9 = new Car("XP", "Q9");
    c9.setTypeName("Flat Car");
    c9.setLength("90");
    c9.setMoves(11);
    c9.setLoadName("L");
    c9.setWeightTons("90");
    cmanager.register(c9);
    Car c10 = new Car("CP", "Q10");
    c10.setTypeName("Coil Car");
    c10.setLength("40");
    c10.setMoves(8);
    c10.setLoadName("L");
    c10.setWeightTons("100");
    cmanager.register(c10);
    Car c11 = new Car("CP", "Q11");
    c11.setTypeName("Coil Car");
    c11.setLength("40");
    c11.setMoves(9);
    c11.setLoadName("Coils");
    c11.setWeightTons("110");
    cmanager.register(c11);
    Car c12 = new Car("CP", "Q12");
    c12.setTypeName("Coil Car");
    c12.setLength("40");
    c12.setMoves(10);
    c12.setWeightTons("120");
    cmanager.register(c12);
    Car c13 = new Car("CP", "Q13");
    c13.setTypeName("XCaboose");
    c13.setCaboose(true);
    c13.setLength("40");
    c13.setMoves(7);
    c13.setWeightTons("130");
    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, loc1trk1));
    train1.build();
    train2.build();
    // now check to where cars are going to be delivered
    Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination", "", c4.getDestinationTrackName());
    Assert.assertEquals("c9 destination", "Chelmsford Interchange 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination", "Bedford Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination", "Chelmsford Interchange 2", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination", "Bedford Yard 1", c12.getDestinationTrackName());
    Assert.assertEquals("c5 destination", "Chelmsford Interchange 2", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination", "Bedford Yard 1", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination", "Chelmsford Interchange 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination", "Bedford Yard 1", c8.getDestinationTrackName());
    // now check which trains
    Assert.assertEquals("c9 train", train1, c9.getTrain());
    Assert.assertEquals("c10 train", train1, c10.getTrain());
    Assert.assertEquals("c11 train", train1, c11.getTrain());
    Assert.assertEquals("c12 train", train1, c12.getTrain());
    Assert.assertEquals("c5 train", train2, c5.getTrain());
    Assert.assertEquals("c6 train", train2, c6.getTrain());
    Assert.assertEquals("c7 train", train2, c7.getTrain());
    Assert.assertEquals("c8 train", train2, c8.getTrain());
    // try restricting interchange 1 to train1 and interchange 2 to train2
    loc2trk1.setDropOption(Track.TRAINS);
    loc2trk1.addDropId(train1.getId());
    loc2trk2.setDropOption(Track.TRAINS);
    loc2trk2.addDropId(train2.getId());
    train1.build();
    train2.build();
    // now check to where cars are going to be delivered
    Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
    Assert.assertEquals("c5 destination", "", c5.getDestinationTrackName());
    Assert.assertEquals("c9 destination 2", "Chelmsford Interchange 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 2", "Bedford Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 2", "Bedford Yard 1", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination 2", "Chelmsford Freight 4", c12.getDestinationTrackName());
    Assert.assertEquals("c4 destination 2", "Chelmsford Interchange 2", c4.getDestinationTrackName());
    Assert.assertEquals("c6 destination 2", "Bedford Yard 1", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 2", "Chelmsford Interchange 2", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 2", "Bedford Yard 1", c8.getDestinationTrackName());
    // now check which trains
    Assert.assertEquals("c9 train", train1, c9.getTrain());
    Assert.assertEquals("c10 train", train1, c10.getTrain());
    Assert.assertEquals("c11 train", train1, c11.getTrain());
    Assert.assertEquals("c12 train", train1, c12.getTrain());
    Assert.assertEquals("c4 train", train2, c4.getTrain());
    Assert.assertEquals("c6 train", train2, c6.getTrain());
    Assert.assertEquals("c7 train", train2, c7.getTrain());
    Assert.assertEquals("c8 train", train2, c8.getTrain());
    // move and terminate
    Assert.assertEquals("Check train 1 departure location name", "Old Westford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 departure location", r1l1, train1.getCurrentLocation());
    // #1
    train1.move();
    Assert.assertEquals("Check train 1 location name", "Old Chelmsford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", r1l2, train1.getCurrentLocation());
    // #2
    train1.move();
    Assert.assertEquals("Check train 1 location name", "Old Bedford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", r1l3, train1.getCurrentLocation());
    // #3 terminate
    train1.move();
    Assert.assertEquals("Check train 1 location name", "", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", null, train1.getCurrentLocation());
    Assert.assertEquals("Check train 2 departure location name", "Old Westford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 departure location", r1l1, train2.getCurrentLocation());
    // #1
    train2.move();
    Assert.assertEquals("Check train 2 location name", "Old Chelmsford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", r1l2, train2.getCurrentLocation());
    // #2
    train2.move();
    Assert.assertEquals("Check train 2 location name", "Old Bedford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", r1l3, train2.getCurrentLocation());
    // #3 terminate
    train2.move();
    Assert.assertEquals("Check train 2 location name", "", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", null, train2.getCurrentLocation());
    r1l1.setMaxCarMoves(2);
    r1l2.setMaxCarMoves(6);
    r1l3.setMaxCarMoves(6);
    // note that train3 uses rte1, should not pickup cars at interchange
    train3.build();
    Assert.assertEquals("c1 destination 3", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 3", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 3", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 3", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 3", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 3", "", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 3", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 3", "", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 3", "Bedford Yard 1", c12.getDestinationTrackName());
    // Change the route to 2, should be able to pickup c4, c7, c9
    train3.reset();
    train3.setRoute(rte2);
    // confirm that c2 and c3 have the same move counts
    Assert.assertEquals("c2 move count", 18, c2.getMoves());
    Assert.assertEquals("c3 move count", 18, c3.getMoves());
    Assert.assertEquals("c4 move count", 17, c4.getMoves());
    // bias c2
    c2.setMoves(19);
    train3.build();
    Assert.assertEquals("c1 destination 4", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 4", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 4", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 4", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 4", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 4", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 4", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 4", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 4", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 4", "Bedford Yard 1", c12.getDestinationTrackName());
    // bias c3
    c3.setMoves(20);
    // Change back to route to 1, should be able to pickup c4, c7
    train3.reset();
    train3.setRoute(rte1);
    loc2trk2.setPickupOption(Track.TRAINS);
    loc2trk2.addPickupId(train3.getId());
    train3.build();
    Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 5", "Chelmsford Freight 4", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 5", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 5", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 5", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 5", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 5", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 5", "", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 5", "Bedford Yard 1", c12.getDestinationTrackName());
    // check car move counts
    Assert.assertEquals("c1 move count", 20, c1.getMoves());
    Assert.assertEquals("c2 move count", 19, c2.getMoves());
    Assert.assertEquals("c3 move count", 21, c3.getMoves());
    Assert.assertEquals("c4 move count", 18, c4.getMoves());
    Assert.assertEquals("c5 move count", 18, c5.getMoves());
    Assert.assertEquals("c6 move count", 16, c6.getMoves());
    Assert.assertEquals("c7 move count", 16, c7.getMoves());
    Assert.assertEquals("c8 move count", 14, c8.getMoves());
    Assert.assertEquals("c9 move count", 14, c9.getMoves());
    Assert.assertEquals("c12 move count", 14, c12.getMoves());
    c1.setMoves(19);
    // Change back to route to 1, should be able to pickup c4, c7, and c9
    train3.reset();
    train3.setRoute(rte1);
    loc2trk1.setPickupOption(Track.ROUTES);
    loc2trk1.addPickupId(rte1.getId());
    train3.build();
    Assert.assertEquals("c1 destination 6", "Bedford Yard 1", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 6", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 6", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 6", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 6", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 6", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 6", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 6", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 6", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 6", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 6", "", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination 6", "Bedford Yard 1", c12.getDestinationTrackName());
    // now allow train 3 to drop
    train3.reset();
    loc2trk1.setDropOption(Track.ROUTES);
    loc2trk1.addDropId(rte1.getId());
    c5.setMoves(19);
    c2.setMoves(20);
    c1.setMoves(21);
    train3.build();
    Assert.assertEquals("c1 destination 7", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 7", "Chelmsford Interchange 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 7", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 7", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 7", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 7", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 7", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 7", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 7", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 7", "Bedford Yard 1", c12.getDestinationTrackName());
    // move and terminate
    train3.move();
    train3.move();
    train3.move();
    train3.move();
    // check tracks
    Assert.assertEquals("c1 track", "Westford Yard 1", c1.getTrackName());
    Assert.assertEquals("c2 track", "Chelmsford Interchange 1", c2.getTrackName());
    Assert.assertEquals("c3 track", "Westford Yard 1", c3.getTrackName());
    Assert.assertEquals("c4 track", "Bedford Yard 1", c4.getTrackName());
    Assert.assertEquals("c5 track", "Bedford Yard 1", c5.getTrackName());
    Assert.assertEquals("c6 track", "Bedford Yard 1", c6.getTrackName());
    Assert.assertEquals("c7 track", "Bedford Yard 1", c7.getTrackName());
    Assert.assertEquals("c8 track", "Bedford Yard 1", c8.getTrackName());
    Assert.assertEquals("c9 track", "Bedford Yard 1", c9.getTrackName());
    Assert.assertEquals("c10 track", "Bedford Yard 1", c10.getTrackName());
    Assert.assertEquals("c11 track", "Bedford Yard 1", c11.getTrackName());
    Assert.assertEquals("c12 track", "Bedford Yard 1", c12.getTrackName());
    // check train length and tonnage
    Assert.assertEquals("Depart Westford length", 138, r1l1.getTrainLength());
    Assert.assertEquals("Depart Old Chelmsford length", 310, r1l2.getTrainLength());
    // In train 2 cars, c2 E and c5 L car weight 20/3 + 50 = 56
    Assert.assertEquals("Depart Old Westford tonnage", 56, r1l1.getTrainWeight());
    // In train 5 cars, c4 E, c5 L, c7 E, c9 L, c12 L = 40/3 + 50 + 70/3 + 90 + 120 = 296
    Assert.assertEquals("Depart Old Chelmsford tonnage", 296, r1l2.getTrainWeight());
    // test route pickup and drop controls
    train3.setRequirements(Train.CABOOSE);
    r1l1.setPickUpAllowed(false);
    c1.setMoves(10);
    c3.setMoves(21);
    train3.build();
    Assert.assertEquals("c1 destination 8", "", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 8", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 8", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 8", "Bedford Yard 1", c13.getDestinationTrackName());
    r1l1.setPickUpAllowed(true);
    r1l2.setPickUpAllowed(false);
    train3.build();
    Assert.assertEquals("c1 destination 9", "Chelmsford Interchange 1", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 9", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 9", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 9", "Bedford Yard 1", c13.getDestinationTrackName());
    r1l2.setPickUpAllowed(true);
    // Old Chelmsford
    r1l2.setDropAllowed(false);
    train3.build();
    Assert.assertEquals("c1 destination 10", "Bedford Yard 1", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 10", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 10", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 10", "Bedford Yard 1", c13.getDestinationTrackName());
    train3.reset();
    // try forcing c1 to Chelmsford
    c1.setDestination(loc2, null);
    train3.build();
    Assert.assertEquals("c1 destination Old Chelmsford", "", c1.getDestinationTrackName());
    // confirm that c1 isn't part of this train
    Assert.assertNull("c1 isn't assigned to a train", c1.getTrain());
    Assert.assertNull("c1 destination has been set to null", c1.getDestination());
    Assert.assertNull("c1 next destination should be null", c1.getFinalDestination());
    Assert.assertNull("c1 next destination track should be null", c1.getFinalDestinationTrack());
    // try without moves
    r1l2.setDropAllowed(true);
    r1l2.setMaxCarMoves(0);
    c1.setDestination(loc2, null);
    train3.build();
    Assert.assertEquals("c1 destination Old Chelmsford, no moves", "", c1.getDestinationTrackName());
    c1.setDestination(null, null);
    r1l2.setMaxCarMoves(6);
    // Should be able to drop off caboose
    r1l3.setDropAllowed(false);
    train3.build();
    Assert.assertEquals("c1 destination 11", "Chelmsford Interchange 1", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 11", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 11", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 11", "Bedford Yard 1", c13.getDestinationTrackName());
    // test to see if FRED also get delivered
    train3.setRequirements(Train.FRED);
    Assert.assertEquals("Place c2 at start of route", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    c2.setFred(true);
    train3.build();
    Assert.assertTrue("Train 3 built", train3.isBuilt());
    Assert.assertEquals("c1 destination 12", "Chelmsford Interchange 1", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 12", "Bedford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 12", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 12", "", c13.getDestinationTrackName());
    // move and terminate
    train3.move();
    train3.move();
    train3.move();
    train3.move();
    Assert.assertEquals("c1 track 12", "Chelmsford Interchange 1", c1.getTrackName());
    Assert.assertEquals("c2 track 12", "Bedford Yard 1", c2.getTrackName());
    Assert.assertEquals("c3 track 12", "Westford Yard 1", c3.getTrackName());
    Assert.assertEquals("c13 track 12", "Westford Yard 1", c13.getTrackName());
    // test previous car delivered pickup interchange operation
    loc2trk1.setDropOption(Track.ANY);
    loc2trk1.setPickupOption(Track.TRAINS);
    loc2trk2.setDropOption(Track.ANY);
    loc2trk2.setPickupOption(Track.TRAINS);
    // Place car with FRED back at start of route
    Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    train3.build();
    Assert.assertTrue("train 3 should build", train3.isBuilt());
    Assert.assertEquals("car BM Q1 should not be part of train", null, c1.getTrain());
    Assert.assertEquals("car XP Q3 should be part of train", train3, c3.getTrain());
    // put some cars at start of Route
    Assert.assertEquals("Place c1 again", Track.OKAY, c1.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c3 again", Track.OKAY, c3.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c4 again", Track.OKAY, c4.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c6 again", Track.OKAY, c6.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c7 again", Track.OKAY, c7.setLocation(loc2, loc2trk2));
    r1l1.setMaxCarMoves(5);
    loc2trk1.setDropOption(Track.ROUTES);
    loc2trk1.setPickupOption(Track.ROUTES);
    loc2trk2.setDropOption(Track.ROUTES);
    loc2trk2.setPickupOption(Track.ROUTES);
    train3.build();
    Assert.assertTrue("train 3 should build", train3.isBuilt());
    Assert.assertEquals("BM Q1 in train", null, c1.getTrain());
    Assert.assertEquals("UP Q2 in train", train3, c2.getTrain());
    Assert.assertEquals("XP Q3 in train", train3, c3.getTrain());
    Assert.assertEquals("PU Q4 in train", train3, c4.getTrain());
    Assert.assertEquals("UP Q5 in train", null, c5.getTrain());
    Assert.assertEquals("CP Q6 in train", null, c6.getTrain());
    Assert.assertEquals("UP Q7 in train", null, c7.getTrain());
    Assert.assertEquals("UP Q2 destination", "Bedford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("XP Q3 destination", "Chelmsford Freight 4", c3.getDestinationTrackName());
    Assert.assertEquals("PU Q4 destination", "Chelmsford Yard 3", c4.getDestinationTrackName());
    Assert.assertEquals("UP Q5 destination", "", c5.getDestinationTrackName());
    // interchange testing done, now test replace car type and road
    Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    // replace should modify locations and trains
    ct.replaceName("Boxcar", "boxcar");
    Assert.assertFalse("loc1 should not accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("loc2 should not accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    Assert.assertFalse("track loc1trk1 should not accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("track loc2trk1 should not accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 1 should not accept Boxcar", train1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 2 should not accept Boxcar", train2.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 3 should not accept Boxcar", train3.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc1 should accept boxcar", loc1.acceptsTypeName("boxcar"));
    Assert.assertTrue("loc2 should accept boxcar", loc2.acceptsTypeName("boxcar"));
    Assert.assertTrue("track loc1trk1 should accept boxcar", loc1trk1.acceptsTypeName("boxcar"));
    Assert.assertTrue("track loc2trk1 should accept boxcar", loc2trk1.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 1 should accept boxcar", train1.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 2 should accept boxcar", train2.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 3 should accept boxcar", train3.acceptsTypeName("boxcar"));
    ct.replaceName("boxcar", "Boxcar");
    Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    Assert.assertTrue("track loc1trk1 should accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("track loc2trk1 should accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 1 should accept Boxcar", train1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 2 should accept Boxcar", train2.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 3 should accept Boxcar", train3.acceptsTypeName("Boxcar"));
    // now test road name replace
    CarRoads cr = CarRoads.instance();
    cr.addName("CP");
    loc1trk1.setRoadOption(Track.INCLUDE_ROADS);
    loc1trk1.addRoadName("CP");
    loc1trk1.addRoadName("PC");
    train1.setRoadOption(Train.INCLUDE_ROADS);
    train1.addRoadName("CP");
    train1.addRoadName("PC");
    train1.setCabooseRoad("CP");
    train1.setEngineRoad("CP");
    Assert.assertTrue("track loc1trk1 should accept road CP", loc1trk1.acceptsRoadName("CP"));
    Assert.assertTrue("track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
    Assert.assertFalse("track loc1trk1 should Not accept road PC", loc1trk1.acceptsRoadName("UP"));
    Assert.assertTrue("Train 1 should accept road CP", train1.acceptsRoadName("CP"));
    Assert.assertTrue("Train 1 should accept road PC", train1.acceptsRoadName("PC"));
    Assert.assertFalse("Train 1 should Not accept road UP", train1.acceptsRoadName("UP"));
    Assert.assertEquals("Caboose road", "CP", train1.getCabooseRoad());
    Assert.assertEquals("Engine road", "CP", train1.getEngineRoad());
    cr.replaceName("CP", "UP");
    Assert.assertFalse("after replace track loc1trk1 should Not accept road CP", loc1trk1.acceptsRoadName("CP"));
    Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
    Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("UP"));
    Assert.assertFalse("after replace Train 1 should Not accept road CP", train1.acceptsRoadName("CP"));
    Assert.assertTrue("after replace Train 1 should accept road PC", train1.acceptsRoadName("PC"));
    Assert.assertTrue("after replace Train 1 should accept road UP", train1.acceptsRoadName("UP"));
    Assert.assertEquals("Caboose road", "UP", train1.getCabooseRoad());
    Assert.assertEquals("Engine road", "UP", train1.getEngineRoad());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) CarRoads(jmri.jmrit.operations.rollingstock.cars.CarRoads) 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)

Aggregations

CarRoads (jmri.jmrit.operations.rollingstock.cars.CarRoads)9 Location (jmri.jmrit.operations.locations.Location)7 Track (jmri.jmrit.operations.locations.Track)7 LocationManager (jmri.jmrit.operations.locations.LocationManager)6 CarOwners (jmri.jmrit.operations.rollingstock.cars.CarOwners)5 Car (jmri.jmrit.operations.rollingstock.cars.Car)3 Route (jmri.jmrit.operations.routes.Route)3 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)3 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)2 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)2 RouteManager (jmri.jmrit.operations.routes.RouteManager)2 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)1 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)1 ScheduleManager (jmri.jmrit.operations.locations.schedules.ScheduleManager)1 CarColors (jmri.jmrit.operations.rollingstock.cars.CarColors)1 CarLengths (jmri.jmrit.operations.rollingstock.cars.CarLengths)1 CarLoads (jmri.jmrit.operations.rollingstock.cars.CarLoads)1 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)1 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)1 EngineModels (jmri.jmrit.operations.rollingstock.engines.EngineModels)1