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


Python Car.setColour方法代码示例

本文整理汇总了Python中car.Car.setColour方法的典型用法代码示例。如果您正苦于以下问题:Python Car.setColour方法的具体用法?Python Car.setColour怎么用?Python Car.setColour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在car.Car的用法示例。


在下文中一共展示了Car.setColour方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCar

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import setColour [as 别名]
class TestCar(unittest.TestCase):
    def setUp(self):
        self.car = Car()
        # unittest runs the test cases for the class.  TestCase is a subclass of the unit test class.
        # the setUp function uses the standard practice of naming the variable self to call itself.
        # def setUp(self):

    def test_car_mileage_and_move(self):
        # Function to test the mileage starts by testing 0 the default value called from the base class Car
        # move(15) calls the move method move which takes in the value in this case 15 and tests if the mileage
        # has increased by 15 which it has, 12 is added to make 27, than 13 to make 40 than 3.5 to make 43.5.  0
        # is tested and finally changing the value of mileage using setMileage is tested with the value 20 which is
        # passed to the function in the Car class this is tested and the change is confirmed mileage is 20.
        self.assertEqual(0, self.car.getMileage())
        self.car.move(15)
        self.assertEqual(15, self.car.getMileage())
        self.car.move(12)
        self.assertEqual(27, self.car.getMileage())
        self.car.move(13)
        self.assertEqual(40, self.car.getMileage())
        self.car.move(3.5)
        self.assertEqual(43.5, self.car.getMileage())
        self.car.move(0)
        self.assertEqual(43.5, self.car.getMileage())
        self.car.setMileage(20)
        self.assertEqual(20, self.car.getMileage())

    def test_car_make(self):
        # The default value for make is ' ' from the Car class so this is called.  The make is set to Ferrari
        # tests that the value has successfully changed to Ferrari.  Next it is set to Ford and finally Honda Civic.
        self.assertEqual(' ', self.car.getMake())
        self.car.setMake('Ferrari')
        self.assertEqual('Ferrari', self.car.getMake())
        self.car.setMake('Ford')
        self.assertEqual('Ford', self.car.getMake())
        self.car.setMake('Honda Civic')
        self.assertEqual('Honda Civic', self.car.getMake())

    def test_car_engineSize(self):
        # The default engineSize value is ' ' so this is tested first followed by 1.8 and 3.0
        self.assertEqual(' ', self.car.getEngineSize())
        self.car.setEngineSize(1.8)
        self.assertEqual(1.8, self.car.getEngineSize())
        self.car.setEngineSize(3.0)
        self.assertEqual(3.0, self.car.getEngineSize())

    def test_car_colour_and_paint(self):
        # First the default value for colour of ' ' is tested called from the Car class.  Next the paint function is
        # used to test changing the colour of a car object.  In this case the car is painted red so the colour
        # becomes red which is tested next.  The paint function is applied using blue and finally the setColour method
        # of the Car class that takes in the value green in this case using the getColour method which returns the
        # value held in colour and tests it against the string which is correct.
        self.assertEqual(' ', self.car.getColour())
        self.car.paint('red')
        self.assertEqual('red', self.car.getColour())
        self.car.paint('blue')
        self.assertEqual('blue', self.car.getColour())
        self.car.setColour('green')
        self.assertEqual('green', self.car.getColour())
开发者ID:padraicmannion,项目名称:big-data-programming,代码行数:61,代码来源:car_test.py


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