def test_garages_count(self): cesar = Cesar('Alfred') garage_1 = Garage(4) garage_2 = Garage(2) garage_3 = Garage(8) cesar.add_garage(garage_1) cesar.add_garage(garage_2) cesar.add_garage(garage_3) self.assertEqual(cesar.garages_count(), 3)
def test_remove_car(self): garage = Garage(3) car_1 = Car(10, 10) car_2 = Car(11, 11) car_3 = Car(12, 12) garage.add_car(car_1) garage.add_car(car_2) garage.add_car(car_3) garage.remove(car_3) self.assertEqual(garage.free_place(), 1)
def json_hook(obj): if 'set' in obj: return set(obj) car_args = object_comparison(obj, Car) cesar_args = object_comparison(obj, Cesar) garage_args = object_comparison(obj, Garage) if all(car_args): create_car = Car( price=obj['price'], type_car=obj['type_car'], producer=obj['producer'], mileage=obj['mileage'] ) create_car.number = obj['number'] return create_car if all(garage_args): create_garage = Garage( town=obj['town'], places=obj['places'], cars=obj['cars'], owner=obj['owner'] ) return create_garage if all(cesar_args): create_cesar = Cesar(name=obj['name'], garages=obj['garages']) create_cesar.register_id = obj['register_id'] return create_cesar return obj
def test_hit_hat(self): garage = Garage(3) car_1 = Car(110, 10) car_2 = Car(110, 11) car_3 = Car(110, 12) garage.add_car(car_1) garage.add_car(car_2) garage.add_car(car_3) self.assertEqual(garage.hit_hat(), 330)
def test_hit_hat(self): cesar = Cesar('Alfred') garage_1 = Garage(4) garage_2 = Garage(2) garage_3 = Garage(8) car_1 = Car(25000, 10000) car_2 = Car(30000, 5000) car_3 = Car(3000, 500) car_4 = Car(300, 50) car_5 = Car(300000, 50000) car_6 = Car(3000000, 500000) cesar.add_garage(garage_1) cesar.add_garage(garage_2) cesar.add_garage(garage_3) cesar.add_car(car_1, garage_1) cesar.add_car(car_2, garage_1) cesar.add_car(car_3, garage_2) cesar.add_car(car_4, garage_2) cesar.add_car(car_5, garage_3) cesar.add_car(car_6, garage_3) self.assertEqual(cesar.hit_hat(), 3358300)
def test_equal(self): cesar_1 = Cesar('Alfred') cesar_2 = Cesar('Hector') garage_1 = Garage(2) garage_2 = Garage(2) garage_3 = Garage(2) garage_4 = Garage(2) car_1 = Car(100, 10000) car_2 = Car(100, 5000) car_3 = Car(100, 500) car_4 = Car(100, 50) car_5 = Car(100, 50000) car_6 = Car(100, 500000) cesar_1.add_garage(garage_1) cesar_1.add_garage(garage_2) cesar_2.add_garage(garage_3) cesar_2.add_garage(garage_4) cesar_1.add_car(car_1, garage_1) cesar_1.add_car(car_2, garage_2) cesar_1.add_car(car_3, garage_2) cesar_2.add_car(car_4, garage_3) cesar_2.add_car(car_5, garage_4) cesar_2.add_car(car_6, garage_4) self.assertEqual(cesar_1.hit_hat(), cesar_2.hit_hat())
def test_add_car(self): garage = Garage(2) car_1 = Car(10, 10) car_2 = Car(11, 11) car_3 = Car(12, 12) garage.add_car(car_1) garage.add_car(car_2) self.assertEqual(garage.free_place(), 0) self.assertEqual(garage.add_car(car_3), "you do not have enough space in garage")
def test_add_car(self): cesar = Cesar('Alfred') garage_1 = Garage(4) garage_2 = Garage(2) garage_3 = Garage(8) car_1 = Car(25000, 10000) car_2 = Car(30000, 5000) cesar.add_garage(garage_1) cesar.add_garage(garage_2) cesar.add_garage(garage_3) cesar.add_car(car_1, garage_1) # add car with specific garage cesar.add_car(car_2) # add car without specific garage self.assertEqual(garage_1.free_place(), 3) # check our method self.assertEqual(garage_3.free_place(), 7) # check our method
bmw = Car(price=35000.145, type_car='Sedan', producer='BMW', mileage=1) bmw3 = Car(price=random.randint(1000, 100000) * 1.2, type_car=random.choice(CARS_TYPES), producer=random.choice(CARS_PRODUCER), mileage=random.randint(10, 1000) * 1.2) bmw4 = Car(price=random.randint(1000, 100000) * 1.2, type_car=random.choice(CARS_TYPES), producer=random.choice(CARS_PRODUCER), mileage=random.randint(10, 1000) * 1.2) ford = Car(price=25000.145, type_car='Sedan', producer='Ford', mileage=1) cars_list = [bmw3, bmw4, ford] garages_list = [ Garage(town=random.choice(TOWNS), places=random.randint(1, 7)) for _ in range(3) ] garages_list2 = [ Garage(town=random.choice(TOWNS), places=3) for _ in range(4) ] gara = Garage(town='Amsterdam', places=3) gara2 = Garage(town='Prague', places=3) for car in cars_list: gara.add(car) gara.add(ford) gara2.add(ford) gara2.add(bmw) cesas = Cesar('Petro', garages_list) cesas2 = Cesar('Vasia', garages_list2)
def garage_from_json(data): places = data['places'] # owner = data['owner'] gr = Garage(places=places) return gr
Advanced Добавити опрацьовку формату ini """ from objects_and_classes.homework.homework import ( Cesar, Garage, Car ) import json import ruamel.yaml from ruamel.yaml import YAML import pickle heorh = Cesar('Heorh') king_garage = Garage(4) elite_car = Car(500000, 5000) # ___________convert by JSON____________ def heorh_to_json(obj: Cesar): data = {'name': obj.name} return data def king_garage_to_json(obj: Garage): data = {'places': obj.places, 'owner': None} return data
def test_add_garage(self): cesar = Cesar('Alfred') garage_1 = Garage(6) cesar.add_garage(garage_1) self.assertEqual(len(cesar.garages), 1)
def test_free_place(self): garage = Garage(7) car = Car(10, 100) garage.add_car(car) self.assertEqual(garage.free_place(), 6)
producer=random.choice(CARS_PRODUCER), mileage=random.uniform(1000, 5000)) car4 = Car(price=random.uniform(5000, 50000), car_type=random.choice(CARS_TYPES), producer=random.choice(CARS_PRODUCER), mileage=random.uniform(1000, 5000)) car5 = Car(price=random.uniform(5000, 50000), car_type=random.choice(CARS_TYPES), producer=random.choice(CARS_PRODUCER), mileage=random.uniform(1000, 5000)) car6 = Car(price=random.uniform(5000, 50000), car_type=random.choice(CARS_TYPES), producer=random.choice(CARS_PRODUCER), mileage=random.uniform(1000, 5000)) garage1 = Garage(town=random.choice(TOWNS), places=2) garage2 = Garage(town=random.choice(TOWNS), places=3) garage3 = Garage(town=random.choice(TOWNS), places=4) garage4 = Garage(town=random.choice(TOWNS), places=4, owner=c2, cars=[car5, car4]) # print(garage4) # print("\n - ACTION") garage1.add(car1) garage2.add(car2) garage3.add(car3) c4 = Cesar(name="Gover", garages=[garage1])