1class Car:
2 def __init__(self):
3 self.students = set()
4
5 def add_student(self, student):
6 if len(self.students) < 4:
7 self.students.add(student)
8 student.current_car = self
9 else:
10 raise EnvironmentError("Car is full")
11
12 def remove_student(self, student):
13 if student in self.students:
14 self.students.remove(student)
15 student.current_car = None
16 else:
17 raise EnvironmentError("Student not in car")
18
19class Student:
20 def __init__(self, preferences):
21 self.preferences = preferences
22 self.current_car = None
23
24 def is_comfy(self):
25 if self.current_car:
26 return all(self.preferences == student.preferences for student in self.current_car.students)
27 else:
28 return None
29
30def organize(cars, students):
31 if len(cars) < len(students)/4 :
32 return False
33 for car in cars:
34 for student in students:
35 if not bool(student.current_car):
36 try:
37 car.add_student(student)
38 if all(student.is_comfy() for student in student.current_car.students):
39 continue
40 else:
41 car.remove_student(student)
42 except EnvironmentError:
43 continue
44 return all(bool(student.current_car) for student in students)
E.EEE
======================================================================
ERROR: test_big_input (test.TesFull)
Test a big case to ensure no huge bruteforcing.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 90, in test_big_input
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 35, in organize
if not bool(student.current_car):
AttributeError: 'Student' object has no attribute 'current_car'
======================================================================
ERROR: test_real_case_false (test.TesFull)
Test a real case for False.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 36, in test_real_case_false
anti_rusalov_false(self, organize(cars, students))
File "/tmp/solution.py", line 35, in organize
if not bool(student.current_car):
AttributeError: 'Student' object has no attribute 'current_car'
======================================================================
ERROR: test_regular_case (test.TesFull)
Test a regular case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 47, in test_regular_case
anti_rusalov_true(self, organize(cars, students))
File "/tmp/solution.py", line 35, in organize
if not bool(student.current_car):
AttributeError: 'Student' object has no attribute 'current_car'
======================================================================
ERROR: 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))
File "/tmp/solution.py", line 35, in organize
if not bool(student.current_car):
AttributeError: 'Student' object has no attribute 'current_car'
----------------------------------------------------------------------
Ran 5 tests in 0.001s
FAILED (errors=4)
![]()
Георги Кунчев
07.12.2023 16:44Ти си дефинирал твои версии на студент и кола, но ние ще тестваме с наши. В кодът си очакваш студентите да имат "current_car", но нашите нямат.
Единтвените методи, с които можеш да интерфейсваш студент и кола, са трите, които са в условието.
|
f | 1 | class Car: | f | 1 | class Car: |
2 | def __init__(self): | 2 | def __init__(self): | ||
3 | self.students = set() | 3 | self.students = set() | ||
4 | 4 | ||||
5 | def add_student(self, student): | 5 | def add_student(self, student): | ||
6 | if len(self.students) < 4: | 6 | if len(self.students) < 4: | ||
7 | self.students.add(student) | 7 | self.students.add(student) | ||
8 | student.current_car = self | 8 | student.current_car = self | ||
9 | else: | 9 | else: | ||
10 | raise EnvironmentError("Car is full") | 10 | raise EnvironmentError("Car is full") | ||
11 | 11 | ||||
12 | def remove_student(self, student): | 12 | def remove_student(self, student): | ||
13 | if student in self.students: | 13 | if student in self.students: | ||
14 | self.students.remove(student) | 14 | self.students.remove(student) | ||
15 | student.current_car = None | 15 | student.current_car = None | ||
16 | else: | 16 | else: | ||
17 | raise EnvironmentError("Student not in car") | 17 | raise EnvironmentError("Student not in car") | ||
18 | 18 | ||||
19 | class Student: | 19 | class Student: | ||
20 | def __init__(self, preferences): | 20 | def __init__(self, preferences): | ||
21 | self.preferences = preferences | 21 | self.preferences = preferences | ||
22 | self.current_car = None | 22 | self.current_car = None | ||
23 | 23 | ||||
24 | def is_comfy(self): | 24 | def is_comfy(self): | ||
25 | if self.current_car: | 25 | if self.current_car: | ||
26 | return all(self.preferences == student.preferences for student in self.current_car.students) | 26 | return all(self.preferences == student.preferences for student in self.current_car.students) | ||
27 | else: | 27 | else: | ||
28 | return None | 28 | return None | ||
29 | 29 | ||||
30 | def organize(cars, students): | 30 | def organize(cars, students): | ||
31 | if len(cars) < len(students)/4 : | 31 | if len(cars) < len(students)/4 : | ||
32 | return False | 32 | return False | ||
33 | for car in cars: | 33 | for car in cars: | ||
34 | for student in students: | 34 | for student in students: | ||
35 | if not bool(student.current_car): | 35 | if not bool(student.current_car): | ||
36 | try: | 36 | try: | ||
37 | car.add_student(student) | 37 | car.add_student(student) | ||
38 | if all(student.is_comfy() for student in student.current_car.students): | 38 | if all(student.is_comfy() for student in student.current_car.students): | ||
39 | continue | 39 | continue | ||
40 | else: | 40 | else: | ||
41 | car.remove_student(student) | 41 | car.remove_student(student) | ||
42 | except EnvironmentError: | 42 | except EnvironmentError: | ||
43 | continue | 43 | continue | ||
t | 44 | if not all(bool(student.current_car) for student in students): | t | 44 | return all(bool(student.current_car) for student in students) |
45 | return False | ||||
46 | else: | ||||
47 | return True |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|