From f3a67f7f04f98307cb4e043ff823515aec32d0fc Mon Sep 17 00:00:00 2001 From: Michael Morehouse <640167+yawpitch@users.noreply.github.com> Date: Thu, 13 Feb 2020 15:26:27 +0000 Subject: [PATCH 1/3] [book-store] Add additional tests Adds tests that requires use of booth groups of 4 and 5 volumes. Closes #2141, which had gone stale. --- .../book-store/.meta/additional_tests.json | 22 ++++++++++++++++++ exercises/book-store/.meta/template.j2 | 23 +++++++++++++++---- exercises/book-store/book_store_test.py | 12 ++++++++++ exercises/book-store/example.py | 1 + 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 exercises/book-store/.meta/additional_tests.json diff --git a/exercises/book-store/.meta/additional_tests.json b/exercises/book-store/.meta/additional_tests.json new file mode 100644 index 0000000000..1fb19354bd --- /dev/null +++ b/exercises/book-store/.meta/additional_tests.json @@ -0,0 +1,22 @@ +{ + "cases": [ + { + "property": "total", + "description": "Two groups of four and a group of five", + "comments": ["Suggested grouping, [[1,2,3,4],[1,2,3,5],[1,2,3,4,5]]. Solutions can pass all the other tests if they just try to group without using any groups of 5. This test case breaks that since it requires both 4-groups and 5-groups."], + "input": { + "basket": [1,1,1,2,2,2,3,3,3,4,4,5,5] + }, + "expected": 8120 + }, + { + "property": "total", + "description": "Shuffled book order", + "comments": ["Suggested grouping, [[1,2,3,4],[1,2,3,5],[1,2,3,4,5]]. All the other tests give the books in sorted order. Robust solutions should be able to handle any order"], + "input": { + "basket": [1,2,3,4,5,1,2,3,4,5,1,2,3] + }, + "expected": 8120 + } + ] +} diff --git a/exercises/book-store/.meta/template.j2 b/exercises/book-store/.meta/template.j2 index 1802852a48..6da90d6e51 100644 --- a/exercises/book-store/.meta/template.j2 +++ b/exercises/book-store/.meta/template.j2 @@ -1,14 +1,27 @@ {%- import "generator_macros.j2" as macros with context -%} -{{ macros.header() }} - -class {{ exercise | camel_case }}Test(unittest.TestCase): - {% for casegroup in cases %}{% for case in casegroup["cases"] -%} +{% macro test_case(case) -%} {%- set input = case["input"] -%} def test_{{ case["description"] | to_snake }}(self): results = {{ input["basket"] }} table = {{ case["expected"] }} self.assertEqual({{ case["property"] }}(results), table) +{%- endmacro %} +{{ macros.header() }} + +class {{ exercise | camel_case }}Test(unittest.TestCase): + {% for casegroup in cases %} + {% for case in casegroup["cases"] -%} + {{ test_case(case) }} + {% endfor %} + {% endfor %} + + {% if additional_cases | length -%} + + # Additional tests for this track - {% endfor %}{% endfor %} + {% for case in additional_cases -%} + {{ test_case(case) }} + {% endfor %} + {%- endif %} {{ macros.footer() }} diff --git a/exercises/book-store/book_store_test.py b/exercises/book-store/book_store_test.py index 9bf91b85f9..b1750b9953 100644 --- a/exercises/book-store/book_store_test.py +++ b/exercises/book-store/book_store_test.py @@ -83,6 +83,18 @@ def test_four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three( table = 10240 self.assertEqual(total(results), table) + # Additional tests for this track + + def test_two_groups_of_four_and_a_group_of_five(self): + results = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5] + table = 8120 + self.assertEqual(total(results), table) + + def test_shuffled_book_order(self): + results = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3] + table = 8120 + self.assertEqual(total(results), table) + if __name__ == "__main__": unittest.main() diff --git a/exercises/book-store/example.py b/exercises/book-store/example.py index 4236656ada..24f1a0873c 100644 --- a/exercises/book-store/example.py +++ b/exercises/book-store/example.py @@ -47,5 +47,6 @@ def step(basket, book): def total(basket): if len(basket) == 0: return 0 + basket = sorted(basket) start = Grouping([{basket[0]}]) return round(min(reduce(step, basket[1:], [start])).total()) From 4925abd36701c9d28ed12798841bcece7c50df01 Mon Sep 17 00:00:00 2001 From: Michael Morehouse <640167+yawpitch@users.noreply.github.com> Date: Thu, 13 Feb 2020 15:41:12 +0000 Subject: [PATCH 2/3] [book-store] Update from latest template. --- exercises/book-store/book_store_test.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/exercises/book-store/book_store_test.py b/exercises/book-store/book_store_test.py index b8bef0bfcc..79bda78f37 100644 --- a/exercises/book-store/book_store_test.py +++ b/exercises/book-store/book_store_test.py @@ -71,14 +71,12 @@ def test_four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three( # Additional tests for this track def test_two_groups_of_four_and_a_group_of_five(self): - results = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5] - table = 8120 - self.assertEqual(total(results), table) + basket = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5] + self.assertEqual(total(basket), 8120) def test_shuffled_book_order(self): - results = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3] - table = 8120 - self.assertEqual(total(results), table) + basket = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3] + self.assertEqual(total(basket), 8120) if __name__ == "__main__": From 6aeba391cb362cfbf09cc12072a170765f8a6397 Mon Sep 17 00:00:00 2001 From: Michael Morehouse <640167+yawpitch@users.noreply.github.com> Date: Thu, 20 Feb 2020 16:47:44 +0000 Subject: [PATCH 3/3] Crank the handle on Travis