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 b775264677..708a594c4c 100644 --- a/exercises/book-store/.meta/template.j2 +++ b/exercises/book-store/.meta/template.j2 @@ -1,13 +1,26 @@ {%- 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): basket = {{ input["basket"] }} self.assertEqual({{ case["property"] }}(basket), {{ case["expected"] }}) +{%- 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() }} +{{ macros.footer() }} \ No newline at end of file diff --git a/exercises/book-store/book_store_test.py b/exercises/book-store/book_store_test.py index b993f2969c..79bda78f37 100644 --- a/exercises/book-store/book_store_test.py +++ b/exercises/book-store/book_store_test.py @@ -68,6 +68,16 @@ def test_four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three( basket = [1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5] self.assertEqual(total(basket), 10240) + # Additional tests for this track + + def test_two_groups_of_four_and_a_group_of_five(self): + 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): + basket = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3] + self.assertEqual(total(basket), 8120) + if __name__ == "__main__": unittest.main() diff --git a/exercises/book-store/example.py b/exercises/book-store/example.py index a9d0054b11..6d169ff187 100644 --- a/exercises/book-store/example.py +++ b/exercises/book-store/example.py @@ -23,4 +23,4 @@ def _total(books): def total(books): if not books: return 0 - return _total(sorted(books)) + return _total(sorted(books)) \ No newline at end of file