Skip to content

Commit

Permalink
Merge pull request #488 from dodona-edu/enhance/newlines
Browse files Browse the repository at this point in the history
Enable strict text checking by default
  • Loading branch information
niknetniko authored Jan 8, 2024
2 parents 6a7a1a7 + 3c7ae92 commit ee807a8
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 185 deletions.
4 changes: 4 additions & 0 deletions tested/dsl/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@
"description" : "Ignore trailing whitespace",
"type" : "boolean"
},
"normalizeTrailingNewlines": {
"description": "Normalize trailing newlines",
"type": "boolean"
},
"roundTo" : {
"description" : "The number of decimals to round at, when applying the rounding on floats",
"type" : "integer"
Expand Down
4 changes: 4 additions & 0 deletions tested/dsl/schema_draft7.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@
"description" : "Ignore trailing whitespace",
"type" : "boolean"
},
"normalizeTrailingNewlines": {
"description": "Normalize trailing newlines",
"type": "boolean"
},
"roundTo" : {
"description" : "The number of decimals to round at, when applying the rounding on floats",
"type" : "integer"
Expand Down
5 changes: 4 additions & 1 deletion tested/dsl/translate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,20 @@ def _convert_custom_check_oracle(stream: dict) -> CustomCheckOracle:

def _convert_text_output_channel(stream: YamlObject) -> TextOutputChannel:
if isinstance(stream, str):
data = stream
data = _ensure_trailing_newline(stream)
return TextOutputChannel(data=data, oracle=GenericTextOracle())
else:
assert isinstance(stream, dict)
data = str(stream["data"])
if "oracle" not in stream or stream["oracle"] == "builtin":
config = cast(dict, stream.get("config", {}))
if config.get("normalizeTrailingNewlines", True):
data = _ensure_trailing_newline(data)
return TextOutputChannel(
data=data, oracle=GenericTextOracle(options=config)
)
elif stream["oracle"] == "custom_check":
data = _ensure_trailing_newline(data)
return TextOutputChannel(
data=data, oracle=_convert_custom_check_oracle(stream)
)
Expand Down
2 changes: 1 addition & 1 deletion tested/judge/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PlannedExecutionUnit:

def get_stdin(self, resources: Path) -> str:
potential = [c.context.get_stdin(resources) for c in self.contexts]
return "\n".join(p for p in potential if p)
return "".join(p for p in potential if p)

def has_main_testcase(self) -> bool:
return self.contexts[0].context.has_main_testcase()
Expand Down
8 changes: 5 additions & 3 deletions tested/oracles/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ def _is_number(string: str) -> float | None:
def _text_options(config: OracleConfig) -> dict:
defaults = {
# Options for textual comparison
"ignoreWhitespace": True,
"ignoreWhitespace": False,
"caseInsensitive": False,
# Options for numerical comparison
"tryFloatingPoint": False,
"applyRounding": False,
"roundTo": 3,
# This option is used in the DSL, no in the actual oracle.
"normalizeTrailingNewlines": True,
}
defaults.update(config.options)
return defaults
Expand Down Expand Up @@ -53,9 +55,9 @@ def compare_text(options: dict[str, Any], expected: str, actual: str) -> OracleR

if (
options["tryFloatingPoint"]
and (actual_float := _is_number(actual_eval)) is not None
and (actual_float := _is_number(actual_eval.strip())) is not None
):
expected_float = float(expected_eval)
expected_float = float(expected_eval.strip())
if options["applyRounding"]:
numbers = int(options["roundTo"])
# noinspection PyUnboundLocalVariable
Expand Down
Loading

0 comments on commit ee807a8

Please sign in to comment.