コード例 #1
0
 def test_CarRefuel_whenNegativeFuel_shouldRaiseException(self):
     make = "Mercedes"
     model = "GT"
     fuel_consumption = 20
     capacity = 80
     car = Car(make, model, fuel_consumption, capacity)
     with self.assertRaises(Exception) as context:
         car.refuel(-10)
     self.assertIsNotNone(context.exception)
コード例 #2
0
 def test_CarDrive_whenNotEnoughFuel_shouldRaiseException(self):
     make = 'Mercedes'
     model = "GT"
     fuel_consumption = 20
     capacity = 80
     car = Car(make, model, fuel_consumption, capacity)
     with self.assertRaises(Exception) as context:
         car.drive(1000)
     self.assertIsNotNone(context.exception)
コード例 #3
0
 def test_CarRefuel_whenPositiveFuelAndMoreThanCapacity_shouldSetAmountToCapacity(
         self):
     make = 'Mercedes'
     model = "GT"
     fuel_consumption = 20
     capacity = 80
     refuel_amount = 100
     car = Car(make, model, fuel_consumption, capacity)
     car.refuel(refuel_amount)
     self.assertEqual(capacity, car.fuel_capacity)
コード例 #4
0
 def test_CarRefuel_whenPositiveFuelAndEnoughCapacity_shouldIncreaseFuel(
         self):
     make = 'Mercedes'
     model = "GT"
     fuel_consumption = 20
     capacity = 80
     refuel_amount = 30
     car = Car(make, model, fuel_consumption, capacity)
     car.refuel(refuel_amount)
     self.assertEqual(refuel_amount, car.fuel_amount)
コード例 #5
0
 def test_CarInit_whenZeroCapacity_shouldRaiseException(self):
     make = "Mercedes"
     model = "GT"
     fuel_consumption = 20
     capacity = 0
     with self.assertRaises(Exception) as context:
         Car(make, model, fuel_consumption, capacity)
     self.assertIsNotNone(context.exception)
コード例 #6
0
 def test_CarInit_whenEmptyString_shouldRaiseException(self):
     make = ""
     model = "GT"
     fuel_consumption = 20
     capacity = 80
     with self.assertRaises(Exception) as context:
         Car(make, model, fuel_consumption, capacity)
     self.assertIsNotNone(context.exception)
コード例 #7
0
 def test_CarInit_whenProperInputIsGiven_shouldBeAllRight(self):
     make = 'Mercedes'
     model = "GT"
     fuel_consumption = 20
     capacity = 80
     car = Car(make, model, fuel_consumption, capacity)
     self.assertEqual(make, car.make)
     self.assertEqual(model, car.model)
     self.assertEqual(fuel_consumption, car.fuel_consumption)
     self.assertEqual(capacity, car.fuel_capacity)
コード例 #8
0
 def test_CarDrive_whenEnoughFuel_shouldDecreaseFuel(self):
     make = 'Mercedes'
     model = "GT"
     fuel_consumption = 20
     capacity = 80
     refuel_amount = 80
     kilometers = 100
     amount_needed = kilometers * fuel_consumption / 100
     car = Car(make, model, fuel_consumption, capacity)
     car.refuel(refuel_amount)
     car.drive(kilometers)
     self.assertEqual(capacity - amount_needed, car.fuel_amount)