Skip to content

Commit

Permalink
[book-store] Add additional tests (#2174)
Browse files Browse the repository at this point in the history
* [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] Update from latest template.

* Crank the handle on Travis
  • Loading branch information
yawpitch authored Feb 20, 2020
1 parent d99090c commit 02d26aa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
22 changes: 22 additions & 0 deletions exercises/book-store/.meta/additional_tests.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
25 changes: 19 additions & 6 deletions exercises/book-store/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -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() }}
10 changes: 10 additions & 0 deletions exercises/book-store/book_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion exercises/book-store/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def _total(books):
def total(books):
if not books:
return 0
return _total(sorted(books))
return _total(sorted(books))

0 comments on commit 02d26aa

Please sign in to comment.