Ejemplo n.º 1
0
  /**
   * @author Robert Dempsey, Student Number: N5400872 Tests that when passengers board, the
   *     individual cars are filling up, not just a total number on the whole train
   */
  @Test
  public void testIndividualPassengerCarsAreBeingAddedTo() throws TrainException {
    final Integer SEATS = 20;
    final Integer PASSENGERS = 79;
    final Integer GROSS_WEIGHT = 90;
    final Integer ZERO_PASSENGERS = 0;
    final String CLASSIFICATION = "4S";

    final Locomotive LOCOMOTIVE = new Locomotive(GROSS_WEIGHT, CLASSIFICATION);
    final PassengerCar PASSENGER_01 = new PassengerCar(GROSS_WEIGHT, SEATS);
    final PassengerCar PASSENGER_02 = new PassengerCar(GROSS_WEIGHT, SEATS);
    final PassengerCar PASSENGER_03 = new PassengerCar(GROSS_WEIGHT, SEATS);
    final PassengerCar PASSENGER_04 = new PassengerCar(GROSS_WEIGHT, SEATS);

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCOMOTIVE);
    departingTrain.addCarriage(PASSENGER_01);
    departingTrain.addCarriage(PASSENGER_02);
    departingTrain.addCarriage(PASSENGER_03);
    departingTrain.addCarriage(PASSENGER_04);

    departingTrain.board(PASSENGERS);

    assertTrue(PASSENGER_01.numberOnBoard() > ZERO_PASSENGERS);
    assertTrue(PASSENGER_02.numberOnBoard() > ZERO_PASSENGERS);
    assertTrue(PASSENGER_03.numberOnBoard() > ZERO_PASSENGERS);
    assertTrue(PASSENGER_04.numberOnBoard() > ZERO_PASSENGERS);
  }
Ejemplo n.º 2
0
  /**
   * Test toString with passengers
   *
   * @throws TrainException
   */
  @Test
  public void testToStringMultipleCarriagePassengers() throws TrainException {
    final Integer GROSS_WEIGHT = 90;
    final String GOODS_TYPE = "G";
    final Integer SEATS = 20;
    final Integer PASSENGERS = 10;
    final String CLASSIFICATION = "4S";

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

    final String TO_STRING =
        "Loco("
            + CLASSIFICATION
            + ")-Passenger("
            + PASSENGERS
            + "/"
            + SEATS
            + ")-Freight("
            + GOODS_TYPE
            + ")";

    DepartingTrain departingTrain = new DepartingTrain();

    departingTrain.addCarriage(LOCO);
    departingTrain.addCarriage(PASSENGER);
    departingTrain.addCarriage(FREIGHT);
    departingTrain.board(PASSENGERS);

    assertEquals(TO_STRING, departingTrain.toString());
  }
Ejemplo n.º 3
0
 /**
  * Tests Add Carriage while Passengers Aboard
  *
  * @throws TrainException
  */
 @Test(expected = TrainException.class)
 public void testAddCarAfterBoarding() throws TrainException {
   final Integer PASSENGERS = 20;
   final Locomotive LOCO = new Locomotive(90, "4S");
   final FreightCar FREIGHT = new FreightCar(90, "G");
   final PassengerCar PASSENGER = new PassengerCar(90, PASSENGERS);
   DepartingTrain departingTrain = new DepartingTrain();
   departingTrain.addCarriage(LOCO);
   departingTrain.addCarriage(PASSENGER);
   departingTrain.board(PASSENGERS);
   departingTrain.addCarriage(FREIGHT);
 }
Ejemplo n.º 4
0
  /**
   * Test Boarding Passengers to a Valid Train with negative boarding passengers
   *
   * @throws TrainException
   */
  @Test(expected = TrainException.class)
  public void testBoardPassengersValidTrainNegative() throws TrainException {
    final Integer PASSENGERS = -20;
    final Integer GROSS_WEIGHT = 90;
    final String POWER_CLASS = "4S";

    final Locomotive LOCO = new Locomotive(GROSS_WEIGHT, POWER_CLASS);
    final PassengerCar PASSENGER = new PassengerCar(GROSS_WEIGHT, PASSENGERS);

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCO);
    departingTrain.addCarriage(PASSENGER);
    @SuppressWarnings("unused")
    Integer noSeats = departingTrain.board(PASSENGERS);
  }
Ejemplo n.º 5
0
  /**
   * @author Robert Dempsey, Student Number: N5400872 Tests that an exception is thrown if a
   *     carriage is attempted to be removed when there are passengers on the train
   * @throws TrainException
   */
  @Test(expected = TrainException.class)
  public void testRemoveCarriagePassengersOnTrain() throws TrainException {
    final Integer SEATS = 20;
    final Integer PASSENGERS = 19;
    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.board(PASSENGERS);
    departingTrain.removeCarriage();
  }
Ejemplo n.º 6
0
  /**
   * Test Boarding Passengers to a Valid Train
   *
   * @throws TrainException
   */
  @Test
  public void testBoardPassengersValidTrainPositive() throws TrainException {
    final Integer PASSENGERS = 20;
    final Integer GROSS_WEIGHT = 90;
    final String POWER_CLASS = "4S";

    final Locomotive LOCO = new Locomotive(GROSS_WEIGHT, POWER_CLASS);
    final PassengerCar PASSENGER = new PassengerCar(GROSS_WEIGHT, PASSENGERS);

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCO);
    departingTrain.addCarriage(PASSENGER);
    @SuppressWarnings("unused")
    Integer noSeats = departingTrain.board(PASSENGERS);
    assertEquals(departingTrain.numberOnBoard(), PASSENGERS);
  }
Ejemplo n.º 7
0
  /**
   * Test Boarding To Many Passengers to a Valid Train
   *
   * @throws TrainException
   */
  @Test
  public void testBoardTooManyPassengersValidTrain() throws TrainException {
    final Integer SEATS = 20;
    final Integer PASSENGERS = 40;
    final Integer EXPECTED_OVER = PASSENGERS - SEATS;
    final Integer GROSS_WEIGHT = 90;
    final String POWER_CLASS = "4S";

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

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCO);
    departingTrain.addCarriage(PASSENGER);
    Integer noSeats = departingTrain.board(PASSENGERS);
    assertEquals(noSeats, EXPECTED_OVER);
  }
Ejemplo n.º 8
0
  /**
   * Test Boarding Passengers to a Invalid Train
   *
   * @throws TrainException
   */
  @Test
  public void testBoardPassengersInvalidTrain() throws TrainException {
    final Integer PASSENGERS = 20;
    final Integer GROSS_WEIGHT = 90;
    final String POWER_CLASS = "4S";
    final String GOODS_TYPE = "G";

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

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCO);
    departingTrain.addCarriage(FREIGHT);
    Integer noSeats = departingTrain.board(PASSENGERS);

    assertEquals(noSeats, PASSENGERS);
  }
Ejemplo n.º 9
0
  /**
   * Test Boarding Passengers to a Valid Combo Train with multiple PassengerCar carriages and single
   * FreightCar carriages
   *
   * @throws TrainException
   */
  @Test
  public void testBoardPassengersValidComboTrainPassengerMultiple() throws TrainException {
    final Integer SEATS = 20;
    final Integer PASSENGERS = SEATS * 2;
    final Integer GROSS_WEIGHT = 90;
    final String POWER_CLASS = "4S";
    final String GOODS_TYPE = "G";

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

    DepartingTrain departingTrain = new DepartingTrain();
    departingTrain.addCarriage(LOCO);
    departingTrain.addCarriage(PASSENGER01);
    departingTrain.addCarriage(PASSENGER02);
    departingTrain.addCarriage(FREIGHT);
    @SuppressWarnings("unused")
    Integer noSeats = departingTrain.board(PASSENGERS);
    assertEquals(departingTrain.numberOnBoard(), PASSENGERS);
  }