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())
Esempio n. 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()
class TestCar(unittest.TestCase):
    def setUp(self):
        self.car = Car()
        self.car1 = ElectricCar(1)
        self.car2 = PetrolCar(2)
        self.car3 = DieselCar(3)
        self.car4 = HybridCar(4)
        self.dealership = Dealership()
        self.dealership.create_current_stock()

    def test_car_mileage(self):
        self.assertEqual(0, self.car.getMileage())
        self.car.move(15)  # this function exists for all child classes of car
        self.assertEqual(15, self.car.getMileage())

    def test_car_make(self):
        self.car.setMake(
            'Ferrari')  # this function exists for all child classes of car
        self.assertEqual('Ferrari', self.car.getMake())
        self.assertEqual('Ferrari', self.car.getMake())
        self.assertEqual('Tesla', self.car1.getMake())
        self.assertEqual('Toyota', self.car2.getMake())
        self.assertEqual('Volkswagon', self.car3.getMake())
        self.assertEqual('Mitsubishi', self.car4.getMake())

    def test_car_colour(self):
        self.assertEqual("Aungier Rental Red - Branded", self.car.getColour())
        self.car.paint(
            'red')  # this function exists for all child classes of car
        self.assertEqual('red', self.car.getColour())

    def test_car_engine(self):
        self.assertEqual('85-kWh', self.car1.getEngineSize())
        self.assertEqual('1.6 ltr', self.car2.getEngineSize())
        self.assertEqual('1.9 ltr', self.car3.getEngineSize())
        self.assertEqual('2.0 ltr', self.car4.getEngineSize())

    def test_rentalprocess(
        self
    ):  # test the rental process by renting out one car and checking it back in. verifies stock levels also
        self.assertEqual(0, len(self.dealership.rented_cars))
        self.assertEqual(8, len(self.dealership.hybrid_cars))
        self.dealership.rent(self.dealership.hybrid_cars, 1, "Test")
        self.assertEqual(1, len(self.dealership.rented_cars))
        self.assertEqual("Test", self.dealership.rented_cars[0][1])
        self.assertEqual(7, len(self.dealership.hybrid_cars))

        original_raw_input = __builtins__.raw_input
        __builtins__.raw_input = lambda _: "135"
        self.assertEqual(self.dealership.rented("Test"), None)
        __builtins__.raw_input = original_raw_input

        self.assertEqual(0, len(self.dealership.rented_cars))
        self.assertEqual(8, len(self.dealership.hybrid_cars))
print('The mileage is ' + str(car3.getMileage())) + 'kms'
car3.engineSize = '3.1'
print 'The engine size is ' + car3.engineSize

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'
Esempio n. 5
0
car1.setNumberFuelCells(2)
print 'Electric car type: ' + car1.getMake()
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()
Esempio n. 6
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 "_________________________________________"