Skip to content

Commit

Permalink
Fix various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Jan 26, 2024
1 parent 144ddf1 commit 64c4c84
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 31 deletions.
4 changes: 4 additions & 0 deletions tested/datatypes/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class AdvancedStringTypes(_AdvancedDataType):
"""
A single character
"""
STRING = "string", BasicStringTypes.TEXT
"""
A string (sequence of characters).
"""


class AdvancedNothingTypes(_AdvancedDataType):
Expand Down
12 changes: 9 additions & 3 deletions tested/descriptions/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ def _types(self) -> list[str]:
elif isinstance(self.type_, AdvancedTypes):
result = [generate_type_declaration(self.language, self.type_)]
else:
possible_types = []
possible_types = [self.type_]
supported_types = self.language.datatype_support()
for advanced_type_enum in get_args(AdvancedTypes):
for advanced_type in advanced_type_enum:
if (
advanced_type.base_type == self.type_
and supported_types.get(advanced_type)
!= TypeSupport.UNSUPPORTED
and supported_types.get(advanced_type) == TypeSupport.SUPPORTED
):
possible_types.append(advanced_type)

Expand All @@ -67,6 +66,13 @@ def __str__(self) -> str:
[", ".join(types[:-1]), types[-1]] if len(types) > 2 else types
)

@property
def simple(self) -> str:
if len(self.others):
return generate_type_declaration(self.language, (self.type_, self.others))
else:
return generate_type_declaration(self.language, self.type_)

@property
def singular(self) -> str:
return get_i18n_string(f"types.singular.{self.type_}")
Expand Down
6 changes: 2 additions & 4 deletions tested/languages/bash/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def naming_conventions(self) -> dict[Conventionable, NamingConventions]:
def datatype_support(self) -> dict[AllTypes, TypeSupport]:
return {
AdvancedStringTypes.CHAR: TypeSupport.REDUCED,
AdvancedStringTypes.STRING: TypeSupport.SUPPORTED,
BasicStringTypes.TEXT: TypeSupport.SUPPORTED,
}

Expand Down Expand Up @@ -107,9 +108,6 @@ def generate_encoder(self, values: list[Value]) -> str:

def get_declaration_metadata(self) -> TypeDeclarationMetadata:
return {
"names": { # type: ignore
"text": "str",
"char": "str",
},
"names": {"text": "str", "char": "str", "string": "str"}, # type: ignore
"prompt": "$",
}
2 changes: 2 additions & 0 deletions tested/languages/c/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]:
"real": "supported",
"char": "supported",
"text": "supported",
"string": "supported",
"boolean": "supported",
"nothing": "supported",
"undefined": "reduced",
Expand Down Expand Up @@ -166,6 +167,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"real": "double",
"char": "char",
"text": "char*",
"string": "char*",
"boolean": "bool",
"nothing": "void",
"undefined": "void",
Expand Down
2 changes: 2 additions & 0 deletions tested/languages/csharp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]:
"integer": "supported",
"real": "supported",
"char": "reduced",
"string": "supported",
"text": "supported",
"boolean": "supported",
"sequence": "supported",
Expand Down Expand Up @@ -245,6 +246,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"real": "Double",
"char": "char",
"text": "string",
"string": "string",
"boolean": "Boolean",
"sequence": "List",
"set": "Set",
Expand Down
2 changes: 2 additions & 0 deletions tested/languages/haskell/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]:
"integer": "supported",
"real": "supported",
"char": "supported",
"string": "supported",
"text": "supported",
"boolean": "supported",
"sequence": "supported",
Expand Down Expand Up @@ -186,6 +187,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"integer": "Int",
"real": "Double",
"char": "Char",
"string": "String",
"text": "String",
"boolean": "Bool",
"nothing": "Nothing",
Expand Down
2 changes: 2 additions & 0 deletions tested/languages/java/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]:
"integer": "supported",
"real": "supported",
"char": "supported",
"string": "supported",
"text": "supported",
"boolean": "supported",
"sequence": "supported",
Expand Down Expand Up @@ -165,6 +166,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"real": "double",
"char": "char",
"text": "String",
"string": "String",
"boolean": "boolean",
"sequence": "List",
"set": "Set",
Expand Down
2 changes: 2 additions & 0 deletions tested/languages/javascript/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]:
"real": "supported",
"char": "reduced",
"text": "supported",
"string": "supported",
"boolean": "supported",
"sequence": "supported",
"set": "supported",
Expand Down Expand Up @@ -209,6 +210,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"real": "number",
"char": "string",
"text": "string",
"string": "string",
"boolean": "boolean",
"sequence": "array",
"set": "set",
Expand Down
3 changes: 3 additions & 0 deletions tested/languages/kotlin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]:
"real": "supported",
"char": "supported",
"text": "supported",
"string": "supported",
"boolean": "supported",
"sequence": "supported",
"set": "supported",
Expand Down Expand Up @@ -106,6 +107,7 @@ def map_type_restrictions(self) -> set[ExpressionTypes] | None:
"real",
"char",
"text",
"string",
"boolean",
"sequence",
"set",
Expand Down Expand Up @@ -235,6 +237,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"real": "Double",
"char": "Char",
"text": "String",
"string": "String",
"boolean": "Boolean",
"sequence": "List",
"set": "Set",
Expand Down
2 changes: 2 additions & 0 deletions tested/languages/python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def datatype_support(self) -> dict[AllTypes, TypeSupport]:
"real": "supported",
"char": "reduced",
"text": "supported",
"string": "supported",
"boolean": "supported",
"sequence": "supported",
"set": "supported",
Expand Down Expand Up @@ -235,6 +236,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"real": "float",
"char": "str",
"text": "str",
"string": "str",
"boolean": "bool",
"sequence": "list",
"set": "set",
Expand Down
2 changes: 1 addition & 1 deletion tests/descriptions/example.md.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Aan de functie `{{ function("splits_in_woorden") }}` moet een string (`{{ datatype("text") }}`) doorgegeven worden.
Aan de functie `{{ function("splits_in_woorden") }}` moet een string (`{{ datatype("string") }}`) doorgegeven worden.
De functie geeft een lijst van letters (`{{ datatype("sequence", "char") }}`) terug.

```tested
Expand Down
2 changes: 1 addition & 1 deletion tests/descriptions/example.python.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Aan de functie `splits_in_woorden` moet een string (`str`) doorgegeven worden.
De functie geeft een lijst van letters (`List[str]`) terug.
De functie geeft een lijst van letters (`list[str]`) terug.

```python
a_function_call('yes')
Expand Down
28 changes: 6 additions & 22 deletions tests/test_problem_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,34 @@ def test_template_function_name(lang: str, expected: str):
@pytest.mark.parametrize(
("lang", "tested_type", "expected"),
[
# Python
("python", "'integer'", "int"),
("python", "'real'", "float"),
("python", "'text'", "str"),
("python", '"sequence", "integer"', "List[int]"),
("python", '"array", ("set", ("integer", ))', "List[Set[int]]"),
("python", '"sequence", "integer"', "list[int]"),
("python", '"array", ("set", ("integer", ))', "list[set[int]]"),
(
"python",
'"tuple", ("sequence", ("real", )), "text"',
"Tuple[List[float], str]",
"tuple[list[float], str]",
),
# Java
("java", "'integer'", "int"),
("java", "'real'", "double"),
("java", "'text'", "String"),
("java", '"sequence", "integer"', "List<Integer>"),
("java", '"array", ("set", ("integer", ))', "Set<Integer>[]"),
# c
("c", "'integer'", "int"),
("c", "'real'", "double"),
("c", "'text'", "char*"),
# Kotlin
("kotlin", "'integer'", "Int"),
("kotlin", "'real'", "Double"),
("kotlin", "'text'", "String"),
("kotlin", '"sequence", "integer"', "List<Int>"),
("kotlin", '"array", ("set", ("integer", ))', "Array<Set<Int>>"),
# JavaScript
("javascript", "'integer'", "number"),
("javascript", "'real'", "number"),
("javascript", "'text'", "string"),
("javascript", '"sequence", "integer"', "array<number>"),
("javascript", '"array", ("set", ("integer", ))', "array<set<number>>"),
# Haskell
("haskell", "'integer'", "Int"),
("haskell", "'real'", "Double"),
("haskell", "'text'", "String"),
Expand All @@ -89,59 +83,49 @@ def test_template_function_name(lang: str, expected: str):
],
)
def test_template_type_name(lang: str, tested_type: Any, expected: str):
template = f"""{{{{ datatype({tested_type}) }}}}"""
template = f"""{{{{ datatype({tested_type}).simple }}}}"""
instance = process_problem_statement(template, lang)
assert instance == f"{expected}"


@pytest.mark.parametrize(
("lang", "tested_type", "expected"),
[
# Python
("python", "'sequence'", "sequence"),
("python", "'map'", "map"),
# Java
("java", "'sequence'", "sequence"),
("java", "'map'", "map"),
# Kotlin
("kotlin", "'sequence'", "sequence"),
("kotlin", "'map'", "map"),
# JavaScript
("javascript", "'sequence'", "sequence"),
("javascript", "'map'", "map"),
# Haskell
("haskell", "'sequence'", "sequence"),
("haskell", "'list'", "list"),
],
)
def test_template_natural_type_name(lang: str, tested_type: Any, expected: str):
template = f"""{{{{ datatype_common({tested_type}) }}}}"""
template = f"""{{{{ datatype({tested_type}).singular }}}}"""
instance = process_problem_statement(template, lang)
assert instance == f"{expected}"


@pytest.mark.parametrize(
("lang", "tested_type", "expected"),
[
# Python
("python", "'sequence'", "sequentie"),
("python", "'map'", "afbeelding"),
# Java
("java", "'sequence'", "sequentie"),
("java", "'map'", "afbeelding"),
# Kotlin
("kotlin", "'sequence'", "sequentie"),
("kotlin", "'map'", "afbeelding"),
# JavaScript
("javascript", "'sequence'", "sequentie"),
("javascript", "'map'", "afbeelding"),
# Haskell
("haskell", "'sequence'", "sequentie"),
("haskell", "'list'", "lijst"),
],
)
def test_template_natural_type_name_nl(lang: str, tested_type: Any, expected: str):
template = f"""{{{{ datatype_common({tested_type}) }}}}"""
template = f"""{{{{ datatype({tested_type}).singular }}}}"""
instance = process_problem_statement(template, lang, "nl")
assert instance == f"{expected}"

Expand Down

0 comments on commit 64c4c84

Please sign in to comment.