diff --git a/exercises/practice/high-scores/.meta/config.json b/exercises/practice/high-scores/.meta/config.json index 3567a3e6a8..37ec344ff5 100644 --- a/exercises/practice/high-scores/.meta/config.json +++ b/exercises/practice/high-scores/.meta/config.json @@ -9,6 +9,7 @@ "Dog", "gabriel376", "GascaK", + "IsaacG", "simmol", "tqa236", "yawpitch" diff --git a/exercises/practice/high-scores/.meta/template.j2 b/exercises/practice/high-scores/.meta/template.j2 index abfa13e4b0..c32ae121ae 100644 --- a/exercises/practice/high-scores/.meta/template.j2 +++ b/exercises/practice/high-scores/.meta/template.j2 @@ -1,14 +1,23 @@ {%- import "generator_macros.j2" as macros with context -%} +{%- macro get_property(property) %} + {%- if property == "scores" %} + scores + {%- else %} + {{ property | to_snake }}() + {% endif -%} +{% endmacro -%} + {%- macro testcase(case) %} def test_{{ case["description"] | to_snake }}(self): scores = {{ case["input"]["scores"] }} expected = {{ case["expected"] }} - {%- if "latest_after_" not in ( case["property"] | to_snake ) %} - self.assertEqual(HighScores(scores).{{ case["property"] | to_snake }}(), expected) + {%- if "_after_" not in ( case["property"] | to_snake ) %} + self.assertEqual(HighScores(scores).{{ get_property(case["property"]) }}, expected) {%- else %} + {%- set property, function = (case["property"] | to_snake).split("_after_") %} highscores = HighScores(scores) - highscores.{{ case["property"] | to_snake | replace("latest_after_", "personal_") }}() - self.assertEqual(highscores.latest(), expected) + highscores.personal_{{ function }}() + self.assertEqual(highscores.{{ get_property(property) }}, expected) {% endif -%} {% endmacro -%} @@ -19,13 +28,9 @@ class {{ exercise | camel_case }}Test(unittest.TestCase): {%- for case in cases -%} {%- if "cases" in case -%} {%- for subcase in case["cases"] -%} - {%- if "scores_after_" not in ( subcase["property"] | to_snake ) %} {{- testcase(subcase) -}} - {% endif -%} {% endfor %} {%- else %} - {%- if case["property"] != "scores" %} {{- testcase(case) -}} {% endif -%} - {% endif -%} {% endfor %} diff --git a/exercises/practice/high-scores/high_scores_test.py b/exercises/practice/high-scores/high_scores_test.py index f38edec940..3d47d27578 100644 --- a/exercises/practice/high-scores/high_scores_test.py +++ b/exercises/practice/high-scores/high_scores_test.py @@ -8,6 +8,11 @@ class HighScoresTest(unittest.TestCase): + def test_list_of_scores(self): + scores = [30, 50, 20, 70] + expected = [30, 50, 20, 70] + self.assertEqual(HighScores(scores).scores, expected) + def test_latest_score(self): scores = [100, 0, 90, 30] expected = 30 @@ -49,3 +54,10 @@ def test_latest_score_after_personal_top_scores(self): highscores = HighScores(scores) highscores.personal_top_three() self.assertEqual(highscores.latest(), expected) + + def test_scores_after_personal_top_scores(self): + scores = [30, 50, 20, 70] + expected = [30, 50, 20, 70] + highscores = HighScores(scores) + highscores.personal_top_three() + self.assertEqual(highscores.scores, expected)