Skip to content

Commit e64b1ea

Browse files
kytrinyxkotp
authored andcommitted
Sync book-store with problem-specifications
The sync updated the docs and the tests.toml file. Regenerating the test suite added several new tests. One of the tests had a failure due to a rounding difference: Expected: 145.6 Actual: 145.60000000000002 I changed the test suite to use assert_in_delta instead.
1 parent 6e11019 commit e64b1ea

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

exercises/practice/book-store/.docs/instructions.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
# Instructions
22

3-
To try and encourage more sales of different books from a popular 5 book
4-
series, a bookshop has decided to offer discounts on multiple book purchases.
3+
To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts on multiple book purchases.
54

65
One copy of any of the five books costs $8.
76

8-
If, however, you buy two different books, you get a 5%
9-
discount on those two books.
7+
If, however, you buy two different books, you get a 5% discount on those two books.
108

119
If you buy 3 different books, you get a 10% discount.
1210

1311
If you buy 4 different books, you get a 20% discount.
1412

1513
If you buy all 5, you get a 25% discount.
1614

17-
Note: that if you buy four books, of which 3 are
18-
different titles, you get a 10% discount on the 3 that
19-
form part of a set, but the fourth book still costs $8.
15+
Note: that if you buy four books, of which 3 are different titles, you get a 10% discount on the 3 that form part of a set, but the fourth book still costs $8.
2016

21-
Your mission is to write a piece of code to calculate the
22-
price of any conceivable shopping basket (containing only
23-
books of the same series), giving as big a discount as
24-
possible.
17+
Your mission is to write a piece of code to calculate the price of any conceivable shopping basket (containing only books of the same series), giving as big a discount as possible.
2518

2619
For example, how much does this basket of books cost?
2720

@@ -43,8 +36,8 @@ This would give a total of:
4336

4437
Resulting in:
4538

46-
- 5 x (8 - 2.00) == 5 x 6.00 == $30.00
47-
- +3 x (8 - 0.80) == 3 x 7.20 == $21.60
39+
- 5 × (8 - 2.00) = 5 × 6.00 = $30.00
40+
- +3 × (8 - 0.80) = 3 × 7.20 = $21.60
4841

4942
For a total of $51.60
5043

@@ -60,8 +53,8 @@ This would give a total of:
6053

6154
Resulting in:
6255

63-
- 4 x (8 - 1.60) == 4 x 6.40 == $25.60
64-
- +4 x (8 - 1.60) == 4 x 6.40 == $25.60
56+
- 4 × (8 - 1.60) = 4 × 6.40 = $25.60
57+
- +4 × (8 - 1.60) = 4 × 6.40 = $25.60
6558

6659
For a total of $51.20
6760

exercises/practice/book-store/.meta/tests.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,25 @@ description = "Two groups of four is cheaper than groups of five and three"
4040
description = "Group of four plus group of two is cheaper than two groups of three"
4141

4242
[68ea9b78-10ad-420e-a766-836a501d3633]
43-
description = "Two each of first 4 books and 1 copy each of rest"
43+
description = "Two each of first four books and one copy each of rest"
4444

4545
[c0a779d5-a40c-47ae-9828-a340e936b866]
4646
description = "Two copies of each book"
4747

4848
[18fd86fe-08f1-4b68-969b-392b8af20513]
49-
description = "Three copies of first book and 2 each of remaining"
49+
description = "Three copies of first book and two each of remaining"
5050

5151
[0b19a24d-e4cf-4ec8-9db2-8899a41af0da]
52-
description = "Three each of first 2 books and 2 each of remaining books"
52+
description = "Three each of first two books and two each of remaining books"
5353

5454
[bb376344-4fb2-49ab-ab85-e38d8354a58d]
5555
description = "Four groups of four are cheaper than two groups each of five and three"
56+
57+
[5260ddde-2703-4915-b45a-e54dbbac4303]
58+
description = "Check that groups of four are created properly even when there are more groups of three than groups of five"
59+
60+
[b0478278-c551-4747-b0fc-7e0be3158b1f]
61+
description = "One group of one and four is cheaper than one group of two and three"
62+
63+
[cf868453-6484-4ae1-9dfc-f8ee85bbde01]
64+
description = "One group of one and two plus three groups of four is cheaper than one group of each size"

exercises/practice/book-store/book_store_test.rb

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,108 @@ class BookStoreTest < Minitest::Test
55
def test_only_a_single_book
66
# skip
77
basket = [1]
8-
assert_equal 8.00, BookStore.calculate_price(basket)
8+
assert_in_delta 8.00, BookStore.calculate_price(basket), 0.001
99
end
1010

1111
def test_two_of_the_same_book
1212
skip
1313
basket = [2, 2]
14-
assert_equal 16.00, BookStore.calculate_price(basket)
14+
assert_in_delta 16.00, BookStore.calculate_price(basket), 0.001
1515
end
1616

1717
def test_empty_basket
1818
skip
1919
basket = []
20-
assert_equal 0.00, BookStore.calculate_price(basket)
20+
assert_in_delta 0.00, BookStore.calculate_price(basket), 0.001
2121
end
2222

2323
def test_two_different_books
2424
skip
2525
basket = [1, 2]
26-
assert_equal 15.20, BookStore.calculate_price(basket)
26+
assert_in_delta 15.20, BookStore.calculate_price(basket), 0.001
2727
end
2828

2929
def test_three_different_books
3030
skip
3131
basket = [1, 2, 3]
32-
assert_equal 21.60, BookStore.calculate_price(basket)
32+
assert_in_delta 21.60, BookStore.calculate_price(basket), 0.001
3333
end
3434

3535
def test_four_different_books
3636
skip
3737
basket = [1, 2, 3, 4]
38-
assert_equal 25.60, BookStore.calculate_price(basket)
38+
assert_in_delta 25.60, BookStore.calculate_price(basket), 0.001
3939
end
4040

4141
def test_five_different_books
4242
skip
4343
basket = [1, 2, 3, 4, 5]
44-
assert_equal 30.00, BookStore.calculate_price(basket)
44+
assert_in_delta 30.00, BookStore.calculate_price(basket), 0.001
4545
end
4646

4747
def test_two_groups_of_four_is_cheaper_than_group_of_five_plus_group_of_three
4848
skip
4949
basket = [1, 1, 2, 2, 3, 3, 4, 5]
50-
assert_equal 51.20, BookStore.calculate_price(basket)
50+
assert_in_delta 51.20, BookStore.calculate_price(basket), 0.001
5151
end
5252

5353
def test_two_groups_of_four_is_cheaper_than_groups_of_five_and_three
5454
skip
5555
basket = [1, 1, 2, 3, 4, 4, 5, 5]
56-
assert_equal 51.20, BookStore.calculate_price(basket)
56+
assert_in_delta 51.20, BookStore.calculate_price(basket), 0.001
5757
end
5858

5959
def test_group_of_four_plus_group_of_two_is_cheaper_than_two_groups_of_three
6060
skip
6161
basket = [1, 1, 2, 2, 3, 4]
62-
assert_equal 40.80, BookStore.calculate_price(basket)
62+
assert_in_delta 40.80, BookStore.calculate_price(basket), 0.001
6363
end
6464

65-
def test_two_each_of_first_4_books_and_1_copy_each_of_rest
65+
def test_two_each_of_first_four_books_and_one_copy_each_of_rest
6666
skip
6767
basket = [1, 1, 2, 2, 3, 3, 4, 4, 5]
68-
assert_equal 55.60, BookStore.calculate_price(basket)
68+
assert_in_delta 55.60, BookStore.calculate_price(basket), 0.001
6969
end
7070

7171
def test_two_copies_of_each_book
7272
skip
7373
basket = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
74-
assert_equal 60.00, BookStore.calculate_price(basket)
74+
assert_in_delta 60.00, BookStore.calculate_price(basket), 0.001
7575
end
7676

77-
def test_three_copies_of_first_book_and_2_each_of_remaining
77+
def test_three_copies_of_first_book_and_two_each_of_remaining
7878
skip
7979
basket = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1]
80-
assert_equal 68.00, BookStore.calculate_price(basket)
80+
assert_in_delta 68.00, BookStore.calculate_price(basket), 0.001
8181
end
8282

83-
def test_three_each_of_first_2_books_and_2_each_of_remaining_books
83+
def test_three_each_of_first_two_books_and_two_each_of_remaining_books
8484
skip
8585
basket = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2]
86-
assert_equal 75.20, BookStore.calculate_price(basket)
86+
assert_in_delta 75.20, BookStore.calculate_price(basket), 0.001
8787
end
8888

8989
def test_four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three
9090
skip
9191
basket = [1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5]
92-
assert_equal 102.40, BookStore.calculate_price(basket)
92+
assert_in_delta 102.40, BookStore.calculate_price(basket), 0.001
93+
end
94+
95+
def test_check_that_groups_of_four_are_created_properly_even_when_there_are_more_groups_of_three_than_groups_of_five
96+
skip
97+
basket = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5]
98+
assert_in_delta 145.60, BookStore.calculate_price(basket), 0.001
99+
end
100+
101+
def test_one_group_of_one_and_four_is_cheaper_than_one_group_of_two_and_three
102+
skip
103+
basket = [1, 1, 2, 3, 4]
104+
assert_in_delta 33.60, BookStore.calculate_price(basket), 0.001
105+
end
106+
107+
def test_one_group_of_one_and_two_plus_three_groups_of_four_is_cheaper_than_one_group_of_each_size
108+
skip
109+
basket = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
110+
assert_in_delta 100.00, BookStore.calculate_price(basket), 0.001
93111
end
94112
end

0 commit comments

Comments
 (0)