Open DieterPi opened 4 days ago
Issued as a bug for TESTed: https://github.com/dodona-edu/universal-judge/issues/561
This does not seem like a general issue with the evaluation of maps in TESTed. TESTed behaved as expected when I tried evaluating functions returning maps in both Python and JavaScript. Option that remains open is that the issue occurs because the map was defined as a YAML-map. We already know that TESTed-DSL has two different "interpretations" for a map for a return
value:
TESTed has to make a distinction between both based on a heuristic, which is where it might go wrong here. I guess we would definitely get the correct behaviour if the expected return value is specified as
return: !!expression "{'NED': 12, 'FRA': 10, ...}"
In the documentation I see we later added "typed" maps to explicitly express the meaning of YAML-maps for return values. For example, a map representing the use of an oracle to test the return value becomes:
return: !!oracle
key: value # properties for oracle object
But is no type is given, than TESTed still relies on a heuristic. I think we should stop using the heuristic and always type maps, with a non-typed map always defaulting to a literal map as a return value. This also makes it more extensible.
A map for different programming languages has nothing explicit type for now as far as I know (also recognized heuristically), but we should also force a type in this case to avoid heuristic choices going wrong.
Changed the testfile to:
return: !expression "{'NED': 12, 'FRA': 10, 'NAT': 2, 'ENG': 8, 'DUI', ...}"
And the test still accepts the 'empty dictionary' solution. 🤔
Did you use double exclamation before expression (should be !!expression)? Does it accept a non-empty dictionary (other than the expected one)?
1) I tried !!expression
, then checked the docs, and according to the docs:
return
Specifieert de verwachte returnwaarde.
Standaard wordt de returnwaarde beschouwd als een YAML-waarde. Een string in het testplan zal dus ook een string worden in de testcode.
Voor geavanceerde returnwaarden zijn er twee opties:
Een string met de tag !expression gebruikt het dezelfde Python-syntaxis te gebruiken als voor de [expressies en statements](https://docs.dodona.be/nl/references/tested/dsl/#expressies-en-statements).
Een object met de tag !oracle is het object voor een eigen orakel (een eigen checkfunctie) (zie [hieronder](https://docs.dodona.be/nl/references/tested/dsl/#eigen-checkfuncties-orakels)).`
2) The current test file accepts both the correct solution and the empty dictionary. It does not accept any other dicts.
The following solution:
is accepted in an exercise with the following yaml test suite:
(this exercise: https://dodona.be/nl/courses/3770/activities/1952125562/)