Esempio n. 1
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))
Esempio n. 3
0
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 '------------------'

# Hybrid car
car4 = HybridCar()
car4.setMake('Ford')
car4.setModel('Fusion Hybrid')
car4.setColour('Blue')
car4.setMileage(600)
car4.setNumberVoltCells(28)
print 'Hybrid car type: ' + car4.getMake()
print 'Model: ' + car4.getModel()
Esempio n. 4
0
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.
carE = ElectricCar()
carE.setMake("Nissan Leaf")
carE.setColour("Green")
carE.setNumberFuelCells(4)
carE.setMileage(450)
print " Make of Electric car is    :" + carE.getMake()
print " Colour of the car is       :" + carE.getColour()
print " Number of fuel cells       :" + str(carE.getNumberFuelCells())
print " Milegae of Electric car is :" + str(carE.getMileage())
class TestDieselCar(unittest.TestCase):
    def setUp(self):
        # The DieselCar calls itself using self.
        self.diesel_car = DieselCar()

    def test_DieselCar_fuel_cylinders(self):
        # This tests fuel_cylinders for a DieselCar class similar to a petrol car however the default value for
        # number of cylinders is higher for diesel.  Then setNumberOfFuelCylinders method calls the function
        # from the base class DieselCar to change the value to 8.  This is tested and confirmed to be true.
        # The next tests test cylinders for the values 2 and 4 which are confirmed in the test cases as true.
        self.assertEqual(5, self.diesel_car.getNumberOfFuelCylinders())
        self.diesel_car.setNumberOfFuelCylinders(8)
        self.assertEqual(8, self.diesel_car.getNumberOfFuelCylinders())
        self.diesel_car.setNumberOfFuelCylinders(2)
        self.assertEqual(2, self.diesel_car.getNumberOfFuelCylinders())
        self.diesel_car.setNumberOfFuelCylinders(4)
        self.assertEqual(4, self.diesel_car.getNumberOfFuelCylinders())

    def test_DieselCar_mileage_and_move(self):
        # Function for testing the mileage of a DieselCar class.  As with other cars the default value is 0.
        # The move function is called taking the value 8.  This moves the car by 8km's.  Next it is increased
        # by 20 to make 28, tested with increasing by 0 and remains 28.  The setMileage function calls the function
        # in the DieselCar class which inherits the function from the Car class.  This sets mileage at 30 which is
        # tested and is true and lastly move by 7.5 to increase mileage to 37.5 which is tested and is true.
        self.assertEqual(0, self.diesel_car.getMileage())
        self.diesel_car.move(8)
        self.assertEqual(8, self.diesel_car.getMileage())
        self.diesel_car.move(20)
        self.assertEqual(28, self.diesel_car.getMileage())
        self.diesel_car.move(0)
        self.assertEqual(28, self.diesel_car.getMileage())
        self.diesel_car.setMileage(30)
        self.assertEqual(30, self.diesel_car.getMileage())
        self.diesel_car.move(7.5)
        self.assertEqual(37.5, self.diesel_car.getMileage())

    def test_DieselCar_make(self):
        # Testing make function for DieselCar.
        self.assertEqual(' ', self.diesel_car.getMake())
        self.diesel_car.setMake('Chevy')
        self.assertEqual('Chevy', self.diesel_car.getMake())
        self.diesel_car.setMake('Chevy Impala')
        self.assertEqual('Chevy Impala', self.diesel_car.getMake())
        self.diesel_car.setMake('Chevrolet Silverado 2500 HD')
        self.assertEqual('Chevrolet Silverado 2500 HD', self.diesel_car.getMake())

    def test_DieselCar_engineSize(self):
        # Testing engineSize for DieselCar class.
        self.assertEqual(' ', self.diesel_car.getEngineSize())
        self.diesel_car.setEngineSize(3.3)
        self.assertEqual(3.3, self.diesel_car.getEngineSize())
        self.diesel_car.setEngineSize(3.5)
        self.assertEqual(3.5, self.diesel_car.getEngineSize())

    def test_DieselCar_colour_and_paint(self):
        # Testing colour and paint for DieselCar Class.
        self.assertEqual(' ', self.diesel_car.getColour())
        self.diesel_car.paint('silver')
        self.assertEqual('silver', self.diesel_car.getColour())
        self.diesel_car.setColour('white')
        self.assertEqual('white', self.diesel_car.getColour())

    class TestHybridCar(unittest.TestCase):
        def setUp(self):
            # The HybridCar calls itself using self.
            self.hybrid_car = HybridCar()

        def test_HybridCar_fuel_cylinders(self):
            # Similar to petrol and diesel except default value is 1.  The default value is tested as well as 4, 6
            # and 3 which all result in true.
            self.assertEqual(1, self.hybrid_car.getNumberOfFuelCylinders())
            self.hybrid_car.setNumberOfFuelCylinders(4)
            self.assertEqual(4, self.hybrid_car.getNumberOfFuelCylinders())
            self.hybrid_car.setNumberOfFuelCylinders(6)
            self.assertEqual(6, self.hybrid_car.getNumberOfFuelCylinders())
            self.hybrid_car.setNumberOfFuelCylinders(3)
            self.assertEqual(3, self.hybrid_car.getNumberOfFuelCylinders())

        def test_HybridCar_fuel_cells(self):
            # Similar to ElectricCar test_car_fuel_cells.  The default value 1 is tested as well as 4 and 2.
            self.assertEqual(1, self.hybrid_car.getNumberOfFuelCells())
            self.hybrid_car.setNumberOfFuelCells(4)
            self.assertEqual(4, self.hybrid_car.getNumberOfFuelCells())
            self.hybrid_car.setNumberOfFuelCells(2)
            self.assertEqual(2, self.hybrid_car.getNumberOfFuelCells())

        def test_HybridCar_mileage_and_move(self):
            # As in other cases testing the mileage default value.  Then entering a value for move to ensure
            # it moves that amount to test the mileage of a car.  The car is moved by 7.7 to make 19.7 moved 0
            # output stays the same and lastly setMileage is tested with a value of 15 which is true.
            self.assertEqual(0, self.hybrid_car.getMileage())
            self.hybrid_car.move(12)
            self.assertEqual(12, self.hybrid_car.getMileage())
            self.hybrid_car.move(7.7)
            self.assertEqual(19.7, self.hybrid_car.getMileage())
            self.hybrid_car.move(0)
            self.assertEqual(19.7, self.hybrid_car.getMileage())
            self.hybrid_car.setMileage(15)
            self.assertEqual(15, self.hybrid_car.getMileage())

        def test_HybridCar_make(self):
            # Testing make function for HybridCar.
            self.assertEqual(' ', self.hybrid_car.getMake())
            self.hybrid_car.setMake('Chevrolet Malibu')
            self.assertEqual('Chevrolet Malibu', self.hybrid_car.getMake())
            self.hybrid_car.setMake('Chevrolet Cruz')
            self.assertEqual('Chevrolet Cruz', self.hybrid_car.getMake())

        def test_HybridCar_engineSize(self):
            # Testing engineSize for HybridCar.
            self.assertEqual(' ', self.hybrid_car.getEngineSize())
            self.hybrid_car.setEngineSize(1.6)
            self.assertEqual(1.6, self.hybrid_car.getEngineSize())
            self.hybrid_car.setEngineSize(1.8)
            self.assertEqual(1.8, self.hybrid_car.getEngineSize())

        def test_HybridCar_colour_and_paint(self):
            # Testing colour and paint for HybridCar.
            self.assertEqual(' ', self.hybrid_car.getColour())
            self.hybrid_car.paint('red')
            self.assertEqual('red', self.hybrid_car.getColour())
            self.hybrid_car.setColour('light blue')
            self.assertEqual('light blue', self.hybrid_car.getColour())