Rewrite parser of unit expressions
To complete the rewrite of all core parts, the parsing, interpretation and conversion of units must also be rewritten. The aim is to have consistent validation of student input (server-side) and make it easier for the users to define their own conversion rules and/or rulesets.
Pull Request Test Coverage Report for Build 13627077473
Details
- 77 of 136 (56.62%) changed or added relevant lines in 2 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage decreased (-1.3%) to 92.643%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| classes/local/unit_parser.php | 77 | 86 | 89.53% |
| classes/local/shunting_yard.php | 0 | 50 | 0.0% |
| <!-- | Total: | 77 | 136 |
| Totals | |
|---|---|
| Change from base Build 13615610519: | -1.3% |
| Covered Lines: | 3740 |
| Relevant Lines: | 4037 |
💛 - Coveralls
Some examples to illustrate the current limitations. Given a question with the answer 3600 s.
| Other rules | Answer | Grading |
|---|---|---|
min = 60 s; h = 60 min |
60 min | wrong |
| (same) | 1 h | wrong |
| (same) | 3600000 ms | wrong |
min = 60 s; 60 min = 1 h |
1 h | correct |
| (same) | 3600000 ms | wrong |
3600 s = 60 min = 1 h |
1 h | correct |
3600 s = 60 min = 1 h |
60 min | correct |
h = 60 min; min = 60 s |
60 min | correct |
| (same) | 1 h | correct |
The first three cases are graded wrong, because the current system checks whether there are any rules for the unit "min", which is not the case. Therefore, a new "dimension" (e. g. dimension number 16) is created for the unit "min" and a relation is created between "min" and "s" with "s" being shifted to dimension number 16. Afterwards, the system checks whether there is a rule for the unit "h", which is – again – not the case. Another new "dimension" (e. g. dimension number 17) is created for the unit "h" and relation is created between "h" and "min" with "min" (but not "s") being shifted to dimension number 17.
When the student enters "60 min", the system searches for a conversion rule for the unit "min". Once found, it reads the dimension (17) and compares that to the dimension of the model answer (16). As the dimension numbers are not the same, the system concludes that the two units are not compatible. The same happens, if the response is "1 h". For the response "3600000 ms", the answer's dimension is the original number (e. g. 1), so this unit has also become incompatible. Hence, all these answers are graded wrong.
The fifth case is wrong, because when parsing the rule min = 60 s, the new dimension (17) is propagated to the unit "s" whereas the unit "ms" is left at the original dimension (1), so "ms" has become incompatible to "s".