use of jmri.jmrit.operations.rollingstock.cars.CarRoads in project JMRI by JMRI.
the class EngineAttributeEditFrameTest 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));
}
use of jmri.jmrit.operations.rollingstock.cars.CarRoads in project JMRI by JMRI.
the class EngineEditFrameTest 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));
}
use of jmri.jmrit.operations.rollingstock.cars.CarRoads in project JMRI by JMRI.
the class LocationTest method testRoadNameSupport.
public void testRoadNameSupport() {
// use LocationManager to allow replace car road to work properly
Location l = LocationManager.instance().newLocation("Test Name 2");
Assert.assertEquals("Location Name", "Test Name 2", l.getName());
Track t = l.addTrack("new track", Track.SPUR);
Assert.assertEquals("Location", l, t.getLocation());
t.setRoadOption(Track.INCLUDE_ROADS);
t.addRoadName("Test Road Name");
t.addRoadName("Test Road Name 2");
ScheduleManager sm = ScheduleManager.instance();
Schedule s = sm.newSchedule("test schedule");
ScheduleItem i1 = s.addItem("BoxCar");
ScheduleItem i2 = s.addItem("BoxCar");
i1.setRoadName("Test Road Name");
i2.setRoadName("Test Road Name 2");
Assert.assertTrue("track should accept road Test Road Name", t.acceptsRoadName("Test Road Name"));
Assert.assertTrue("track should accept road Test Road Name 2", t.acceptsRoadName("Test Road Name 2"));
Assert.assertFalse("track should Not accept road New Test Road Name", t.acceptsRoadName("New Test Road Name"));
Assert.assertEquals("ScheudleItem i1 Road Test Road Name", "Test Road Name", i1.getRoadName());
Assert.assertEquals("ScheudleItem i2 Road Test Road Name", "Test Road Name 2", i2.getRoadName());
CarRoads cr = CarRoads.instance();
cr.replaceName("Test Road Name", "New Test Road Name");
Assert.assertFalse("track should Not accept road Test Road Name", t.acceptsRoadName("Test Road Name"));
Assert.assertTrue("track should accept road Test Road Name 2", t.acceptsRoadName("Test Road Name 2"));
Assert.assertTrue("track should accept road New Test Road Name", t.acceptsRoadName("New Test Road Name"));
Assert.assertEquals("ScheudleItem i1 Road Test Road Name", "New Test Road Name", i1.getRoadName());
Assert.assertEquals("Check ScheudleItem i2 Road Test Road Name", "Test Road Name 2", i2.getRoadName());
// remove all schedules
sm.dispose();
}
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());
}
use of jmri.jmrit.operations.rollingstock.cars.CarRoads in project JMRI by JMRI.
the class InterchangeEditFrameTest method setUp.
// Ensure minimal setup for log4J
@Override
@Before
public void setUp() throws Exception {
super.setUp();
loadLocations();
// add UP road name
CarRoads cr = CarRoads.instance();
cr.addName("UP");
lManager = LocationManager.instance();
l = lManager.getLocationByName("Test Loc C");
}
Aggregations