1def organize(cars, students):
2
3 free_students = students.copy()
4
5 def is_valid_configuration():
6 for car in cars:
7 for student in car.students:
8 if not student.is_comfy():
9 return False
10 return True
11
12 if not is_valid_configuration():
13 return False
14
15 for car in cars:
16 while len(car.students) < car.CAPACITY and free_students:
17 student = free_students.pop()
18 try:
19 car.add_student(student)
20 except EnvironmentError:
21 free_students.append(student)
22
23 if not is_valid_configuration():
24 return False
25
26 return True
.F..F
======================================================================
FAIL: test_empty (test.TesFull)
Test with empty cars.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 27, in test_empty
anti_rusalov_false(self, organize([], students))
AssertionError: True is not false
======================================================================
FAIL: test_single_solution_case (test.TesFull)
Test a single-solution case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 65, in test_single_solution_case
anti_rusalov_true(self, organize(cars, students))
AssertionError: False is not true
----------------------------------------------------------------------
Ran 5 tests in 0.000s
FAILED (failures=2)
f | 1 | def organize(cars, students): | f | 1 | def organize(cars, students): |
n | n | 2 | |||
3 | free_students = students.copy() | ||||
4 | |||||
5 | def is_valid_configuration(): | ||||
6 | for car in cars: | ||||
7 | for student in car.students: | ||||
8 | if not student.is_comfy(): | ||||
9 | return False | ||||
10 | return True | ||||
11 | |||||
12 | if not is_valid_configuration(): | ||||
13 | return False | ||||
14 | |||||
2 | for car in cars: | 15 | for car in cars: | ||
n | 3 | for student in students: | n | 16 | while len(car.students) < car.CAPACITY and free_students: |
17 | student = free_students.pop() | ||||
4 | try: | 18 | try: | ||
5 | car.add_student(student) | 19 | car.add_student(student) | ||
n | 6 | if all(passenger.is_comfy() for passenger in car.passengers): | n | ||
7 | return True | ||||
8 | except EnvironmentError: | 20 | except EnvironmentError: | ||
n | 9 | pass | n | ||
10 | finally: | ||||
11 | car.remove_student(student) | 21 | free_students.append(student) | ||
12 | 22 | ||||
t | t | 23 | if not is_valid_configuration(): | ||
13 | return False | 24 | return False | ||
25 | |||||
26 | return True |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|