def main(): """Demo test code to show how to use car class.""" my_car = Car("Car", 180) my_car.drive(30) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car)) limo = Car("limo", 100) limo.add_fuel(20) print("The {} has {} units of fuel. The odometer reads: {}".format(limo.name, limo.fuel, limo.odometer)) limo.drive(115) print("The {} has {} units of fuel. The odometer reads: {}".format(limo.name, limo.fuel, limo.odometer))
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_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')
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`')
# 04/03/2021 This file is for executing the cars.py classes # Execution # drive() we will not have an access to this function name yet from cars import Car mycar = Car("BMW", "530xi", "black") # Car is the class, yourcar = Car("Lexus", "Lexus IS", "silver") mycar.drive() mycar.set_odometer_reader(50) mycar.get_description() yourcar.do_something() mycar.get_description() print("***************************") yourcar.get_description() yourcar.drive() yourcar.set_odometer_reader(30) yourcar.get_description() ## 04/03/2021 print("___Electric car instances______") class ElecricCar(Car): def __init__(self, brand, model, color): super().__init__(brand, model, color) self.battery_size = 60