Skip to content

Commit 75e1e23

Browse files
committed
Update bob and change and book store
1 parent 2b6c97d commit 75e1e23

5 files changed

Lines changed: 100 additions & 37 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'minitest/autorun'
2+
require_relative 'bob'
3+
4+
class BobTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
remark = <%= cases["input"]["heyBob"].dump() %>
9+
assert_equal "<%= cases["expected"] %>", Bob.hey(remark), <%= "Bob hears #{ cases["input"]["heyBob"].dump}, and..".dump %>
10+
end
11+
<% end %>
12+
end

exercises/practice/bob/bob_test.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,150 +5,150 @@ class BobTest < Minitest::Test
55
def test_stating_something
66
# skip
77
remark = "Tom-ay-to, tom-aaaah-to."
8-
assert_equal "Whatever.", Bob.hey(remark), 'Bob hears "Tom-ay-to, tom-aaaah-to.", and..'
8+
assert_equal "Whatever.", Bob.hey(remark), "Bob hears \"Tom-ay-to, tom-aaaah-to.\", and.."
99
end
1010

1111
def test_shouting
1212
skip
1313
remark = "WATCH OUT!"
14-
assert_equal "Whoa, chill out!", Bob.hey(remark), 'Bob hears "WATCH OUT!", and..'
14+
assert_equal "Whoa, chill out!", Bob.hey(remark), "Bob hears \"WATCH OUT!\", and.."
1515
end
1616

1717
def test_shouting_gibberish
1818
skip
1919
remark = "FCECDFCAAB"
20-
assert_equal "Whoa, chill out!", Bob.hey(remark), 'Bob hears "FCECDFCAAB", and..'
20+
assert_equal "Whoa, chill out!", Bob.hey(remark), "Bob hears \"FCECDFCAAB\", and.."
2121
end
2222

2323
def test_asking_a_question
2424
skip
2525
remark = "Does this cryogenic chamber make me look fat?"
26-
assert_equal "Sure.", Bob.hey(remark), 'Bob hears "Does this cryogenic chamber make me look fat?", and..'
26+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \"Does this cryogenic chamber make me look fat?\", and.."
2727
end
2828

2929
def test_asking_a_numeric_question
3030
skip
3131
remark = "You are, what, like 15?"
32-
assert_equal "Sure.", Bob.hey(remark), 'Bob hears "You are, what, like 15?", and..'
32+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \"You are, what, like 15?\", and.."
3333
end
3434

3535
def test_asking_gibberish
3636
skip
3737
remark = "fffbbcbeab?"
38-
assert_equal "Sure.", Bob.hey(remark), 'Bob hears "fffbbcbeab?", and..'
38+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \"fffbbcbeab?\", and.."
3939
end
4040

4141
def test_talking_forcefully
4242
skip
4343
remark = "Hi there!"
44-
assert_equal "Whatever.", Bob.hey(remark), 'Bob hears "Hi there!", and..'
44+
assert_equal "Whatever.", Bob.hey(remark), "Bob hears \"Hi there!\", and.."
4545
end
4646

4747
def test_using_acronyms_in_regular_speech
4848
skip
4949
remark = "It's OK if you don't want to go work for NASA."
50-
assert_equal "Whatever.", Bob.hey(remark), %q(Bob hears "It's OK if you don't want to go work for NASA.", and..)
50+
assert_equal "Whatever.", Bob.hey(remark), "Bob hears \"It's OK if you don't want to go work for NASA.\", and.."
5151
end
5252

5353
def test_forceful_question
5454
skip
5555
remark = "WHAT'S GOING ON?"
56-
assert_equal "Calm down, I know what I'm doing!", Bob.hey(remark), %q(Bob hears "WHAT'S GOING ON?", and..)
56+
assert_equal "Calm down, I know what I'm doing!", Bob.hey(remark), "Bob hears \"WHAT'S GOING ON?\", and.."
5757
end
5858

5959
def test_shouting_numbers
6060
skip
6161
remark = "1, 2, 3 GO!"
62-
assert_equal "Whoa, chill out!", Bob.hey(remark), 'Bob hears "1, 2, 3 GO!", and..'
62+
assert_equal "Whoa, chill out!", Bob.hey(remark), "Bob hears \"1, 2, 3 GO!\", and.."
6363
end
6464

6565
def test_no_letters
6666
skip
6767
remark = "1, 2, 3"
68-
assert_equal "Whatever.", Bob.hey(remark), 'Bob hears "1, 2, 3", and..'
68+
assert_equal "Whatever.", Bob.hey(remark), "Bob hears \"1, 2, 3\", and.."
6969
end
7070

7171
def test_question_with_no_letters
7272
skip
7373
remark = "4?"
74-
assert_equal "Sure.", Bob.hey(remark), 'Bob hears "4?", and..'
74+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \"4?\", and.."
7575
end
7676

7777
def test_shouting_with_special_characters
7878
skip
7979
remark = "ZOMG THE %^*@\#$(*^ ZOMBIES ARE COMING!!11!!1!"
80-
assert_equal "Whoa, chill out!", Bob.hey(remark), %q{Bob hears "ZOMG THE %^*@\#$(*^ ZOMBIES ARE COMING!!11!!1!", and..}
80+
assert_equal "Whoa, chill out!", Bob.hey(remark), "Bob hears \"ZOMG THE %^*@\\\#$(*^ ZOMBIES ARE COMING!!11!!1!\", and.."
8181
end
8282

8383
def test_shouting_with_no_exclamation_mark
8484
skip
8585
remark = "I HATE THE DENTIST"
86-
assert_equal "Whoa, chill out!", Bob.hey(remark), 'Bob hears "I HATE THE DENTIST", and..'
86+
assert_equal "Whoa, chill out!", Bob.hey(remark), "Bob hears \"I HATE THE DENTIST\", and.."
8787
end
8888

8989
def test_statement_containing_question_mark
9090
skip
9191
remark = "Ending with ? means a question."
92-
assert_equal "Whatever.", Bob.hey(remark), 'Bob hears "Ending with ? means a question.", and..'
92+
assert_equal "Whatever.", Bob.hey(remark), "Bob hears \"Ending with ? means a question.\", and.."
9393
end
9494

9595
def test_non_letters_with_question
9696
skip
9797
remark = ":) ?"
98-
assert_equal "Sure.", Bob.hey(remark), 'Bob hears ":) ?", and..'
98+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \":) ?\", and.."
9999
end
100100

101101
def test_prattling_on
102102
skip
103103
remark = "Wait! Hang on. Are you going to be OK?"
104-
assert_equal "Sure.", Bob.hey(remark), 'Bob hears "Wait! Hang on. Are you going to be OK?", and..'
104+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \"Wait! Hang on. Are you going to be OK?\", and.."
105105
end
106106

107107
def test_silence
108108
skip
109109
remark = ""
110-
assert_equal "Fine. Be that way!", Bob.hey(remark), 'Bob hears "", and..'
110+
assert_equal "Fine. Be that way!", Bob.hey(remark), "Bob hears \"\", and.."
111111
end
112112

113113
def test_prolonged_silence
114114
skip
115115
remark = " "
116-
assert_equal "Fine. Be that way!", Bob.hey(remark), 'Bob hears " ", and..'
116+
assert_equal "Fine. Be that way!", Bob.hey(remark), "Bob hears \" \", and.."
117117
end
118118

119119
def test_alternate_silence
120120
skip
121121
remark = "\t\t\t\t\t\t\t\t\t\t"
122-
assert_equal "Fine. Be that way!", Bob.hey(remark), %q(Bob hears "\t\t\t\t\t\t\t\t\t\t", and..)
123-
end
124-
125-
def test_multiple_line_question
126-
skip
127-
remark = "\nDoes this cryogenic chamber make me look fat?\nNo."
128-
assert_equal "Whatever.", Bob.hey(remark), %q(Bob hears "\nDoes this cryogenic chamber make me look fat?\nNo.", and..)
122+
assert_equal "Fine. Be that way!", Bob.hey(remark), "Bob hears \"\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\", and.."
129123
end
130124

131125
def test_starting_with_whitespace
132126
skip
133127
remark = " hmmmmmmm..."
134-
assert_equal "Whatever.", Bob.hey(remark), 'Bob hears " hmmmmmmm...", and..'
128+
assert_equal "Whatever.", Bob.hey(remark), "Bob hears \" hmmmmmmm...\", and.."
135129
end
136130

137131
def test_ending_with_whitespace
138132
skip
139133
remark = "Okay if like my spacebar quite a bit? "
140-
assert_equal "Sure.", Bob.hey(remark), 'Bob hears "Okay if like my spacebar quite a bit? ", and..'
134+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \"Okay if like my spacebar quite a bit? \", and.."
141135
end
142136

143137
def test_other_whitespace
144138
skip
145139
remark = "\n\r \t"
146-
assert_equal "Fine. Be that way!", Bob.hey(remark), %q(Bob hears "\n\r \t", and..)
140+
assert_equal "Fine. Be that way!", Bob.hey(remark), "Bob hears \"\\n\\r \\t\", and.."
147141
end
148142

149143
def test_non_question_ending_with_whitespace
150144
skip
151145
remark = "This is a statement ending with whitespace "
152-
assert_equal "Whatever.", Bob.hey(remark), 'Bob hears "This is a statement ending with whitespace ", and..'
146+
assert_equal "Whatever.", Bob.hey(remark), "Bob hears \"This is a statement ending with whitespace \", and.."
147+
end
148+
149+
def test_multiple_line_question
150+
skip
151+
remark = "\nDoes this cryogenic chamber make\n me look fat?"
152+
assert_equal "Sure.", Bob.hey(remark), "Bob hears \"\\nDoes this cryogenic chamber make\\n me look fat?\", and.."
153153
end
154154
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'minitest/autorun'
2+
require_relative 'book_store'
3+
4+
class BookStoreTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
basket = <%= cases["input"]["basket"] %>
9+
assert_in_delta <%= cases["expected"] / 100.0 %>0, BookStore.calculate_price(basket), 0.001
10+
end
11+
<% end %>
12+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'minitest/autorun'
2+
require_relative 'change'
3+
4+
class ChangeTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
<%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%>
9+
<%- if cases["expected"]["error"] == "can't make target with given coins" -%>
10+
assert_raises(Change::ImpossibleCombinationError) do
11+
<%- elsif cases["expected"]["error"] == "target can't be negative" -%>
12+
assert_raises(Change::NegativeTargetError) do
13+
<%- end -%>
14+
Change.generate(<%= cases["input"]["coins"] %>, <%= cases["input"]["target"] %>)
15+
end
16+
<%- else -%>
17+
<%- if cases["expected"].empty? -%>
18+
assert_empty Change.generate(<%= cases["input"]["coins"] %>, <%= cases["input"]["target"] %>)
19+
<%- else -%>
20+
expected = <%= cases["expected"] %>
21+
assert_equal expected, Change.generate(<%= cases["input"]["coins"] %>, <%= cases["input"]["target"] %>)
22+
<%- end -%>
23+
<%- end -%>
24+
end
25+
<% end %>
26+
end

exercises/practice/change/change_test.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,32 @@
44
class ChangeTest < Minitest::Test
55
def test_change_for_1_cent
66
# skip
7-
assert_equal [1], Change.generate([1, 5, 10, 25], 1)
7+
expected = [1]
8+
assert_equal expected, Change.generate([1, 5, 10, 25], 1)
89
end
910

1011
def test_single_coin_change
1112
skip
12-
assert_equal [25], Change.generate([1, 5, 10, 25, 100], 25)
13+
expected = [25]
14+
assert_equal expected, Change.generate([1, 5, 10, 25, 100], 25)
1315
end
1416

1517
def test_multiple_coin_change
1618
skip
17-
assert_equal [5, 10], Change.generate([1, 5, 10, 25, 100], 15)
19+
expected = [5, 10]
20+
assert_equal expected, Change.generate([1, 5, 10, 25, 100], 15)
1821
end
1922

2023
def test_change_with_lilliputian_coins
2124
skip
22-
assert_equal [4, 4, 15], Change.generate([1, 4, 15, 20, 50], 23)
25+
expected = [4, 4, 15]
26+
assert_equal expected, Change.generate([1, 4, 15, 20, 50], 23)
2327
end
2428

2529
def test_change_with_lower_elbonia_coins
2630
skip
27-
assert_equal [21, 21, 21], Change.generate([1, 5, 10, 21, 25], 63)
31+
expected = [21, 21, 21]
32+
assert_equal expected, Change.generate([1, 5, 10, 21, 25], 63)
2833
end
2934

3035
def test_large_target_values
@@ -35,12 +40,20 @@ def test_large_target_values
3540

3641
def test_possible_change_without_unit_coins_available
3742
skip
38-
assert_equal [2, 2, 2, 5, 10], Change.generate([2, 5, 10, 20, 50], 21)
43+
expected = [2, 2, 2, 5, 10]
44+
assert_equal expected, Change.generate([2, 5, 10, 20, 50], 21)
3945
end
4046

4147
def test_another_possible_change_without_unit_coins_available
4248
skip
43-
assert_equal [4, 4, 4, 5, 5, 5], Change.generate([4, 5], 27)
49+
expected = [4, 4, 4, 5, 5, 5]
50+
assert_equal expected, Change.generate([4, 5], 27)
51+
end
52+
53+
def test_a_greedy_approach_is_not_optimal
54+
skip
55+
expected = [10, 10]
56+
assert_equal expected, Change.generate([1, 10, 11], 20)
4457
end
4558

4659
def test_no_coins_make_0_change

0 commit comments

Comments
 (0)