class TestPetrolCar(unittest.TestCase):

    def setUp(self):
        # The PetrolCar class calls itself.
        self.petrol_car = PetrolCar()

    def test_PetrolCar_fuel_cylinders(self):
        # Testing a PetrolCar the default value of 3 is called from the base class Petrol Car and is tested to
        # ensure the base class PetrolCar functions are being correctly implemented.  The setNumberOfFuelCylinders
        # in this case changes the default value from 3 to 7 this is tested and it has become 7 so is true.
        # This is similar to ElectricCar FuelCells implementation but with cylinders instead of cells.
        # The cylinders are tested with values for 2 and 5 which pass.
        self.assertEqual(3, self.petrol_car.getNumberOfFuelCylinders())
        self.petrol_car.setNumberOfFuelCylinders(7)
        self.assertEqual(7, self.petrol_car.getNumberOfFuelCylinders())
        self.petrol_car.setNumberOfFuelCylinders(2)
        self.assertEqual(2, self.petrol_car.getNumberOfFuelCylinders())
        self.petrol_car.setNumberOfFuelCylinders(5)
        self.assertEqual(5, self.petrol_car.getNumberOfFuelCylinders())

    def test_PetrolCar_mileage_and_move(self):
        # Ths function tests the mileage of the PetrolCar class.  As in the other tests it starts with the default
        # value from the base class.  Move is then called using the value 5 this is tested against the value
        # retrieved from getMileage which is now increased to 5 so it's true.  It is increased by 12 to make 17,
        # tested by adding 0 still gives 17, tested adding a decimal 6.5 to get 23.5.
        self.assertEqual(0, self.petrol_car.getMileage())
        self.petrol_car.move(5)
        self.assertEqual(5, self.petrol_car.getMileage())
        self.petrol_car.move(12)
        self.assertEqual(17, self.petrol_car.getMileage())
        self.petrol_car.move(0)
        self.assertEqual(17, self.petrol_car.getMileage())
        self.petrol_car.move(6.5)
        self.assertEqual(23.5, self.petrol_car.getMileage())

    def test_PetrolCar_make(self):
        # Testing make function for PetrolCar to ensure correctly inherited from base class Car.
        self.assertEqual(' ', self.petrol_car.getMake())
        self.petrol_car.setMake('Ford')
        self.assertEqual('Ford', self.petrol_car.getMake())
        self.petrol_car.setMake('Ford Focus')
        self.assertEqual('Ford Focus', self.petrol_car.getMake())

    def test_PetrolCar_engineSize(self):
        # Testing engineSize for PetrolCar class.
        self.assertEqual(' ', self.petrol_car.getEngineSize())
        self.petrol_car.setEngineSize(2.2)
        self.assertEqual(2.2, self.petrol_car.getEngineSize())
        self.petrol_car.setEngineSize(2.6)
        self.assertEqual(2.6, self.petrol_car.getEngineSize())

    def test_PetrolCar_colour_and_paint(self):
        # Testing colour and paint for PetrolCar Class
        self.assertEqual(' ', self.petrol_car.getColour())
        self.petrol_car.paint('black')
        self.assertEqual('black', self.petrol_car.getColour())
        self.petrol_car.setColour('dark blue')
        self.assertEqual('dark blue', self.petrol_car.getColour())
car3.setNumberOfFuelCells(2)
print('The number of fuel cells is ' + str(car3.getNumberOfFuelCells()))
car3.setNumberOfFuelCylinders(1)
print('The number of fuel cylinders is ' + str(car3.getNumberOfFuelCylinders()))


# Car4 calls the PetrolCar class and performs similar functions as other class'.  The colour is red, mileage
# is set to 150 and increased by 25 to 175kms.  The engine size is set at 2.9.  The petrol car is a Toyota Corolla
# and has 3 cylinders set as the value for the variable NumberOfFuelCylinders.
car4 = PetrolCar()
car4.setMake('Toyota Corolla')
print '\nOur petrol option is ' + car4.getMake()

car4.setColour('Red')
print('The colour is: ' + car4.getColour())

car4.setMileage(150)
car4.move(25)
print('The mileage is ' + str(car4.getMileage())) + 'kms'
car4.engineSize = '2.9'
print 'The engine size is ' + car4.engineSize

car4.setNumberOfFuelCylinders(3)
print('The number of fuel cylinders is ' + str(car4.getNumberOfFuelCylinders()))


# Car5 is calling a DieselCar objects and will implement its functions and variables.  Similar to other class'
# the car sets a model and returns it in this case Mercedes Benz, the colour is set as silver, the mileage is
# 1000 and increased by 40 to 1040 as the mileage returned, the engineSize is 3.2 and the car uses 5 cylinders.
car5 = DieselCar()
Exemplo n.º 3
0
print 'Model: ' + car1.getModel()
print 'Colour: ' + car1.getColour()
print 'Number of fuel cells: ' + str(car1.getNumberFuelCells())
print 'Mileage on the clock: ' + str(car1.getMileage())
print '------------------'

#Petrol car
car2 = PetrolCar()
car2.setMake('Toyota')
car2.setModel('Yaris')
car2.setColour('Green')
car2.setMileage(653)
car2.setNumberCylinders(4)
print 'Petrol car type: ' + car2.getMake()
print 'Model: ' + car2.getModel()
print 'Colour: ' + car2.getColour()
print 'Number of cylinders: ' + str(car2.getNumberCylinders())
print 'Mileage on the clock: ' + str(car2.getMileage())
print '------------------'

# Diesel car
car3 = DieselCar()
car3.setMake('Ford')
car3.setModel('Mondeo')
car3.setColour('Black')
car3.setMileage(2500)
car3.setNumberDieselCylinders(6)
print 'Diesel car type: ' + car3.getMake()
print 'Model: ' + car3.getModel()
print 'Colour: ' + car3.getColour()
print 'Number of cylinders: ' + str(car3.getNumberDieselCylinders())
Exemplo n.º 4
0
print
print "Welcome to DBS car rental, we have the following types of cars in stock to offer."
print

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

#We made that in our stock we have 40 cars, 4 different types, each type of the same make, model and specifications.

#Petrol car details.
carP = PetrolCar()
carP.setMake("Volkswagen Beetle")
carP.setColour("Blue")
carP.setNumberCylinders(4)
carP.setMileage(1000)
print " Make of Petrol car is      :" + carP.getMake()
print " Colour of the car is       :" + carP.getColour()
print " Number of cylinders        :" + str(carP.getNumberCylinders())
print " Mileage of Petrol car is   :" + str(carP.getMileage())
print "_________________________________________"

#Diesel car details.
carD = DieselCar()
carD.setMake("Audi Q7")
carD.setColour("Silver")
carD.setNumberCylinders(4)
carD.setMileage(500)
print " Make of Diesel car is      :" + carD.getMake()
print " Colour of the car is       :" + carD.getColour()
print " Number of cylinders        :" + str(carD.getNumberCylinders())
print " Milegae of Diesel car is   :" + str(carD.getMileage())
print "_________________________________________"