From c4ea11c1bba700c4b98ec89d295eb7970367c479 Mon Sep 17 00:00:00 2001 From: meatball Date: Mon, 29 Sep 2025 21:51:57 +0200 Subject: [PATCH] Add templates for exercises batch 10 --- .../roman-numerals/.meta/test_template.erb | 13 ++ .../roman-numerals/roman_numerals_test.rb | 139 +++++++++++++----- .../rotational-cipher/.meta/test_template.erb | 13 ++ .../rotational_cipher_test.rb | 41 ++++-- .../.meta/test_template.erb | 21 +++ .../run_length_encoding_test.rb | 80 +++++----- .../saddle-points/.meta/test_template.erb | 18 +++ .../practice/say/.meta/test_template.erb | 20 +++ exercises/practice/say/say_test.rb | 102 ++++++------- .../scrabble-score/.meta/test_template.erb | 13 ++ .../scrabble-score/scrabble_score_test.rb | 44 ++++-- .../secret-handshake/.meta/test_template.erb | 13 ++ .../secret-handshake/secret_handshake_test.rb | 79 ++++++---- 13 files changed, 418 insertions(+), 178 deletions(-) create mode 100644 exercises/practice/roman-numerals/.meta/test_template.erb create mode 100644 exercises/practice/rotational-cipher/.meta/test_template.erb create mode 100644 exercises/practice/run-length-encoding/.meta/test_template.erb create mode 100644 exercises/practice/saddle-points/.meta/test_template.erb create mode 100644 exercises/practice/say/.meta/test_template.erb create mode 100644 exercises/practice/scrabble-score/.meta/test_template.erb create mode 100644 exercises/practice/secret-handshake/.meta/test_template.erb diff --git a/exercises/practice/roman-numerals/.meta/test_template.erb b/exercises/practice/roman-numerals/.meta/test_template.erb new file mode 100644 index 0000000000..fe7bbe7623 --- /dev/null +++ b/exercises/practice/roman-numerals/.meta/test_template.erb @@ -0,0 +1,13 @@ +require 'minitest/autorun' +require_relative 'roman_numerals' + +class RomanNumeralsTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + actual = <%= cases["input"]["number"] %>.to_roman + expected = '<%= cases["expected"] %>' + assert_equal expected, actual + end + <% end %> +end diff --git a/exercises/practice/roman-numerals/roman_numerals_test.rb b/exercises/practice/roman-numerals/roman_numerals_test.rb index b858c0ef64..9c1cb7c1ae 100644 --- a/exercises/practice/roman-numerals/roman_numerals_test.rb +++ b/exercises/practice/roman-numerals/roman_numerals_test.rb @@ -4,131 +4,190 @@ class RomanNumeralsTest < Minitest::Test def test_1_is_i # skip - assert_equal "I", 1.to_roman + actual = 1.to_roman + expected = 'I' + assert_equal expected, actual end def test_2_is_ii skip - assert_equal "II", 2.to_roman + actual = 2.to_roman + expected = 'II' + assert_equal expected, actual end def test_3_is_iii skip - assert_equal "III", 3.to_roman + actual = 3.to_roman + expected = 'III' + assert_equal expected, actual end def test_4_is_iv skip - assert_equal "IV", 4.to_roman + actual = 4.to_roman + expected = 'IV' + assert_equal expected, actual end def test_5_is_v skip - assert_equal "V", 5.to_roman + actual = 5.to_roman + expected = 'V' + assert_equal expected, actual end def test_6_is_vi skip - assert_equal "VI", 6.to_roman + actual = 6.to_roman + expected = 'VI' + assert_equal expected, actual end def test_9_is_ix skip - assert_equal "IX", 9.to_roman + actual = 9.to_roman + expected = 'IX' + assert_equal expected, actual + end + + def test_16_is_xvi + skip + actual = 16.to_roman + expected = 'XVI' + assert_equal expected, actual end def test_27_is_xxvii skip - assert_equal "XXVII", 27.to_roman + actual = 27.to_roman + expected = 'XXVII' + assert_equal expected, actual end def test_48_is_xlviii skip - assert_equal "XLVIII", 48.to_roman + actual = 48.to_roman + expected = 'XLVIII' + assert_equal expected, actual end def test_49_is_xlix skip - assert_equal "XLIX", 49.to_roman + actual = 49.to_roman + expected = 'XLIX' + assert_equal expected, actual end def test_59_is_lix skip - assert_equal "LIX", 59.to_roman + actual = 59.to_roman + expected = 'LIX' + assert_equal expected, actual end - def test_93_is_xciii + def test_66_is_lxvi skip - assert_equal "XCIII", 93.to_roman + actual = 66.to_roman + expected = 'LXVI' + assert_equal expected, actual end - def test_141_is_cxli + def test_93_is_xciii skip - assert_equal "CXLI", 141.to_roman + actual = 93.to_roman + expected = 'XCIII' + assert_equal expected, actual end - def test_163_is_clxiii + def test_141_is_cxli skip - assert_equal "CLXIII", 163.to_roman + actual = 141.to_roman + expected = 'CXLI' + assert_equal expected, actual end - def test_402_is_cdii + def test_163_is_clxiii skip - assert_equal "CDII", 402.to_roman + actual = 163.to_roman + expected = 'CLXIII' + assert_equal expected, actual end - def test_575_is_dlxxv + def test_166_is_clxvi skip - assert_equal "DLXXV", 575.to_roman + actual = 166.to_roman + expected = 'CLXVI' + assert_equal expected, actual end - def test_911_is_cmxi + def test_402_is_cdii skip - assert_equal "CMXI", 911.to_roman + actual = 402.to_roman + expected = 'CDII' + assert_equal expected, actual end - def test_1024_is_mxxiv + def test_575_is_dlxxv skip - assert_equal "MXXIV", 1024.to_roman + actual = 575.to_roman + expected = 'DLXXV' + assert_equal expected, actual end - def test_3000_is_mmm + def test_666_is_dclxvi skip - assert_equal "MMM", 3000.to_roman + actual = 666.to_roman + expected = 'DCLXVI' + assert_equal expected, actual end - def test_16_is_xvi + def test_911_is_cmxi skip - assert_equal "XVI", 16.to_roman + actual = 911.to_roman + expected = 'CMXI' + assert_equal expected, actual end - def test_66_is_lxvi + def test_1024_is_mxxiv skip - assert_equal "LXVI", 66.to_roman + actual = 1024.to_roman + expected = 'MXXIV' + assert_equal expected, actual end - def test_166_is_clxvi + def test_1666_is_mdclxvi skip - assert_equal "CLXVI", 166.to_roman + actual = 1666.to_roman + expected = 'MDCLXVI' + assert_equal expected, actual end - def test_666_is_dclxvi + def test_3000_is_mmm skip - assert_equal "DCLXVI", 666.to_roman + actual = 3000.to_roman + expected = 'MMM' + assert_equal expected, actual end - def test_1666_is_mdclxvi + def test_3001_is_mmmi skip - assert_equal "MDCLXVI", 1666.to_roman + actual = 3001.to_roman + expected = 'MMMI' + assert_equal expected, actual end - def test_3001_is_mmmi + def test_3888_is_mmmdccclxxxviii skip - assert_equal "MMMI", 3001.to_roman + actual = 3888.to_roman + expected = 'MMMDCCCLXXXVIII' + assert_equal expected, actual end def test_3999_is_mmmcmxcix skip - assert_equal "MMMCMXCIX", 3999.to_roman + actual = 3999.to_roman + expected = 'MMMCMXCIX' + assert_equal expected, actual end end diff --git a/exercises/practice/rotational-cipher/.meta/test_template.erb b/exercises/practice/rotational-cipher/.meta/test_template.erb new file mode 100644 index 0000000000..9179104c3d --- /dev/null +++ b/exercises/practice/rotational-cipher/.meta/test_template.erb @@ -0,0 +1,13 @@ +require 'minitest/autorun' +require_relative 'rotational_cipher' + +class RotationalCipherTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + actual = RotationalCipher.rotate("<%= cases["input"]["text"] %>", <%= cases["input"]["shiftKey"] %>) + expected = "<%= cases["expected"] %>" + assert_equal expected, actual + end + <% end %> +end diff --git a/exercises/practice/rotational-cipher/rotational_cipher_test.rb b/exercises/practice/rotational-cipher/rotational_cipher_test.rb index dae7ff6095..94b1b8083c 100644 --- a/exercises/practice/rotational-cipher/rotational_cipher_test.rb +++ b/exercises/practice/rotational-cipher/rotational_cipher_test.rb @@ -4,52 +4,71 @@ class RotationalCipherTest < Minitest::Test def test_rotate_a_by_0_same_output_as_input # skip - assert_equal "a", RotationalCipher.rotate("a", 0) + actual = RotationalCipher.rotate("a", 0) + expected = "a" + assert_equal expected, actual end def test_rotate_a_by_1 skip - assert_equal "b", RotationalCipher.rotate("a", 1) + actual = RotationalCipher.rotate("a", 1) + expected = "b" + assert_equal expected, actual end def test_rotate_a_by_26_same_output_as_input skip - assert_equal "a", RotationalCipher.rotate("a", 26) + actual = RotationalCipher.rotate("a", 26) + expected = "a" + assert_equal expected, actual end def test_rotate_m_by_13 skip - assert_equal "z", RotationalCipher.rotate("m", 13) + actual = RotationalCipher.rotate("m", 13) + expected = "z" + assert_equal expected, actual end def test_rotate_n_by_13_with_wrap_around_alphabet skip - assert_equal "a", RotationalCipher.rotate("n", 13) + actual = RotationalCipher.rotate("n", 13) + expected = "a" + assert_equal expected, actual end def test_rotate_capital_letters skip - assert_equal "TRL", RotationalCipher.rotate("OMG", 5) + actual = RotationalCipher.rotate("OMG", 5) + expected = "TRL" + assert_equal expected, actual end def test_rotate_spaces skip - assert_equal "T R L", RotationalCipher.rotate("O M G", 5) + actual = RotationalCipher.rotate("O M G", 5) + expected = "T R L" + assert_equal expected, actual end def test_rotate_numbers skip - assert_equal "Xiwxmrk 1 2 3 xiwxmrk", RotationalCipher.rotate("Testing 1 2 3 testing", 4) + actual = RotationalCipher.rotate("Testing 1 2 3 testing", 4) + expected = "Xiwxmrk 1 2 3 xiwxmrk" + assert_equal expected, actual end def test_rotate_punctuation skip - assert_equal "Gzo'n zvo, Bmviyhv!", RotationalCipher.rotate("Let's eat, Grandma!", 21) + actual = RotationalCipher.rotate("Let's eat, Grandma!", 21) + expected = "Gzo'n zvo, Bmviyhv!" + assert_equal expected, actual end def test_rotate_all_letters skip - assert_equal "Gur dhvpx oebja sbk whzcf bire gur ynml qbt.", - RotationalCipher.rotate("The quick brown fox jumps over the lazy dog.", 13) + actual = RotationalCipher.rotate("The quick brown fox jumps over the lazy dog.", 13) + expected = "Gur dhvpx oebja sbk whzcf bire gur ynml qbt." + assert_equal expected, actual end end diff --git a/exercises/practice/run-length-encoding/.meta/test_template.erb b/exercises/practice/run-length-encoding/.meta/test_template.erb new file mode 100644 index 0000000000..9965e1a388 --- /dev/null +++ b/exercises/practice/run-length-encoding/.meta/test_template.erb @@ -0,0 +1,21 @@ +require 'minitest/autorun' +require_relative 'run_length_encoding' + +class RunLengthEncodingTest < Minitest::Test +<% json["cases"].each do |cases| %> + <% cases["cases"].each do |sub_case| %> + def test_<%= sub_case["property"] %>_<%= underscore(sub_case["description"]) %> + <%= skip? %> + <%- if sub_case["property"] == "consistency" -%> + actual = RunLengthEncoding.decode(RunLengthEncoding.encode('<%= sub_case["input"]["string"] %>')) + expected = '<%= sub_case["expected"] %>' + assert_equal expected, actual + <%- else -%> + actual = RunLengthEncoding.<%= sub_case["property"] %>('<%= sub_case["input"]["string"] %>') + expected = '<%= sub_case["expected"] %>' + assert_equal expected, actual + <%- end -%> + end + <% end %> +<% end %> +end diff --git a/exercises/practice/run-length-encoding/run_length_encoding_test.rb b/exercises/practice/run-length-encoding/run_length_encoding_test.rb index e029bb4478..bf3f61a079 100644 --- a/exercises/practice/run-length-encoding/run_length_encoding_test.rb +++ b/exercises/practice/run-length-encoding/run_length_encoding_test.rb @@ -4,92 +4,92 @@ class RunLengthEncodingTest < Minitest::Test def test_encode_empty_string # skip - input = '' - output = '' - assert_equal output, RunLengthEncoding.encode(input) + actual = RunLengthEncoding.encode('') + expected = '' + assert_equal expected, actual end def test_encode_single_characters_only_are_encoded_without_count skip - input = 'XYZ' - output = 'XYZ' - assert_equal output, RunLengthEncoding.encode(input) + actual = RunLengthEncoding.encode('XYZ') + expected = 'XYZ' + assert_equal expected, actual end def test_encode_string_with_no_single_characters skip - input = 'AABBBCCCC' - output = '2A3B4C' - assert_equal output, RunLengthEncoding.encode(input) + actual = RunLengthEncoding.encode('AABBBCCCC') + expected = '2A3B4C' + assert_equal expected, actual end def test_encode_single_characters_mixed_with_repeated_characters skip - input = 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' - output = '12WB12W3B24WB' - assert_equal output, RunLengthEncoding.encode(input) + actual = RunLengthEncoding.encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB') + expected = '12WB12W3B24WB' + assert_equal expected, actual end def test_encode_multiple_whitespace_mixed_in_string skip - input = ' hsqq qww ' - output = '2 hs2q q2w2 ' - assert_equal output, RunLengthEncoding.encode(input) + actual = RunLengthEncoding.encode(' hsqq qww ') + expected = '2 hs2q q2w2 ' + assert_equal expected, actual end def test_encode_lowercase_characters skip - input = 'aabbbcccc' - output = '2a3b4c' - assert_equal output, RunLengthEncoding.encode(input) + actual = RunLengthEncoding.encode('aabbbcccc') + expected = '2a3b4c' + assert_equal expected, actual end def test_decode_empty_string skip - input = '' - output = '' - assert_equal output, RunLengthEncoding.decode(input) + actual = RunLengthEncoding.decode('') + expected = '' + assert_equal expected, actual end def test_decode_single_characters_only skip - input = 'XYZ' - output = 'XYZ' - assert_equal output, RunLengthEncoding.decode(input) + actual = RunLengthEncoding.decode('XYZ') + expected = 'XYZ' + assert_equal expected, actual end def test_decode_string_with_no_single_characters skip - input = '2A3B4C' - output = 'AABBBCCCC' - assert_equal output, RunLengthEncoding.decode(input) + actual = RunLengthEncoding.decode('2A3B4C') + expected = 'AABBBCCCC' + assert_equal expected, actual end def test_decode_single_characters_with_repeated_characters skip - input = '12WB12W3B24WB' - output = 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' - assert_equal output, RunLengthEncoding.decode(input) + actual = RunLengthEncoding.decode('12WB12W3B24WB') + expected = 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' + assert_equal expected, actual end def test_decode_multiple_whitespace_mixed_in_string skip - input = '2 hs2q q2w2 ' - output = ' hsqq qww ' - assert_equal output, RunLengthEncoding.decode(input) + actual = RunLengthEncoding.decode('2 hs2q q2w2 ') + expected = ' hsqq qww ' + assert_equal expected, actual end - def test_decode_lower_case_string + def test_decode_lowercase_string skip - input = '2a3b4c' - output = 'aabbbcccc' - assert_equal output, RunLengthEncoding.decode(input) + actual = RunLengthEncoding.decode('2a3b4c') + expected = 'aabbbcccc' + assert_equal expected, actual end def test_consistency_encode_followed_by_decode_gives_original_string skip - input = 'zzz ZZ zZ' - encoded = RunLengthEncoding.encode(input) - assert_equal input, RunLengthEncoding.decode(encoded) + actual = RunLengthEncoding.decode(RunLengthEncoding.encode('zzz ZZ zZ')) + expected = 'zzz ZZ zZ' + assert_equal expected, actual end end diff --git a/exercises/practice/saddle-points/.meta/test_template.erb b/exercises/practice/saddle-points/.meta/test_template.erb new file mode 100644 index 0000000000..98f88872c5 --- /dev/null +++ b/exercises/practice/saddle-points/.meta/test_template.erb @@ -0,0 +1,18 @@ +require 'minitest/autorun' +require_relative 'saddle_points' + +class SaddlePointsTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + input = <%= cases["input"]["matrix"] %> + expected = <%= cases["expected"] %>.sort_by do |coordinates| + [coordinates["row"], coordinates["column"]] + end + actual = Grid.saddle_points(input).sort_by do |coordinates| + [coordinates["row"], coordinates["column"]] + end + assert_equal expected, actual + end + <% end %> +end diff --git a/exercises/practice/say/.meta/test_template.erb b/exercises/practice/say/.meta/test_template.erb new file mode 100644 index 0000000000..aa8854f506 --- /dev/null +++ b/exercises/practice/say/.meta/test_template.erb @@ -0,0 +1,20 @@ +require 'minitest/autorun' +require_relative 'say' + +class SayTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + <%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%> + number = <%= cases["input"]["number"] %> + assert_raises(ArgumentError) do + Say.new(number).in_english + end + <%- else -%> + actual = Say.new(<%= cases["input"]["number"] %>).in_english + expected = '<%= cases["expected"] %>' + assert_equal expected, actual + <%- end -%> + end + <% end %> +end diff --git a/exercises/practice/say/say_test.rb b/exercises/practice/say/say_test.rb index fe80c6f77d..d23a5454f7 100644 --- a/exercises/practice/say/say_test.rb +++ b/exercises/practice/say/say_test.rb @@ -4,121 +4,121 @@ class SayTest < Minitest::Test def test_zero # skip - number = 0 - expected = "zero" - assert_equal expected, Say.new(number).in_english + actual = Say.new(0).in_english + expected = 'zero' + assert_equal expected, actual end def test_one skip - number = 1 - expected = "one" - assert_equal expected, Say.new(number).in_english + actual = Say.new(1).in_english + expected = 'one' + assert_equal expected, actual end def test_fourteen skip - number = 14 - expected = "fourteen" - assert_equal expected, Say.new(number).in_english + actual = Say.new(14).in_english + expected = 'fourteen' + assert_equal expected, actual end def test_twenty skip - number = 20 - expected = "twenty" - assert_equal expected, Say.new(number).in_english + actual = Say.new(20).in_english + expected = 'twenty' + assert_equal expected, actual end def test_twenty_two skip - number = 22 - expected = "twenty-two" - assert_equal expected, Say.new(number).in_english + actual = Say.new(22).in_english + expected = 'twenty-two' + assert_equal expected, actual end def test_thirty skip - number = 30 - expected = "thirty" - assert_equal expected, Say.new(number).in_english + actual = Say.new(30).in_english + expected = 'thirty' + assert_equal expected, actual end def test_ninety_nine skip - number = 99 - expected = "ninety-nine" - assert_equal expected, Say.new(number).in_english + actual = Say.new(99).in_english + expected = 'ninety-nine' + assert_equal expected, actual end def test_one_hundred skip - number = 100 - expected = "one hundred" - assert_equal expected, Say.new(number).in_english + actual = Say.new(100).in_english + expected = 'one hundred' + assert_equal expected, actual end def test_one_hundred_twenty_three skip - number = 123 - expected = "one hundred twenty-three" - assert_equal expected, Say.new(number).in_english + actual = Say.new(123).in_english + expected = 'one hundred twenty-three' + assert_equal expected, actual end def test_two_hundred skip - number = 200 - expected = "two hundred" - assert_equal expected, Say.new(number).in_english + actual = Say.new(200).in_english + expected = 'two hundred' + assert_equal expected, actual end def test_nine_hundred_ninety_nine skip - number = 999 - expected = "nine hundred ninety-nine" - assert_equal expected, Say.new(number).in_english + actual = Say.new(999).in_english + expected = 'nine hundred ninety-nine' + assert_equal expected, actual end def test_one_thousand skip - number = 1000 - expected = "one thousand" - assert_equal expected, Say.new(number).in_english + actual = Say.new(1000).in_english + expected = 'one thousand' + assert_equal expected, actual end def test_one_thousand_two_hundred_thirty_four skip - number = 1234 - expected = "one thousand two hundred thirty-four" - assert_equal expected, Say.new(number).in_english + actual = Say.new(1234).in_english + expected = 'one thousand two hundred thirty-four' + assert_equal expected, actual end def test_one_million skip - number = 1_000_000 - expected = "one million" - assert_equal expected, Say.new(number).in_english + actual = Say.new(1_000_000).in_english + expected = 'one million' + assert_equal expected, actual end def test_one_million_two_thousand_three_hundred_forty_five skip - number = 1_002_345 - expected = "one million two thousand three hundred forty-five" - assert_equal expected, Say.new(number).in_english + actual = Say.new(1_002_345).in_english + expected = 'one million two thousand three hundred forty-five' + assert_equal expected, actual end def test_one_billion skip - number = 1_000_000_000 - expected = "one billion" - assert_equal expected, Say.new(number).in_english + actual = Say.new(1_000_000_000).in_english + expected = 'one billion' + assert_equal expected, actual end def test_a_big_number skip - number = 987_654_321_123 - expected = "nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three" - assert_equal expected, Say.new(number).in_english + actual = Say.new(987_654_321_123).in_english + expected = 'nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three' + assert_equal expected, actual end def test_numbers_below_zero_are_out_of_range diff --git a/exercises/practice/scrabble-score/.meta/test_template.erb b/exercises/practice/scrabble-score/.meta/test_template.erb new file mode 100644 index 0000000000..5b22d78b74 --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/test_template.erb @@ -0,0 +1,13 @@ +require 'minitest/autorun' +require_relative 'scrabble_score' + +class ScrabbleScoreTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + actual = Scrabble.new('<%= cases["input"]["word"] %>').score + expected = <%= cases["expected"] %> + assert_equal expected, actual + end + <% end %> +end diff --git a/exercises/practice/scrabble-score/scrabble_score_test.rb b/exercises/practice/scrabble-score/scrabble_score_test.rb index e51a886a2b..b8e9b19a8c 100644 --- a/exercises/practice/scrabble-score/scrabble_score_test.rb +++ b/exercises/practice/scrabble-score/scrabble_score_test.rb @@ -4,56 +4,78 @@ class ScrabbleScoreTest < Minitest::Test def test_lowercase_letter # skip - assert_equal 1, Scrabble.new("a").score + actual = Scrabble.new('a').score + expected = 1 + assert_equal expected, actual end def test_uppercase_letter skip - assert_equal 1, Scrabble.new("A").score + actual = Scrabble.new('A').score + expected = 1 + assert_equal expected, actual end def test_valuable_letter skip - assert_equal 4, Scrabble.new("f").score + actual = Scrabble.new('f').score + expected = 4 + assert_equal expected, actual end def test_short_word skip - assert_equal 2, Scrabble.new("at").score + actual = Scrabble.new('at').score + expected = 2 + assert_equal expected, actual end def test_short_valuable_word skip - assert_equal 12, Scrabble.new("zoo").score + actual = Scrabble.new('zoo').score + expected = 12 + assert_equal expected, actual end def test_medium_word skip - assert_equal 6, Scrabble.new("street").score + actual = Scrabble.new('street').score + expected = 6 + assert_equal expected, actual end def test_medium_valuable_word skip - assert_equal 22, Scrabble.new("quirky").score + actual = Scrabble.new('quirky').score + expected = 22 + assert_equal expected, actual end def test_long_mixed_case_word skip - assert_equal 41, Scrabble.new("OxyphenButazone").score + actual = Scrabble.new('OxyphenButazone').score + expected = 41 + assert_equal expected, actual end def test_english_like_word skip - assert_equal 8, Scrabble.new("pinata").score + actual = Scrabble.new('pinata').score + expected = 8 + assert_equal expected, actual end def test_empty_input skip - assert_equal 0, Scrabble.new("").score + actual = Scrabble.new('').score + expected = 0 + assert_equal expected, actual end def test_entire_alphabet_available skip - assert_equal 87, Scrabble.new("abcdefghijklmnopqrstuvwxyz").score + actual = Scrabble.new('abcdefghijklmnopqrstuvwxyz').score + expected = 87 + assert_equal expected, actual end end diff --git a/exercises/practice/secret-handshake/.meta/test_template.erb b/exercises/practice/secret-handshake/.meta/test_template.erb new file mode 100644 index 0000000000..3c10827907 --- /dev/null +++ b/exercises/practice/secret-handshake/.meta/test_template.erb @@ -0,0 +1,13 @@ +require 'minitest/autorun' +require_relative 'secret_handshake' + +class SecretHandshakeTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + actual = SecretHandshake.new(<%= cases["input"]["number"] %>).commands + expected = <%= cases["expected"] %> + assert_equal expected, actual + end + <% end %> +end diff --git a/exercises/practice/secret-handshake/secret_handshake_test.rb b/exercises/practice/secret-handshake/secret_handshake_test.rb index 347bbead74..61a28beda6 100644 --- a/exercises/practice/secret-handshake/secret_handshake_test.rb +++ b/exercises/practice/secret-handshake/secret_handshake_test.rb @@ -2,51 +2,80 @@ require_relative 'secret_handshake' class SecretHandshakeTest < Minitest::Test - def test_handshake_1_to_wink - handshake = SecretHandshake.new(1) - assert_equal ['wink'], handshake.commands + def test_wink_for_1 + # skip + actual = SecretHandshake.new(1).commands + expected = ["wink"] + assert_equal expected, actual end - def test_handshake_10_to_double_blink + def test_double_blink_for_10 skip - handshake = SecretHandshake.new(2) - assert_equal ['double blink'], handshake.commands + actual = SecretHandshake.new(2).commands + expected = ["double blink"] + assert_equal expected, actual end - def test_handshake_100_to_close_your_eyes + def test_close_your_eyes_for_100 skip - handshake = SecretHandshake.new(4) - assert_equal ['close your eyes'], handshake.commands + actual = SecretHandshake.new(4).commands + expected = ["close your eyes"] + assert_equal expected, actual end - def test_handshake_1000_to_jump + def test_jump_for_1000 skip - handshake = SecretHandshake.new(8) - assert_equal ['jump'], handshake.commands + actual = SecretHandshake.new(8).commands + expected = ["jump"] + assert_equal expected, actual end - def test_handshake_11_to_wink_and_double_blink + def test_combine_two_actions skip - handshake = SecretHandshake.new(3) - assert_equal ['wink', 'double blink'], handshake.commands + actual = SecretHandshake.new(3).commands + expected = ["wink", "double blink"] + assert_equal expected, actual end - def test_handshake_10011_to_double_blink_and_wink + def test_reverse_two_actions skip - handshake = SecretHandshake.new(19) - assert_equal ['double blink', 'wink'], handshake.commands + actual = SecretHandshake.new(19).commands + expected = ["double blink", "wink"] + assert_equal expected, actual end - def test_handshake_11111_to_double_blink_and_wink + def test_reversing_one_action_gives_the_same_action skip - handshake = SecretHandshake.new(31) - expected = ['jump', 'close your eyes', 'double blink', 'wink'] - assert_equal expected, handshake.commands + actual = SecretHandshake.new(24).commands + expected = ["jump"] + assert_equal expected, actual end - def test_invalid_handshake + def test_reversing_no_actions_still_gives_no_actions skip - handshake = SecretHandshake.new('piggies') - assert_empty handshake.commands + actual = SecretHandshake.new(16).commands + expected = [] + assert_equal expected, actual + end + + def test_all_possible_actions + skip + actual = SecretHandshake.new(15).commands + expected = ["wink", "double blink", "close your eyes", "jump"] + assert_equal expected, actual + end + + def test_reverse_all_possible_actions + skip + actual = SecretHandshake.new(31).commands + expected = ["jump", "close your eyes", "double blink", "wink"] + assert_equal expected, actual + end + + def test_do_nothing_for_zero + skip + actual = SecretHandshake.new(0).commands + expected = [] + assert_equal expected, actual end end