Skip to content

Commit 55f7b91

Browse files
authored
Merge pull request #563 from hilary/pig_latin_with_generator
pig-latin: generate tests using canonical data
2 parents 7ae5bec + a15b651 commit 55f7b91

File tree

5 files changed

+119
-24
lines changed

5 files changed

+119
-24
lines changed

exercises/pig-latin/.meta/.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

exercises/pig-latin/example.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ def parse_initial_consonant_sound_and_remainder
2727
word.scan(/\A([^aeiou]?qu|[^aeiou]+)(.*)/).first
2828
end
2929
end
30+
31+
module BookKeeping
32+
VERSION = 1
33+
end

exercises/pig-latin/example.tt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env ruby
2+
gem 'minitest', '>= 5.0.0'
3+
require 'minitest/autorun'
4+
require_relative 'pig_latin'
5+
6+
# Common test data version: <%= abbreviated_commit_hash %>
7+
class PigLatinTest < Minitest::Test
8+
<% test_cases.each do |test_case| %>
9+
def <%= test_case.name %>
10+
<%= test_case.skipped %>
11+
<%= test_case.workload %>
12+
end
13+
14+
<% end %>
15+
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
16+
17+
def test_bookkeeping
18+
skip
19+
assert_equal <%= version %>, BookKeeping::VERSION
20+
end
21+
end

exercises/pig-latin/pig_latin_test.rb

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,127 @@
33
require 'minitest/autorun'
44
require_relative 'pig_latin'
55

6+
# Common test data version: d4e9a22
67
class PigLatinTest < Minitest::Test
78
def test_word_beginning_with_a
8-
assert_equal 'appleay', PigLatin.translate('apple')
9+
# skip
10+
assert_equal "appleay", PigLatin.translate("apple")
911
end
1012

11-
def test_other_word_beginning_e
13+
def test_word_beginning_with_e
1214
skip
13-
assert_equal 'earay', PigLatin.translate('ear')
15+
assert_equal "earay", PigLatin.translate("ear")
16+
end
17+
18+
def test_word_beginning_with_i
19+
skip
20+
assert_equal "iglooay", PigLatin.translate("igloo")
21+
end
22+
23+
def test_word_beginning_with_o
24+
skip
25+
assert_equal "objectay", PigLatin.translate("object")
26+
end
27+
28+
def test_word_beginning_with_u
29+
skip
30+
assert_equal "underay", PigLatin.translate("under")
31+
end
32+
33+
def test_word_beginning_with_a_vowel_and_followed_by_a_qu
34+
skip
35+
assert_equal "equalay", PigLatin.translate("equal")
1436
end
1537

1638
def test_word_beginning_with_p
1739
skip
18-
assert_equal 'igpay', PigLatin.translate('pig')
40+
assert_equal "igpay", PigLatin.translate("pig")
1941
end
2042

2143
def test_word_beginning_with_k
2244
skip
23-
assert_equal 'oalakay', PigLatin.translate('koala')
45+
assert_equal "oalakay", PigLatin.translate("koala")
46+
end
47+
48+
def test_word_beginning_with_y
49+
skip
50+
assert_equal "ellowyay", PigLatin.translate("yellow")
51+
end
52+
53+
def test_word_beginning_with_x
54+
skip
55+
assert_equal "enonxay", PigLatin.translate("xenon")
56+
end
57+
58+
def test_word_beginning_with_q_without_a_following_u
59+
skip
60+
assert_equal "atqay", PigLatin.translate("qat")
2461
end
2562

2663
def test_word_beginning_with_ch
2764
skip
28-
assert_equal 'airchay', PigLatin.translate('chair')
65+
assert_equal "airchay", PigLatin.translate("chair")
2966
end
3067

3168
def test_word_beginning_with_qu
3269
skip
33-
assert_equal 'eenquay', PigLatin.translate('queen')
70+
assert_equal "eenquay", PigLatin.translate("queen")
3471
end
3572

36-
def test_word_with_consonant_preceding_qu
73+
def test_word_beginning_with_qu_and_a_preceding_consonant
3774
skip
38-
assert_equal 'aresquay', PigLatin.translate('square')
75+
assert_equal "aresquay", PigLatin.translate("square")
3976
end
4077

4178
def test_word_beginning_with_th
4279
skip
43-
assert_equal 'erapythay', PigLatin.translate('therapy')
80+
assert_equal "erapythay", PigLatin.translate("therapy")
4481
end
4582

4683
def test_word_beginning_with_thr
4784
skip
48-
assert_equal 'ushthray', PigLatin.translate('thrush')
85+
assert_equal "ushthray", PigLatin.translate("thrush")
4986
end
5087

5188
def test_word_beginning_with_sch
5289
skip
53-
assert_equal 'oolschay', PigLatin.translate('school')
90+
assert_equal "oolschay", PigLatin.translate("school")
5491
end
5592

56-
def test_translates_phrase
93+
def test_word_beginning_with_yt
5794
skip
58-
assert_equal 'ickquay astfay unray', PigLatin.translate('quick fast run')
95+
assert_equal "yttriaay", PigLatin.translate("yttria")
5996
end
6097

61-
def test_word_beginning_with_ye
98+
def test_word_beginning_with_xr
6299
skip
63-
assert_equal 'ellowyay', PigLatin.translate('yellow')
100+
assert_equal "xrayay", PigLatin.translate("xray")
64101
end
65102

66-
def test_word_beginning_with_yt
103+
def test_a_whole_phrase
67104
skip
68-
assert_equal 'yttriaay', PigLatin.translate('yttria')
105+
assert_equal "ickquay astfay unray", PigLatin.translate("quick fast run")
69106
end
70107

71-
def test_word_beginning_with_xe
72-
skip
73-
assert_equal 'enonxay', PigLatin.translate('xenon')
74-
end
108+
# Problems in exercism evolve over time, as we find better ways to ask
109+
# questions.
110+
# The version number refers to the version of the problem you solved,
111+
# not your solution.
112+
#
113+
# Define a constant named VERSION inside of the top level BookKeeping
114+
# module, which may be placed near the end of your file.
115+
#
116+
# In your file, it will look like this:
117+
#
118+
# module BookKeeping
119+
# VERSION = 1 # Where the version number matches the one in the test.
120+
# end
121+
#
122+
# If you are curious, read more about constants on RubyDoc:
123+
# http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html
75124

76-
def test_word_beginning_with_xr
125+
def test_bookkeeping
77126
skip
78-
assert_equal 'xrayay', PigLatin.translate('xray')
127+
assert_equal 1, BookKeeping::VERSION
79128
end
80129
end

lib/pig_latin_cases.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'exercise_cases'
2+
3+
class PigLatinCase < OpenStruct
4+
def name
5+
'test_%s' % description.tr('- ', '__')
6+
end
7+
8+
def workload
9+
%Q(assert_equal #{expected.inspect}, PigLatin.translate(#{input.inspect}))
10+
end
11+
12+
def skipped
13+
index.zero? ? '# skip' : 'skip'
14+
end
15+
end
16+
17+
PigLatinCases = proc do |data|
18+
JSON.parse(data)['cases'].flat_map {|section| section['cases'] }. # extract all the cases into a single array
19+
map.with_index { |test, index| PigLatinCase.new(test.merge('index' => index)) }
20+
end

0 commit comments

Comments
 (0)