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_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_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_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 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' )
#importing a class from car_class import Car my_car = Car('audi', 'a6', 2016) print(my_car.get_descriptive_name()) my_car.odometer_reading = 23 my_car.read_odometer() #storing multiple class in a module #from class_elctric import ElectricCar #Importing multiple class in a module #from car import Car, ElectricCar #importing an entire module #import car #“Importing All Classes from a Module” #from module_name import *
def test_is_instance(self): self.assertIsInstance(Car(), Car)
def test_object_type(self): honda = Car('Honda') self.assertTrue((type(honda) is Car), msg='The object should be a type of `Car`')
# ------- Vehicle Parking System for Kigali Arena ------- # # @Authors : Achille Tanwouo and Samuel Anumudu # Import modules / files import time from moto_class import Moto from car_class import Car from truck_class import Truck from controller import Controller queue = [ ] # Here we wish to create an empty array for queuing vehicles for organizational purposes for i in range(30): if i < 10: queue.append(Moto()) time.sleep(0.05) elif 10 < i < 20: queue.append(Car()) time.sleep(0.05) else: queue.append(Truck()) time.sleep(0.05) # Checking for cars in the queue for vehicle in queue: Controller.control_vehicles(vehicle) print(queue)
def test_time_for_car(self): car_1 = Car() self.assertEqual(type(car_1.time), float)
from car_class import Car from mexp import * if __name__ == "__main__": listTesti = [] listTesti.append(Car('Jack', 'benlalla', True, 1)) listTesti.append(Car('Jack2', 'elarrs', False, 5)) listTesti.append(Car('Marc', 'roro', False, 2)) result = find(listTesti, lname = 'roro') print(result)
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_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')
import car_class my_new_car = car_class.Car('audi', 'a4', 2019) print(my_new_car.get_descriptive_name()) my_new_car.odometer_reading = 23 print(my_new_car.get_descriptive_name()) import car_class as CC my_new_car_5 = CC.Car('audi', 'a5', 2019) print(my_new_car_5.get_descriptive_name()) from car_class import Car my_new_car_2 = Car('audi', 'a4', 2018) print(my_new_car_2.get_descriptive_name()) from electric_car import ElectricCar my_new_car_3 = ElectricCar('audi', 'a4', 2019, 150) my_new_car_3.battery.get_battery_size() from electric_car import ElectricCar as EC my_new_car_6 = EC('audi', 'a4', 2019, 200) my_new_car_6.battery.get_battery_size() from electric_car import * my_new_car_4 = Battery(350)
from car_class import Car # импортируем класс Car из отдельного файла car_class.py my_new_car = Car("audi", "a4", 2016) print(my_new_car.get_descriptive_name()) my_new_car.odometer_reading = 23 my_new_car.read_odometer()
def main(): honda = Car() honda.set_make() honda.set_model() honda.set_milage() honda.set_price() honda.set_color() honda.set_maximum_load() honda.set_size_of_trunk() print(honda)
def main(): create_mammals() car = Car() car.set_make() car.set_model() car.set_milage() car.set_price() car.set_color() car.set_maximum_load() car.set_size_of_trunk() print(car) dice = Dice() dice.roll_the_dice() dice.get_side_up() for object in mammal_list: if object.id == dice.side_up: print("Selected animal: ") print(object) check_car_max_load(car, object)
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')
from car_class import Car import threading import time #====prob1 def wait_semaphor(event): event.wait() semaphor = threading.Event() car1 = Car(1, wait_semaphor, (semaphor, )) car2 = Car(2, wait_semaphor, (semaphor, )) car3 = Car(3, wait_semaphor, (semaphor, )) car4 = Car(4, wait_semaphor, (semaphor, )) car1.start() car2.start() car3.start() car4.start() print("Red light") time.sleep(1) print("Yellow light") time.sleep(1) print("Green Light") print("Go!") semaphor.set() #=====
print( "Testing Vehicle with Passengers = 4 and Cargo = 6. Expected result: 4, 3") print(vehicle1.n_passengers) print(vehicle1.size_cargo) print( "\nTesting Vehicle with Passengers = 12 and Cargo = 10. Expected result: 12, 10" ) print(vehicle2.n_passengers) print(vehicle2.size_cargo) # create 2 car instances # make car accelerate and make them break # make car honk and park car1 = Car(4, 6, "Isuzu", 25, 250) car2 = Car(12, 10, "Tesla", 84, 150) print("\nTesting Car accelleration") print(car1.accelerate()) print(car2.accelerate()) print("\nTesting Car breaking") print(car1.breaking()) print(car2.breaking()) print("\nTesting Car honking") print(car1.honk()) print(car2.honk()) print("\nTesting Car parking")
from car_class import Car, ElectricCar # импортировани нескольких определенных классов из одного модуля """from car - импортирование всего модуля""" """from car import * - импортирование всех классов из модуля""" my_beetle = Car("volkswagen", "beetle", 2016) print(my_beetle.get_descriptive_name()) my_tesla = ElectricCar("tesla", "roadstep", 2018) print(my_tesla.get_descriptive_name())