Skip to content

Commit 65e9683

Browse files
committed
OutputOnly: Add compare real numbers evaluation option
1 parent 19fbdce commit 65e9683

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

cms/grading/tasktypes/OutputOnly.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class OutputOnly(TaskType):
5757
# Constants used in the parameter definition.
5858
OUTPUT_EVAL_DIFF = "diff"
5959
OUTPUT_EVAL_CHECKER = "comparator"
60+
OUTPUT_EVAL_REALPREC = "realprecision"
6061

6162
# Other constants to specify the task type behaviour and parameters.
6263
ALLOW_PARTIAL_SUBMISSION = True
@@ -66,7 +67,8 @@ class OutputOnly(TaskType):
6667
"output_eval",
6768
"",
6869
{OUTPUT_EVAL_DIFF: "Outputs compared with white diff",
69-
OUTPUT_EVAL_CHECKER: "Outputs are compared by a comparator"})
70+
OUTPUT_EVAL_CHECKER: "Outputs are compared by a comparator",
71+
OUTPUT_EVAL_REALPREC: "Outputs compared as real numbers (with precision of 1e-6)"})
7072

7173
ACCEPTED_PARAMETERS = [_EVALUATION]
7274

@@ -97,6 +99,9 @@ def get_auto_managers(self):
9799
def _uses_checker(self) -> bool:
98100
return self.output_eval == OutputOnly.OUTPUT_EVAL_CHECKER
99101

102+
def _uses_realprecision(self) -> bool:
103+
return self.output_eval == self.OUTPUT_EVAL_REALPREC
104+
100105
@staticmethod
101106
def _get_user_output_filename(job: Job):
102107
return OutputOnly.USER_OUTPUT_FILENAME_TEMPLATE % \
@@ -127,6 +132,7 @@ def evaluate(self, job, file_cacher):
127132
box_success, outcome, text = eval_output(
128133
file_cacher, job,
129134
OutputOnly.CHECKER_CODENAME if self._uses_checker() else None,
135+
use_realprecision = self._uses_realprecision(),
130136
user_output_digest=job.files[user_output_filename].digest)
131137

132138
# Fill in the job with the results.

cmstestsuite/unit_tests/grading/tasktypes/OutputOnlyTest.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ def assertResultsInJob(self, job, success, outcome, text, stats):
6767
self.assertEqual(job.text, text)
6868
self.assertEqual(job.plus, stats)
6969

70+
def test_realprecision_success(self):
71+
tt, job = self.prepare(["realprecision"], {
72+
"output_001.txt": FILE_001,
73+
"output_023.txt": FILE_023
74+
})
75+
76+
tt.evaluate(job, self.file_cacher)
77+
78+
self.eval_output.assert_called_once_with(
79+
self.file_cacher, job, None, use_realprecision=True,
80+
user_output_digest="digest of 023")
81+
self.assertResultsInJob(job, True, str(OUTCOME), TEXT, {})
82+
7083
def test_diff_success(self):
7184
tt, job = self.prepare(["diff"], {
7285
"output_001.txt": FILE_001,
@@ -76,7 +89,8 @@ def test_diff_success(self):
7689
tt.evaluate(job, self.file_cacher)
7790

7891
self.eval_output.assert_called_once_with(
79-
self.file_cacher, job, None, user_output_digest="digest of 023")
92+
self.file_cacher, job, None, use_realprecision=False,
93+
user_output_digest="digest of 023")
8094
self.assertResultsInJob(job, True, str(OUTCOME), TEXT, {})
8195

8296
def test_diff_missing_file(self):
@@ -100,7 +114,8 @@ def test_diff_failure(self):
100114
tt.evaluate(job, self.file_cacher)
101115

102116
self.eval_output.assert_called_once_with(
103-
self.file_cacher, job, None, user_output_digest="digest of 023")
117+
self.file_cacher, job, None, use_realprecision=False,
118+
user_output_digest="digest of 023")
104119
self.assertResultsInJob(job, False, None, None, None)
105120

106121
def test_comparator_success(self):
@@ -113,6 +128,7 @@ def test_comparator_success(self):
113128

114129
self.eval_output.assert_called_once_with(
115130
self.file_cacher, job, "checker",
131+
use_realprecision=False,
116132
user_output_digest="digest of 023")
117133
self.assertResultsInJob(job, True, str(OUTCOME), TEXT, {})
118134

0 commit comments

Comments
 (0)