Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 7bb938d

Browse files
committed
Fixed terry tests
1 parent fb191a0 commit 7bb938d

File tree

8 files changed

+94
-92
lines changed

8 files changed

+94
-92
lines changed

python/formats/terry_format.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ def get_request(config: Config) -> (TerryTask, List[SourceFile]):
9393

9494

9595
def evaluate_task(frontend: Frontend, task: TerryTask,
96-
solutions: List[SourceFile], config: Config):
96+
solutions: List[SourceFile],
97+
config: Config) -> TerryUIInterface:
9798
ui_interface = TerryUIInterface(task, config.ui == UIS.PRINT)
9899
if config.ui == UIS.CURSES:
99100
curses_ui = TerryCursesUI(ui_interface)

python/task_maker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python3
22

3-
# enable discovery of capnp folder and installed venv
3+
# enable discovery of the installed venv
44
from task_maker.syspath_patch import patch_sys_path
5-
from task_maker.uis.ioi import IOIUIInterface
65

76
patch_sys_path() # noqa
87

@@ -16,9 +15,11 @@
1615
from task_maker.formats import ioi_format, tm_format, terry_format
1716
from task_maker.languages import LanguageManager
1817
from task_maker.manager import get_frontend, spawn_server, spawn_worker
18+
from task_maker.uis.ioi import IOIUIInterface
19+
from task_maker.uis.terry import TerryUIInterface
1920

2021

21-
def run(config: Config) -> Union[None, IOIUIInterface]:
22+
def run(config: Config) -> Union[None, IOIUIInterface, TerryUIInterface]:
2223
if config.run_server:
2324
return spawn_server(config)
2425
if config.run_worker:

python/tests/terry_with_bugged_gen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
from task_maker.tests.test import run_tests, TestingUI
3+
from task_maker.tests.test import run_tests
44

55

66
def test_task():
@@ -10,8 +10,8 @@ def test_task():
1010
interface.set_generator("generator.py")
1111
interface.set_validator("validator.py")
1212
interface.set_checker("checker.py")
13-
interface.set_fatal_error()
14-
interface.run_checks(TestingUI.inst)
13+
interface.expect_error("Failed to validate input")
14+
interface.run_checks()
1515

1616

1717
if __name__ == "__main__":

python/tests/terry_with_validator.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
#!/usr/bin/env python3
22

3-
from task_maker.tests.test import run_tests, TestingUI
4-
5-
from event_pb2 import CORRECT, MISSING, WRONG
3+
from task_maker.tests.test import run_tests
4+
from task_maker.uis.terry import TestcaseStatus
65

76

87
def test_task():
98
from task_maker.tests.utils import TerryTestInterface
9+
1010
interface = TerryTestInterface("terry_with_validator",
1111
"Testing task-maker", 100)
1212
interface.set_generator("generator.py")
1313
interface.set_validator("validator.py")
1414
interface.set_checker("checker.py")
15-
interface.add_solution("solution.py", 100, [CORRECT] * 5)
16-
interface.add_solution("unordered.py", 100, [CORRECT] * 5)
17-
interface.add_solution("wrong.py", 0, [WRONG] * 5)
18-
interface.add_solution("missing.py", 0, [MISSING] * 5)
19-
interface.add_solution("partial.py", 40,
20-
[CORRECT, CORRECT, WRONG, MISSING, MISSING])
21-
interface.run_checks(TestingUI.inst)
15+
interface.add_solution("solution.py", 100, [TestcaseStatus.CORRECT] * 5)
16+
interface.add_solution("unordered.py", 100, [TestcaseStatus.CORRECT] * 5)
17+
interface.add_solution("wrong.py", 0, [TestcaseStatus.WRONG] * 5)
18+
interface.add_solution("missing.py", 0, [TestcaseStatus.MISSING] * 5)
19+
interface.add_solution("partial.py", 40, [
20+
TestcaseStatus.CORRECT, TestcaseStatus.CORRECT, TestcaseStatus.WRONG,
21+
TestcaseStatus.MISSING, TestcaseStatus.MISSING
22+
])
23+
interface.run_checks()
2224

2325

2426
if __name__ == "__main__":

python/tests/terry_without_validator.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python3
22

3-
from task_maker.tests.test import run_tests, TestingUI
4-
5-
from event_pb2 import CORRECT, MISSING, WRONG
3+
from task_maker.tests.test import run_tests
4+
from task_maker.uis.terry import TestcaseStatus
65

76

87
def test_task():
@@ -11,8 +10,8 @@ def test_task():
1110
"Testing task-maker", 100)
1211
interface.set_generator("generator.py")
1312
interface.set_checker("checker.py")
14-
interface.add_solution("solution.py", 100, [CORRECT] * 5)
15-
interface.run_checks(TestingUI.inst)
13+
interface.add_solution("solution.py", 100, [TestcaseStatus.CORRECT] * 5)
14+
interface.run_checks()
1615

1716

1817
if __name__ == "__main__":

python/tests/utils.py

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python3
22
from functools import reduce
3-
from task_maker.task_maker_frontend import ResultStatus
4-
5-
from task_maker.uis.ioi import SourceFileCompilationStatus, \
6-
TestcaseSolutionStatus
73
from typing import Optional, List, Tuple
84

5+
from task_maker.task_maker_frontend import ResultStatus
96
from task_maker.tests.test import interface
7+
from task_maker.uis import SourceFileCompilationStatus
8+
from task_maker.uis.ioi import TestcaseSolutionStatus
9+
from task_maker.uis.terry import SolutionInfo
1010

1111

1212
class TestSolution:
@@ -69,24 +69,24 @@ def __repr__(self):
6969
return "<TestSolutionNotCompile name=%s>" % self.name
7070

7171

72-
# class TerryTestSolution:
73-
# def __init__(self, task: "TerryTestInterface", name: str, score: float,
74-
# tc_score: Optional[List]):
75-
# self.task = task
76-
# self.name = name
77-
# self.score = score
78-
# self.tc_score = tc_score
79-
#
80-
# def check_solution(self):
81-
# assert self.name in ui.solutions
82-
# assert ui._compilation_status[self.name] == DONE
83-
# solution = ui._terry_test_status[self.name]
84-
# assert abs(solution.result.score * self.task.max_score -
85-
# self.score) < 0.0001
86-
# if self.tc_score:
87-
# for status, expected in zip(solution.result.testcases,
88-
# self.tc_score):
89-
# assert status == expected
72+
class TerryTestSolution:
73+
def __init__(self, task: "TerryTestInterface", name: str, score: float,
74+
tc_score: Optional[List]):
75+
self.task = task
76+
self.name = name
77+
self.score = score
78+
self.tc_score = tc_score
79+
80+
def check_solution(self):
81+
assert self.name in interface.solutions
82+
assert self.name in interface.solutions_info
83+
assert interface.solutions[
84+
self.name].status == SourceFileCompilationStatus.DONE
85+
info = interface.solutions_info[self.name] # type: SolutionInfo
86+
assert abs(info.score * self.task.max_score - self.score) < 0.0001
87+
if self.tc_score:
88+
for status, expected in zip(info.testcases_status, self.tc_score):
89+
assert status == expected
9090

9191

9292
class TestInterface:
@@ -185,45 +185,42 @@ def run_checks(self):
185185
sol.check_solution()
186186

187187

188-
# class TerryTestInterface:
189-
# def __init__(self, name: str, desc: str, max_score: float):
190-
# self.solutions = [] # type: List[TerryTestSolution]
191-
# self.generator_name = None # type: Optional[str]
192-
# self.validator_name = None # type: Optional[str]
193-
# self.checker_name = None # type: Optional[str]
194-
# self.max_score = max_score
195-
# self.name = name
196-
# self.desc = desc
197-
# self.fatal_error = False
198-
#
199-
# def set_generator(self, name: str):
200-
# self.generator_name = name
201-
#
202-
# def set_validator(self, name: str):
203-
# self.validator_name = name
204-
#
205-
# def set_checker(self, name: str):
206-
# self.checker_name = name
207-
#
208-
# def set_fatal_error(self):
209-
# self.fatal_error = True
210-
#
211-
# def add_solution(self, name: str, score: float, tc_score: Optional[List]):
212-
# self.solutions.append(TerryTestSolution(self, name, score, tc_score))
213-
#
214-
# def run_checks(self, ui: TestingUI):
215-
# assert ui.task_name == "%s (%s)" % (self.desc, self.name)
216-
# if self.fatal_error:
217-
# assert ui.fatal_errors
218-
# else:
219-
# assert not ui.fatal_errors
220-
#
221-
# for sol in self.solutions:
222-
# sol.check_solution(ui)
223-
#
224-
# if self.generator_name:
225-
# assert self.generator_name in ui._other_compilations
226-
# if self.validator_name:
227-
# assert self.validator_name in ui._other_compilations
228-
# if self.checker_name:
229-
# assert self.checker_name in ui._other_compilations
188+
class TerryTestInterface:
189+
def __init__(self, name: str, desc: str, max_score: float):
190+
self.solutions = [] # type: List[TerryTestSolution]
191+
self.generator_name = None # type: Optional[str]
192+
self.validator_name = None # type: Optional[str]
193+
self.checker_name = None # type: Optional[str]
194+
self.max_score = max_score
195+
self.name = name
196+
self.desc = desc
197+
self.error = ""
198+
199+
def set_generator(self, name: str):
200+
self.generator_name = name
201+
202+
def set_validator(self, name: str):
203+
self.validator_name = name
204+
205+
def set_checker(self, name: str):
206+
self.checker_name = name
207+
208+
def expect_error(self, error: str):
209+
self.error = error
210+
211+
def add_solution(self, name: str, score: float, tc_score: Optional[List]):
212+
self.solutions.append(TerryTestSolution(self, name, score, tc_score))
213+
214+
def run_checks(self):
215+
assert interface.task.name == self.name
216+
assert interface.task.title == self.desc
217+
if self.generator_name:
218+
assert self.generator_name in interface.non_solutions
219+
if self.validator_name:
220+
assert self.validator_name in interface.non_solutions
221+
if self.checker_name:
222+
assert self.checker_name in interface.non_solutions
223+
if self.error:
224+
assert any(self.error in error for error in interface.errors)
225+
for sol in self.solutions:
226+
sol.check_solution()

python/uis/ioi_curses_ui.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
from task_maker.formats import Task
66
from task_maker.printer import CursesPrinter, Printer
77
from task_maker.task_maker_frontend import ResultStatus
8-
from task_maker.uis import CursesUI, get_max_sol_len
9-
from task_maker.uis.ioi import IOIUIInterface, SourceFileCompilationStatus, \
10-
TestcaseGenerationStatus, SubtaskSolutionResult, TestcaseSolutionStatus, \
11-
SolutionStatus, TestcaseSolutionInfo
8+
from task_maker.uis import CursesUI, get_max_sol_len, \
9+
SourceFileCompilationStatus
10+
from task_maker.uis.ioi import IOIUIInterface, TestcaseGenerationStatus, \
11+
SubtaskSolutionResult, TestcaseSolutionStatus, SolutionStatus, \
12+
TestcaseSolutionInfo
1213

1314

1415
def print_solution_column(printer: Printer, solution: str, max_sol_len: int):

python/uis/ioi_finish_ui.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from task_maker.config import Config
44
from task_maker.formats import Task
55
from task_maker.task_maker_frontend import ResultStatus
6-
from task_maker.uis import result_to_str, FinishUI, get_max_sol_len
7-
from task_maker.uis.ioi import IOIUIInterface, SourceFileCompilationStatus
6+
from task_maker.uis import result_to_str, FinishUI, get_max_sol_len, \
7+
SourceFileCompilationStatus
8+
from task_maker.uis.ioi import IOIUIInterface
89
from task_maker.uis.ioi_curses_ui import print_solutions_result
910

1011

0 commit comments

Comments
 (0)