Beispiel #1
0
  @Test
  public void testAddGas() {
    Car testCar = new Car(50);
    testCar.addGas(20);
    double gallons = testCar.getGasInTank();
    assertEquals(20.0, gallons, 1e-6);

    testCar.addGas(5);
    gallons = testCar.getGasInTank();
    assertEquals(25.0, gallons, 1e-6);
  }
Beispiel #2
0
  @Test
  public void testDrive() {
    Car testCar = new Car(50);
    testCar.addGas(20);
    testCar.drive(25);
    double gallons = testCar.getGasInTank();
    assertEquals(19.5, gallons, 1e-6);

    testCar.drive(100);
    gallons = testCar.getGasInTank();
    assertEquals(17.5, gallons, 1e-6);
  }
Beispiel #3
0
  @Test
  public void test() {
    Car car = new Car(50);

    car.addGas(20); // Tank 20 gallons
    car.drive(100); // Drive 100 miles
    double gasLeft = car.getGasInTank(); // Get gas remaining in tank

    // expected 18
    assertEquals(18, gasLeft, 0);
  }
Beispiel #4
0
 @Test
 public void testGetGasInTank() {
   Car testCar = new Car(50);
   double gallons = testCar.getGasInTank();
   assertEquals(0.0, gallons, 1e-6);
 }