diff --git a/exercises/pig-latin/.meta/.version b/exercises/pig-latin/.meta/.version new file mode 100644 index 0000000000..56a6051ca2 --- /dev/null +++ b/exercises/pig-latin/.meta/.version @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/exercises/pig-latin/example.rb b/exercises/pig-latin/example.rb index 52a227ee79..df5ad03003 100644 --- a/exercises/pig-latin/example.rb +++ b/exercises/pig-latin/example.rb @@ -27,3 +27,7 @@ def parse_initial_consonant_sound_and_remainder word.scan(/\A([^aeiou]?qu|[^aeiou]+)(.*)/).first end end + +module BookKeeping + VERSION = 1 +end diff --git a/exercises/pig-latin/example.tt b/exercises/pig-latin/example.tt new file mode 100644 index 0000000000..f27a0f9d56 --- /dev/null +++ b/exercises/pig-latin/example.tt @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby +gem 'minitest', '>= 5.0.0' +require 'minitest/autorun' +require_relative 'pig_latin' + +# Common test data version: <%= abbreviated_commit_hash %> +class PigLatinTest < Minitest::Test +<% test_cases.each do |test_case| %> + def <%= test_case.name %> + <%= test_case.skipped %> + <%= test_case.workload %> + end + +<% end %> +<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %> + + def test_bookkeeping + skip + assert_equal <%= version %>, BookKeeping::VERSION + end +end diff --git a/exercises/pig-latin/pig_latin_test.rb b/exercises/pig-latin/pig_latin_test.rb index f62a7dee8f..83a2e534f1 100755 --- a/exercises/pig-latin/pig_latin_test.rb +++ b/exercises/pig-latin/pig_latin_test.rb @@ -3,78 +3,127 @@ require 'minitest/autorun' require_relative 'pig_latin' +# Common test data version: d4e9a22 class PigLatinTest < Minitest::Test def test_word_beginning_with_a - assert_equal 'appleay', PigLatin.translate('apple') + # skip + assert_equal "appleay", PigLatin.translate("apple") end - def test_other_word_beginning_e + def test_word_beginning_with_e skip - assert_equal 'earay', PigLatin.translate('ear') + assert_equal "earay", PigLatin.translate("ear") + end + + def test_word_beginning_with_i + skip + assert_equal "iglooay", PigLatin.translate("igloo") + end + + def test_word_beginning_with_o + skip + assert_equal "objectay", PigLatin.translate("object") + end + + def test_word_beginning_with_u + skip + assert_equal "underay", PigLatin.translate("under") + end + + def test_word_beginning_with_a_vowel_and_followed_by_a_qu + skip + assert_equal "equalay", PigLatin.translate("equal") end def test_word_beginning_with_p skip - assert_equal 'igpay', PigLatin.translate('pig') + assert_equal "igpay", PigLatin.translate("pig") end def test_word_beginning_with_k skip - assert_equal 'oalakay', PigLatin.translate('koala') + assert_equal "oalakay", PigLatin.translate("koala") + end + + def test_word_beginning_with_y + skip + assert_equal "ellowyay", PigLatin.translate("yellow") + end + + def test_word_beginning_with_x + skip + assert_equal "enonxay", PigLatin.translate("xenon") + end + + def test_word_beginning_with_q_without_a_following_u + skip + assert_equal "atqay", PigLatin.translate("qat") end def test_word_beginning_with_ch skip - assert_equal 'airchay', PigLatin.translate('chair') + assert_equal "airchay", PigLatin.translate("chair") end def test_word_beginning_with_qu skip - assert_equal 'eenquay', PigLatin.translate('queen') + assert_equal "eenquay", PigLatin.translate("queen") end - def test_word_with_consonant_preceding_qu + def test_word_beginning_with_qu_and_a_preceding_consonant skip - assert_equal 'aresquay', PigLatin.translate('square') + assert_equal "aresquay", PigLatin.translate("square") end def test_word_beginning_with_th skip - assert_equal 'erapythay', PigLatin.translate('therapy') + assert_equal "erapythay", PigLatin.translate("therapy") end def test_word_beginning_with_thr skip - assert_equal 'ushthray', PigLatin.translate('thrush') + assert_equal "ushthray", PigLatin.translate("thrush") end def test_word_beginning_with_sch skip - assert_equal 'oolschay', PigLatin.translate('school') + assert_equal "oolschay", PigLatin.translate("school") end - def test_translates_phrase + def test_word_beginning_with_yt skip - assert_equal 'ickquay astfay unray', PigLatin.translate('quick fast run') + assert_equal "yttriaay", PigLatin.translate("yttria") end - def test_word_beginning_with_ye + def test_word_beginning_with_xr skip - assert_equal 'ellowyay', PigLatin.translate('yellow') + assert_equal "xrayay", PigLatin.translate("xray") end - def test_word_beginning_with_yt + def test_a_whole_phrase skip - assert_equal 'yttriaay', PigLatin.translate('yttria') + assert_equal "ickquay astfay unray", PigLatin.translate("quick fast run") end - def test_word_beginning_with_xe - skip - assert_equal 'enonxay', PigLatin.translate('xenon') - end + # Problems in exercism evolve over time, as we find better ways to ask + # questions. + # The version number refers to the version of the problem you solved, + # not your solution. + # + # Define a constant named VERSION inside of the top level BookKeeping + # module, which may be placed near the end of your file. + # + # In your file, it will look like this: + # + # module BookKeeping + # VERSION = 1 # Where the version number matches the one in the test. + # end + # + # If you are curious, read more about constants on RubyDoc: + # http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html - def test_word_beginning_with_xr + def test_bookkeeping skip - assert_equal 'xrayay', PigLatin.translate('xray') + assert_equal 1, BookKeeping::VERSION end end diff --git a/lib/pig_latin_cases.rb b/lib/pig_latin_cases.rb new file mode 100644 index 0000000000..e256dfdefe --- /dev/null +++ b/lib/pig_latin_cases.rb @@ -0,0 +1,20 @@ +require 'exercise_cases' + +class PigLatinCase < OpenStruct + def name + 'test_%s' % description.tr('- ', '__') + end + + def workload + %Q(assert_equal #{expected.inspect}, PigLatin.translate(#{input.inspect})) + end + + def skipped + index.zero? ? '# skip' : 'skip' + end +end + +PigLatinCases = proc do |data| + JSON.parse(data)['cases'].flat_map {|section| section['cases'] }. # extract all the cases into a single array + map.with_index { |test, index| PigLatinCase.new(test.merge('index' => index)) } +end