Skip to content

Commit

Permalink
[test] Convert submission and validators from C++ to Python, to avoid…
Browse files Browse the repository at this point in the history
… compile time for every test
  • Loading branch information
mpsijm committed Feb 21, 2024
1 parent 3e0fe03 commit e85a63c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion test/problems/skel/generators/generators.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
solution: /submissions/accepted/hello.cpp
solution: /submissions/accepted/hello.py
#visualizer: /visualizers/asy.sh
# By default, generated files are not ignored.
#gitignore_generated: false
Expand Down
7 changes: 0 additions & 7 deletions test/problems/skel/input_validators/input_validator.cpp

This file was deleted.

11 changes: 11 additions & 0 deletions test/problems/skel/input_validators/input_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3

try:
if 0 <= int(input()) < 1_000_000:
exit(42)
else:
print("Out of range")
exit(43)
except Exception as e:
print(e)
exit(43)
9 changes: 0 additions & 9 deletions test/problems/skel/output_validators/output_validator.cpp

This file was deleted.

19 changes: 19 additions & 0 deletions test/problems/skel/output_validators/output_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
import math
import sys

try:
# Do not use the default_output_validator.cpp, because it's wasteful to compile it for every test
if math.isclose(
4 * float(open(sys.argv[1]).read()) ** 0.5,
float(open(sys.argv[2]).read()),
rel_tol=1e-6,
abs_tol=1e-6,
):
exit(42)
else:
print("WA")
exit(43)
except Exception as e:
print(e)
exit(43)
4 changes: 2 additions & 2 deletions test/problems/skel/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ uuid: 8ee7605a-9391-8727-1ee4-61028b8de953
license: cc by-sa
rights_owner: author
# 'default', 'custom', or 'custom interactive'
validation: default
validation: custom # Do not use the default_output_validator.cpp, because it's wasteful to compile it for every test

# One or more of:
# case_sensitive
# space_change_sensitive
# float_absolute_tolerance eps
# float_relative_tolerance eps
# float_tolerance eps
validator_flags: float_tolerance 1e-6
#validator_flags:

# To change the time limit factors for problemtools/Kattis, use:
limits:
Expand Down
11 changes: 0 additions & 11 deletions test/problems/skel/submissions/accepted/hello.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions test/problems/skel/submissions/accepted/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env python3
print(4 * int(input()) ** 0.5)
4 changes: 2 additions & 2 deletions test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def setup_skel_problem(request):
@pytest.mark.usefixtures('setup_skel_problem')
class TestUnit:
def test_memory(self):
shutil.copy('submissions/accepted/hello.cpp', 'submissions/run_time_error/hello.cpp')
shutil.copy('submissions/accepted/hello.py', 'submissions/run_time_error/hello.py')
os.system(
'sed -i "s/cin >> n/auto huge = new int[100000000]; cin >> huge[42]; n = huge[42]/" submissions/run_time_error/hello.cpp'
'sed -i "s/print/list(range(int(1e8)));print/" submissions/run_time_error/hello.py'
)
tools.test('run --no-generate -m 256'.split())

Expand Down

0 comments on commit e85a63c

Please sign in to comment.