From 0efe3415a69c3a5d606cd5a3354303d6efe13276 Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Fri, 31 May 2024 17:10:14 +0200 Subject: [PATCH] Add test for reduced types in set Fixes #515 --- tested/features.py | 6 +++++- tested/languages/java/config.py | 1 + tested/languages/javascript/config.py | 10 +++++++++- .../evaluation/advanced_values_in_set.yaml | 6 ++++++ tests/exercises/objects/solution/correct.java | 8 +++++++- tests/exercises/objects/solution/correct.js | 4 ++++ tests/test_functionality.py | 16 ++++++++++++++++ 7 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/exercises/objects/evaluation/advanced_values_in_set.yaml diff --git a/tested/features.py b/tested/features.py index 619f8921..9109e23d 100644 --- a/tested/features.py +++ b/tested/features.py @@ -224,6 +224,10 @@ def is_supported(language: "Language") -> list[Message] | None: key, collection_restrictions.get(basic_key) ) + # If None, skip as there are no restrictions. + if restrictions is None: + continue + # Types that have reduced support are converted, so we also need to # convert them here in the checks. basic_value_types = set() @@ -233,7 +237,7 @@ def is_supported(language: "Language") -> list[Message] | None: else: basic_value_types.add(value_type) - if not (basic_value_types <= restricted[key]): # type: ignore + if not (basic_value_types <= restrictions): # type: ignore _logger.warning("This test suite is not compatible!") _logger.warning( f"Required {key} types are {value_types} (or {basic_value_types})." diff --git a/tested/languages/java/config.py b/tested/languages/java/config.py index a7438210..798d4974 100644 --- a/tested/languages/java/config.py +++ b/tested/languages/java/config.py @@ -74,6 +74,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]: "text": "supported", "boolean": "supported", "sequence": "supported", + "tuple": "reduced", "set": "supported", "map": "supported", "dictionary": "supported", diff --git a/tested/languages/javascript/config.py b/tested/languages/javascript/config.py index 98df61a8..ddea8bb9 100644 --- a/tested/languages/javascript/config.py +++ b/tested/languages/javascript/config.py @@ -6,6 +6,8 @@ from tested.datatypes import ( AdvancedObjectTypes, AllTypes, + BasicNumericTypes, + BasicSequenceTypes, BasicStringTypes, ExpressionTypes, ) @@ -100,7 +102,13 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]: } def collection_restrictions(self) -> dict[AllTypes, set[ExpressionTypes]]: - return {AdvancedObjectTypes.OBJECT: {BasicStringTypes.TEXT}} + return { + AdvancedObjectTypes.OBJECT: {BasicStringTypes.TEXT}, + BasicSequenceTypes.SET: { + BasicSequenceTypes.SEQUENCE, + BasicNumericTypes.INTEGER, + }, + } def compilation(self, files: list[str]) -> CallbackResult: submission = submission_file(self) diff --git a/tests/exercises/objects/evaluation/advanced_values_in_set.yaml b/tests/exercises/objects/evaluation/advanced_values_in_set.yaml new file mode 100644 index 00000000..25634298 --- /dev/null +++ b/tests/exercises/objects/evaluation/advanced_values_in_set.yaml @@ -0,0 +1,6 @@ +namespace: "EqualChecker" +tabs: +- tab: "Feedback" + testcases: + - expression: 'set_test()' + return: !expression "{(1, 2), (2, 3)}" diff --git a/tests/exercises/objects/solution/correct.java b/tests/exercises/objects/solution/correct.java index 3d131302..1975dc99 100644 --- a/tests/exercises/objects/solution/correct.java +++ b/tests/exercises/objects/solution/correct.java @@ -1,3 +1,5 @@ +import java.util.*; + class EqualChecker { private final int number; @@ -9,4 +11,8 @@ class EqualChecker { public boolean check(int other) { return this.number == other; } -} \ No newline at end of file + + public static Set> setTest() { + return Set.of(List.of(1, 2), List.of(2, 3)); + } +} diff --git a/tests/exercises/objects/solution/correct.js b/tests/exercises/objects/solution/correct.js index e8ba0081..bf107914 100644 --- a/tests/exercises/objects/solution/correct.js +++ b/tests/exercises/objects/solution/correct.js @@ -7,3 +7,7 @@ class EqualChecker { return other === this.number; } } + +function setTest() { + return new Set([[1, 2], [2, 3]]); +} diff --git a/tests/test_functionality.py b/tests/test_functionality.py index 2e2ee823..b81f30c9 100644 --- a/tests/test_functionality.py +++ b/tests/test_functionality.py @@ -552,6 +552,22 @@ def test_missing_key_types_detected_js_dictionary( assert updates.find_status_enum() == ["correct"] +@pytest.mark.parametrize("lang", ["java"]) +def test_advanced_types_are_allowed(lang: str, tmp_path: Path, pytestconfig): + conf = configuration( + pytestconfig, + "objects", + lang, + tmp_path, + "advanced_values_in_set.yaml", + "correct", + ) + result = execute_config(conf) + updates = assert_valid_output(result, pytestconfig) + assert len(updates.find_all("start-testcase")) == 1 + assert updates.find_status_enum() == ["correct"] + + @pytest.mark.parametrize("lang", ["python", "java", "kotlin", "javascript", "csharp"]) def test_programmed_evaluator_lotto(lang: str, tmp_path: Path, pytestconfig): conf = configuration(