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_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 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
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())
Добавити опрацьовку формату 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 elite_car_to_json(obj: Car):
def test_equal(self): car_1 = Car(100, 100) car_2 = Car(100, 100) self.assertEqual(car_1.price, car_2.price)
def test_less_equal(self): car_1 = Car(100, 100) car_2 = Car(101, 100) self.assertLessEqual(car_1.price, car_2.price)
def test_more_equal(self): car_1 = Car(1000, 100) car_2 = Car(100, 100) self.assertGreaterEqual(car_1.price, car_2.price)
import random from objects_and_classes.homework.constants import CARS_TYPES, CARS_PRODUCER, TOWNS from objects_and_classes.homework.homework import Cesar, Garage, Car c1 = Cesar(name="2131") c2 = Cesar(name="Naumov") c3 = Cesar(name="Gavryl") car1 = Car(price=random.uniform(5000, 50000), car_type=random.choice(CARS_TYPES), producer=random.choice(CARS_PRODUCER), mileage=random.uniform(1000, 5000)) car2 = Car(price=random.uniform(5000, 50000), car_type=random.choice(CARS_TYPES), producer=random.choice(CARS_PRODUCER), mileage=random.uniform(1000, 5000)) car3 = Car(price=random.uniform(5000, 50000), car_type=random.choice(CARS_TYPES), 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),
def test_less_than(self): car_1 = Car(100, 100) car_2 = Car(101, 100) self.assertLess(car_1.price, car_2.price)
def test_change_number(self): car = Car(100, 1000) self.assertNotEqual(car.number, car.change_number())
def test_free_place(self): garage = Garage(7) car = Car(10, 100) garage.add_car(car) self.assertEqual(garage.free_place(), 6)
def car_from_json(data): price = data['price'] mileage = data['mileage'] car = Car(price=price, mileage=mileage) return car
with open(file_pickle, "rb") as file: load_file = pickle.load(file) return load_file @staticmethod def pickle_damps(obj): return pickle.dumps(obj) @staticmethod def pickle_loads(obj): return pickle.loads(obj) if __name__ == '__main__': 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)
def test_more_than(self): car_1 = Car(1000, 100) car_2 = Car(100, 100) self.assertGreater(car_1.price, car_2.price)