コード例 #1
0
 @Test
 public void electricCarRefuelTest() {
   ElectricCar ec = new ElectricCar();
   assertEquals(
       "electric car 2 should start with a fuel level of 1000", 1000f, ec.checkFuelLevel(), 0.01f);
   ec.turnOn();
   ec.drive();
   assertEquals(
       "electric car 2 should now have a fuel level of 980", 980f, ec.checkFuelLevel(), 0.01f);
   ec.refuel();
   assertEquals(
       "electric car 2 should still have a fuel level of 980, since it was on",
       980f,
       ec.checkFuelLevel(),
       0.01f);
   ec.turnOff();
   ec.refuel();
   assertEquals(
       "electric Car 2 should now have a fuel level of 1000 after refueling",
       1000f,
       ec.checkFuelLevel(),
       0.01f);
 }
コード例 #2
0
 @Test
 public void electricCarDriveTest() {
   ElectricCar ec = new ElectricCar();
   assertEquals(
       "electricCar should start with a fuel level of 1000", 1000f, ec.checkFuelLevel(), 0.01f);
   ec.drive();
   assertEquals(
       "electricCar was not on, so its fuel level should still be 1000",
       1000f,
       ec.checkFuelLevel(),
       0.01f);
   ec.turnOn();
   ec.drive();
   assertEquals(
       "electric car should now have a fuel level of 980", 980f, ec.checkFuelLevel(), 0.01f);
 }