From fed9dbe0d4012594f9d6d6e93d38ae6de683b42f Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 30 Aug 2025 21:46:29 +0200 Subject: [PATCH 1/7] Add templates to exercises batch 1 --- .../practice/acronym/.meta/test_template.erb | 2 +- exercises/practice/acronym/acronym_test.rb | 24 +- .../affine-cipher/.meta/test_template.erb | 26 +++ .../all-your-base/.meta/test_template.erb | 26 +++ .../all-your-base/all_your_base_test.rb | 57 +++-- .../allergies/.meta/test_template.erb | 19 ++ .../practice/allergies/allergies_test.rb | 220 +++++++++--------- .../practice/anagram/.meta/test_template.erb | 15 ++ exercises/practice/anagram/.meta/tests.toml | 2 + exercises/practice/anagram/anagram_test.rb | 54 +++-- .../armstrong-numbers/.meta/test_template.erb | 11 + .../atbash-cipher/.meta/test_template.erb | 21 ++ .../atbash-cipher/atbash_cipher_test.rb | 4 +- .../bank-account/.meta/test_template.erb | 43 ++++ .../practice/bank-account/.meta/tests.toml | 2 +- .../bank-account/bank_account_test.rb | 2 +- .../binary-search/.meta/test_template.erb | 16 ++ .../binary-search/binary_search_test.rb | 4 +- 18 files changed, 386 insertions(+), 162 deletions(-) create mode 100644 exercises/practice/affine-cipher/.meta/test_template.erb create mode 100644 exercises/practice/all-your-base/.meta/test_template.erb create mode 100644 exercises/practice/allergies/.meta/test_template.erb create mode 100644 exercises/practice/anagram/.meta/test_template.erb create mode 100644 exercises/practice/armstrong-numbers/.meta/test_template.erb create mode 100644 exercises/practice/atbash-cipher/.meta/test_template.erb create mode 100644 exercises/practice/bank-account/.meta/test_template.erb create mode 100644 exercises/practice/binary-search/.meta/test_template.erb diff --git a/exercises/practice/acronym/.meta/test_template.erb b/exercises/practice/acronym/.meta/test_template.erb index 66c45804f7..3b4db5d302 100644 --- a/exercises/practice/acronym/.meta/test_template.erb +++ b/exercises/practice/acronym/.meta/test_template.erb @@ -5,7 +5,7 @@ class AcronymTest < Minitest::Test <% json["cases"].each do |cases| %> def test_<%= underscore(cases["description"]) %> <%= skip? %> - assert_equal '<%= cases["expected"] %>', <%= camel_case(json["exercise"]) %>.<%= underscore(cases["property"]) %>('<%= cases["input"]["phrase"] %>') + assert_equal "<%= cases["expected"] %>", <%= camel_case(json["exercise"]) %>.<%= underscore(cases["property"]) %>("<%= cases["input"]["phrase"] %>") end <% end %> end diff --git a/exercises/practice/acronym/acronym_test.rb b/exercises/practice/acronym/acronym_test.rb index 7dde064850..db6766585f 100644 --- a/exercises/practice/acronym/acronym_test.rb +++ b/exercises/practice/acronym/acronym_test.rb @@ -4,36 +4,46 @@ class AcronymTest < Minitest::Test def test_basic # skip - assert_equal 'PNG', Acronym.abbreviate('Portable Network Graphics') + assert_equal "PNG", Acronym.abbreviate("Portable Network Graphics") end def test_lowercase_words skip - assert_equal 'ROR', Acronym.abbreviate('Ruby on Rails') + assert_equal "ROR", Acronym.abbreviate("Ruby on Rails") end def test_punctuation skip - assert_equal 'FIFO', Acronym.abbreviate('First In, First Out') + assert_equal "FIFO", Acronym.abbreviate("First In, First Out") end def test_all_caps_word skip - assert_equal 'GIMP', Acronym.abbreviate('GNU Image Manipulation Program') + assert_equal "GIMP", Acronym.abbreviate("GNU Image Manipulation Program") end def test_punctuation_without_whitespace skip - assert_equal 'CMOS', Acronym.abbreviate('Complementary metal-oxide semiconductor') + assert_equal "CMOS", Acronym.abbreviate("Complementary metal-oxide semiconductor") end def test_very_long_abbreviation skip - assert_equal 'ROTFLSHTMDCOALM', Acronym.abbreviate('Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me') + assert_equal "ROTFLSHTMDCOALM", Acronym.abbreviate("Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me") end def test_consecutive_delimiters skip - assert_equal 'SIMUFTA', Acronym.abbreviate('Something - I made up from thin air') + assert_equal "SIMUFTA", Acronym.abbreviate("Something - I made up from thin air") + end + + def test_apostrophes + skip + assert_equal "HC", Acronym.abbreviate("Halley's Comet") + end + + def test_underscore_emphasis + skip + assert_equal "TRNT", Acronym.abbreviate("The Road _Not_ Taken") end end diff --git a/exercises/practice/affine-cipher/.meta/test_template.erb b/exercises/practice/affine-cipher/.meta/test_template.erb new file mode 100644 index 0000000000..0a62fdb4e3 --- /dev/null +++ b/exercises/practice/affine-cipher/.meta/test_template.erb @@ -0,0 +1,26 @@ +require 'minitest/autorun' +require_relative 'affine_cipher' + +class AffineCipherTest < Minitest::Test +<% json["cases"].each do |group| %> + <% group["cases"].each do |sub_case| %> + def test_<%= underscore(sub_case["description"]) %> + <%= skip? %> + <%- if sub_case["expected"].is_a?(Hash) && sub_case["expected"].key?("error") -%> + assert_raises(ArgumentError) { Affine.new(<%= sub_case["input"]["key"]["a"] %>, <%= sub_case["input"]["key"]["b"] %>) } + <%- else -%> + cipher = Affine.new(<%= sub_case["input"]["key"]["a"] %>, <%= sub_case["input"]["key"]["b"] %>) + <%- if sub_case["property"] == "encode" -%> + plaintext = '<%= sub_case["input"]["phrase"] %>' + ciphertext = '<%= sub_case["expected"] %>' + assert_equal ciphertext, cipher.encode(plaintext) + <%- elsif sub_case["property"] == "decode" -%> + ciphertext = '<%= sub_case["input"]["phrase"] %>' + plaintext = '<%= sub_case["expected"] %>' + assert_equal plaintext, cipher.decode(ciphertext) + <%- end -%> + <%- end -%> + end + <% end %> +<% end %> +end diff --git a/exercises/practice/all-your-base/.meta/test_template.erb b/exercises/practice/all-your-base/.meta/test_template.erb new file mode 100644 index 0000000000..b1260006f0 --- /dev/null +++ b/exercises/practice/all-your-base/.meta/test_template.erb @@ -0,0 +1,26 @@ +require 'minitest/autorun' +require_relative 'all_your_base' + +class AllYourBaseTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + digits = <%= cases["input"]["digits"] %> + input_base = <%= cases["input"]["inputBase"] %> + output_base = <%= cases["input"]["outputBase"] %> + <% if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") %> + assert_raises(ArgumentError) do + BaseConverter.convert(input_base, digits, output_base) + end + <% else %>expected = <%= cases["expected"] %> + + converted = BaseConverter.convert(input_base, digits, output_base) + + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." + + assert_equal expected, converted, hint + <% end %> + end + <% end %> +end diff --git a/exercises/practice/all-your-base/all_your_base_test.rb b/exercises/practice/all-your-base/all_your_base_test.rb index 3ef5f434e5..c565a75aec 100644 --- a/exercises/practice/all-your-base/all_your_base_test.rb +++ b/exercises/practice/all-your-base/all_your_base_test.rb @@ -11,8 +11,8 @@ def test_single_bit_one_to_decimal converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 2, output base 10. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -26,8 +26,8 @@ def test_binary_to_single_decimal converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 2, output base 10. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -41,8 +41,8 @@ def test_single_decimal_to_binary converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 10, output base 2. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -56,8 +56,8 @@ def test_binary_to_multiple_decimal converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 2, output base 10. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -71,8 +71,8 @@ def test_decimal_to_binary converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 10, output base 2. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -86,8 +86,8 @@ def test_trinary_to_hexadecimal converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 3, output base 16. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -101,8 +101,8 @@ def test_hexadecimal_to_trinary converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 16, output base 3. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -116,8 +116,8 @@ def test_15_bit_integer converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 97, output base 73. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -131,8 +131,8 @@ def test_empty_list converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 2, output base 10. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -146,8 +146,8 @@ def test_single_zero converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 10, output base 2. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -161,8 +161,8 @@ def test_multiple_zeros converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 10, output base 2. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -176,8 +176,8 @@ def test_leading_zeros converted = BaseConverter.convert(input_base, digits, output_base) - hint = "Input base: 7, output base 10. " \ - "Expected #{expected} but got #{converted}." + hint = "Input base: #{input_base}, output base #{output_base}. " \ + "Expected #{expected} but got #{converted}." assert_equal expected, converted, hint end @@ -187,6 +187,7 @@ def test_input_base_is_one digits = [0] input_base = 1 output_base = 10 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -197,6 +198,7 @@ def test_input_base_is_zero digits = [] input_base = 0 output_base = 10 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -207,6 +209,7 @@ def test_input_base_is_negative digits = [1] input_base = -2 output_base = 10 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -217,6 +220,7 @@ def test_negative_digit digits = [1, -1, 1, 0, 1, 0] input_base = 2 output_base = 10 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -227,6 +231,7 @@ def test_invalid_positive_digit digits = [1, 2, 1, 0, 1, 0] input_base = 2 output_base = 10 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -237,6 +242,7 @@ def test_output_base_is_one digits = [1, 0, 1, 0, 1, 0] input_base = 2 output_base = 1 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -247,6 +253,7 @@ def test_output_base_is_zero digits = [7] input_base = 10 output_base = 0 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -257,6 +264,7 @@ def test_output_base_is_negative digits = [1] input_base = 2 output_base = -7 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end @@ -267,6 +275,7 @@ def test_both_bases_are_negative digits = [1] input_base = -2 output_base = -7 + assert_raises(ArgumentError) do BaseConverter.convert(input_base, digits, output_base) end diff --git a/exercises/practice/allergies/.meta/test_template.erb b/exercises/practice/allergies/.meta/test_template.erb new file mode 100644 index 0000000000..df97cd71ce --- /dev/null +++ b/exercises/practice/allergies/.meta/test_template.erb @@ -0,0 +1,19 @@ +require 'minitest/autorun' +require_relative 'allergies' + +class AllergiesTest < Minitest::Test +<% json["cases"].each do |group| %> + <% group["cases"].each do |sub_case| %> + def test_<%= underscore(sub_case["description"]) %> + <%= skip? %> + allergies = Allergies.new(<%= sub_case["input"]["score"] %>) + <%- if sub_case["property"] == "allergicTo" -%> + <%= sub_case["expected"] ? "assert" : "refute" %> allergies.allergic_to?("<%= sub_case["input"]["item"] %>"), "Tom is allergic, but it says he is<%= sub_case["expected"] ? "" : " not" %>." + <%- else -%> + expected = %w[<%= sub_case["expected"].join(" ") %>] + assert_equal expected, allergies.list + <% end %> + end + <% end %> + <% end %> +end diff --git a/exercises/practice/allergies/allergies_test.rb b/exercises/practice/allergies/allergies_test.rb index d5d244968f..0e46add2a1 100644 --- a/exercises/practice/allergies/allergies_test.rb +++ b/exercises/practice/allergies/allergies_test.rb @@ -2,303 +2,313 @@ require_relative 'allergies' class AllergiesTest < Minitest::Test - def test_testing_for_eggs_allergy_not_allergic_to_anything + def test_not_allergic_to_anything # skip allergies = Allergies.new(0) - refute allergies.allergic_to?("eggs"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." end - def test_testing_for_eggs_allergy_allergic_only_to_eggs + def test_allergic_only_to_eggs skip allergies = Allergies.new(1) - assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is." end - def test_testing_for_eggs_allergy_allergic_to_eggs_and_something_else + def test_allergic_to_eggs_and_something_else skip allergies = Allergies.new(3) - assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is." end - def test_testing_for_eggs_allergy_allergic_to_something_but_not_eggs + def test_allergic_to_something_but_not_eggs skip allergies = Allergies.new(2) - refute allergies.allergic_to?("eggs"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." end - def test_testing_for_eggs_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is." end - def test_testing_for_peanuts_allergy_not_allergic_to_anything + def test_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("peanuts"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." end - def test_testing_for_peanuts_allergy_allergic_only_to_peanuts + def test_allergic_only_to_peanuts skip allergies = Allergies.new(2) - assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." end - def test_testing_for_peanuts_allergy_allergic_to_peanuts_and_something_else + def test_allergic_to_peanuts_and_something_else skip allergies = Allergies.new(7) - assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." end - def test_testing_for_peanuts_allergy_allergic_to_something_but_not_peanuts + def test_allergic_to_something_but_not_peanuts skip allergies = Allergies.new(5) - refute allergies.allergic_to?("peanuts"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." end - def test_testing_for_peanuts_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." end - def test_testing_for_shellfish_allergy_not_allergic_to_anything + def test_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("shellfish"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." end - def test_testing_for_shellfish_allergy_allergic_only_to_shellfish + def test_allergic_only_to_shellfish skip allergies = Allergies.new(4) - assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." end - def test_testing_for_shellfish_allergy_allergic_to_shellfish_and_something_else + def test_allergic_to_shellfish_and_something_else skip allergies = Allergies.new(14) - assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." end - def test_testing_for_shellfish_allergy_allergic_to_something_but_not_shellfish + def test_allergic_to_something_but_not_shellfish skip allergies = Allergies.new(10) - refute allergies.allergic_to?("shellfish"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." end - def test_testing_for_shellfish_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." end - def test_testing_for_strawberries_allergy_not_allergic_to_anything + def test_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("strawberries"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." end - def test_testing_for_strawberries_allergy_allergic_only_to_strawberries + def test_allergic_only_to_strawberries skip allergies = Allergies.new(8) - assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." end - def test_testing_for_strawberries_allergy_allergic_to_strawberries_and_something_else + def test_allergic_to_strawberries_and_something_else skip allergies = Allergies.new(28) - assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." end - def test_testing_for_strawberries_allergy_allergic_to_something_but_not_strawberries + def test_allergic_to_something_but_not_strawberries skip allergies = Allergies.new(20) - refute allergies.allergic_to?("strawberries"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." end - def test_testing_for_strawberries_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." end - def test_testing_for_tomatoes_allergy_not_allergic_to_anything + def test_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("tomatoes"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." end - def test_testing_for_tomatoes_allergy_allergic_only_to_tomatoes + def test_allergic_only_to_tomatoes skip allergies = Allergies.new(16) - assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." end - def test_testing_for_tomatoes_allergy_allergic_to_tomatoes_and_something_else + def test_allergic_to_tomatoes_and_something_else skip allergies = Allergies.new(56) - assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." end - def test_testing_for_tomatoes_allergy_allergic_to_something_but_not_tomatoes + def test_allergic_to_something_but_not_tomatoes skip allergies = Allergies.new(40) - refute allergies.allergic_to?("tomatoes"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." end - def test_testing_for_tomatoes_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." end - def test_testing_for_chocolate_allergy_not_allergic_to_anything + def test_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("chocolate"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." end - def test_testing_for_chocolate_allergy_allergic_only_to_chocolate + def test_allergic_only_to_chocolate skip allergies = Allergies.new(32) - assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." end - def test_testing_for_chocolate_allergy_allergic_to_chocolate_and_something_else + def test_allergic_to_chocolate_and_something_else skip allergies = Allergies.new(112) - assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." end - def test_testing_for_chocolate_allergy_allergic_to_something_but_not_chocolate + def test_allergic_to_something_but_not_chocolate skip allergies = Allergies.new(80) - refute allergies.allergic_to?("chocolate"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." end - def test_testing_for_chocolate_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." end - def test_testing_for_pollen_allergy_not_allergic_to_anything + def test_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("pollen"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." end - def test_testing_for_pollen_allergy_allergic_only_to_pollen + def test_allergic_only_to_pollen skip allergies = Allergies.new(64) - assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." end - def test_testing_for_pollen_allergy_allergic_to_pollen_and_something_else + def test_allergic_to_pollen_and_something_else skip allergies = Allergies.new(224) - assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." end - def test_testing_for_pollen_allergy_allergic_to_something_but_not_pollen + def test_allergic_to_something_but_not_pollen skip allergies = Allergies.new(160) - refute allergies.allergic_to?("pollen"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." end - def test_testing_for_pollen_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." end - def test_testing_for_cats_allergy_not_allergic_to_anything + def test_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("cats"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." end - def test_testing_for_cats_allergy_allergic_only_to_cats + def test_allergic_only_to_cats skip allergies = Allergies.new(128) - assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." end - def test_testing_for_cats_allergy_allergic_to_cats_and_something_else + def test_allergic_to_cats_and_something_else skip allergies = Allergies.new(192) - assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." end - def test_testing_for_cats_allergy_allergic_to_something_but_not_cats + def test_allergic_to_something_but_not_cats skip allergies = Allergies.new(64) - refute allergies.allergic_to?("cats"), "Tom is not allergic, but it says he is." + refute allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." end - def test_testing_for_cats_allergy_allergic_to_everything + def test_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." end - def test_list_when_no_allergies + def test_no_allergies skip - expected = [] - assert_equal expected, Allergies.new(0).list + allergies = Allergies.new(0) + expected = %w[] + assert_equal expected, allergies.list end - def test_list_when_just_eggs + def test_just_eggs skip - expected = ["eggs"] - assert_equal expected, Allergies.new(1).list + allergies = Allergies.new(1) + expected = %w[eggs] + assert_equal expected, allergies.list end - def test_list_when_just_peanuts + def test_just_peanuts skip - expected = ["peanuts"] - assert_equal expected, Allergies.new(2).list + allergies = Allergies.new(2) + expected = %w[peanuts] + assert_equal expected, allergies.list end - def test_list_when_just_strawberries + def test_just_strawberries skip - expected = ["strawberries"] - assert_equal expected, Allergies.new(8).list + allergies = Allergies.new(8) + expected = %w[strawberries] + assert_equal expected, allergies.list end - def test_list_when_eggs_and_peanuts + def test_eggs_and_peanuts skip + allergies = Allergies.new(3) expected = %w[eggs peanuts] - assert_equal expected, Allergies.new(3).list + assert_equal expected, allergies.list end - def test_list_when_more_than_eggs_but_not_peanuts + def test_more_than_eggs_but_not_peanuts skip + allergies = Allergies.new(5) expected = %w[eggs shellfish] - assert_equal expected, Allergies.new(5).list + assert_equal expected, allergies.list end - def test_list_when_lots_of_stuff + def test_lots_of_stuff skip + allergies = Allergies.new(248) expected = %w[strawberries tomatoes chocolate pollen cats] - assert_equal expected, Allergies.new(248).list + assert_equal expected, allergies.list end - def test_list_when_everything + def test_everything skip + allergies = Allergies.new(255) expected = %w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats] - assert_equal expected, Allergies.new(255).list + assert_equal expected, allergies.list end - def test_list_when_no_allergen_score_parts + def test_no_allergen_score_parts skip + allergies = Allergies.new(509) expected = %w[eggs shellfish strawberries tomatoes chocolate pollen cats] - assert_equal expected, Allergies.new(509).list + assert_equal expected, allergies.list end - def test_list_when_no_allergen_score_parts_without_highest_valid_score + def test_no_allergen_score_parts_without_highest_valid_score skip - expected = ["eggs"] - assert_equal expected, Allergies.new(257).list + allergies = Allergies.new(257) + expected = %w[eggs] + assert_equal expected, allergies.list end end diff --git a/exercises/practice/anagram/.meta/test_template.erb b/exercises/practice/anagram/.meta/test_template.erb new file mode 100644 index 0000000000..34574df81e --- /dev/null +++ b/exercises/practice/anagram/.meta/test_template.erb @@ -0,0 +1,15 @@ +require 'minitest/autorun' +require_relative 'anagram' + +class AnagramTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + detector = Anagram.new("<%= cases["input"]["subject"] %>") + anagrams = detector.match(%w[<%= cases["input"]["candidates"].join(" ") %>]) + expected = %w[<%= cases["expected"].join(" ") %>] + + assert_equal expected, anagrams + end + <% end %> +end diff --git a/exercises/practice/anagram/.meta/tests.toml b/exercises/practice/anagram/.meta/tests.toml index 4d90562705..8b680daca3 100644 --- a/exercises/practice/anagram/.meta/tests.toml +++ b/exercises/practice/anagram/.meta/tests.toml @@ -81,6 +81,8 @@ reimplements = "a0705568-628c-4b55-9798-82e4acde51ca" [a6854f66-eec1-4afd-a137-62ef2870c051] description = "handles case of greek letters" +include = false [fd3509e5-e3ba-409d-ac3d-a9ac84d13296] description = "different characters may have the same bytes" +include = false diff --git a/exercises/practice/anagram/anagram_test.rb b/exercises/practice/anagram/anagram_test.rb index cd5f4fc98c..d52b20b214 100644 --- a/exercises/practice/anagram/anagram_test.rb +++ b/exercises/practice/anagram/anagram_test.rb @@ -6,7 +6,8 @@ def test_no_matches # skip detector = Anagram.new("diaper") anagrams = detector.match(%w[hello world zombies pants]) - expected = [] + expected = %w[] + assert_equal expected, anagrams end @@ -15,6 +16,7 @@ def test_detects_two_anagrams detector = Anagram.new("solemn") anagrams = detector.match(%w[lemons cherry melons]) expected = %w[lemons melons] + assert_equal expected, anagrams end @@ -22,7 +24,8 @@ def test_does_not_detect_anagram_subsets skip detector = Anagram.new("good") anagrams = detector.match(%w[dog goody]) - expected = [] + expected = %w[] + assert_equal expected, anagrams end @@ -30,7 +33,8 @@ def test_detects_anagram skip detector = Anagram.new("listen") anagrams = detector.match(%w[enlists google inlets banana]) - expected = ["inlets"] + expected = %w[inlets] + assert_equal expected, anagrams end @@ -39,6 +43,7 @@ def test_detects_three_anagrams detector = Anagram.new("allergy") anagrams = detector.match(%w[gallery ballerina regally clergy largely leading]) expected = %w[gallery regally largely] + assert_equal expected, anagrams end @@ -47,14 +52,16 @@ def test_detects_multiple_anagrams_with_different_case detector = Anagram.new("nose") anagrams = detector.match(%w[Eons ONES]) expected = %w[Eons ONES] + assert_equal expected, anagrams end def test_does_not_detect_non_anagrams_with_identical_checksum skip detector = Anagram.new("mass") - anagrams = detector.match(["last"]) - expected = [] + anagrams = detector.match(%w[last]) + expected = %w[] + assert_equal expected, anagrams end @@ -62,7 +69,8 @@ def test_detects_anagrams_case_insensitively skip detector = Anagram.new("Orchestra") anagrams = detector.match(%w[cashregister Carthorse radishes]) - expected = ["Carthorse"] + expected = %w[Carthorse] + assert_equal expected, anagrams end @@ -70,7 +78,8 @@ def test_detects_anagrams_using_case_insensitive_subject skip detector = Anagram.new("Orchestra") anagrams = detector.match(%w[cashregister carthorse radishes]) - expected = ["carthorse"] + expected = %w[carthorse] + assert_equal expected, anagrams end @@ -78,47 +87,53 @@ def test_detects_anagrams_using_case_insensitive_possible_matches skip detector = Anagram.new("orchestra") anagrams = detector.match(%w[cashregister Carthorse radishes]) - expected = ["Carthorse"] + expected = %w[Carthorse] + assert_equal expected, anagrams end def test_does_not_detect_an_anagram_if_the_original_word_is_repeated skip detector = Anagram.new("go") - anagrams = detector.match(["go Go GO"]) - expected = [] + anagrams = detector.match(%w[goGoGO]) + expected = %w[] + assert_equal expected, anagrams end def test_anagrams_must_use_all_letters_exactly_once skip detector = Anagram.new("tapper") - anagrams = detector.match(["patter"]) - expected = [] + anagrams = detector.match(%w[patter]) + expected = %w[] + assert_equal expected, anagrams end def test_words_are_not_anagrams_of_themselves skip detector = Anagram.new("BANANA") - anagrams = detector.match(["BANANA"]) - expected = [] + anagrams = detector.match(%w[BANANA]) + expected = %w[] + assert_equal expected, anagrams end def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different skip detector = Anagram.new("BANANA") - anagrams = detector.match(["Banana"]) - expected = [] + anagrams = detector.match(%w[Banana]) + expected = %w[] + assert_equal expected, anagrams end def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different skip detector = Anagram.new("BANANA") - anagrams = detector.match(["banana"]) - expected = [] + anagrams = detector.match(%w[banana]) + expected = %w[] + assert_equal expected, anagrams end @@ -126,7 +141,8 @@ def test_words_other_than_themselves_can_be_anagrams skip detector = Anagram.new("LISTEN") anagrams = detector.match(%w[LISTEN Silent]) - expected = ["Silent"] + expected = %w[Silent] + assert_equal expected, anagrams end end diff --git a/exercises/practice/armstrong-numbers/.meta/test_template.erb b/exercises/practice/armstrong-numbers/.meta/test_template.erb new file mode 100644 index 0000000000..a39a63b2a7 --- /dev/null +++ b/exercises/practice/armstrong-numbers/.meta/test_template.erb @@ -0,0 +1,11 @@ +require 'minitest/autorun' +require_relative 'armstrong_numbers' + +class ArmstrongNumbersTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + <%= cases["expected"] ? "assert_includes" : "refute_includes" %> ArmstrongNumbers, <%= cases["input"]["number"] %> + end + <% end %> +end diff --git a/exercises/practice/atbash-cipher/.meta/test_template.erb b/exercises/practice/atbash-cipher/.meta/test_template.erb new file mode 100644 index 0000000000..f0f0ac9e1e --- /dev/null +++ b/exercises/practice/atbash-cipher/.meta/test_template.erb @@ -0,0 +1,21 @@ +require 'minitest/autorun' +require_relative 'armstrong_numbers' + +class ArmstrongNumbersTest < Minitest::Test +<% json["cases"].each do |cases| %> + <% cases["cases"].each do |sub_case| %> + def test_<%= underscore(sub_case["description"]) %> + <%= skip? %> + <%- if sub_case["property"] == "encode" -%> + plaintext = '<%= sub_case["input"]["phrase"] %>' + ciphertext = '<%= sub_case["expected"] %>' + assert_equal ciphertext, Atbash.encode(plaintext) + <%- else -%> + ciphertext = '<%= sub_case["input"]["phrase"] %>' + plaintext = '<%= sub_case["expected"] %>' + assert_equal plaintext, Atbash.decode(ciphertext) + <% end %> + end + <% end %> +<% end %> +end diff --git a/exercises/practice/atbash-cipher/atbash_cipher_test.rb b/exercises/practice/atbash-cipher/atbash_cipher_test.rb index 7775163e56..e39028b58b 100644 --- a/exercises/practice/atbash-cipher/atbash_cipher_test.rb +++ b/exercises/practice/atbash-cipher/atbash_cipher_test.rb @@ -1,7 +1,7 @@ require 'minitest/autorun' -require_relative 'atbash_cipher' +require_relative 'armstrong_numbers' -class AtbashCipherTest < Minitest::Test +class ArmstrongNumbersTest < Minitest::Test def test_encode_yes # skip plaintext = 'yes' diff --git a/exercises/practice/bank-account/.meta/test_template.erb b/exercises/practice/bank-account/.meta/test_template.erb new file mode 100644 index 0000000000..f2e9acf13f --- /dev/null +++ b/exercises/practice/bank-account/.meta/test_template.erb @@ -0,0 +1,43 @@ +require 'minitest/autorun' +require_relative 'bank_account' + +class BankAccountTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + bank_account = BankAccount.new + <%- cases["input"]["operations"][...-1].each do |operation| -%> + <%- if operation["operation"] == "open" -%> + bank_account.open + <%- elsif operation["operation"] == "close" -%> + bank_account.close + <%- elsif operation["operation"] == "deposit" -%> + bank_account.deposit(<%= operation["amount"] %>) + <%- elsif operation["operation"] == "withdraw" -%> + bank_account.withdraw(<%= operation["amount"] %>) + <%- end -%> + <%- end -%> + <%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%> + assert_raises(ArgumentError, <%- if cases["expected"]["error"] == "account not open" && cases["input"]["operations"][-1]["operation"] == "balance" -%> + "You can't check the balance of a closed account" + <%- elsif cases["expected"]["error"] == "account not open" && cases["input"]["operations"][-1]["operation"] == "withdraw" -%> + "You can't withdraw money into a closed account" + <%- elsif cases["expected"]["error"] == "account not open" && cases["input"]["operations"][-1]["operation"] == "deposit" -%> + "You can't deposit money into a closed account" + <%- elsif cases["expected"]["error"] == "account not open" -%> + "You can't close an already closed account" + <%- elsif cases["expected"]["error"] == "account already open" -%> + "You can't open an already open account" + <%- elsif cases["expected"]["error"] == "amount must be less than balance" -%> + "You can't withdraw more than you have" + <%- elsif cases["expected"]["error"] == "amount must be greater than 0" && cases["input"]["operations"][-1]["operation"] == "withdraw" -%> + "You can't withdraw a negative amount" + <%- elsif cases["expected"]["error"] == "amount must be greater than 0" -%> + "You can't deposit a negative amount" + <%- end -%> ) { bank_account.<%= cases["input"]["operations"][-1]["operation"]%>(<%= cases["input"]["operations"][-1]["amount"] %>) } + <%- else -%> + assert_equal <%= cases["expected"] %>, bank_account.balance + <%- end -%> + end +<% end %> +end \ No newline at end of file diff --git a/exercises/practice/bank-account/.meta/tests.toml b/exercises/practice/bank-account/.meta/tests.toml index 655ea7ae5a..1704a08c5a 100644 --- a/exercises/practice/bank-account/.meta/tests.toml +++ b/exercises/practice/bank-account/.meta/tests.toml @@ -59,4 +59,4 @@ description = "Cannot deposit negative" [ba0c1e0b-0f00-416f-8097-a7dfc97871ff] description = "Can handle concurrent transactions" -include = false \ No newline at end of file +include = false diff --git a/exercises/practice/bank-account/bank_account_test.rb b/exercises/practice/bank-account/bank_account_test.rb index edc44b4559..926b987c6d 100644 --- a/exercises/practice/bank-account/bank_account_test.rb +++ b/exercises/practice/bank-account/bank_account_test.rb @@ -6,7 +6,7 @@ def test_newly_opened_account_has_zero_balance # skip bank_account = BankAccount.new bank_account.open - assert_equal bank_account.balance, 0 + assert_equal 0, bank_account.balance end def test_single_deposit diff --git a/exercises/practice/binary-search/.meta/test_template.erb b/exercises/practice/binary-search/.meta/test_template.erb new file mode 100644 index 0000000000..27b55b5a33 --- /dev/null +++ b/exercises/practice/binary-search/.meta/test_template.erb @@ -0,0 +1,16 @@ +require 'minitest/autorun' +require_relative 'binary_search' + +class BinarySearchTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + binary = BinarySearch.new(<%= cases["input"]["array"] %>) + <%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%> + assert_nil binary.search_for(<%= cases["input"]["value"] %>) + <%- else -%> + assert_equal <%= cases["expected"] %>, binary.search_for(<%= cases["input"]["value"] %>) + <%- end -%> + end + <% end %> +end diff --git a/exercises/practice/binary-search/binary_search_test.rb b/exercises/practice/binary-search/binary_search_test.rb index bc928a666c..6f9c9ebd4b 100644 --- a/exercises/practice/binary-search/binary_search_test.rb +++ b/exercises/practice/binary-search/binary_search_test.rb @@ -44,13 +44,13 @@ def test_identifies_that_a_value_is_not_included_in_the_array assert_nil binary.search_for(7) end - def test_a_value_smaller_than_the_array_s_smallest_value_is_not_found + def test_a_value_smaller_than_the_arrays_smallest_value_is_not_found skip binary = BinarySearch.new([1, 3, 4, 6, 8, 9, 11]) assert_nil binary.search_for(0) end - def test_a_value_larger_than_the_array_s_largest_value_is_not_found + def test_a_value_larger_than_the_arrays_largest_value_is_not_found skip binary = BinarySearch.new([1, 3, 4, 6, 8, 9, 11]) assert_nil binary.search_for(13) From f13ce4f2bed12f7574c1a32675474e92cc191c5b Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 30 Aug 2025 21:57:15 +0200 Subject: [PATCH 2/7] Make test name unique in allergies --- .../allergies/.meta/test_template.erb | 4 +- .../practice/allergies/allergies_test.rb | 90 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/exercises/practice/allergies/.meta/test_template.erb b/exercises/practice/allergies/.meta/test_template.erb index df97cd71ce..3bf51b6b2a 100644 --- a/exercises/practice/allergies/.meta/test_template.erb +++ b/exercises/practice/allergies/.meta/test_template.erb @@ -2,9 +2,9 @@ require 'minitest/autorun' require_relative 'allergies' class AllergiesTest < Minitest::Test -<% json["cases"].each do |group| %> +<% json["cases"].each_with_index do |group, index| %> <% group["cases"].each do |sub_case| %> - def test_<%= underscore(sub_case["description"]) %> + def test_<%= underscore(sub_case["description"]) %><%= index.zero? ? "" : "_#{index}" %> <%= skip? %> allergies = Allergies.new(<%= sub_case["input"]["score"] %>) <%- if sub_case["property"] == "allergicTo" -%> diff --git a/exercises/practice/allergies/allergies_test.rb b/exercises/practice/allergies/allergies_test.rb index 0e46add2a1..630fefa28a 100644 --- a/exercises/practice/allergies/allergies_test.rb +++ b/exercises/practice/allergies/allergies_test.rb @@ -32,280 +32,280 @@ def test_allergic_to_everything assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is." end - def test_not_allergic_to_anything + def test_not_allergic_to_anything_1 skip allergies = Allergies.new(0) refute allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." end - def test_allergic_only_to_peanuts + def test_allergic_only_to_peanuts_1 skip allergies = Allergies.new(2) assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." end - def test_allergic_to_peanuts_and_something_else + def test_allergic_to_peanuts_and_something_else_1 skip allergies = Allergies.new(7) assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." end - def test_allergic_to_something_but_not_peanuts + def test_allergic_to_something_but_not_peanuts_1 skip allergies = Allergies.new(5) refute allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." end - def test_allergic_to_everything + def test_allergic_to_everything_1 skip allergies = Allergies.new(255) assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." end - def test_not_allergic_to_anything + def test_not_allergic_to_anything_2 skip allergies = Allergies.new(0) refute allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." end - def test_allergic_only_to_shellfish + def test_allergic_only_to_shellfish_2 skip allergies = Allergies.new(4) assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." end - def test_allergic_to_shellfish_and_something_else + def test_allergic_to_shellfish_and_something_else_2 skip allergies = Allergies.new(14) assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." end - def test_allergic_to_something_but_not_shellfish + def test_allergic_to_something_but_not_shellfish_2 skip allergies = Allergies.new(10) refute allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." end - def test_allergic_to_everything + def test_allergic_to_everything_2 skip allergies = Allergies.new(255) assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." end - def test_not_allergic_to_anything + def test_not_allergic_to_anything_3 skip allergies = Allergies.new(0) refute allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." end - def test_allergic_only_to_strawberries + def test_allergic_only_to_strawberries_3 skip allergies = Allergies.new(8) assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." end - def test_allergic_to_strawberries_and_something_else + def test_allergic_to_strawberries_and_something_else_3 skip allergies = Allergies.new(28) assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." end - def test_allergic_to_something_but_not_strawberries + def test_allergic_to_something_but_not_strawberries_3 skip allergies = Allergies.new(20) refute allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." end - def test_allergic_to_everything + def test_allergic_to_everything_3 skip allergies = Allergies.new(255) assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." end - def test_not_allergic_to_anything + def test_not_allergic_to_anything_4 skip allergies = Allergies.new(0) refute allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." end - def test_allergic_only_to_tomatoes + def test_allergic_only_to_tomatoes_4 skip allergies = Allergies.new(16) assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." end - def test_allergic_to_tomatoes_and_something_else + def test_allergic_to_tomatoes_and_something_else_4 skip allergies = Allergies.new(56) assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." end - def test_allergic_to_something_but_not_tomatoes + def test_allergic_to_something_but_not_tomatoes_4 skip allergies = Allergies.new(40) refute allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." end - def test_allergic_to_everything + def test_allergic_to_everything_4 skip allergies = Allergies.new(255) assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." end - def test_not_allergic_to_anything + def test_not_allergic_to_anything_5 skip allergies = Allergies.new(0) refute allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." end - def test_allergic_only_to_chocolate + def test_allergic_only_to_chocolate_5 skip allergies = Allergies.new(32) assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." end - def test_allergic_to_chocolate_and_something_else + def test_allergic_to_chocolate_and_something_else_5 skip allergies = Allergies.new(112) assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." end - def test_allergic_to_something_but_not_chocolate + def test_allergic_to_something_but_not_chocolate_5 skip allergies = Allergies.new(80) refute allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." end - def test_allergic_to_everything + def test_allergic_to_everything_5 skip allergies = Allergies.new(255) assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." end - def test_not_allergic_to_anything + def test_not_allergic_to_anything_6 skip allergies = Allergies.new(0) refute allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." end - def test_allergic_only_to_pollen + def test_allergic_only_to_pollen_6 skip allergies = Allergies.new(64) assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." end - def test_allergic_to_pollen_and_something_else + def test_allergic_to_pollen_and_something_else_6 skip allergies = Allergies.new(224) assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." end - def test_allergic_to_something_but_not_pollen + def test_allergic_to_something_but_not_pollen_6 skip allergies = Allergies.new(160) refute allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." end - def test_allergic_to_everything + def test_allergic_to_everything_6 skip allergies = Allergies.new(255) assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." end - def test_not_allergic_to_anything + def test_not_allergic_to_anything_7 skip allergies = Allergies.new(0) refute allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." end - def test_allergic_only_to_cats + def test_allergic_only_to_cats_7 skip allergies = Allergies.new(128) assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." end - def test_allergic_to_cats_and_something_else + def test_allergic_to_cats_and_something_else_7 skip allergies = Allergies.new(192) assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." end - def test_allergic_to_something_but_not_cats + def test_allergic_to_something_but_not_cats_7 skip allergies = Allergies.new(64) refute allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." end - def test_allergic_to_everything + def test_allergic_to_everything_7 skip allergies = Allergies.new(255) assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." end - def test_no_allergies + def test_no_allergies_8 skip allergies = Allergies.new(0) expected = %w[] assert_equal expected, allergies.list end - def test_just_eggs + def test_just_eggs_8 skip allergies = Allergies.new(1) expected = %w[eggs] assert_equal expected, allergies.list end - def test_just_peanuts + def test_just_peanuts_8 skip allergies = Allergies.new(2) expected = %w[peanuts] assert_equal expected, allergies.list end - def test_just_strawberries + def test_just_strawberries_8 skip allergies = Allergies.new(8) expected = %w[strawberries] assert_equal expected, allergies.list end - def test_eggs_and_peanuts + def test_eggs_and_peanuts_8 skip allergies = Allergies.new(3) expected = %w[eggs peanuts] assert_equal expected, allergies.list end - def test_more_than_eggs_but_not_peanuts + def test_more_than_eggs_but_not_peanuts_8 skip allergies = Allergies.new(5) expected = %w[eggs shellfish] assert_equal expected, allergies.list end - def test_lots_of_stuff + def test_lots_of_stuff_8 skip allergies = Allergies.new(248) expected = %w[strawberries tomatoes chocolate pollen cats] assert_equal expected, allergies.list end - def test_everything + def test_everything_8 skip allergies = Allergies.new(255) expected = %w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats] assert_equal expected, allergies.list end - def test_no_allergen_score_parts + def test_no_allergen_score_parts_8 skip allergies = Allergies.new(509) expected = %w[eggs shellfish strawberries tomatoes chocolate pollen cats] assert_equal expected, allergies.list end - def test_no_allergen_score_parts_without_highest_valid_score + def test_no_allergen_score_parts_without_highest_valid_score_8 skip allergies = Allergies.new(257) expected = %w[eggs] From 14ad136bfc0b023565450a4839ad5b0c9246033e Mon Sep 17 00:00:00 2001 From: Victor Goff Date: Sun, 31 Aug 2025 04:19:58 -0400 Subject: [PATCH 3/7] EOL Fix --- exercises/practice/bank-account/.meta/test_template.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/bank-account/.meta/test_template.erb b/exercises/practice/bank-account/.meta/test_template.erb index f2e9acf13f..7bda18768f 100644 --- a/exercises/practice/bank-account/.meta/test_template.erb +++ b/exercises/practice/bank-account/.meta/test_template.erb @@ -40,4 +40,4 @@ class BankAccountTest < Minitest::Test <%- end -%> end <% end %> -end \ No newline at end of file +end From fad6950c8c32ef67c085573b44a99831bb0bcb05 Mon Sep 17 00:00:00 2001 From: meatball Date: Sun, 31 Aug 2025 10:22:49 +0200 Subject: [PATCH 4/7] Changed exercises to use singel qoutes. Changed template for allergies so it should match the old version. --- .../practice/acronym/.meta/test_template.erb | 2 +- exercises/practice/acronym/acronym_test.rb | 18 +- .../allergies/.meta/test_template.erb | 6 +- .../practice/allergies/allergies_test.rb | 180 +++++++++--------- .../practice/anagram/.meta/test_template.erb | 2 +- exercises/practice/anagram/anagram_test.rb | 32 ++-- 6 files changed, 120 insertions(+), 120 deletions(-) diff --git a/exercises/practice/acronym/.meta/test_template.erb b/exercises/practice/acronym/.meta/test_template.erb index 3b4db5d302..c2b235f152 100644 --- a/exercises/practice/acronym/.meta/test_template.erb +++ b/exercises/practice/acronym/.meta/test_template.erb @@ -5,7 +5,7 @@ class AcronymTest < Minitest::Test <% json["cases"].each do |cases| %> def test_<%= underscore(cases["description"]) %> <%= skip? %> - assert_equal "<%= cases["expected"] %>", <%= camel_case(json["exercise"]) %>.<%= underscore(cases["property"]) %>("<%= cases["input"]["phrase"] %>") + assert_equal '<%= cases["expected"] %>', <%= camel_case(json["exercise"]) %>.<%= underscore(cases["property"]) %>('<%= cases["input"]["phrase"].gsub("'", "\\\\'") %>') end <% end %> end diff --git a/exercises/practice/acronym/acronym_test.rb b/exercises/practice/acronym/acronym_test.rb index db6766585f..0716d5b5b8 100644 --- a/exercises/practice/acronym/acronym_test.rb +++ b/exercises/practice/acronym/acronym_test.rb @@ -4,46 +4,46 @@ class AcronymTest < Minitest::Test def test_basic # skip - assert_equal "PNG", Acronym.abbreviate("Portable Network Graphics") + assert_equal 'PNG', Acronym.abbreviate('Portable Network Graphics') end def test_lowercase_words skip - assert_equal "ROR", Acronym.abbreviate("Ruby on Rails") + assert_equal 'ROR', Acronym.abbreviate('Ruby on Rails') end def test_punctuation skip - assert_equal "FIFO", Acronym.abbreviate("First In, First Out") + assert_equal 'FIFO', Acronym.abbreviate('First In, First Out') end def test_all_caps_word skip - assert_equal "GIMP", Acronym.abbreviate("GNU Image Manipulation Program") + assert_equal 'GIMP', Acronym.abbreviate('GNU Image Manipulation Program') end def test_punctuation_without_whitespace skip - assert_equal "CMOS", Acronym.abbreviate("Complementary metal-oxide semiconductor") + assert_equal 'CMOS', Acronym.abbreviate('Complementary metal-oxide semiconductor') end def test_very_long_abbreviation skip - assert_equal "ROTFLSHTMDCOALM", Acronym.abbreviate("Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me") + assert_equal 'ROTFLSHTMDCOALM', Acronym.abbreviate('Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me') end def test_consecutive_delimiters skip - assert_equal "SIMUFTA", Acronym.abbreviate("Something - I made up from thin air") + assert_equal 'SIMUFTA', Acronym.abbreviate('Something - I made up from thin air') end def test_apostrophes skip - assert_equal "HC", Acronym.abbreviate("Halley's Comet") + assert_equal 'HC', Acronym.abbreviate('Halley\'s Comet') end def test_underscore_emphasis skip - assert_equal "TRNT", Acronym.abbreviate("The Road _Not_ Taken") + assert_equal 'TRNT', Acronym.abbreviate('The Road _Not_ Taken') end end diff --git a/exercises/practice/allergies/.meta/test_template.erb b/exercises/practice/allergies/.meta/test_template.erb index 3bf51b6b2a..70ddced656 100644 --- a/exercises/practice/allergies/.meta/test_template.erb +++ b/exercises/practice/allergies/.meta/test_template.erb @@ -2,13 +2,13 @@ require 'minitest/autorun' require_relative 'allergies' class AllergiesTest < Minitest::Test -<% json["cases"].each_with_index do |group, index| %> +<% json["cases"].each do |group| %> <% group["cases"].each do |sub_case| %> - def test_<%= underscore(sub_case["description"]) %><%= index.zero? ? "" : "_#{index}" %> + def test_<%= underscore(group["description"]) %>_<%= underscore(sub_case["description"]) %> <%= skip? %> allergies = Allergies.new(<%= sub_case["input"]["score"] %>) <%- if sub_case["property"] == "allergicTo" -%> - <%= sub_case["expected"] ? "assert" : "refute" %> allergies.allergic_to?("<%= sub_case["input"]["item"] %>"), "Tom is allergic, but it says he is<%= sub_case["expected"] ? "" : " not" %>." + <%= sub_case["expected"] ? "assert" : "refute" %> allergies.allergic_to?('<%= sub_case["input"]["item"] %>'), 'Tom is<%= sub_case["expected"] ? "" : " not" %> allergic, but it says he is<%= sub_case["expected"] ? " not" : "" %>.' <%- else -%> expected = %w[<%= sub_case["expected"].join(" ") %>] assert_equal expected, allergies.list diff --git a/exercises/practice/allergies/allergies_test.rb b/exercises/practice/allergies/allergies_test.rb index 630fefa28a..f9e6e27c7c 100644 --- a/exercises/practice/allergies/allergies_test.rb +++ b/exercises/practice/allergies/allergies_test.rb @@ -2,310 +2,310 @@ require_relative 'allergies' class AllergiesTest < Minitest::Test - def test_not_allergic_to_anything + def test_testing_for_eggs_allergy_not_allergic_to_anything # skip allergies = Allergies.new(0) - refute allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('eggs'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_eggs + def test_testing_for_eggs_allergy_allergic_only_to_eggs skip allergies = Allergies.new(1) - assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('eggs'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_eggs_and_something_else + def test_testing_for_eggs_allergy_allergic_to_eggs_and_something_else skip allergies = Allergies.new(3) - assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('eggs'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_eggs + def test_testing_for_eggs_allergy_allergic_to_something_but_not_eggs skip allergies = Allergies.new(2) - refute allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('eggs'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything + def test_testing_for_eggs_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('eggs'), 'Tom is allergic, but it says he is not.' end - def test_not_allergic_to_anything_1 + def test_testing_for_peanuts_allergy_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('peanuts'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_peanuts_1 + def test_testing_for_peanuts_allergy_allergic_only_to_peanuts skip allergies = Allergies.new(2) - assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('peanuts'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_peanuts_and_something_else_1 + def test_testing_for_peanuts_allergy_allergic_to_peanuts_and_something_else skip allergies = Allergies.new(7) - assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('peanuts'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_peanuts_1 + def test_testing_for_peanuts_allergy_allergic_to_something_but_not_peanuts skip allergies = Allergies.new(5) - refute allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('peanuts'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything_1 + def test_testing_for_peanuts_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('peanuts'), 'Tom is allergic, but it says he is not.' end - def test_not_allergic_to_anything_2 + def test_testing_for_shellfish_allergy_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('shellfish'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_shellfish_2 + def test_testing_for_shellfish_allergy_allergic_only_to_shellfish skip allergies = Allergies.new(4) - assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('shellfish'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_shellfish_and_something_else_2 + def test_testing_for_shellfish_allergy_allergic_to_shellfish_and_something_else skip allergies = Allergies.new(14) - assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('shellfish'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_shellfish_2 + def test_testing_for_shellfish_allergy_allergic_to_something_but_not_shellfish skip allergies = Allergies.new(10) - refute allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('shellfish'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything_2 + def test_testing_for_shellfish_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('shellfish'), 'Tom is allergic, but it says he is not.' end - def test_not_allergic_to_anything_3 + def test_testing_for_strawberries_allergy_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('strawberries'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_strawberries_3 + def test_testing_for_strawberries_allergy_allergic_only_to_strawberries skip allergies = Allergies.new(8) - assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('strawberries'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_strawberries_and_something_else_3 + def test_testing_for_strawberries_allergy_allergic_to_strawberries_and_something_else skip allergies = Allergies.new(28) - assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('strawberries'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_strawberries_3 + def test_testing_for_strawberries_allergy_allergic_to_something_but_not_strawberries skip allergies = Allergies.new(20) - refute allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('strawberries'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything_3 + def test_testing_for_strawberries_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('strawberries'), 'Tom is allergic, but it says he is not.' end - def test_not_allergic_to_anything_4 + def test_testing_for_tomatoes_allergy_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('tomatoes'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_tomatoes_4 + def test_testing_for_tomatoes_allergy_allergic_only_to_tomatoes skip allergies = Allergies.new(16) - assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('tomatoes'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_tomatoes_and_something_else_4 + def test_testing_for_tomatoes_allergy_allergic_to_tomatoes_and_something_else skip allergies = Allergies.new(56) - assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('tomatoes'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_tomatoes_4 + def test_testing_for_tomatoes_allergy_allergic_to_something_but_not_tomatoes skip allergies = Allergies.new(40) - refute allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('tomatoes'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything_4 + def test_testing_for_tomatoes_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('tomatoes'), 'Tom is allergic, but it says he is not.' end - def test_not_allergic_to_anything_5 + def test_testing_for_chocolate_allergy_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('chocolate'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_chocolate_5 + def test_testing_for_chocolate_allergy_allergic_only_to_chocolate skip allergies = Allergies.new(32) - assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('chocolate'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_chocolate_and_something_else_5 + def test_testing_for_chocolate_allergy_allergic_to_chocolate_and_something_else skip allergies = Allergies.new(112) - assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('chocolate'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_chocolate_5 + def test_testing_for_chocolate_allergy_allergic_to_something_but_not_chocolate skip allergies = Allergies.new(80) - refute allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('chocolate'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything_5 + def test_testing_for_chocolate_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('chocolate'), 'Tom is allergic, but it says he is not.' end - def test_not_allergic_to_anything_6 + def test_testing_for_pollen_allergy_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('pollen'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_pollen_6 + def test_testing_for_pollen_allergy_allergic_only_to_pollen skip allergies = Allergies.new(64) - assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('pollen'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_pollen_and_something_else_6 + def test_testing_for_pollen_allergy_allergic_to_pollen_and_something_else skip allergies = Allergies.new(224) - assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('pollen'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_pollen_6 + def test_testing_for_pollen_allergy_allergic_to_something_but_not_pollen skip allergies = Allergies.new(160) - refute allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('pollen'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything_6 + def test_testing_for_pollen_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('pollen'), 'Tom is allergic, but it says he is not.' end - def test_not_allergic_to_anything_7 + def test_testing_for_cats_allergy_not_allergic_to_anything skip allergies = Allergies.new(0) - refute allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('cats'), 'Tom is not allergic, but it says he is.' end - def test_allergic_only_to_cats_7 + def test_testing_for_cats_allergy_allergic_only_to_cats skip allergies = Allergies.new(128) - assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('cats'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_cats_and_something_else_7 + def test_testing_for_cats_allergy_allergic_to_cats_and_something_else skip allergies = Allergies.new(192) - assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('cats'), 'Tom is allergic, but it says he is not.' end - def test_allergic_to_something_but_not_cats_7 + def test_testing_for_cats_allergy_allergic_to_something_but_not_cats skip allergies = Allergies.new(64) - refute allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + refute allergies.allergic_to?('cats'), 'Tom is not allergic, but it says he is.' end - def test_allergic_to_everything_7 + def test_testing_for_cats_allergy_allergic_to_everything skip allergies = Allergies.new(255) - assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is." + assert allergies.allergic_to?('cats'), 'Tom is allergic, but it says he is not.' end - def test_no_allergies_8 + def test_list_when_no_allergies skip allergies = Allergies.new(0) expected = %w[] assert_equal expected, allergies.list end - def test_just_eggs_8 + def test_list_when_just_eggs skip allergies = Allergies.new(1) expected = %w[eggs] assert_equal expected, allergies.list end - def test_just_peanuts_8 + def test_list_when_just_peanuts skip allergies = Allergies.new(2) expected = %w[peanuts] assert_equal expected, allergies.list end - def test_just_strawberries_8 + def test_list_when_just_strawberries skip allergies = Allergies.new(8) expected = %w[strawberries] assert_equal expected, allergies.list end - def test_eggs_and_peanuts_8 + def test_list_when_eggs_and_peanuts skip allergies = Allergies.new(3) expected = %w[eggs peanuts] assert_equal expected, allergies.list end - def test_more_than_eggs_but_not_peanuts_8 + def test_list_when_more_than_eggs_but_not_peanuts skip allergies = Allergies.new(5) expected = %w[eggs shellfish] assert_equal expected, allergies.list end - def test_lots_of_stuff_8 + def test_list_when_lots_of_stuff skip allergies = Allergies.new(248) expected = %w[strawberries tomatoes chocolate pollen cats] assert_equal expected, allergies.list end - def test_everything_8 + def test_list_when_everything skip allergies = Allergies.new(255) expected = %w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats] assert_equal expected, allergies.list end - def test_no_allergen_score_parts_8 + def test_list_when_no_allergen_score_parts skip allergies = Allergies.new(509) expected = %w[eggs shellfish strawberries tomatoes chocolate pollen cats] assert_equal expected, allergies.list end - def test_no_allergen_score_parts_without_highest_valid_score_8 + def test_list_when_no_allergen_score_parts_without_highest_valid_score skip allergies = Allergies.new(257) expected = %w[eggs] diff --git a/exercises/practice/anagram/.meta/test_template.erb b/exercises/practice/anagram/.meta/test_template.erb index 34574df81e..003e246495 100644 --- a/exercises/practice/anagram/.meta/test_template.erb +++ b/exercises/practice/anagram/.meta/test_template.erb @@ -5,7 +5,7 @@ class AnagramTest < Minitest::Test <% json["cases"].each do |cases| %> def test_<%= underscore(cases["description"]) %> <%= skip? %> - detector = Anagram.new("<%= cases["input"]["subject"] %>") + detector = Anagram.new('<%= cases["input"]["subject"] %>') anagrams = detector.match(%w[<%= cases["input"]["candidates"].join(" ") %>]) expected = %w[<%= cases["expected"].join(" ") %>] diff --git a/exercises/practice/anagram/anagram_test.rb b/exercises/practice/anagram/anagram_test.rb index d52b20b214..93bbdd3a9a 100644 --- a/exercises/practice/anagram/anagram_test.rb +++ b/exercises/practice/anagram/anagram_test.rb @@ -4,7 +4,7 @@ class AnagramTest < Minitest::Test def test_no_matches # skip - detector = Anagram.new("diaper") + detector = Anagram.new('diaper') anagrams = detector.match(%w[hello world zombies pants]) expected = %w[] @@ -13,7 +13,7 @@ def test_no_matches def test_detects_two_anagrams skip - detector = Anagram.new("solemn") + detector = Anagram.new('solemn') anagrams = detector.match(%w[lemons cherry melons]) expected = %w[lemons melons] @@ -22,7 +22,7 @@ def test_detects_two_anagrams def test_does_not_detect_anagram_subsets skip - detector = Anagram.new("good") + detector = Anagram.new('good') anagrams = detector.match(%w[dog goody]) expected = %w[] @@ -31,7 +31,7 @@ def test_does_not_detect_anagram_subsets def test_detects_anagram skip - detector = Anagram.new("listen") + detector = Anagram.new('listen') anagrams = detector.match(%w[enlists google inlets banana]) expected = %w[inlets] @@ -40,7 +40,7 @@ def test_detects_anagram def test_detects_three_anagrams skip - detector = Anagram.new("allergy") + detector = Anagram.new('allergy') anagrams = detector.match(%w[gallery ballerina regally clergy largely leading]) expected = %w[gallery regally largely] @@ -49,7 +49,7 @@ def test_detects_three_anagrams def test_detects_multiple_anagrams_with_different_case skip - detector = Anagram.new("nose") + detector = Anagram.new('nose') anagrams = detector.match(%w[Eons ONES]) expected = %w[Eons ONES] @@ -58,7 +58,7 @@ def test_detects_multiple_anagrams_with_different_case def test_does_not_detect_non_anagrams_with_identical_checksum skip - detector = Anagram.new("mass") + detector = Anagram.new('mass') anagrams = detector.match(%w[last]) expected = %w[] @@ -67,7 +67,7 @@ def test_does_not_detect_non_anagrams_with_identical_checksum def test_detects_anagrams_case_insensitively skip - detector = Anagram.new("Orchestra") + detector = Anagram.new('Orchestra') anagrams = detector.match(%w[cashregister Carthorse radishes]) expected = %w[Carthorse] @@ -76,7 +76,7 @@ def test_detects_anagrams_case_insensitively def test_detects_anagrams_using_case_insensitive_subject skip - detector = Anagram.new("Orchestra") + detector = Anagram.new('Orchestra') anagrams = detector.match(%w[cashregister carthorse radishes]) expected = %w[carthorse] @@ -85,7 +85,7 @@ def test_detects_anagrams_using_case_insensitive_subject def test_detects_anagrams_using_case_insensitive_possible_matches skip - detector = Anagram.new("orchestra") + detector = Anagram.new('orchestra') anagrams = detector.match(%w[cashregister Carthorse radishes]) expected = %w[Carthorse] @@ -94,7 +94,7 @@ def test_detects_anagrams_using_case_insensitive_possible_matches def test_does_not_detect_an_anagram_if_the_original_word_is_repeated skip - detector = Anagram.new("go") + detector = Anagram.new('go') anagrams = detector.match(%w[goGoGO]) expected = %w[] @@ -103,7 +103,7 @@ def test_does_not_detect_an_anagram_if_the_original_word_is_repeated def test_anagrams_must_use_all_letters_exactly_once skip - detector = Anagram.new("tapper") + detector = Anagram.new('tapper') anagrams = detector.match(%w[patter]) expected = %w[] @@ -112,7 +112,7 @@ def test_anagrams_must_use_all_letters_exactly_once def test_words_are_not_anagrams_of_themselves skip - detector = Anagram.new("BANANA") + detector = Anagram.new('BANANA') anagrams = detector.match(%w[BANANA]) expected = %w[] @@ -121,7 +121,7 @@ def test_words_are_not_anagrams_of_themselves def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different skip - detector = Anagram.new("BANANA") + detector = Anagram.new('BANANA') anagrams = detector.match(%w[Banana]) expected = %w[] @@ -130,7 +130,7 @@ def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_d def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different skip - detector = Anagram.new("BANANA") + detector = Anagram.new('BANANA') anagrams = detector.match(%w[banana]) expected = %w[] @@ -139,7 +139,7 @@ def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_ def test_words_other_than_themselves_can_be_anagrams skip - detector = Anagram.new("LISTEN") + detector = Anagram.new('LISTEN') anagrams = detector.match(%w[LISTEN Silent]) expected = %w[Silent] From 667dd4e96b3add8d4ae602a5b2bca1cf9a15e3f4 Mon Sep 17 00:00:00 2001 From: meatball Date: Sun, 31 Aug 2025 10:31:22 +0200 Subject: [PATCH 5/7] Update acronym solution to work on the new test --- exercises/practice/acronym/.meta/example.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/exercises/practice/acronym/.meta/example.rb b/exercises/practice/acronym/.meta/example.rb index d0230dd623..7ff6892849 100644 --- a/exercises/practice/acronym/.meta/example.rb +++ b/exercises/practice/acronym/.meta/example.rb @@ -7,9 +7,7 @@ def self.abbreviate(phrase) end.join end - def self.each_word(phrase) - phrase.scan(/[A-Z]+[a-z]*|[a-z]+/) do |word| - yield word - end + def self.each_word(phrase, &block) + phrase.scan(/[A-Za-z]+(?:'[A-Za-z]+)*/, &block) end end From 6c4452f8724f8d641cd1d452ff0c9d05f89c22cf Mon Sep 17 00:00:00 2001 From: meatball Date: Sun, 31 Aug 2025 10:38:26 +0200 Subject: [PATCH 6/7] Fix import and class in atbash test --- exercises/practice/atbash-cipher/atbash_cipher_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/practice/atbash-cipher/atbash_cipher_test.rb b/exercises/practice/atbash-cipher/atbash_cipher_test.rb index e39028b58b..7775163e56 100644 --- a/exercises/practice/atbash-cipher/atbash_cipher_test.rb +++ b/exercises/practice/atbash-cipher/atbash_cipher_test.rb @@ -1,7 +1,7 @@ require 'minitest/autorun' -require_relative 'armstrong_numbers' +require_relative 'atbash_cipher' -class ArmstrongNumbersTest < Minitest::Test +class AtbashCipherTest < Minitest::Test def test_encode_yes # skip plaintext = 'yes' From 884f5a61dbdfd832b2588bfe6c1ee7a0c9c020e9 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:52:52 +0200 Subject: [PATCH 7/7] Fix exercise naming in generator (#1770) (#1774) * Enhance underscore method to filter invalid characters and update test file naming convention * Add test case which test underscore for special characters * Use character classes in regex. Also expose description for nested test cases. * Underscore must not create multiple underscores around special characters --- bin/generate | 6 +++++- generatorv2/lib/generator.rb | 6 +++--- generatorv2/lib/utils.rb | 2 +- generatorv2/test/utils_test.rb | 10 ++++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bin/generate b/bin/generate index fd6f32f277..4966be4299 100755 --- a/bin/generate +++ b/bin/generate @@ -9,6 +9,10 @@ def exercises .select { |file| File.directory? File.join('./exercises/practice', file) } end +def underscore(str) + str.gsub(/[^\w\s-]/, '').gsub(/[-\s]/, '_').downcase +end + class VerificationError < StandardError MESSAGE = 'The result generated for %s, does not match the current file' @@ -39,7 +43,7 @@ end parser.on('--verify', 'Verify all exercises') do exercises.each do |exercise| if File.exist?("./exercises/practice/#{exercise}/.meta/test_template.erb") - current_code = File.read("./exercises/practice/#{exercise}/#{exercise}_test.rb") + current_code = File.read("./exercises/practice/#{exercise}/#{underscore(exercise)}_test.rb") f = File.new("./exercises/practice/#{exercise}/temp_test.rb", 'w+') Generator.new(exercise).generate(f.path) generated_code = f.read diff --git a/generatorv2/lib/generator.rb b/generatorv2/lib/generator.rb index a0d669e929..5f15b0b43c 100644 --- a/generatorv2/lib/generator.rb +++ b/generatorv2/lib/generator.rb @@ -21,17 +21,17 @@ def generate(result_path = "./exercises/practice/#{@exercise}/#{underscore(@exer additional_json(json) json["cases"] = remove_tests(uuid, json) status = proc { status } - template = ERB.new File.read("./exercises/practice/#{@exercise}/.meta/test_template.erb") + template = ERB.new(File.read("./exercises/practice/#{@exercise}/.meta/test_template.erb"), trim_mode: '-') result = template.result(binding) File.write(result_path, result) RuboCop::CLI.new. - run(['-x', '-c', '.rubocop.yml', '-o', NullDevice.path, result_path]) + run(['-a', '-c', '.rubocop.yml', '-o', NullDevice.path, result_path]) end def underscore(str) - str.gsub(/[-\s]/, '_').downcase + str.gsub(/[^\w\s-]/, '').gsub(' ', ' ').gsub(/[-\s]/, '_').downcase end def camel_case(str) diff --git a/generatorv2/lib/utils.rb b/generatorv2/lib/utils.rb index d6b80971e6..a728848e8c 100644 --- a/generatorv2/lib/utils.rb +++ b/generatorv2/lib/utils.rb @@ -47,7 +47,7 @@ def additional_json(json) def remove_tests(uuid, json) json["cases"].each_with_object([]) do |x, acc| if x["cases"] - acc << { "cases" => remove_tests(uuid, x) } + acc << { "cases" => remove_tests(uuid, x), "description" => x["description"] } elsif uuid.include?(x["uuid"]) acc << x end diff --git a/generatorv2/test/utils_test.rb b/generatorv2/test/utils_test.rb index 235021882c..944e0b66b8 100644 --- a/generatorv2/test/utils_test.rb +++ b/generatorv2/test/utils_test.rb @@ -22,6 +22,16 @@ def test_underscore_with_two_words Generator.new("two-fer").underscore("two-fer") end + def test_underscore_with_special_characters + assert_equal "two_fer", + Generator.new("two-fer").underscore("two,!@#$%^&*()-fer") + end + + def test_underscore_with_special_characters_should_not_create_multiple_spaces + assert_equal "two_fer", + Generator.new("two-fer").underscore("two = fer") + end + def test_first_time_includes_hastag assert_equal "# skip", Generator.new("acronym").skip?