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


Python Car.getMake方法代码示例

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


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

示例1: TestCar

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMake [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

示例2: TestCar

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMake [as 别名]
class TestCar(unittest.TestCase):

    def setUp(self):
        self.car = Car()

    def test_default_constructor(self):
        self.assertEquals('', self.car.make)
        self.assertEquals('', self.car.model)

    def test_car_get_method(self):
        self.assertEquals('', self.car.getMake())
        self.assertEquals('', self.car.getModel())

    def test_car_set_method(self):
        self.car.setMake('Mercedes')
        self.car.setModel('e230')
        self.assertEquals('Mercedes', self.car.getMake())
        self.assertEquals('e230', self.car.getModel())
开发者ID:wade12,项目名称:ProgrammingForBigDataCA2CarRental,代码行数:20,代码来源:car_test.py

示例3: TestCar

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMake [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())
开发者ID:evelynkirwan,项目名称:ev_prog_big_data,代码行数:21,代码来源:test_car.py

示例4: Car

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMake [as 别名]
# to the user.  red_car is the name of the 1st object that takes in the functions from the generic Car base class.
# DBS Car Rental is the name of the client so they will appear on the welcome message.

from car import Car, ElectricCar, PetrolCar, DieselCar, HybridCar

print 'Welcome to DBS Car Rental below is a list of available cars and the car details\n.'
red_car = Car()

# setMake calls the function from the Car class with the same name.  It has 2 variables self and make.  I
# am passing in the string Ferrari as the value for make.  This allows the app program to set a value
# 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

开发者ID:padraicmannion,项目名称:big-data-programming,代码行数:31,代码来源:car_app.py

示例5: Car

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import getMake [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
开发者ID:evelynkirwan,项目名称:ev_prog_big_data,代码行数:25,代码来源:car_app.py


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