Search in sources :

Example 41 with LocationManager

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

the class TrainTest method testMaxEngines.

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

Example 42 with LocationManager

use of jmri.jmrit.operations.locations.LocationManager 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 43 with LocationManager

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

the class TrainTest method testAutoEnginesSingleEngine.

public void testAutoEnginesSingleEngine() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Train train = tmanager.newTrain("AutoEngineTest");
    train.setNumberEngines(Train.AUTO);
    Route route = rmanager.newRoute("AutoEngineTest");
    train.setRoute(route);
    Location A = lmanager.newLocation("A");
    Location B = lmanager.newLocation("B");
    Location C = lmanager.newLocation("C");
    Track At = A.addTrack("track", Track.SPUR);
    Track Bt = B.addTrack("track", Track.SPUR);
    Track Ct = C.addTrack("track", Track.SPUR);
    At.setLength(300);
    Bt.setLength(300);
    Ct.setLength(300);
    RouteLocation rA = route.addLocation(A);
    RouteLocation rB = route.addLocation(B);
    RouteLocation rC = route.addLocation(C);
    rA.setMaxCarMoves(5);
    rB.setMaxCarMoves(5);
    rC.setMaxCarMoves(5);
    Engine e1 = emanager.newEngine("E", "1");
    e1.setModel("GP40");
    Engine e2 = emanager.newEngine("E", "2");
    e2.setModel("GP40");
    Engine e3 = emanager.newEngine("E", "3");
    e3.setModel("GP40");
    Engine e4 = emanager.newEngine("E", "4");
    e4.setModel("GP40");
    e1.setLocation(A, At);
    e2.setLocation(A, At);
    e3.setLocation(A, At);
    e4.setLocation(A, At);
    train.build();
    Assert.assertTrue("Train should build, only needs a single engine", train.isBuilt());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 44 with LocationManager

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

the class TrainTest method testAutoEnginesTwoEngines.

public void testAutoEnginesTwoEngines() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Train train = tmanager.newTrain("AutoEngineTest");
    train.setNumberEngines(Train.AUTO);
    Route route = rmanager.newRoute("AutoEngineTest");
    train.setRoute(route);
    Location A = lmanager.newLocation("A");
    Location B = lmanager.newLocation("B");
    Location C = lmanager.newLocation("C");
    Track At = A.addTrack("track", Track.SPUR);
    Track Bt = B.addTrack("track", Track.SPUR);
    Track Ct = C.addTrack("track", Track.SPUR);
    At.setLength(300);
    Bt.setLength(300);
    Ct.setLength(300);
    RouteLocation rA = route.addLocation(A);
    RouteLocation rB = route.addLocation(B);
    RouteLocation rC = route.addLocation(C);
    rA.setMaxCarMoves(5);
    rB.setMaxCarMoves(5);
    rC.setMaxCarMoves(5);
    Engine e1 = emanager.newEngine("E", "1");
    e1.setModel("GP40");
    Engine e2 = emanager.newEngine("E", "2");
    e2.setModel("GP40");
    Engine e3 = emanager.newEngine("E", "3");
    e3.setModel("GP40");
    Engine e4 = emanager.newEngine("E", "4");
    e4.setModel("GP40");
    e1.setLocation(A, At);
    e2.setLocation(A, At);
    e3.setLocation(A, At);
    e4.setLocation(A, At);
    // change requirements
    rA.setMaxCarMoves(12);
    rB.setMaxCarMoves(12);
    rC.setMaxCarMoves(12);
    train.build();
    Assert.assertFalse("Train should not build, only single engines", train.isBuilt());
    Consist c = emanager.newConsist("c");
    e1.setConsist(c);
    e2.setConsist(c);
    // train should require two engines
    train.build();
    Assert.assertTrue("Train should build", train.isBuilt());
    Assert.assertEquals("e1 should be assigned to train", train, e1.getTrain());
    Assert.assertEquals("e2 should be assigned to train", train, e2.getTrain());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 45 with LocationManager

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

the class JUnitOperationsUtil method initOperationsData.

/**
     * Populate the Operations Managers with a common set of data for tests.
     */
public static void initOperationsData() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    EngineTypes et = EngineTypes.instance();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    et.addName("Diesel");
    // Set up four engines in two consists
    Consist con1 = emanager.newConsist("C16");
    Consist con2 = emanager.newConsist("C14");
    Engine e1 = new Engine("PC", "5016");
    e1.setModel("GP40");
    e1.setConsist(con1);
    e1.setMoves(123);
    e1.setOwner("AT");
    e1.setBuilt("1990");
    emanager.register(e1);
    Engine e2 = new Engine("PC", "5019");
    e2.setModel("GP40");
    e2.setConsist(con1);
    e2.setMoves(321);
    e2.setOwner("AT");
    e2.setBuilt("1990");
    emanager.register(e2);
    Engine e3 = new Engine("PC", "5524");
    e3.setModel("SD45");
    e3.setConsist(con2);
    e3.setOwner("DAB");
    e3.setBuilt("1980");
    emanager.register(e3);
    Engine e4 = new Engine("PC", "5559");
    e4.setModel("SD45");
    e4.setConsist(con2);
    e4.setOwner("DAB");
    e4.setBuilt("1980");
    emanager.register(e4);
    // Set up two cabooses and six box cars
    Car c1 = new Car("CP", "C10099");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(23);
    c1.setOwner("AT");
    c1.setBuilt("1980");
    c1.setCaboose(true);
    cmanager.register(c1);
    Car c2 = new Car("CP", "C20099");
    c2.setTypeName("Caboose");
    c2.setLength("32");
    c2.setMoves(54);
    c2.setOwner("DAB");
    c2.setBuilt("1984");
    c2.setCaboose(true);
    cmanager.register(c2);
    Car c3 = new Car("CP", "X10001");
    c3.setTypeName("Boxcar");
    c3.setLength("40");
    c3.setOwner("DAB");
    c3.setBuilt("1984");
    cmanager.register(c3);
    Car c4 = new Car("CP", "X10002");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setOwner("AT");
    c4.setBuilt("1-84");
    c4.setMoves(4444);
    cmanager.register(c4);
    Car c5 = new Car("CP", "X20001");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setOwner("DAB");
    c5.setBuilt("1980");
    cmanager.register(c5);
    Car c6 = new Car("CP", "X20002");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setOwner("DAB");
    c6.setBuilt("1978");
    cmanager.register(c6);
    Car c7 = new Car("CP", "777");
    c7.setTypeName("Flat");
    c7.setLength("50");
    c7.setOwner("AT");
    c7.setBuilt("1990");
    c7.setMoves(6);
    cmanager.register(c7);
    Car c8 = new Car("CP", "888");
    c8.setTypeName("Boxcar");
    c8.setLength("60");
    c8.setOwner("DAB");
    c8.setBuilt("1985");
    cmanager.register(c8);
    Car c9 = new Car("CP", "99");
    c9.setTypeName("Flat");
    c9.setLength("90");
    c9.setOwner("AT");
    c9.setBuilt("6-80");
    cmanager.register(c9);
    // Set up a route of 3 locations: North End Staging (2 tracks),
    // North Industries (1 track), and South End Staging (2 tracks).
    Location l1 = new Location("1", "North End");
    l1.setLocationOps(Location.STAGING);
    l1.setTrainDirections(DIRECTION_ALL);
    l1.setSwitchListEnabled(true);
    lmanager.register(l1);
    Track l1s1 = new Track("1s1", "North End 1", Track.STAGING, l1);
    l1s1.setLength(300);
    l1s1.setTrainDirections(DIRECTION_ALL);
    l1s1.setRoadOption(Track.ALL_ROADS);
    l1s1.setDropOption(Track.ANY);
    l1s1.setPickupOption(Track.ANY);
    Track l1s2 = new Track("1s2", "North End 2", Track.STAGING, l1);
    l1s2.setLength(400);
    l1s2.setTrainDirections(DIRECTION_ALL);
    l1s2.setRoadOption(Track.ALL_ROADS);
    l1s2.setDropOption(Track.ANY);
    l1s2.setPickupOption(Track.ANY);
    l1.addTrack("North End 1", Track.STAGING);
    l1.addTrack("North End 2", Track.STAGING);
    l1.register(l1s1);
    l1.register(l1s2);
    Location l2 = new Location("2", "North Industries");
    l2.setLocationOps(Location.NORMAL);
    l2.setTrainDirections(DIRECTION_ALL);
    l2.setSwitchListEnabled(true);
    lmanager.register(l2);
    Track l2s1 = new Track("2s1", "NI Yard", Track.YARD, l2);
    l2s1.setLength(432);
    l2s1.setTrainDirections(DIRECTION_ALL);
    l2.register(l2s1);
    Location l3 = new Location("3", "South End");
    l3.setLocationOps(Location.STAGING);
    l3.setTrainDirections(DIRECTION_ALL);
    l3.setSwitchListEnabled(true);
    lmanager.register(l3);
    Track l3s1 = new Track("3s1", "South End 1", Track.STAGING, l3);
    l3s1.setLength(300);
    l3s1.setTrainDirections(DIRECTION_ALL);
    l3s1.setRoadOption(Track.ALL_ROADS);
    l3s1.setDropOption(Track.ANY);
    l3s1.setPickupOption(Track.ANY);
    Track l3s2 = new Track("3s2", "South End 2", Track.STAGING, l3);
    l3s2.setLength(401);
    l3s2.setTrainDirections(DIRECTION_ALL);
    l3s2.setRoadOption(Track.ALL_ROADS);
    l3s2.setDropOption(Track.ANY);
    l3s2.setPickupOption(Track.ANY);
    l3.addTrack("South End 1", Track.STAGING);
    l3.addTrack("South End 2", Track.STAGING);
    l3.register(l3s1);
    l3.register(l3s2);
    // Place 4 Boxcars on Staging tracks
    c3.setLocation(l1, l1s1);
    c4.setLocation(l1, l1s1);
    c5.setLocation(l1, l1s2);
    c6.setLocation(l1, l1s2);
    // Place 2 Boxcars and Flat in yard
    c7.setLocation(l2, l2s1);
    c8.setLocation(l2, l2s1);
    c9.setLocation(l2, l2s1);
    // Place Cabooses on Staging tracks
    c1.setLocation(l1, l1s1);
    // Define the route.
    Route route1 = new Route("1", "Southbound Main Route");
    RouteLocation rl1 = new RouteLocation("1r1", l1);
    rl1.setSequenceId(1);
    rl1.setTrainDirection(RouteLocation.SOUTH);
    rl1.setMaxCarMoves(5);
    rl1.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl1.setTrainIconX(25);
    rl1.setTrainIconY(25);
    RouteLocation rl2 = new RouteLocation("1r2", l2);
    rl2.setSequenceId(2);
    rl2.setTrainDirection(RouteLocation.SOUTH);
    // test for only 1 pickup and 1 drop
    rl2.setMaxCarMoves(2);
    rl2.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(25);
    RouteLocation rl3 = new RouteLocation("1r3", l3);
    rl3.setSequenceId(3);
    rl3.setTrainDirection(RouteLocation.SOUTH);
    rl3.setMaxCarMoves(5);
    rl3.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl3.setTrainIconX(125);
    rl3.setTrainIconY(25);
    route1.register(rl1);
    route1.register(rl2);
    route1.register(rl3);
    rmanager.register(route1);
    // Finally ready to define the trains.
    Train train1 = new Train("1", "STF");
    train1.setRequirements(Train.CABOOSE);
    train1.setCabooseRoad("CP");
    train1.deleteTypeName("Flat");
    train1.setRoadOption(Train.ALL_ROADS);
    train1.setRoute(route1);
    train1.setDepartureTime("6", "5");
    tmanager.register(train1);
    Train train2 = new Train("2", "SFF");
    // there are boxcars waiting in staging so build should fail
    train2.deleteTypeName("Boxcar");
    train2.deleteTypeName("Flat");
    train2.setRoute(route1);
    train2.setDepartureTime("22", "45");
    tmanager.register(train2);
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) TrainManager(jmri.jmrit.operations.trains.TrainManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Train(jmri.jmrit.operations.trains.Train) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Aggregations

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