Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

book-store: Add test checking that solutions can mix groups of 4 and 5 #2141

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion exercises/book-store/book_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from book_store import total

# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.5.0


class BookStoreTest(unittest.TestCase):
Expand Down Expand Up @@ -83,6 +83,16 @@ def test_four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three(
table = 10240
self.assertEqual(total(results), table)

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()
1 change: 1 addition & 0 deletions exercises/book-store/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())