1BASE_MATERIAL_DENSITIES = {
2 'Concrete': 2500,
3 'Brick': 2000,
4 'Stone': 1600,
5 'Wood': 600,
6 'Steel': 7700
7}
8
9classes = {}
10
11
12def initializer_with_density(density):
13 def instance_initializer_method(instance_reference, mass):
14 setattr(instance_reference, "mass", mass)
15 setattr(instance_reference, "volume", mass / density)
16 setattr(instance_reference, "used", False)
17 return instance_initializer_method
18
19
20class Material:
21 def __init__(self, mass):
22 self.mass = mass
23 self.used = False
24
25
26def class_generator(*class_names_list):
27
28 class_name = "_".join(class_names_list)
29
30 if class_name in classes:
31 return classes[class_name]
32
33 if class_name in BASE_MATERIAL_DENSITIES:
34 density = BASE_MATERIAL_DENSITIES[class_name]
35 else:
36 density = sum(map(lambda cls: BASE_MATERIAL_DENSITIES[cls] / len(class_names_list), class_names_list))
37
38 classes[class_name] = type(class_name, (Material,), {'volume': property(lambda self: self.mass / density)})
39 return classes[class_name]
40
41
42Concrete = class_generator('Concrete')
43Brick = class_generator('Brick')
44Stone = class_generator('Stone')
45Steel = class_generator('Steel')
46Wood = class_generator('Wood')
47
48
49class Factory:
50
51 __factory_instances = []
52
53 def __init__(self):
54 self.__factory_instances.append(self)
55 self.__created_materials = []
56
57 def __del__(self):
58 self.__factory_instances.remove(self)
59
60 def __call_with_existing_materials(self, *existing_materials):
61 if any(map(lambda material: material.used, existing_materials)):
62 raise AssertionError
63 else:
64 for material in existing_materials:
65 material.used = True
66
67 sorted_names = sum(list(map(lambda class_name: class_name.split('_'),
68 map(lambda material: material.__class__.__name__, existing_materials))), [])
69 sorted_names.sort()
70 obj = class_generator(*sorted_names)(sum(map(lambda material: material.mass, existing_materials)))
71 self.__created_materials.append(obj)
72 return obj
73
74 def __call_with_new_materials(self, **new_materials):
75 newly_created_materials = []
76 for material_name, mass in new_materials.items():
77 if material_name in classes:
78 obj = classes[material_name](mass)
79 self.__created_materials.append(obj)
80 newly_created_materials.append(obj)
81 else:
82 raise ValueError
83
84 return tuple(newly_created_materials)
85
86 def __call__(self, *existing_materials, **new_materials):
87 if not (len(existing_materials) ^ len(new_materials)):
88 raise ValueError
89
90 if len(existing_materials) > 0:
91 return self.__call_with_existing_materials(*existing_materials)
92
93 if len(new_materials) > 0:
94 return self.__call_with_new_materials(**new_materials)
95
96 @property
97 def volume(self):
98 return sum(map(lambda ref: ref.volume,
99 filter(lambda ref: not ref.used, self.__created_materials)))
100
101 @classmethod
102 def can_build_together(cls, desired_volume):
103 return sum(map(lambda ref: ref.volume, cls.__factory_instances)) >= desired_volume
104
105 def can_build(self, desired_volume):
106 return self.volume >= desired_volume
..........
----------------------------------------------------------------------
Ran 10 tests in 0.014s
OK
f | 1 | f | 1 | ||
2 | BASE_MATERIAL_DENSITIES = { | 2 | BASE_MATERIAL_DENSITIES = { | ||
3 | 'Concrete': 2500, | 3 | 'Concrete': 2500, | ||
4 | 'Brick': 2000, | 4 | 'Brick': 2000, | ||
5 | 'Stone': 1600, | 5 | 'Stone': 1600, | ||
6 | 'Wood': 600, | 6 | 'Wood': 600, | ||
7 | 'Steel': 7700 | 7 | 'Steel': 7700 | ||
8 | } | 8 | } | ||
9 | 9 | ||||
n | 10 | CLASSES = {} | n | 10 | classes = {} |
11 | 11 | ||||
12 | 12 | ||||
13 | def initializer_with_density(density): | 13 | def initializer_with_density(density): | ||
14 | def instance_initializer_method(instance_reference, mass): | 14 | def instance_initializer_method(instance_reference, mass): | ||
15 | setattr(instance_reference, "mass", mass) | 15 | setattr(instance_reference, "mass", mass) | ||
16 | setattr(instance_reference, "volume", mass / density) | 16 | setattr(instance_reference, "volume", mass / density) | ||
17 | setattr(instance_reference, "used", False) | 17 | setattr(instance_reference, "used", False) | ||
18 | return instance_initializer_method | 18 | return instance_initializer_method | ||
19 | 19 | ||||
20 | 20 | ||||
n | n | 21 | class Material: | ||
22 | def __init__(self, mass): | ||||
23 | self.mass = mass | ||||
24 | self.used = False | ||||
25 | |||||
26 | |||||
21 | def class_generator(*class_names_list): | 27 | def class_generator(*class_names_list): | ||
22 | 28 | ||||
23 | class_name = "_".join(class_names_list) | 29 | class_name = "_".join(class_names_list) | ||
24 | 30 | ||||
n | 25 | if class_name in CLASSES: | n | 31 | if class_name in classes: |
26 | return CLASSES[class_name] | 32 | return classes[class_name] | ||
27 | 33 | ||||
28 | if class_name in BASE_MATERIAL_DENSITIES: | 34 | if class_name in BASE_MATERIAL_DENSITIES: | ||
29 | density = BASE_MATERIAL_DENSITIES[class_name] | 35 | density = BASE_MATERIAL_DENSITIES[class_name] | ||
30 | else: | 36 | else: | ||
31 | density = sum(map(lambda cls: BASE_MATERIAL_DENSITIES[cls] / len(class_names_list), class_names_list)) | 37 | density = sum(map(lambda cls: BASE_MATERIAL_DENSITIES[cls] / len(class_names_list), class_names_list)) | ||
32 | 38 | ||||
n | 33 | CLASSES[class_name] = type(class_name, (), {'__init__': initializer_with_density(density)}) | n | 39 | classes[class_name] = type(class_name, (Material,), {'volume': property(lambda self: self.mass / density)}) |
34 | return CLASSES[class_name] | 40 | return classes[class_name] | ||
35 | 41 | ||||
36 | 42 | ||||
37 | Concrete = class_generator('Concrete') | 43 | Concrete = class_generator('Concrete') | ||
38 | Brick = class_generator('Brick') | 44 | Brick = class_generator('Brick') | ||
39 | Stone = class_generator('Stone') | 45 | Stone = class_generator('Stone') | ||
40 | Steel = class_generator('Steel') | 46 | Steel = class_generator('Steel') | ||
41 | Wood = class_generator('Wood') | 47 | Wood = class_generator('Wood') | ||
42 | 48 | ||||
43 | 49 | ||||
44 | class Factory: | 50 | class Factory: | ||
45 | 51 | ||||
n | 46 | __factory_instances_list = list() | n | 52 | __factory_instances = [] |
47 | 53 | ||||
48 | def __init__(self): | 54 | def __init__(self): | ||
n | 49 | self.__factory_instances_list.append(self) | n | 55 | self.__factory_instances.append(self) |
50 | self.__created_materials_list = list() | 56 | self.__created_materials = [] | ||
51 | 57 | ||||
52 | def __del__(self): | 58 | def __del__(self): | ||
n | 53 | self.__factory_instances_list.remove(self) | n | 59 | self.__factory_instances.remove(self) |
54 | 60 | ||||
n | n | 61 | def __call_with_existing_materials(self, *existing_materials): | ||
62 | if any(map(lambda material: material.used, existing_materials)): | ||||
63 | raise AssertionError | ||||
64 | else: | ||||
65 | for material in existing_materials: | ||||
66 | material.used = True | ||||
67 | |||||
68 | sorted_names = sum(list(map(lambda class_name: class_name.split('_'), | ||||
69 | map(lambda material: material.__class__.__name__, existing_materials))), []) | ||||
70 | sorted_names.sort() | ||||
71 | obj = class_generator(*sorted_names)(sum(map(lambda material: material.mass, existing_materials))) | ||||
72 | self.__created_materials.append(obj) | ||||
73 | return obj | ||||
74 | |||||
75 | def __call_with_new_materials(self, **new_materials): | ||||
76 | newly_created_materials = [] | ||||
77 | for material_name, mass in new_materials.items(): | ||||
78 | if material_name in classes: | ||||
79 | obj = classes[material_name](mass) | ||||
80 | self.__created_materials.append(obj) | ||||
81 | newly_created_materials.append(obj) | ||||
82 | else: | ||||
83 | raise ValueError | ||||
84 | |||||
85 | return tuple(newly_created_materials) | ||||
86 | |||||
87 | def __call__(self, *existing_materials, **new_materials): | ||||
88 | if not (len(existing_materials) ^ len(new_materials)): | ||||
89 | raise ValueError | ||||
90 | |||||
91 | if len(existing_materials) > 0: | ||||
92 | return self.__call_with_existing_materials(*existing_materials) | ||||
93 | |||||
94 | if len(new_materials) > 0: | ||||
95 | return self.__call_with_new_materials(**new_materials) | ||||
96 | |||||
97 | @property | ||||
55 | def __get_volume(self): | 98 | def volume(self): | ||
56 | return sum(map(lambda ref: ref.volume, | 99 | return sum(map(lambda ref: ref.volume, | ||
n | 57 | filter(lambda ref: not ref.used, self.__created_materials_list))) | n | 100 | filter(lambda ref: not ref.used, self.__created_materials))) |
58 | 101 | ||||
59 | @classmethod | 102 | @classmethod | ||
60 | def can_build_together(cls, desired_volume): | 103 | def can_build_together(cls, desired_volume): | ||
n | 61 | return sum(map(lambda ref: ref.__get_volume(), cls.__factory_instances_list)) >= desired_volume | n | 104 | return sum(map(lambda ref: ref.volume, cls.__factory_instances)) >= desired_volume |
62 | 105 | ||||
63 | def can_build(self, desired_volume): | 106 | def can_build(self, desired_volume): | ||
t | 64 | return self.__get_volume() >= desired_volume | t | 107 | return self.volume >= desired_volume |
65 | |||||
66 | def __call__(self, *existing_materials, **new_materials): | ||||
67 | if ((len(existing_materials) == 0 and len(new_materials) == 0) or | ||||
68 | (len(existing_materials) > 0 and len(new_materials) > 0)): | ||||
69 | raise ValueError | ||||
70 | |||||
71 | if len(existing_materials) > 0: | ||||
72 | if any(map(lambda material: material.used, existing_materials)): | ||||
73 | raise AssertionError | ||||
74 | else: | ||||
75 | for material in existing_materials: | ||||
76 | material.used = True | ||||
77 | |||||
78 | sorted_names = sum(list(map(lambda class_name: class_name.split('_'), | ||||
79 | map(lambda material: material.__class__.__name__, existing_materials))), []) | ||||
80 | sorted_names.sort() | ||||
81 | obj = class_generator(*sorted_names)(sum(map(lambda material: material.mass, existing_materials))) | ||||
82 | self.__created_materials_list.append(obj) | ||||
83 | return obj | ||||
84 | |||||
85 | if len(new_materials) > 0: | ||||
86 | newly_created_materials = [] | ||||
87 | for material_name, mass in new_materials.items(): | ||||
88 | if material_name in CLASSES: | ||||
89 | obj = CLASSES[material_name](mass) | ||||
90 | self.__created_materials_list.append(obj) | ||||
91 | newly_created_materials.append(obj) | ||||
92 | else: | ||||
93 | raise ValueError | ||||
94 | |||||
95 | return tuple(newly_created_materials) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | BASE_MATERIAL_DENSITIES = { | 2 | BASE_MATERIAL_DENSITIES = { | ||
3 | 'Concrete': 2500, | 3 | 'Concrete': 2500, | ||
4 | 'Brick': 2000, | 4 | 'Brick': 2000, | ||
5 | 'Stone': 1600, | 5 | 'Stone': 1600, | ||
6 | 'Wood': 600, | 6 | 'Wood': 600, | ||
7 | 'Steel': 7700 | 7 | 'Steel': 7700 | ||
8 | } | 8 | } | ||
9 | 9 | ||||
10 | CLASSES = {} | 10 | CLASSES = {} | ||
11 | 11 | ||||
12 | 12 | ||||
13 | def initializer_with_density(density): | 13 | def initializer_with_density(density): | ||
14 | def instance_initializer_method(instance_reference, mass): | 14 | def instance_initializer_method(instance_reference, mass): | ||
15 | setattr(instance_reference, "mass", mass) | 15 | setattr(instance_reference, "mass", mass) | ||
16 | setattr(instance_reference, "volume", mass / density) | 16 | setattr(instance_reference, "volume", mass / density) | ||
17 | setattr(instance_reference, "used", False) | 17 | setattr(instance_reference, "used", False) | ||
18 | return instance_initializer_method | 18 | return instance_initializer_method | ||
19 | 19 | ||||
20 | 20 | ||||
21 | def class_generator(*class_names_list): | 21 | def class_generator(*class_names_list): | ||
22 | 22 | ||||
23 | class_name = "_".join(class_names_list) | 23 | class_name = "_".join(class_names_list) | ||
24 | 24 | ||||
25 | if class_name in CLASSES: | 25 | if class_name in CLASSES: | ||
26 | return CLASSES[class_name] | 26 | return CLASSES[class_name] | ||
27 | 27 | ||||
28 | if class_name in BASE_MATERIAL_DENSITIES: | 28 | if class_name in BASE_MATERIAL_DENSITIES: | ||
29 | density = BASE_MATERIAL_DENSITIES[class_name] | 29 | density = BASE_MATERIAL_DENSITIES[class_name] | ||
30 | else: | 30 | else: | ||
31 | density = sum(map(lambda cls: BASE_MATERIAL_DENSITIES[cls] / len(class_names_list), class_names_list)) | 31 | density = sum(map(lambda cls: BASE_MATERIAL_DENSITIES[cls] / len(class_names_list), class_names_list)) | ||
32 | 32 | ||||
33 | CLASSES[class_name] = type(class_name, (), {'__init__': initializer_with_density(density)}) | 33 | CLASSES[class_name] = type(class_name, (), {'__init__': initializer_with_density(density)}) | ||
34 | return CLASSES[class_name] | 34 | return CLASSES[class_name] | ||
35 | 35 | ||||
36 | 36 | ||||
37 | Concrete = class_generator('Concrete') | 37 | Concrete = class_generator('Concrete') | ||
38 | Brick = class_generator('Brick') | 38 | Brick = class_generator('Brick') | ||
39 | Stone = class_generator('Stone') | 39 | Stone = class_generator('Stone') | ||
40 | Steel = class_generator('Steel') | 40 | Steel = class_generator('Steel') | ||
41 | Wood = class_generator('Wood') | 41 | Wood = class_generator('Wood') | ||
42 | 42 | ||||
43 | 43 | ||||
44 | class Factory: | 44 | class Factory: | ||
45 | 45 | ||||
46 | __factory_instances_list = list() | 46 | __factory_instances_list = list() | ||
47 | 47 | ||||
48 | def __init__(self): | 48 | def __init__(self): | ||
49 | self.__factory_instances_list.append(self) | 49 | self.__factory_instances_list.append(self) | ||
50 | self.__created_materials_list = list() | 50 | self.__created_materials_list = list() | ||
51 | 51 | ||||
52 | def __del__(self): | 52 | def __del__(self): | ||
53 | self.__factory_instances_list.remove(self) | 53 | self.__factory_instances_list.remove(self) | ||
54 | 54 | ||||
55 | def __get_volume(self): | 55 | def __get_volume(self): | ||
n | 56 | return sum(map(lambda ref: ref.volume, filter(lambda ref: not ref.used, self.__created_materials_list))) | n | 56 | return sum(map(lambda ref: ref.volume, |
57 | filter(lambda ref: not ref.used, self.__created_materials_list))) | ||||
57 | 58 | ||||
58 | @classmethod | 59 | @classmethod | ||
59 | def can_build_together(cls, desired_volume): | 60 | def can_build_together(cls, desired_volume): | ||
60 | return sum(map(lambda ref: ref.__get_volume(), cls.__factory_instances_list)) >= desired_volume | 61 | return sum(map(lambda ref: ref.__get_volume(), cls.__factory_instances_list)) >= desired_volume | ||
61 | 62 | ||||
62 | def can_build(self, desired_volume): | 63 | def can_build(self, desired_volume): | ||
63 | return self.__get_volume() >= desired_volume | 64 | return self.__get_volume() >= desired_volume | ||
64 | 65 | ||||
65 | def __call__(self, *existing_materials, **new_materials): | 66 | def __call__(self, *existing_materials, **new_materials): | ||
n | 66 | if (len(existing_materials) == 0 and len(new_materials) == 0) or (len(existing_materials) > 0 and len(new_materials) > 0): | n | 67 | if ((len(existing_materials) == 0 and len(new_materials) == 0) or |
68 | (len(existing_materials) > 0 and len(new_materials) > 0)): | ||||
67 | raise ValueError | 69 | raise ValueError | ||
68 | 70 | ||||
69 | if len(existing_materials) > 0: | 71 | if len(existing_materials) > 0: | ||
70 | if any(map(lambda material: material.used, existing_materials)): | 72 | if any(map(lambda material: material.used, existing_materials)): | ||
71 | raise AssertionError | 73 | raise AssertionError | ||
72 | else: | 74 | else: | ||
73 | for material in existing_materials: | 75 | for material in existing_materials: | ||
74 | material.used = True | 76 | material.used = True | ||
75 | 77 | ||||
t | 76 | sorted_names = sum(list(map(lambda class_name: class_name.split('_'), map(lambda material: material.__class__.__name__, existing_materials))), []) | t | 78 | sorted_names = sum(list(map(lambda class_name: class_name.split('_'), |
79 | map(lambda material: material.__class__.__name__, existing_materials))), []) | ||||
77 | sorted_names.sort() | 80 | sorted_names.sort() | ||
78 | obj = class_generator(*sorted_names)(sum(map(lambda material: material.mass, existing_materials))) | 81 | obj = class_generator(*sorted_names)(sum(map(lambda material: material.mass, existing_materials))) | ||
79 | self.__created_materials_list.append(obj) | 82 | self.__created_materials_list.append(obj) | ||
80 | return obj | 83 | return obj | ||
81 | 84 | ||||
82 | if len(new_materials) > 0: | 85 | if len(new_materials) > 0: | ||
83 | newly_created_materials = [] | 86 | newly_created_materials = [] | ||
84 | for material_name, mass in new_materials.items(): | 87 | for material_name, mass in new_materials.items(): | ||
85 | if material_name in CLASSES: | 88 | if material_name in CLASSES: | ||
86 | obj = CLASSES[material_name](mass) | 89 | obj = CLASSES[material_name](mass) | ||
87 | self.__created_materials_list.append(obj) | 90 | self.__created_materials_list.append(obj) | ||
88 | newly_created_materials.append(obj) | 91 | newly_created_materials.append(obj) | ||
89 | else: | 92 | else: | ||
90 | raise ValueError | 93 | raise ValueError | ||
91 | 94 | ||||
92 | return tuple(newly_created_materials) | 95 | return tuple(newly_created_materials) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | BASE_MATERIAL_DENSITIES = { | 2 | BASE_MATERIAL_DENSITIES = { | ||
3 | 'Concrete': 2500, | 3 | 'Concrete': 2500, | ||
4 | 'Brick': 2000, | 4 | 'Brick': 2000, | ||
5 | 'Stone': 1600, | 5 | 'Stone': 1600, | ||
6 | 'Wood': 600, | 6 | 'Wood': 600, | ||
7 | 'Steel': 7700 | 7 | 'Steel': 7700 | ||
8 | } | 8 | } | ||
9 | 9 | ||||
10 | CLASSES = {} | 10 | CLASSES = {} | ||
11 | 11 | ||||
12 | 12 | ||||
13 | def initializer_with_density(density): | 13 | def initializer_with_density(density): | ||
14 | def instance_initializer_method(instance_reference, mass): | 14 | def instance_initializer_method(instance_reference, mass): | ||
15 | setattr(instance_reference, "mass", mass) | 15 | setattr(instance_reference, "mass", mass) | ||
16 | setattr(instance_reference, "volume", mass / density) | 16 | setattr(instance_reference, "volume", mass / density) | ||
17 | setattr(instance_reference, "used", False) | 17 | setattr(instance_reference, "used", False) | ||
18 | return instance_initializer_method | 18 | return instance_initializer_method | ||
19 | 19 | ||||
20 | 20 | ||||
21 | def class_generator(*class_names_list): | 21 | def class_generator(*class_names_list): | ||
22 | 22 | ||||
23 | class_name = "_".join(class_names_list) | 23 | class_name = "_".join(class_names_list) | ||
24 | 24 | ||||
25 | if class_name in CLASSES: | 25 | if class_name in CLASSES: | ||
26 | return CLASSES[class_name] | 26 | return CLASSES[class_name] | ||
27 | 27 | ||||
28 | if class_name in BASE_MATERIAL_DENSITIES: | 28 | if class_name in BASE_MATERIAL_DENSITIES: | ||
29 | density = BASE_MATERIAL_DENSITIES[class_name] | 29 | density = BASE_MATERIAL_DENSITIES[class_name] | ||
30 | else: | 30 | else: | ||
31 | density = sum(map(lambda cls: BASE_MATERIAL_DENSITIES[cls] / len(class_names_list), class_names_list)) | 31 | density = sum(map(lambda cls: BASE_MATERIAL_DENSITIES[cls] / len(class_names_list), class_names_list)) | ||
32 | 32 | ||||
33 | CLASSES[class_name] = type(class_name, (), {'__init__': initializer_with_density(density)}) | 33 | CLASSES[class_name] = type(class_name, (), {'__init__': initializer_with_density(density)}) | ||
34 | return CLASSES[class_name] | 34 | return CLASSES[class_name] | ||
35 | 35 | ||||
36 | 36 | ||||
37 | Concrete = class_generator('Concrete') | 37 | Concrete = class_generator('Concrete') | ||
38 | Brick = class_generator('Brick') | 38 | Brick = class_generator('Brick') | ||
39 | Stone = class_generator('Stone') | 39 | Stone = class_generator('Stone') | ||
40 | Steel = class_generator('Steel') | 40 | Steel = class_generator('Steel') | ||
41 | Wood = class_generator('Wood') | 41 | Wood = class_generator('Wood') | ||
42 | 42 | ||||
43 | 43 | ||||
44 | class Factory: | 44 | class Factory: | ||
45 | 45 | ||||
n | 46 | __instances_list = list() | n | 46 | __factory_instances_list = list() |
47 | 47 | ||||
48 | def __init__(self): | 48 | def __init__(self): | ||
n | 49 | self.__instances_list.append(self) | n | 49 | self.__factory_instances_list.append(self) |
50 | self.__objects_list = list() | 50 | self.__created_materials_list = list() | ||
51 | 51 | ||||
52 | def __del__(self): | 52 | def __del__(self): | ||
n | 53 | self.__instances_list.remove(self) | n | 53 | self.__factory_instances_list.remove(self) |
54 | 54 | ||||
55 | def __get_volume(self): | 55 | def __get_volume(self): | ||
n | 56 | return sum(map(lambda ref: ref.volume, filter(lambda ref: not ref.used, self.__objects_list))) | n | 56 | return sum(map(lambda ref: ref.volume, filter(lambda ref: not ref.used, self.__created_materials_list))) |
57 | 57 | ||||
58 | @classmethod | 58 | @classmethod | ||
59 | def can_build_together(cls, desired_volume): | 59 | def can_build_together(cls, desired_volume): | ||
n | 60 | return sum(map(lambda ref: ref.__get_volume(), cls.__instances_list)) >= desired_volume | n | 60 | return sum(map(lambda ref: ref.__get_volume(), cls.__factory_instances_list)) >= desired_volume |
61 | 61 | ||||
62 | def can_build(self, desired_volume): | 62 | def can_build(self, desired_volume): | ||
63 | return self.__get_volume() >= desired_volume | 63 | return self.__get_volume() >= desired_volume | ||
64 | 64 | ||||
n | 65 | def __call__(self, *args, **kwargs): | n | 65 | def __call__(self, *existing_materials, **new_materials): |
66 | if (len(args) == 0 and len(kwargs) == 0) or (len(args) > 0 and len(kwargs) > 0): | 66 | if (len(existing_materials) == 0 and len(new_materials) == 0) or (len(existing_materials) > 0 and len(new_materials) > 0): | ||
67 | raise ValueError | 67 | raise ValueError | ||
68 | 68 | ||||
n | 69 | if len(args) > 0: | n | 69 | if len(existing_materials) > 0: |
70 | if any(map(lambda arg: arg.used, args)): | 70 | if any(map(lambda material: material.used, existing_materials)): | ||
71 | raise AssertionError | 71 | raise AssertionError | ||
72 | else: | 72 | else: | ||
n | 73 | for arg in args: | n | 73 | for material in existing_materials: |
74 | arg.used = True | 74 | material.used = True | ||
75 | 75 | ||||
n | 76 | sorted_arguments = sum(list(map(lambda cls: cls.split('_'), map(lambda key: str(key.__class__.__name__), args))), []) | n | 76 | sorted_names = sum(list(map(lambda class_name: class_name.split('_'), map(lambda material: material.__class__.__name__, existing_materials))), []) |
77 | sorted_arguments.sort() | 77 | sorted_names.sort() | ||
78 | obj = class_generator(*sorted_arguments)(sum(map(lambda object: object.mass, args))) | 78 | obj = class_generator(*sorted_names)(sum(map(lambda material: material.mass, existing_materials))) | ||
79 | self.__objects_list.append(obj) | 79 | self.__created_materials_list.append(obj) | ||
80 | return obj | 80 | return obj | ||
81 | 81 | ||||
n | 82 | if len(kwargs) > 0: | n | 82 | if len(new_materials) > 0: |
83 | objects = [] | 83 | newly_created_materials = [] | ||
84 | for key, value in kwargs.items(): | 84 | for material_name, mass in new_materials.items(): | ||
85 | if key in CLASSES: | 85 | if material_name in CLASSES: | ||
86 | obj = CLASSES[key](value) | 86 | obj = CLASSES[material_name](mass) | ||
87 | self.__objects_list.append(obj) | 87 | self.__created_materials_list.append(obj) | ||
88 | objects.append(obj) | 88 | newly_created_materials.append(obj) | ||
89 | else: | 89 | else: | ||
90 | raise ValueError | 90 | raise ValueError | ||
91 | 91 | ||||
t | 92 | return tuple(objects) | t | 92 | return tuple(newly_created_materials) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|