コード例 #1
0
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())
コード例 #2
0
	def process_rental(self):
		answer = str.lower(raw_input('   Would you like to rent a car? Yes: "Y", No: "N" : '))
		if answer == 'y':
			answer = str.lower(raw_input('  Choose "p" for Petrol, "d" for Diesel, "e" for electric and "h" for Hybrid:   '))
			amount = int(raw_input('   How many would you like?  '))
			if answer == 'p':
				self.rent(self.petrol_cars, amount)
				choice = raw_input('   Write the model you would like: Toyota, Kia, Volkswagon, Ford:    ')
				petrol_car = PetrolCar()
				petrol_car.setMake(choice)
				mileage = int(raw_input('   Record the mileage here before you start driving. '))
				petrol_car.setMileage(mileage)
				print 'Your car is: ', petrol_car.getMake()
				print 'The current mileage is set at: ',  petrol_car.getMileage()
				return mileage
				
				
			elif answer == 'd':
				self.rent(self.diesel_cars, amount)
				choice = raw_input('   Write the model you would like: Nissan or Hyundai:  ')
				diesel_car = DieselCar()
				diesel_car.setMake(choice)
				mileage = int(raw_input('   Record the mileage here before you start driving. '))
				diesel_car.setMileage(mileage)
				print 'Your car is: ', diesel_car.getMake()
				print 'The current mileage is set at: ',  diesel_car.getMileage()
				return mileage
				
				
			elif answer == 'e':
				self.rent(self.electric_cars, amount)
				choice = raw_input('   We have a Nissan or a Tesla, please write your choice:   ')
				electric_car = ElectricCar()
				electric_car.setMake(choice)
				mileage = int(raw_input('   Record your mileage here before you start driving. '))
				electric_car.setMileage(mileage)
				print 'Your model is', electric_car.getMake()
				print 'Fuel cells available are', electric_car.getNumberFuelCells()
				print 'Your current mileage is set to:  ', electric_car.getMileage()
				return mileage
			else:
				self.rent(self.hybrid_cars, amount)			
				choice = raw_input(' what hybrid do you want, Prius or Lexus?  ')
				hybrid_car = HybridCar()
				hybrid_car.setMake(choice)
				mileage = int(raw_input('   Record your mileage here before you start driving.  '))
				hybrid_car.setMileage(mileage)
				print 'Your model is', hybrid_car.getMake()
				print 'Our hybrid cars come with :', hybrid_car.getNumberFuelCells(), 'fuel cells and ', hybrid_car.getNumberCylinders(), 'cylinders '
				print 'Your current mileage is set to:  ', hybrid_car.getMileage()
				return mileage
				
			car_fleet = CarFleet()
			car_fleet.rentCar(amount)
		if answer == 'n':
			self.process_returnCar()
		self.stock_count()
コード例 #3
0
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()
car5.setMake('Mercedes Benz')
print '\nOur diesel option is ' + car4.getMake()

car5.setColour('Silver')
コード例 #4
0
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())
print 'Mileage on the clock: ' + str(car3.getMileage())
print '------------------'
コード例 #5
0
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 "_________________________________________"

#Electric car details.