Домашни > Хелоуин в Припят > Решения > Решението на Тодор Недковски

Резултати
5 точки от тестове
0 точки от учител

5 точки общо

6 успешни теста
6 неуспешни теста
Код

 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)

Дискусия
История

f1class Candy:f1class Candy:
2    def __init__(self, mass, uranium):2    def __init__(self, mass, uranium):
3        self.mass = mass3        self.mass = mass
4        self.uranium = uranium4        self.uranium = uranium
55
6    def get_uranium_quantity(self):6    def get_uranium_quantity(self):
7        return self.mass * self.uranium7        return self.mass * self.uranium
88
9    def get_mass(self):9    def get_mass(self):
10        return self.mass10        return self.mass
1111
1212
13class Person:13class Person:
14    def __init__(self, position):14    def __init__(self, position):
15        self.position = position15        self.position = position
1616
17    def get_position(self):17    def get_position(self):
18        return self.position18        return self.position
1919
20    def set_position(self, position):20    def set_position(self, position):
21        self.position = position21        self.position = position
2222
2323
n24class Kid:n24class Kid(Person):
25    CRITICAL_VALUE=20
26 
25    def __init__(self, position, initiative):27    def __init__(self, position, initiative):
26        self.position = position28        self.position = position
27        self.initiative = initiative29        self.initiative = initiative
n28        self.bag = []n30        self.bag = {}
2931
30    def get_initiative(self):32    def get_initiative(self):
31        return self.initiative33        return self.initiative
3234
33    def add_candy(self, candy):35    def add_candy(self, candy):
34        self.bag.append(candy)36        self.bag.append(candy)
3537
36    def is_critical(self):38    def is_critical(self):
n37        sum = 0n39        total = 0
38        for candy in self.bag:40        for candy in self.bag:
n39            sum += candy.uraniumn41            total += candy.uranium
4042
n41        return sum > 20n43        return total > CRITICAL_VALUE
4244
4345
n44class Host:n46class Host(Person):
45    def __init__(self, position, candies):47    def __init__(self, position, candies):
46        self.position = position48        self.position = position
47        self.candies = candies49        self.candies = candies
4850
49    def remove_candy(self, function):51    def remove_candy(self, function):
n50        if len(self.candies) == 0:n52        if not self.candies == 0:
51            return None53            return None
52        else:54        else:
53            return self.candies.pop(function[self.candies])55            return self.candies.pop(function[self.candies])
5456
5557
56class FluxCapacitor:58class FluxCapacitor:
57    def __init__(self, participants):59    def __init__(self, participants):
58        self.participants = participants60        self.participants = participants
5961
60    def get_victim(self):62    def get_victim(self):
61        victims = {}63        victims = {}
6264
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)
6668
tt69        if not self.participants == 0:
70            return None
71        else:
67        return victims72            return victims
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class Candy:f1class Candy:
n2    def __init__(self, mass, uranium ):n2    def __init__(self, mass, uranium):
3        self.mass = mass3        self.mass = mass
4        self.uranium = uranium4        self.uranium = uranium
55
6    def get_uranium_quantity(self):6    def get_uranium_quantity(self):
7        return self.mass * self.uranium7        return self.mass * self.uranium
nn8 
8    def get_mass(self):9    def get_mass(self):
9        return self.mass10        return self.mass
n10    n
1111
1212
13class Person:13class Person:
14    def __init__(self, position):14    def __init__(self, position):
15        self.position = position15        self.position = position
n16    n16 
17    def get_position(self):17    def get_position(self):
18        return self.position18        return self.position
n19    n19 
20    def set_position(self, position):20    def set_position(self, position):
21        self.position = position21        self.position = position
2222
2323
24class Kid:24class Kid:
25    def __init__(self, position, initiative):25    def __init__(self, position, initiative):
26        self.position = position26        self.position = position
27        self.initiative = initiative27        self.initiative = initiative
28        self.bag = []28        self.bag = []
n29    n29 
30    def get_initiative(self):30    def get_initiative(self):
31        return self.initiative31        return self.initiative
n32    n32 
33    def add_candy(self, candy):33    def add_candy(self, candy):
34        self.bag.append(candy)34        self.bag.append(candy)
3535
36    def is_critical(self):36    def is_critical(self):
n37        sum=0n37        sum = 0
38        for candy in self.bag:38        for candy in self.bag:
39            sum += candy.uranium39            sum += candy.uranium
4040
n41        return sum>20n41        return sum > 20
42    42 
43 
43class Host:44class Host:
44    def __init__(self, position, candies):45    def __init__(self, position, candies):
45        self.position = position46        self.position = position
46        self.candies = candies47        self.candies = candies
n47    n48 
48    def remove_candy(self, function):49    def remove_candy(self, function):
n49        if(len(self.candies) == 0):n50        if len(self.candies) == 0:
50            return None51            return None
51        else:52        else:
52            return self.candies.pop(function[self.candies])53            return self.candies.pop(function[self.candies])
5354
tt55 
56class 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
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op