1import unittest
2
3from solution import *
4
5
6class TestSanity(unittest.TestCase):
7 """Sanity test for organize."""
8
9 def test_sanity(self):
10 """Ensure name exists and is callable.."""
11 self.assertTrue(callable(organize))
12
13
14if __name__ == '__main__':
15 unittest.main()
1import unittest
2
3# Thanks to this guy we need to prevent hacking. -> https://py-fmi.org/student/75
4anti_rusalov_false = unittest.TestCase.assertFalse
5anti_rusalov_true = unittest.TestCase.assertTrue
6anti_rusalov_is = unittest.TestCase.assertIs
7
8from solution import *
9
10from helpers import Car, Student
11
12
13class TesFull(unittest.TestCase):
14 """Full test for organize."""
15
16 def setUp(self):
17 """Setup for all test cases."""
18 Car._instances = {}
19 # Getting deep into a student's private internals.
20 # Do you feel it?
21 Student._instances = {}
22
23 def test_empty(self):
24 """Test with empty cars."""
25 students = [Student(smoke=True, chalga=False, cold=None)]
26 for _ in range(20): # Anti Rusalov mechanism against random True/False returns
27 anti_rusalov_false(self, organize([], students))
28
29 def test_real_case_false(self):
30 """Test a real case for False."""
31 cars = [Car(cold=False)]
32 students = [Student(smoke=True, chalga=False, cold=None),
33 Student(smoke=False, chalga=True, cold=None),]
34 # Can't put a smoker and nonsmoker together
35 for _ in range(20): # Anti Rusalov mechanism against random True/False returns
36 anti_rusalov_false(self, organize(cars, students))
37
38 def test_regular_case(self):
39 """Test a regular case."""
40 # https://www.youtube.com/watch?v=5PsnxDQvQpw
41 cars = [Car(cold=False), Car(cold=True)]
42 students = [Student(smoke=True, chalga=False, cold=None),
43 Student(smoke=None, chalga=None, cold=None),
44 Student(smoke=None, chalga=None, cold=None),
45 Student(smoke=None, chalga=None, cold=None),
46 Student(smoke=False, chalga=None, cold=False)]
47 anti_rusalov_true(self, organize(cars, students))
48 anti_rusalov_true(self, all([x.is_comfy() is True for x in students]))
49 # Last student is cold so can only go to first car
50 anti_rusalov_is(self, students[4].car, cars[0])
51 # The one above in the first car doesn't smoke so this one must be in car 2
52 anti_rusalov_is(self, students[0].car, cars[1])
53
54 def test_single_solution_case(self):
55 """Test a single-solution case."""
56 cars = [Car(cold=False), Car(cold=True)]
57 students = [Student(smoke=True, chalga=False, cold=False),
58 Student(smoke=None, chalga=False, cold=None),
59 Student(smoke=None, chalga=False, cold=None),
60 Student(smoke=None, chalga=False, cold=None),
61 Student(smoke=False, chalga=True, cold=None),
62 Student(smoke=False, chalga=None, cold=None),
63 Student(smoke=False, chalga=None, cold=None),
64 Student(smoke=False, chalga=None, cold=None)]
65 anti_rusalov_true(self, organize(cars, students))
66 anti_rusalov_true(self, all([x.is_comfy() is True for x in students]))
67 # There is only one valid solution to this case
68 anti_rusalov_is(self, students[0].car, cars[0])
69 anti_rusalov_is(self, students[1].car, cars[0])
70 anti_rusalov_is(self, students[2].car, cars[0])
71 anti_rusalov_is(self, students[3].car, cars[0])
72 anti_rusalov_is(self, students[4].car, cars[1])
73 anti_rusalov_is(self, students[5].car, cars[1])
74 anti_rusalov_is(self, students[6].car, cars[1])
75 anti_rusalov_is(self, students[7].car, cars[1])
76
77 def test_big_input(self):
78 """Test a big case to ensure no huge bruteforcing."""
79 cars = [Car(cold=False), Car(cold=False), Car(cold=False), Car(cold=True)]
80 students = [Student(smoke=True, chalga=None, cold=None),
81 Student(smoke=True, chalga=None, cold=None),
82 Student(smoke=True, chalga=None, cold=None),
83 Student(smoke=True, chalga=None, cold=None),
84 Student(smoke=None, chalga=True, cold=None),
85 Student(smoke=None, chalga=True, cold=None),
86 Student(smoke=None, chalga=True, cold=None),
87 Student(smoke=None, chalga=True, cold=None),
88 Student(smoke=None, chalga=None, cold=True),
89 Student(smoke=None, chalga=None, cold=True)]
90 anti_rusalov_true(self, organize(cars, students))
91 anti_rusalov_true(self, all([x.is_comfy() is True for x in students]))
92
93
94if __name__ == '__main__':
95 unittest.main()
|
Мирослав Стояновски
07.12.2023 16:13Възможно ли е даден студент да няма отношение по някой от критериите, тоест да е възможно да е comfy хем в кола с чалга, хем в кола без чалга ?
|
Георги Кунчев
06.12.2023 21:39Освен да ти дам пример `organize(cars, students)`, не знам какво повече бих могъл, без да дефинирам коли и студенти.
Ок, идва празник, борите се за една точка, халал да ви е.
Добавям дефиницията на колите и студентите горе в условието.
|
|
|
|
Георги Кунчев
06.12.2023 15:292 секунди за всички тестове.
Осъзнавам, че ако ви изсипем огромна колекция това може да не е достатъчно, затова няма да го правим.
ПП: Най-голямият ни тест е 10 студента с 4 коли.
|
Михаил Цанков
06.12.2023 15:25Имат ли таймаут тестовете? Тоест колко бързо трябва да е решението ни
|
|
|