Skip to content

Commit

Permalink
Add test for reduced types in set
Browse files Browse the repository at this point in the history
Fixes #515
  • Loading branch information
niknetniko committed May 31, 2024
1 parent 19382f5 commit 0efe341
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tested/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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})."
Expand Down
1 change: 1 addition & 0 deletions tested/languages/java/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion tested/languages/javascript/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from tested.datatypes import (
AdvancedObjectTypes,
AllTypes,
BasicNumericTypes,
BasicSequenceTypes,
BasicStringTypes,
ExpressionTypes,
)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace: "EqualChecker"
tabs:
- tab: "Feedback"
testcases:
- expression: 'set_test()'
return: !expression "{(1, 2), (2, 3)}"
8 changes: 7 additions & 1 deletion tests/exercises/objects/solution/correct.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.util.*;

class EqualChecker {

private final int number;
Expand All @@ -9,4 +11,8 @@ class EqualChecker {
public boolean check(int other) {
return this.number == other;
}
}

public static Set<List<Integer>> setTest() {
return Set.of(List.of(1, 2), List.of(2, 3));
}
}
4 changes: 4 additions & 0 deletions tests/exercises/objects/solution/correct.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ class EqualChecker {
return other === this.number;
}
}

function setTest() {
return new Set([[1, 2], [2, 3]]);
}
16 changes: 16 additions & 0 deletions tests/test_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0efe341

Please sign in to comment.