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_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_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 _generate_race(self): drivers_for_curr_race = [] participants = self._read_json('cars.json') for person in participants['people']: person_car = Car(person['car'], person['model'], person['max_speed']) curr_driver = Driver(person['name'], person_car) drivers_for_curr_race.append(curr_driver) curr_race = Race(drivers_for_curr_race) return curr_race
from class_car import Car my_new_car = Car('audi','a4',2016) print(my_new_car.get_discriptive_name()) my_new_car.odometer_reading = 23 my_new_car.read_odometer()
y_coord = SCREEN_HEIGHT / 2 # Get and set position of road image_road = pygame.image.load("data/road.jpg").convert() image_road_position = [0, 0] # Get and set position of road image_car = pygame.image.load("data/car.png").convert() start_top_x = -200 start_top_y = 50 image_car_start_position = [start_top_x, start_top_y] cars_list = [] cars_to_del_list = [] for count in range(2): new_car = Car() new_car.create_car() new_car.id = count new_car.x = count * 800 - new_car.WIDTH # 300 random_speed = randint(new_car.speed_min, new_car.speed_max) new_car.speed = random_speed / 3.6 cars_list.append(new_car) # To test cars_list[0].speed = 60 / 3.6 cars_list[1].speed = 30 / 3.6 select_car = 0 SECUND = 0 FRAMES = -1 MIN_SPACE = 500 table_height = 0
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_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_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_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')
def test_object_type(self): honda = Car('Honda') self.assertTrue((type(honda) is Car), msg='The object should be a type of `Car`')
from class_car import Car from class_electric_car import ElectricCar # from class_electric_car import * my_beetle = Car('volkswagen', 'beetle', 2016) print(my_beetle.get_descriptive_name()) my_tesla = ElectricCar('tesla', 'roadster', 2016) print(my_tesla.get_descriptive_name()) # import class_electric_car # # # my_beetle = class_electric_car.Car('volkswagen', 'beetle', 2016) # print(my_beetle.get_descriptive_name()) # my_tesla = class_electric_car.ElectricCar('tesla', 'roadster', 2016) # print(my_tesla.get_descriptive_name())
from class_car import Car car = Car() car.turnRight()