def test_car_wheels(self): man = Car('MAN', 'Truck', 'trailer') koenigsegg = Car('Koenigsegg', 'Agera R') self.assertEqual( [8, 4], [man.num_of_wheels, koenigsegg.num_of_wheels], msg= 'The car shoud have four (4) wheels except its a type of trailer')
def test_leave_method_returns_correct(self): self.carpark.createParkingLots(2) car1 = Car("KA-01-HH-1234", "Red") car2 = Car("KA-01-HH-1235", "Gray") self.carpark.parkCar(car1) self.carpark.parkCar(car2) res = self.carpark.leave(2) self.assertEqual(True, res)
def test_parkCar_method_returns_negOne_carpark_full(self): self.carpark.createParkingLots(2) car1 = Car("KA-01-HH-1234", "Red") car2 = Car("KA-01-HH-1235", "Gray") car3 = Car("KA-01-HH-1236", "Blue") self.carpark.parkCar(car1) self.carpark.parkCar(car2) res = self.carpark.parkCar(car3) self.assertEqual(-1, res)
def test_car_speed2(self): man = Car('Mercedes', 'SLR500') parked_speed = man.speed moving_speed = man.drive(3).speed self.assertListEqual( [parked_speed, moving_speed], [0, 1000], msg= 'The Mercedes should have speed 0 km/h until you put `the pedal to the metal`' )
def test_car_speed(self): man = Car('MAN', 'Truck', 'trailer') parked_speed = man.speed moving_speed = man.drive(7).speed self.assertListEqual( [parked_speed, moving_speed], [0, 77], msg= 'The Trailer should have speed 0 km/h until you put `the pedal to the metal`' )
def test_car_doors(self): opel = Car('Opel', 'Omega 3') porshe = Car('Porshe', '911 Turbo') self.assertListEqual( [ opel.num_of_doors, porshe.num_of_doors, Car('Koenigsegg', 'Agera R').num_of_doors ], [4, 2, 2], msg= 'The car shoud have four (4) doors except its a Porshe or Koenigsegg' )
def test_drive_car(self): man = Car('MAN', 'Truck', 'trailer') moving_man = man.drive(7) moving_man_instance = isinstance(moving_man, Car) moving_man_type = type(moving_man) is Car self.assertListEqual( [True, True, man.speed], [moving_man_instance, moving_man_type, moving_man.speed], msg= 'The car drive function should return the instance of the Car class' )
class TestCarMethods(unittest.TestCase): def setUp(self): self.car1 = Car("KA-01-HH-1234", "White") self.car2 = Car("KA-02-HH-1234", "Black") self.car3 = Car("KA-03-HH-1234", "black") def test_get_car_color_is_lowercase(self): self.assertEqual(self.car1.getColor(), "white") def test_get_car_color_compare_uppercase_and_lowercase(self): self.assertEqual(self.car2.getColor(), self.car2.getColor()) def test_get_car_reg_no(self): self.assertEqual(self.car1.getRegNo(), "KA-01-HH-1234")
def parse_action(self,inputs): if inputs[0] == "exit": return elif inputs[0] == "create_parking_lot": if self.validate_input(inputs,1): res = self.__interface.create_parking_lots(int(inputs[1])) if res > 0: return "Created a parking lot with " + str(res) + " slots" else: return "Parking lot already exists" elif inputs[0] == "park": if self.validate_input(inputs,2): car = Car(inputs[1],inputs[2]) res = self.__interface.park_car(car) if res > 0: return "Allocated slot number: " + str(res) else: return "Sorry, parking lot is full" elif inputs[0] == "leave": if self.validate_input(inputs,1): res = self.__interface.leave_car(int(inputs[1])) if res: return "Slot number " + inputs[1] + " is free" else: return "No such slot number in parking lot" elif inputs[0] == "status": print("Slot No.".ljust(12) + "Registration No".ljust(19) + "Colour") res = self.__interface.print_status() for line in res: print(line) return elif inputs[0] == "registration_numbers_for_cars_with_colour": res = self.__interface.get_regNum_for_colour(inputs[1]) if len(res) == 0: return "Not Found" printStr = (",").join(res) return printStr elif inputs[0] == "slot_numbers_for_cars_with_colour": res = self.__interface.get_slotNum_for_colour(inputs[1]) if len(res) == 0: return "Not Found" printStr = (",").join(res) return printStr elif inputs[0] == "slot_number_for_registration_number": res = self.__interface.get_slotNum_for_regNum(inputs[1]) if res > 0: return str(res) return "Not found" return "Invalid Input! Please check your input and try your command again."
def test_default_car_name(self): gm = Car() self.assertEqual( 'General', gm.name, msg= 'The car should be called `General` if no name was passed as an argument' )
def test_default_car_model(self): gm = Car() self.assertEqual( 'GM', gm.model, msg= "The car's model should be called `GM` if no model was passed as an argument" )
def newCar(self, reg_no, color): car = Car(reg_no, color) try: slot = self.lot.index(None) self.lot[slot] = car return slot + 1 except ValueError: return -1
def test_car_getDescription_method_returns_correct_result(self): c = Car("Ford Mustang", "red", "GT350") print(c.getDescription(), "Ford MustangGT350 in red color") print(c.getName(), "Ford Mustang")
def test_carCreation_correct_regno(self): car = Car("KA-01-HH-9980", "Black") res = car.getRegNo() self.assertEquals("KA-01-HH-9980", res)
def test_carCreation_correct_colour(self): car = Car("KA-01-HH-9980", "Black") res = car.getColour() self.assertEquals("Black", res)
from flask import Flask, jsonify, Response from flask_cors import cross_origin from app.camera import Camera from app.car import Car app = Flask(__name__) car = Car() car.start() @app.route("/health", methods=["GET"]) def health(): return jsonify({"status": "OK"}) @cross_origin() @app.route('/') def video_feed(): camera = Camera() return Response(camera.stream(), mimetype='multipart/x-mixed-replace; boundary=frame') if __name__ == "__main__": app.run(host='0.0.0.0', port=8081, debug=True) print("Camera is down now")
def test_parkCar_method_returns_negOne_carpark_not_created(self): car3 = Car("KA-01-HH-1236", "Blue") res = self.carpark.parkCar(car3) self.assertEqual(-1, res)
def test_parkCar_method_returns_correct(self): self.carpark.createParkingLots(2) car = Car("KA-01-HH-9988", "Blue") res = self.carpark.parkCar(car) self.assertEqual(1, res)
def test_object_type(self): honda = Car('Honda') self.assertTrue((type(honda) is Car), msg='The object should be a type of `Car`')
def setUp(self): self.car1 = Car("KA-01-HH-1234", "White") self.car2 = Car("KA-02-HH-1234", "Black") self.car3 = Car("KA-03-HH-1234", "black")
def test_car_properties(self): toyota = Car('Toyota', 'Corolla') self.assertListEqual( ['Toyota', 'Corolla'], [toyota.name, toyota.model], msg='The car name and model should be a property of the car')
def test_car_instance(self): honda = Car('Honda') self.assertIsInstance( honda, Car, msg='The object should be an instance of the `Car` class')
def test_car_type(self): koenigsegg = Car('Koenigsegg', 'Agera R') self.assertTrue( koenigsegg.is_saloon(), msg='The car type should be saloon if it is not a trailer')
def test_new_car(self): car = Car("KA-01-HH-1234", "White") reg_no = car.reg_no self.assertEqual("KA-01-HH-1234", reg_no) color = car.color self.assertEqual("White", color)