Skip to content

Commit 3e82c0d

Browse files
committed
Add templates for exercises batch 8
1 parent 4656993 commit 3e82c0d

12 files changed

Lines changed: 225 additions & 124 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'minitest/autorun'
2+
require_relative 'pig_latin'
3+
4+
class PigLatinTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
<% cases["cases"].each do |sub_case|%>
7+
def test_<%= underscore(sub_case["description"]) %>
8+
<%= skip? %>
9+
assert_equal '<%= sub_case["expected"] %>', PigLatin.translate('<%= sub_case["input"]["phrase"] %>')
10+
end
11+
<% end%>
12+
<% end %>
13+
end

exercises/practice/pig-latin/pig_latin_test.rb

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,116 @@
44
class PigLatinTest < Minitest::Test
55
def test_word_beginning_with_a
66
# skip
7-
assert_equal "appleay", PigLatin.translate("apple")
7+
assert_equal 'appleay', PigLatin.translate('apple')
88
end
99

1010
def test_word_beginning_with_e
1111
skip
12-
assert_equal "earay", PigLatin.translate("ear")
12+
assert_equal 'earay', PigLatin.translate('ear')
1313
end
1414

1515
def test_word_beginning_with_i
1616
skip
17-
assert_equal "iglooay", PigLatin.translate("igloo")
17+
assert_equal 'iglooay', PigLatin.translate('igloo')
1818
end
1919

2020
def test_word_beginning_with_o
2121
skip
22-
assert_equal "objectay", PigLatin.translate("object")
22+
assert_equal 'objectay', PigLatin.translate('object')
2323
end
2424

2525
def test_word_beginning_with_u
2626
skip
27-
assert_equal "underay", PigLatin.translate("under")
27+
assert_equal 'underay', PigLatin.translate('under')
2828
end
2929

3030
def test_word_beginning_with_a_vowel_and_followed_by_a_qu
3131
skip
32-
assert_equal "equalay", PigLatin.translate("equal")
32+
assert_equal 'equalay', PigLatin.translate('equal')
3333
end
3434

3535
def test_word_beginning_with_p
3636
skip
37-
assert_equal "igpay", PigLatin.translate("pig")
37+
assert_equal 'igpay', PigLatin.translate('pig')
3838
end
3939

4040
def test_word_beginning_with_k
4141
skip
42-
assert_equal "oalakay", PigLatin.translate("koala")
42+
assert_equal 'oalakay', PigLatin.translate('koala')
4343
end
4444

4545
def test_word_beginning_with_x
4646
skip
47-
assert_equal "enonxay", PigLatin.translate("xenon")
47+
assert_equal 'enonxay', PigLatin.translate('xenon')
4848
end
4949

5050
def test_word_beginning_with_q_without_a_following_u
5151
skip
52-
assert_equal "atqay", PigLatin.translate("qat")
52+
assert_equal 'atqay', PigLatin.translate('qat')
53+
end
54+
55+
def test_word_beginning_with_consonant_and_vowel_containing_qu
56+
skip
57+
assert_equal 'iquidlay', PigLatin.translate('liquid')
5358
end
5459

5560
def test_word_beginning_with_ch
5661
skip
57-
assert_equal "airchay", PigLatin.translate("chair")
62+
assert_equal 'airchay', PigLatin.translate('chair')
5863
end
5964

6065
def test_word_beginning_with_qu
6166
skip
62-
assert_equal "eenquay", PigLatin.translate("queen")
67+
assert_equal 'eenquay', PigLatin.translate('queen')
6368
end
6469

6570
def test_word_beginning_with_qu_and_a_preceding_consonant
6671
skip
67-
assert_equal "aresquay", PigLatin.translate("square")
72+
assert_equal 'aresquay', PigLatin.translate('square')
6873
end
6974

7075
def test_word_beginning_with_th
7176
skip
72-
assert_equal "erapythay", PigLatin.translate("therapy")
77+
assert_equal 'erapythay', PigLatin.translate('therapy')
7378
end
7479

7580
def test_word_beginning_with_thr
7681
skip
77-
assert_equal "ushthray", PigLatin.translate("thrush")
82+
assert_equal 'ushthray', PigLatin.translate('thrush')
7883
end
7984

8085
def test_word_beginning_with_sch
8186
skip
82-
assert_equal "oolschay", PigLatin.translate("school")
87+
assert_equal 'oolschay', PigLatin.translate('school')
8388
end
8489

8590
def test_word_beginning_with_yt
8691
skip
87-
assert_equal "yttriaay", PigLatin.translate("yttria")
92+
assert_equal 'yttriaay', PigLatin.translate('yttria')
8893
end
8994

9095
def test_word_beginning_with_xr
9196
skip
92-
assert_equal "xrayay", PigLatin.translate("xray")
97+
assert_equal 'xrayay', PigLatin.translate('xray')
9398
end
9499

95100
def test_y_is_treated_like_a_consonant_at_the_beginning_of_a_word
96101
skip
97-
assert_equal "ellowyay", PigLatin.translate("yellow")
102+
assert_equal 'ellowyay', PigLatin.translate('yellow')
98103
end
99104

100105
def test_y_is_treated_like_a_vowel_at_the_end_of_a_consonant_cluster
101106
skip
102-
assert_equal "ythmrhay", PigLatin.translate("rhythm")
107+
assert_equal 'ythmrhay', PigLatin.translate('rhythm')
103108
end
104109

105110
def test_y_as_second_letter_in_two_letter_word
106111
skip
107-
assert_equal "ymay", PigLatin.translate("my")
112+
assert_equal 'ymay', PigLatin.translate('my')
108113
end
109114

110115
def test_a_whole_phrase
111116
skip
112-
assert_equal "ickquay astfay unray", PigLatin.translate("quick fast run")
117+
assert_equal 'ickquay astfay unray', PigLatin.translate('quick fast run')
113118
end
114119
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 'poker'
3+
4+
class PokerTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
hands = [<%= cases["input"]["hands"].map{ |hand| "%w[#{hand}]"}.join(", ") %>]
9+
assert_equal [<%= cases["expected"].map{ |hand| "%w[#{hand}]"}.join(", ") %>], Poker.new(hands).best_hand
10+
end
11+
<% end %>
12+
end

exercises/practice/poker/poker_test.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def test_multiple_hands_with_the_same_high_cards_tie_compares_next_highest_ranke
2626
assert_equal [%w[3S 5H 6S 8D 7H]], Poker.new(hands).best_hand
2727
end
2828

29+
def test_winning_high_card_hand_also_has_the_lowest_card
30+
skip
31+
hands = [%w[2S 5H 6S 8D 7H], %w[3S 4D 6D 8C 7S]]
32+
assert_equal [%w[2S 5H 6S 8D 7H]], Poker.new(hands).best_hand
33+
end
34+
2935
def test_one_pair_beats_high_card
3036
skip
3137
hands = [%w[4S 5H 6C 8D KH], %w[2S 4H 6S 4D JH]]
@@ -38,6 +44,12 @@ def test_highest_pair_wins
3844
assert_equal [%w[2S 4H 6C 4D JD]], Poker.new(hands).best_hand
3945
end
4046

47+
def test_both_hands_have_the_same_pair_high_card_wins
48+
skip
49+
hands = [%w[4H 4S AH JC 3D], %w[4C 4D AS 5D 6C]]
50+
assert_equal [%w[4H 4S AH JC 3D]], Poker.new(hands).best_hand
51+
end
52+
4153
def test_two_pairs_beats_one_pair
4254
skip
4355
hands = [%w[2S 8H 6S 8D JH], %w[4S 5H 4C 8C 5C]]
@@ -88,7 +100,7 @@ def test_both_hands_have_three_of_a_kind_tie_goes_to_highest_ranked_triplet
88100

89101
def test_with_multiple_decks_two_players_can_have_same_three_of_a_kind_ties_go_to_highest_remaining_cards
90102
skip
91-
hands = [%w[4S AH AS 7C AD], %w[4S AH AS 8C AD]]
103+
hands = [%w[5S AH AS 7C AD], %w[4S AH AS 8C AD]]
92104
assert_equal [%w[4S AH AS 8C AD]], Poker.new(hands).best_hand
93105
end
94106

@@ -136,8 +148,8 @@ def test_flush_beats_a_straight
136148

137149
def test_both_hands_have_a_flush_tie_goes_to_high_card_down_to_the_last_one_if_necessary
138150
skip
139-
hands = [%w[4H 7H 8H 9H 6H], %w[2S 4S 5S 6S 7S]]
140-
assert_equal [%w[4H 7H 8H 9H 6H]], Poker.new(hands).best_hand
151+
hands = [%w[2H 7H 8H 9H 6H], %w[3S 5S 6S 7S 8S]]
152+
assert_equal [%w[2H 7H 8H 9H 6H]], Poker.new(hands).best_hand
141153
end
142154

143155
def test_full_house_beats_a_flush
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'minitest/autorun'
2+
require_relative 'prime_factors'
3+
4+
class PrimeFactorsTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
assert_equal <%= cases["expected"] %>, PrimeFactors.of(<%= cases["input"]["value"] %>)
9+
end
10+
<% end %>
11+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'minitest/autorun'
2+
require_relative 'protein_translation'
3+
4+
class ProteinTranslationTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
strand = '<%= cases["input"]["strand"] %>'
9+
<%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%>
10+
assert_raises(InvalidCodonError) do
11+
Translation.of_rna(strand)
12+
end
13+
<%- else -%>
14+
expected = %w[<%= cases["expected"].join(" ") %>]
15+
assert_equal expected, Translation.of_rna(strand)
16+
<%- end -%>
17+
end
18+
<% end %>
19+
end

0 commit comments

Comments
 (0)