Пример #1
0
  /**
   * @author Robert Dempsey, Student Number: N5400872 Tests if firstCarriage() followed by
   *     subsequent nextCarriage() calls traverses all carriages on train
   * @throws TrainException
   */
  @Test
  public void testFirstThenNextCarriageFullTraversalOfTrain() throws TrainException {
    final Integer SEATS = 20;
    final Integer GROSS_WEIGHT = 90;
    final String CLASSIFICATION = "4S";

    final Locomotive LOCOMOTIVE = new Locomotive(GROSS_WEIGHT, CLASSIFICATION);
    final PassengerCar PASSENGERCAR_01 = new PassengerCar(GROSS_WEIGHT, SEATS);
    final PassengerCar PASSENGERCAR_02 = new PassengerCar(GROSS_WEIGHT, SEATS);
    final PassengerCar PASSENGERCAR_03 = new PassengerCar(GROSS_WEIGHT, SEATS);
    final PassengerCar PASSENGERCAR_04 = new PassengerCar(GROSS_WEIGHT, SEATS);

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCOMOTIVE);
    departingTrain.addCarriage(PASSENGERCAR_01);
    departingTrain.addCarriage(PASSENGERCAR_02);
    departingTrain.addCarriage(PASSENGERCAR_03);
    departingTrain.addCarriage(PASSENGERCAR_04);

    assertEquals(LOCOMOTIVE, departingTrain.firstCarriage());
    assertEquals(PASSENGERCAR_01, departingTrain.nextCarriage());
    assertEquals(PASSENGERCAR_02, departingTrain.nextCarriage());
    assertEquals(PASSENGERCAR_03, departingTrain.nextCarriage());
    assertEquals(PASSENGERCAR_04, departingTrain.nextCarriage());
  }
Пример #2
0
 /**
  * Tests Add PassengerCar to Departing Train with Loco Only
  *
  * @throws TrainException
  */
 @Test
 public void testAddPassenger() throws TrainException {
   final Locomotive LOCO = new Locomotive(90, "4S");
   final PassengerCar PASSENGER = new PassengerCar(90, 20);
   DepartingTrain departingTrain = new DepartingTrain();
   departingTrain.addCarriage(LOCO);
   departingTrain.addCarriage(PASSENGER);
   assertEquals(departingTrain.firstCarriage(), LOCO);
   assertEquals(departingTrain.nextCarriage(), PASSENGER);
 }
Пример #3
0
 /**
  * Tests Add FreightCar to Departing Train with Loco Only
  *
  * @throws TrainException
  */
 @Test
 public void testAddFreight() throws TrainException {
   final Locomotive LOCO = new Locomotive(90, "4S");
   final FreightCar FREIGHT = new FreightCar(90, "G");
   DepartingTrain departingTrain = new DepartingTrain();
   departingTrain.addCarriage(LOCO);
   departingTrain.addCarriage(FREIGHT);
   assertEquals(departingTrain.firstCarriage(), LOCO);
   assertEquals(departingTrain.nextCarriage(), FREIGHT);
 }
Пример #4
0
  /**
   * Test Get Third or higher Carriage on a Train with Multiple Carriages but doesn't exist and
   * returns null
   *
   * @throws TrainException
   */
  @Test
  public void testGetNextCarriage_Null() throws TrainException {
    final Integer GROSS_WEIGHT = 90;
    final String POWER_CLASS = "4S";
    final Integer SEATS = 20;
    final String GOODS_TYPE = "G";

    final Locomotive LOCO = new Locomotive(GROSS_WEIGHT, POWER_CLASS);
    final PassengerCar PASSENGER = new PassengerCar(GROSS_WEIGHT, SEATS);
    final FreightCar FREIGHT = new FreightCar(GROSS_WEIGHT, GOODS_TYPE);

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCO);
    departingTrain.addCarriage(PASSENGER);
    departingTrain.addCarriage(FREIGHT);

    assertEquals(departingTrain.firstCarriage(), LOCO);
    assertEquals(departingTrain.nextCarriage(), PASSENGER);
    assertEquals(departingTrain.nextCarriage(), FREIGHT);
    assertNull(departingTrain.nextCarriage());
  }
Пример #5
0
  /**
   * @author Robert Dempsey, Student Number: N5400872 Tests that a freight car at the end will be
   *     successfully removed
   * @throws TrainException
   */
  @Test
  public void testRemoveCarriageLastCarriageFreight() throws TrainException {
    final Integer GROSS_WEIGHT = 90;
    final String CLASSIFICATION = "4S";
    final String GOODS_TYPE = "G";
    final Locomotive LOCOMOTIVE = new Locomotive(GROSS_WEIGHT, CLASSIFICATION);
    final FreightCar FREIGHTCAR = new FreightCar(GROSS_WEIGHT, GOODS_TYPE);

    DepartingTrain departingTrain = new DepartingTrain();

    departingTrain.addCarriage(LOCOMOTIVE);
    departingTrain.addCarriage(FREIGHTCAR);
    departingTrain.removeCarriage();
    assertEquals(LOCOMOTIVE, departingTrain.firstCarriage());
    assertNull(departingTrain.nextCarriage());
  }
Пример #6
0
  /**
   * @author Robert Dempsey, Student Number: N5400872 Tests that a passenger car at the end will be
   *     successfully removed
   * @throws TrainException
   */
  @Test
  public void testRemoveCarriageLastCarriagePassenger() throws TrainException {
    final Integer SEATS = 20;
    final Integer GROSS_WEIGHT = 90;
    final String CLASSIFICATION = "4S";
    final Locomotive LOCOMOTIVE = new Locomotive(GROSS_WEIGHT, CLASSIFICATION);
    final PassengerCar PASSENGERCAR_01 = new PassengerCar(GROSS_WEIGHT, SEATS);

    DepartingTrain departingTrain = new DepartingTrain();

    departingTrain.addCarriage(LOCOMOTIVE);
    departingTrain.addCarriage(PASSENGERCAR_01);
    departingTrain.removeCarriage();
    assertEquals(LOCOMOTIVE, departingTrain.firstCarriage());
    assertNull(departingTrain.nextCarriage());
  }