diff --git a/exercises/book-store/book_store_test.py b/exercises/book-store/book_store_test.py index 9bf91b85f9..14de459815 100644 --- a/exercises/book-store/book_store_test.py +++ b/exercises/book-store/book_store_test.py @@ -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): @@ -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() 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())