本文整理汇总了Python中car.Car.crash方法的典型用法代码示例。如果您正苦于以下问题:Python Car.crash方法的具体用法?Python Car.crash怎么用?Python Car.crash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类car.Car
的用法示例。
在下文中一共展示了Car.crash方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCar
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import crash [as 别名]
class TestCar(unittest.TestCase):
def setUp(self):
self.car = Car("Toyota")
self.car.driver = Driver("Nils")
def tearDown(self):
self.car = None
def test_create_car(self):
self.assertIsNotNone(self.car, "Car should be created")
def test_set_model_in_constructor(self):
self.assertEqual(self.car.model, "Toyota", "Model is set to Toyota")
def test_set_model_attribute(self):
self.car.model = "Nissan"
self.assertEqual(self.car.model, "Nissan", "Car model should have been set to Nissan")
def test_crash_car_is_crashed(self):
self.assertFalse(self.car.has_crashed, "Car should not be crashed from the get go")
self.car.crash()
self.assertTrue(self.car.has_crashed, "Car crash have crashed, so it should have remembered that.")
def test_set_driver(self):
self.car.driver = Driver("Kristian")
self.assertEqual(self.car.driver_name(), "Kristian", "Name of driver should be Kristian")
def test_car_crash_should_kill(self):
self.assertTrue(self.car.driver.is_alive(), "A new car has an alive driver")
self.car.crash()
self.assertFalse(self.car.driver.is_alive(), "When the car crashes, driver is killed")
def test_car_crash_volvo_driver_survives(self):
self.car.model = "Volvo"
self.assertTrue(self.car.driver.is_alive(), "A new car has an alive driver")
self.car.crash()
self.assertTrue(self.car.driver.is_alive(), "When the Volvo crashes, driver lives")
def test_car_crash_superman_lives(self):
self.car.driver = Driver("Superman")
self.assertTrue(self.car.driver.is_alive(), "A new car has an alive driver")
self.car.crash()
self.assertTrue(self.car.driver.is_alive(), "When the car crashes, Superman lives")
示例2: test_crash_car_is_crashed
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import crash [as 别名]
def test_crash_car_is_crashed(self):
car = Car("Flikka Automobile")
self.assertFalse(car.has_crashed, "Car should not be crashed from the get go")
car.crash()
self.assertTrue(car.has_crashed, "Car crash have crashed, so it should have remembered that.")
示例3: test_car_crash_should_kill
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import crash [as 别名]
def test_car_crash_should_kill(self):
car = Car("Toyota")
self.assertTrue(car.driver_is_alive, "A new car has an alive driver")
car.crash()
self.assertFalse(car.driver_is_alive, "When the Toyota crashes, driver is killed")