当前位置: 首页>>代码示例>>Python>>正文


Python Car.crash方法代码示例

本文整理汇总了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")
开发者ID:Statoil,项目名称:TDD-intro,代码行数:45,代码来源:testcar.py

示例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.")
开发者ID:Statoil,项目名称:TDD-intro,代码行数:7,代码来源:testcar.py

示例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")
开发者ID:Statoil,项目名称:TDD-intro,代码行数:7,代码来源:testcar.py


注:本文中的car.Car.crash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。