1class Candy:
2 def __init__(self, mass, uranium):
3 self.mass = mass
4 self.uranium = uranium
5
6 def get_uranium_quantity(self):
7 return self.mass * self.uranium
8
9 def get_mass(self):
10 return self.mass
11
12
13class Person:
14 def __init__(self, position):
15 self.position = position
16
17 def get_position(self):
18 return self.position
19
20 def set_position(self, position):
21 self.position = position
22
23
24class Kid(Person):
25 CRITICAL_VALUE=20
26
27 def __init__(self, position, initiative):
28 self.position = position
29 self.initiative = initiative
30 self.bag = {}
31
32 def get_initiative(self):
33 return self.initiative
34
35 def add_candy(self, candy):
36 self.bag.append(candy)
37
38 def is_critical(self):
39 total = 0
40 for candy in self.bag:
41 total += candy.uranium
42
43 return total > CRITICAL_VALUE
44
45
46class Host(Person):
47 def __init__(self, position, candies):
48 self.position = position
49 self.candies = candies
50
51 def remove_candy(self, function):
52 if not self.candies == 0:
53 return None
54 else:
55 return self.candies.pop(function[self.candies])
56
57
58class FluxCapacitor:
59 def __init__(self, participants):
60 self.participants = participants
61
62 def get_victim(self):
63 victims = {}
64
65 for participant in self.participants:
66 if participant.is_critical:
67 victims.add(participant)
68
69 if not self.participants == 0:
70 return None
71 else:
72 return victims
..EEEEE..E..
======================================================================
ERROR: test_empty_hosts (test.FluxCapacitorTest)
Test with empty hosts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
File "/tmp/test.py", line 88, in test_empty_hosts
self.assertEqual(flux_capacitor.get_victim(), None)
File "/tmp/solution.py", line 67, in get_victim
victims.add(participant)
AttributeError: 'dict' object has no attribute 'add'
======================================================================
ERROR: test_empty_kids (test.FluxCapacitorTest)
Test with empty kids.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
File "/tmp/test.py", line 96, in test_empty_kids
self.assertEqual(flux_capacitor.get_victim(), None)
File "/tmp/solution.py", line 66, in get_victim
if participant.is_critical:
AttributeError: 'Host' object has no attribute 'is_critical'
======================================================================
ERROR: test_no_candies (test.FluxCapacitorTest)
Test with no candies.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
File "/tmp/test.py", line 106, in test_no_candies
self.assertEqual(flux_capacitor.get_victim(), None)
File "/tmp/solution.py", line 66, in get_victim
if participant.is_critical:
AttributeError: 'Host' object has no attribute 'is_critical'
======================================================================
ERROR: test_real_case (test.FluxCapacitorTest)
Test with real case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
File "/tmp/test.py", line 115, in test_real_case
self.assertEqual(FluxCapacitor({kid1, kid2, host1, host2}).get_victim(), {kid1, kid2})
File "/tmp/solution.py", line 66, in get_victim
if participant.is_critical:
AttributeError: 'Host' object has no attribute 'is_critical'
======================================================================
ERROR: test_basic_usage (test.HostTest)
Test basic usage of Host class.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 66, in test_basic_usage
self.assertEqual(candy.get_mass(), 456)
AttributeError: 'NoneType' object has no attribute 'get_mass'
======================================================================
ERROR: test_candies (test.KidTest)
Test basic usage of candies in the Kid class.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 45, in test_candies
self.assertFalse(kid.is_critical())
File "/tmp/solution.py", line 43, in is_critical
return total > CRITICAL_VALUE
NameError: name 'CRITICAL_VALUE' is not defined
----------------------------------------------------------------------
Ran 12 tests in 0.001s
FAILED (errors=6)
f | 1 | class Candy: | f | 1 | class Candy: |
2 | def __init__(self, mass, uranium): | 2 | def __init__(self, mass, uranium): | ||
3 | self.mass = mass | 3 | self.mass = mass | ||
4 | self.uranium = uranium | 4 | self.uranium = uranium | ||
5 | 5 | ||||
6 | def get_uranium_quantity(self): | 6 | def get_uranium_quantity(self): | ||
7 | return self.mass * self.uranium | 7 | return self.mass * self.uranium | ||
8 | 8 | ||||
9 | def get_mass(self): | 9 | def get_mass(self): | ||
10 | return self.mass | 10 | return self.mass | ||
11 | 11 | ||||
12 | 12 | ||||
13 | class Person: | 13 | class Person: | ||
14 | def __init__(self, position): | 14 | def __init__(self, position): | ||
15 | self.position = position | 15 | self.position = position | ||
16 | 16 | ||||
17 | def get_position(self): | 17 | def get_position(self): | ||
18 | return self.position | 18 | return self.position | ||
19 | 19 | ||||
20 | def set_position(self, position): | 20 | def set_position(self, position): | ||
21 | self.position = position | 21 | self.position = position | ||
22 | 22 | ||||
23 | 23 | ||||
n | 24 | class Kid: | n | 24 | class Kid(Person): |
25 | CRITICAL_VALUE=20 | ||||
26 | |||||
25 | def __init__(self, position, initiative): | 27 | def __init__(self, position, initiative): | ||
26 | self.position = position | 28 | self.position = position | ||
27 | self.initiative = initiative | 29 | self.initiative = initiative | ||
n | 28 | self.bag = [] | n | 30 | self.bag = {} |
29 | 31 | ||||
30 | def get_initiative(self): | 32 | def get_initiative(self): | ||
31 | return self.initiative | 33 | return self.initiative | ||
32 | 34 | ||||
33 | def add_candy(self, candy): | 35 | def add_candy(self, candy): | ||
34 | self.bag.append(candy) | 36 | self.bag.append(candy) | ||
35 | 37 | ||||
36 | def is_critical(self): | 38 | def is_critical(self): | ||
n | 37 | sum = 0 | n | 39 | total = 0 |
38 | for candy in self.bag: | 40 | for candy in self.bag: | ||
n | 39 | sum += candy.uranium | n | 41 | total += candy.uranium |
40 | 42 | ||||
n | 41 | return sum > 20 | n | 43 | return total > CRITICAL_VALUE |
42 | 44 | ||||
43 | 45 | ||||
n | 44 | class Host: | n | 46 | class Host(Person): |
45 | def __init__(self, position, candies): | 47 | def __init__(self, position, candies): | ||
46 | self.position = position | 48 | self.position = position | ||
47 | self.candies = candies | 49 | self.candies = candies | ||
48 | 50 | ||||
49 | def remove_candy(self, function): | 51 | def remove_candy(self, function): | ||
n | 50 | if len(self.candies) == 0: | n | 52 | if not self.candies == 0: |
51 | return None | 53 | return None | ||
52 | else: | 54 | else: | ||
53 | return self.candies.pop(function[self.candies]) | 55 | return self.candies.pop(function[self.candies]) | ||
54 | 56 | ||||
55 | 57 | ||||
56 | class FluxCapacitor: | 58 | class FluxCapacitor: | ||
57 | def __init__(self, participants): | 59 | def __init__(self, participants): | ||
58 | self.participants = participants | 60 | self.participants = participants | ||
59 | 61 | ||||
60 | def get_victim(self): | 62 | def get_victim(self): | ||
61 | victims = {} | 63 | victims = {} | ||
62 | 64 | ||||
63 | for participant in self.participants: | 65 | for participant in self.participants: | ||
64 | if participant.is_critical: | 66 | if participant.is_critical: | ||
65 | victims.add(participant) | 67 | victims.add(participant) | ||
66 | 68 | ||||
t | t | 69 | if not self.participants == 0: | ||
70 | return None | ||||
71 | else: | ||||
67 | return victims | 72 | return victims |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | class Candy: | f | 1 | class Candy: |
n | 2 | def __init__(self, mass, uranium ): | n | 2 | def __init__(self, mass, uranium): |
3 | self.mass = mass | 3 | self.mass = mass | ||
4 | self.uranium = uranium | 4 | self.uranium = uranium | ||
5 | 5 | ||||
6 | def get_uranium_quantity(self): | 6 | def get_uranium_quantity(self): | ||
7 | return self.mass * self.uranium | 7 | return self.mass * self.uranium | ||
n | n | 8 | |||
8 | def get_mass(self): | 9 | def get_mass(self): | ||
9 | return self.mass | 10 | return self.mass | ||
n | 10 | n | |||
11 | 11 | ||||
12 | 12 | ||||
13 | class Person: | 13 | class Person: | ||
14 | def __init__(self, position): | 14 | def __init__(self, position): | ||
15 | self.position = position | 15 | self.position = position | ||
n | 16 | n | 16 | ||
17 | def get_position(self): | 17 | def get_position(self): | ||
18 | return self.position | 18 | return self.position | ||
n | 19 | n | 19 | ||
20 | def set_position(self, position): | 20 | def set_position(self, position): | ||
21 | self.position = position | 21 | self.position = position | ||
22 | 22 | ||||
23 | 23 | ||||
24 | class Kid: | 24 | class Kid: | ||
25 | def __init__(self, position, initiative): | 25 | def __init__(self, position, initiative): | ||
26 | self.position = position | 26 | self.position = position | ||
27 | self.initiative = initiative | 27 | self.initiative = initiative | ||
28 | self.bag = [] | 28 | self.bag = [] | ||
n | 29 | n | 29 | ||
30 | def get_initiative(self): | 30 | def get_initiative(self): | ||
31 | return self.initiative | 31 | return self.initiative | ||
n | 32 | n | 32 | ||
33 | def add_candy(self, candy): | 33 | def add_candy(self, candy): | ||
34 | self.bag.append(candy) | 34 | self.bag.append(candy) | ||
35 | 35 | ||||
36 | def is_critical(self): | 36 | def is_critical(self): | ||
n | 37 | sum=0 | n | 37 | sum = 0 |
38 | for candy in self.bag: | 38 | for candy in self.bag: | ||
39 | sum += candy.uranium | 39 | sum += candy.uranium | ||
40 | 40 | ||||
n | 41 | return sum>20 | n | 41 | return sum > 20 |
42 | 42 | ||||
43 | |||||
43 | class Host: | 44 | class Host: | ||
44 | def __init__(self, position, candies): | 45 | def __init__(self, position, candies): | ||
45 | self.position = position | 46 | self.position = position | ||
46 | self.candies = candies | 47 | self.candies = candies | ||
n | 47 | n | 48 | ||
48 | def remove_candy(self, function): | 49 | def remove_candy(self, function): | ||
n | 49 | if(len(self.candies) == 0): | n | 50 | if len(self.candies) == 0: |
50 | return None | 51 | return None | ||
51 | else: | 52 | else: | ||
52 | return self.candies.pop(function[self.candies]) | 53 | return self.candies.pop(function[self.candies]) | ||
53 | 54 | ||||
t | t | 55 | |||
56 | class FluxCapacitor: | ||||
57 | def __init__(self, participants): | ||||
58 | self.participants = participants | ||||
59 | |||||
60 | def get_victim(self): | ||||
61 | victims = {} | ||||
62 | |||||
63 | for participant in self.participants: | ||||
64 | if participant.is_critical: | ||||
65 | victims.add(participant) | ||||
66 | |||||
67 | return victims |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|