def test_returncar_for_invalid_rentalTime(self): # create a shop and a customer shop = carRental(10) customer = Customer() # let the customer not rent a car a try to return one. request = customer.returncar() self.assertIsNone(shop.returncar(request)) # manually check return function with error values self.assertIsNone(shop.returncar((0, 0, 0)))
def test_returncar_for_invalid_rentalBasis(self): # create a shop and a customer shop = carRental(10) customer = Customer() # create valid rentalTime and cars customer.rentalTime = datetime.now() customer.cars = 3 # create invalid rentalbasis customer.rentalBasis = 7 request = customer.returncar() self.assertEqual(shop.returncar(request), 0)
def test_return_car_with_valid_input(self): # create a customer customer = Customer() # create valid rentalTime, rentalBasis, cars now = datetime.now() customer.rentalTime = now customer.rentalBasis = 1 customer.cars = 4 self.assertEqual(customer.returncar(), (now, 1, 4))
def test_returncar_for_invalid_numOfcars(self): # create a shop and a customer shop = carRental(10) customer = Customer() # create valid rentalTime and rentalBasis customer.rentalTime = datetime.now() customer.rentalBasis = 1 # create invalid cars customer.cars = 0 request = customer.returncar() self.assertIsNone(shop.returncar(request))
def test_return_car_with_invalid_input(self): # create a customer customer = Customer() # create valid rentalBasis and cars customer.rentalBasis = 1 customer.cars = 0 # create invalid rentalTime customer.rentalTime = 0 self.assertEqual(customer.returncar(), (0, 0, 0)) if __name__ == '__main__':
def test_return_Car_with_invalid_input(self): # create a customer customer = Customer() # create valid rentalBasis and Car customer.rentalBasis = 1 customer.cars = 0 # create invalid rentalTime customer.rentalTime = 0 self.assertEqual(customer.returnCar(), (0, 0, 0))
def main(): shop = CarRental(100) customer = Customer() while True: print(""" ====== Car Rental Shop ======= 1. Display available cars 2. Request a car on hourly basis $5 3. Request a car on daily basis $20 4. Request a car on weekly basis $60 5. Return a car 6. Exit """) choice = input("Enter choice: ") try: choice = int(choice) except ValueError: print("That's not an int!") continue if choice == 1: shop.displaystock() elif choice == 2: customer.rentalTime = shop.rentCarOnHourlyBasis(customer.requestCar()) customer.rentalBasis = 1 elif choice == 3: customer.rentalTime = shop.rentCarOnDailyBasis(customer.requestCar()) customer.rentalBasis = 2 elif choice == 4: customer.rentalTime = shop.rentCarOnWeeklyBasis(customer.requestCar()) customer.rentalBasis = 3 elif choice == 5: customer.bill = shop.returnCar(customer.returnCar()) customer.rentalBasis, customer.rentalTime, customer.cars = 0,0,0 elif choice == 6: break else: print("Invalid input. Please enter number between 1-6 ") print("Thank you for using the car rental system.")
def test_returnCar_for_valid_credentials(self): # create a shop and a various customers shop = CarRental(50) customer1 = Customer() customer2 = Customer() customer3 = Customer() customer4 = Customer() customer5 = Customer() customer6 = Customer() # create valid rentalBasis for each customer customer1.rentalBasis = 1 # hourly customer2.rentalBasis = 1 # hourly customer3.rentalBasis = 2 # daily customer4.rentalBasis = 2 # daily customer5.rentalBasis = 3 # weekly customer6.rentalBasis = 3 # weekly # create valid bikes for each customer customer1.cars = 1 customer2.cars = 5 # eligible for family discount 30% customer3.cars = 2 customer4.cars = 8 customer5.cars = 15 customer6.cars = 30 # create past valid rental times for each customer customer1.rentalTime = datetime.now() + timedelta(hours=-4) customer2.rentalTime = datetime.now() + timedelta(hours=-23) customer3.rentalTime = datetime.now() + timedelta(days=-4) customer4.rentalTime = datetime.now() + timedelta(days=-13) customer5.rentalTime = datetime.now() + timedelta(weeks=-6) customer6.rentalTime = datetime.now() + timedelta(weeks=-12) # make all customers return their bikes request1 = customer1.returnCar() request2 = customer2.returnCar() request3 = customer3.returnCar() request4 = customer4.returnCar() request5 = customer5.returnCar() request6 = customer6.returnCar() # check if all of them get correct bill self.assertEqual(shop.returnCar(request1), 20) self.assertEqual(shop.returnCar(request2), 402.5) self.assertEqual(shop.returnCar(request3), 160) self.assertEqual(shop.returnCar(request4), 2080) self.assertEqual(shop.returnCar(request5), 5400) self.assertEqual(shop.returnCar(request6), 21600)