本文整理汇总了Python中car.Car.getMileage方法的典型用法代码示例。如果您正苦于以下问题:Python Car.getMileage方法的具体用法?Python Car.getMileage怎么用?Python Car.getMileage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类car.Car
的用法示例。
在下文中一共展示了Car.getMileage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCar
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMileage [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())
示例2: TestCar
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMileage [as 别名]
class TestCar(unittest.TestCase):
def setUp(self):
self.car = Car()
def test_car_mileage(self):
self.assertEqual(0, self.car.getMileage())
self.car.move(15)
self.assertEqual(15, self.car.getMileage())
def test_car_make(self):
self.assertEqual('', self.car.getMake())
self.car.setMake('Ferrari')
self.assertEqual('Ferrari', self.car.getMake())
def test_car_colour(self):
self.assertEqual('', self.car.getColour())
self.car.paint('red')
self.assertEqual('red', self.car.getColour())
示例3: str
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMileage [as 别名]
# without changing the structure or default value for any variables. getMake calls the function of the same
# name in Car and returns the value of make which is added to the end of the print statement.
# The paint function of the Car class is called which is passed the value red so the default value ' ' isn't used.
# The getColour functions returns the value being stored in colour for red_car which is now red which is printed.
red_car.setMake('Ferrari')
print 'Our most exclusive offer is a ' + red_car.getMake()
red_car.paint('red')
print 'The colour is ' + red_car.getColour()
# The move function passes the value 15 to the Car class and in the move function adds it to the value held in
# mileage this is used to create the new mileage figure and is printed to the screen in kilometers
# The default value for engineSize is ' '. For the red_car I am assigning it the value 3.7. The value of
# engineSize can be changed to any number without changing the Car class.
red_car.move(15)
print 'The mileage is ' + str(red_car.getMileage()) + 'kms'
red_car.engineSize = '3.7'
print 'The engine size is ' + red_car.engineSize
# A ElectricCar object is called by car2 and can now use the functions of an ElectricCar class. Similar functionality
# as red_car in make function. # Unlike the red_car which used the paint function here I am using the setColour
# function which takes in self and colour as variables in this case while. The getColour function returns the value
# held in colour. In this case the value of colour was changed from ' ' to White which is displayed to the user.
car2 = ElectricCar()
car2.setMake('Nissan LEAF')
print '\nOur environment friendly option is ' + car2.getMake()
car2.setColour('White')
print('The colour is ' + car2.getColour())
示例4: Car
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMileage [as 别名]
print 'Sat car_app.py gamma'
from car import Car
red_car = Car()
print 'Colour ' + red_car.getColour()
print 'Mileage ' + str(red_car.getMileage())
print 'Make ' + red_car.getMake()
red_car.setMake('Ferrari')
print 'Make ' + red_car.getMake()
print('Getting a paint job - the new colour is ' + red_car.paint('red'))
print 'Colour ' + red_car.getColour()
print ('Car moved ' + str(red_car.move(15)) + 'kms')
print 'Mileage ' + str(red_car.getMileage())
print 'Engine Size ' + red_car.engineSize
red_car.engineSize = '3.9'
print 'Engine Size ' + red_car.engineSize