From 1ad515f2bbbe71f307fcb111a2999afe10a56624 Mon Sep 17 00:00:00 2001 From: meatball Date: Mon, 8 Sep 2025 19:46:51 +0200 Subject: [PATCH] Add templates for exercises batch 5 --- .../grade-school/.meta/test_template.erb | 28 +++ .../grade-school/grade_school_test.rb | 124 ++++++------ .../practice/hamming/.meta/test_template.erb | 17 ++ exercises/practice/hamming/hamming_test.rb | 18 +- exercises/practice/house/.meta/example.rb | 11 +- .../practice/house/.meta/test_template.erb | 14 ++ exercises/practice/house/house_test.rb | 190 ++++++++++-------- .../isbn-verifier/.meta/test_template.erb | 12 ++ .../isbn-verifier/isbn_verifier_test.rb | 38 ++-- .../practice/isogram/.meta/test_template.erb | 12 ++ exercises/practice/isogram/isogram_test.rb | 28 +-- .../.meta/test_template.erb | 24 +++ .../kindergarten_garden_test.rb | 34 ++-- 13 files changed, 344 insertions(+), 206 deletions(-) create mode 100644 exercises/practice/grade-school/.meta/test_template.erb create mode 100644 exercises/practice/hamming/.meta/test_template.erb create mode 100644 exercises/practice/house/.meta/test_template.erb create mode 100644 exercises/practice/isbn-verifier/.meta/test_template.erb create mode 100644 exercises/practice/isogram/.meta/test_template.erb create mode 100644 exercises/practice/kindergarten-garden/.meta/test_template.erb diff --git a/exercises/practice/grade-school/.meta/test_template.erb b/exercises/practice/grade-school/.meta/test_template.erb new file mode 100644 index 0000000000..0f6475f838 --- /dev/null +++ b/exercises/practice/grade-school/.meta/test_template.erb @@ -0,0 +1,28 @@ +require 'minitest/autorun' +require_relative 'grade_school' + +class GradeSchoolTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + school = School.new + <%- if cases["property"] == "roster" -%> + <%- cases["input"]["students"].each do |student| -%> + school.add('<%= student[0] %>', <%= student[1] %>) + <%- end -%> + assert_equal <%= cases["expected"] %>, school.roster + <%- elsif cases["property"] == "add" -%> + results = [] + <%- cases["input"]["students"].each do |student| -%> + results << school.add('<%= student[0] %>', <%= student[1] %>) + <%- end -%> + assert_equal <%= cases["expected"] %>, results + <%- elsif cases["property"] == "grade" -%> + <%- cases["input"]["students"].each do |student| -%> + school.add('<%= student[0] %>', <%= student[1] %>) + <%- end -%> + assert_equal <%= cases["expected"] %>, school.grade(<%= cases["input"]["desiredGrade"] %>) + <%- end -%> + end +<% end %> +end diff --git a/exercises/practice/grade-school/grade_school_test.rb b/exercises/practice/grade-school/grade_school_test.rb index 590f5f5f55..21206134d3 100644 --- a/exercises/practice/grade-school/grade_school_test.rb +++ b/exercises/practice/grade-school/grade_school_test.rb @@ -5,21 +5,21 @@ class GradeSchoolTest < Minitest::Test def test_roster_is_empty_when_no_student_is_added # skip school = School.new - assert_empty [], school.roster + assert_empty school.roster end def test_add_a_student skip school = School.new results = [] - results << school.add("Aimee", 2) + results << school.add('Aimee', 2) assert_equal [true], results end def test_student_is_added_to_the_roster skip school = School.new - school.add("Aimee", 2) + school.add('Aimee', 2) assert_equal ["Aimee"], school.roster end @@ -27,18 +27,18 @@ def test_adding_multiple_students_in_the_same_grade_in_the_roster skip school = School.new results = [] - results << school.add("Blair", 2) - results << school.add("James", 2) - results << school.add("Paul", 2) + results << school.add('Blair', 2) + results << school.add('James', 2) + results << school.add('Paul', 2) assert_equal [true, true, true], results end def test_multiple_students_in_the_same_grade_are_added_to_the_roster skip school = School.new - school.add("Blair", 2) - school.add("James", 2) - school.add("Paul", 2) + school.add('Blair', 2) + school.add('James', 2) + school.add('Paul', 2) assert_equal %w[Blair James Paul], school.roster end @@ -46,20 +46,20 @@ def test_cannot_add_student_to_same_grade_in_the_roster_more_than_once skip school = School.new results = [] - results << school.add("Blair", 2) - results << school.add("James", 2) - results << school.add("James", 2) - results << school.add("Paul", 2) + results << school.add('Blair', 2) + results << school.add('James', 2) + results << school.add('James', 2) + results << school.add('Paul', 2) assert_equal [true, true, false, true], results end def test_student_not_added_to_same_grade_in_the_roster_more_than_once skip school = School.new - school.add("Blair", 2) - school.add("James", 2) - school.add("James", 2) - school.add("Paul", 2) + school.add('Blair', 2) + school.add('James', 2) + school.add('James', 2) + school.add('Paul', 2) assert_equal %w[Blair James Paul], school.roster end @@ -67,16 +67,16 @@ def test_adding_students_in_multiple_grades skip school = School.new results = [] - results << school.add("Chelsea", 3) - results << school.add("Logan", 7) + results << school.add('Chelsea', 3) + results << school.add('Logan', 7) assert_equal [true, true], results end def test_students_in_multiple_grades_are_added_to_the_roster skip school = School.new - school.add("Chelsea", 3) - school.add("Logan", 7) + school.add('Chelsea', 3) + school.add('Logan', 7) assert_equal %w[Chelsea Logan], school.roster end @@ -84,106 +84,106 @@ def test_cannot_add_same_student_to_multiple_grades_in_the_roster skip school = School.new results = [] - results << school.add("Blair", 2) - results << school.add("James", 2) - results << school.add("James", 3) - results << school.add("Paul", 3) + results << school.add('Blair', 2) + results << school.add('James', 2) + results << school.add('James', 3) + results << school.add('Paul', 3) assert_equal [true, true, false, true], results end def test_student_not_added_to_multiple_grades_in_the_roster skip school = School.new - school.add("Blair", 2) - school.add("James", 2) - school.add("James", 3) - school.add("Paul", 3) + school.add('Blair', 2) + school.add('James', 2) + school.add('James', 3) + school.add('Paul', 3) assert_equal %w[Blair James Paul], school.roster end def test_students_are_sorted_by_grades_in_the_roster skip school = School.new - school.add("Jim", 3) - school.add("Peter", 2) - school.add("Anna", 1) + school.add('Jim', 3) + school.add('Peter', 2) + school.add('Anna', 1) assert_equal %w[Anna Peter Jim], school.roster end def test_students_are_sorted_by_name_in_the_roster skip school = School.new - school.add("Peter", 2) - school.add("Zoe", 2) - school.add("Alex", 2) + school.add('Peter', 2) + school.add('Zoe', 2) + school.add('Alex', 2) assert_equal %w[Alex Peter Zoe], school.roster end def test_students_are_sorted_by_grades_and_then_by_name_in_the_roster skip school = School.new - school.add("Peter", 2) - school.add("Anna", 1) - school.add("Barb", 1) - school.add("Zoe", 2) - school.add("Alex", 2) - school.add("Jim", 3) - school.add("Charlie", 1) + school.add('Peter', 2) + school.add('Anna', 1) + school.add('Barb', 1) + school.add('Zoe', 2) + school.add('Alex', 2) + school.add('Jim', 3) + school.add('Charlie', 1) assert_equal %w[Anna Barb Charlie Alex Peter Zoe Jim], school.roster end def test_grade_is_empty_if_no_students_in_the_roster skip school = School.new - assert_empty [], school.grade(1) + assert_empty school.grade(1) end def test_grade_is_empty_if_no_students_in_that_grade skip school = School.new - school.add("Peter", 2) - school.add("Zoe", 2) - school.add("Alex", 2) - school.add("Jim", 3) + school.add('Peter', 2) + school.add('Zoe', 2) + school.add('Alex', 2) + school.add('Jim', 3) assert_empty school.grade(1) end def test_student_not_added_to_same_grade_more_than_once skip school = School.new - school.add("Blair", 2) - school.add("James", 2) - school.add("James", 2) - school.add("Paul", 2) + school.add('Blair', 2) + school.add('James', 2) + school.add('James', 2) + school.add('Paul', 2) assert_equal %w[Blair James Paul], school.grade(2) end def test_student_not_added_to_multiple_grades skip school = School.new - school.add("Blair", 2) - school.add("James", 2) - school.add("James", 3) - school.add("Paul", 3) + school.add('Blair', 2) + school.add('James', 2) + school.add('James', 3) + school.add('Paul', 3) assert_equal %w[Blair James], school.grade(2) end def test_student_not_added_to_other_grade_for_multiple_grades skip school = School.new - school.add("Blair", 2) - school.add("James", 2) - school.add("James", 3) - school.add("Paul", 3) + school.add('Blair', 2) + school.add('James', 2) + school.add('James', 3) + school.add('Paul', 3) assert_equal ["Paul"], school.grade(3) end def test_students_are_sorted_by_name_in_a_grade skip school = School.new - school.add("Franklin", 5) - school.add("Bradley", 5) - school.add("Jeff", 1) + school.add('Franklin', 5) + school.add('Bradley', 5) + school.add('Jeff', 1) assert_equal %w[Bradley Franklin], school.grade(5) end end diff --git a/exercises/practice/hamming/.meta/test_template.erb b/exercises/practice/hamming/.meta/test_template.erb new file mode 100644 index 0000000000..8ef17871fc --- /dev/null +++ b/exercises/practice/hamming/.meta/test_template.erb @@ -0,0 +1,17 @@ +require 'minitest/autorun' +require_relative 'hamming' + +class HammingTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + <%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%> + assert_raises(ArgumentError) do + Hamming.compute('<%= cases["input"]["strand1"] %>', '<%= cases["input"]["strand2"] %>') + end + <%- else -%> + assert_equal <%= cases["expected"] %>, Hamming.compute('<%= cases["input"]["strand1"] %>', '<%= cases["input"]["strand2"] %>') + <%- end -%> + end + <% end %> +end diff --git a/exercises/practice/hamming/hamming_test.rb b/exercises/practice/hamming/hamming_test.rb index b5dea4ca9e..9713aba091 100644 --- a/exercises/practice/hamming/hamming_test.rb +++ b/exercises/practice/hamming/hamming_test.rb @@ -4,54 +4,54 @@ class HammingTest < Minitest::Test def test_empty_strands # skip - assert_equal 0, Hamming.compute("", "") + assert_equal 0, Hamming.compute('', '') end def test_single_letter_identical_strands skip - assert_equal 0, Hamming.compute("A", "A") + assert_equal 0, Hamming.compute('A', 'A') end def test_single_letter_different_strands skip - assert_equal 1, Hamming.compute("G", "T") + assert_equal 1, Hamming.compute('G', 'T') end def test_long_identical_strands skip - assert_equal 0, Hamming.compute("GGACTGAAATCTG", "GGACTGAAATCTG") + assert_equal 0, Hamming.compute('GGACTGAAATCTG', 'GGACTGAAATCTG') end def test_long_different_strands skip - assert_equal 9, Hamming.compute("GGACGGATTCTG", "AGGACGGATTCT") + assert_equal 9, Hamming.compute('GGACGGATTCTG', 'AGGACGGATTCT') end def test_disallow_first_strand_longer skip assert_raises(ArgumentError) do - Hamming.compute("AATG", "AAA") + Hamming.compute('AATG', 'AAA') end end def test_disallow_second_strand_longer skip assert_raises(ArgumentError) do - Hamming.compute("ATA", "AGTG") + Hamming.compute('ATA', 'AGTG') end end def test_disallow_empty_first_strand skip assert_raises(ArgumentError) do - Hamming.compute("", "G") + Hamming.compute('', 'G') end end def test_disallow_empty_second_strand skip assert_raises(ArgumentError) do - Hamming.compute("G", "") + Hamming.compute('G', '') end end end diff --git a/exercises/practice/house/.meta/example.rb b/exercises/practice/house/.meta/example.rb index 4b2b8498fa..6dee117921 100644 --- a/exercises/practice/house/.meta/example.rb +++ b/exercises/practice/house/.meta/example.rb @@ -1,18 +1,17 @@ class House - def self.recite - new.recite + def self.recite(start_verse, end_verse) + new.recite(start_verse, end_verse) end - def recite - (1..pieces.length).map { |i| line(i) }.join("\n") + def recite(start_verse, end_verse) + (start_verse..end_verse).map { |i| line(i) }.join end def line(i) - "This is %s.\n" % pieces.last(i).map { |s| s.join("\n") }.join(' ') + "This is %s.\n" % pieces.last(i).join(' ') end private - def pieces [ ['the horse and the hound and the horn', 'that belonged to'], diff --git a/exercises/practice/house/.meta/test_template.erb b/exercises/practice/house/.meta/test_template.erb new file mode 100644 index 0000000000..9856c8c29f --- /dev/null +++ b/exercises/practice/house/.meta/test_template.erb @@ -0,0 +1,14 @@ +require 'minitest/autorun' +require_relative 'house' + +class HouseTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + expected = <<~RHYME +<%= cases["expected"].join("\n") %> + RHYME + assert_equal expected, House.recite(<%= cases["input"]["startVerse"] %>, <%= cases["input"]["endVerse"] %>) + end + <% end %> +end diff --git a/exercises/practice/house/house_test.rb b/exercises/practice/house/house_test.rb index c8fa9316e8..a7e2517c73 100644 --- a/exercises/practice/house/house_test.rb +++ b/exercises/practice/house/house_test.rb @@ -2,98 +2,130 @@ require_relative 'house' class HouseTest < Minitest::Test - def test_rhyme + def test_verse_one___the_house_that_jack_built + # skip expected = <<~RHYME This is the house that Jack built. + RHYME + assert_equal expected, House.recite(1, 1) + end - This is the malt - that lay in the house that Jack built. + def test_verse_two___the_malt_that_lay + skip + expected = <<~RHYME + This is the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(2, 2) + end - This is the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_three___the_rat_that_ate + skip + expected = <<~RHYME + This is the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(3, 3) + end - This is the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_four___the_cat_that_killed + skip + expected = <<~RHYME + This is the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(4, 4) + end - This is the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_five___the_dog_that_worried + skip + expected = <<~RHYME + This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(5, 5) + end + + def test_verse_six___the_cow_with_the_crumpled_horn + skip + expected = <<~RHYME + This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(6, 6) + end + + def test_verse_seven___the_maiden_all_forlorn + skip + expected = <<~RHYME + This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(7, 7) + end - This is the cow with the crumpled horn - that tossed the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_eight___the_man_all_tattered_and_torn + skip + expected = <<~RHYME + This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(8, 8) + end - This is the maiden all forlorn - that milked the cow with the crumpled horn - that tossed the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_nine___the_priest_all_shaven_and_shorn + skip + expected = <<~RHYME + This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(9, 9) + end - This is the man all tattered and torn - that kissed the maiden all forlorn - that milked the cow with the crumpled horn - that tossed the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_10___the_rooster_that_crowed_in_the_morn + skip + expected = <<~RHYME + This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(10, 10) + end - This is the priest all shaven and shorn - that married the man all tattered and torn - that kissed the maiden all forlorn - that milked the cow with the crumpled horn - that tossed the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_11___the_farmer_sowing_his_corn + skip + expected = <<~RHYME + This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(11, 11) + end - This is the rooster that crowed in the morn - that woke the priest all shaven and shorn - that married the man all tattered and torn - that kissed the maiden all forlorn - that milked the cow with the crumpled horn - that tossed the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_verse_12___the_horse_and_the_hound_and_the_horn + skip + expected = <<~RHYME + This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(12, 12) + end - This is the farmer sowing his corn - that kept the rooster that crowed in the morn - that woke the priest all shaven and shorn - that married the man all tattered and torn - that kissed the maiden all forlorn - that milked the cow with the crumpled horn - that tossed the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_multiple_verses + skip + expected = <<~RHYME + This is the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + RHYME + assert_equal expected, House.recite(4, 8) + end - This is the horse and the hound and the horn - that belonged to the farmer sowing his corn - that kept the rooster that crowed in the morn - that woke the priest all shaven and shorn - that married the man all tattered and torn - that kissed the maiden all forlorn - that milked the cow with the crumpled horn - that tossed the dog - that worried the cat - that killed the rat - that ate the malt - that lay in the house that Jack built. + def test_full_rhyme + skip + expected = <<~RHYME + This is the house that Jack built. + This is the malt that lay in the house that Jack built. + This is the rat that ate the malt that lay in the house that Jack built. + This is the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. + This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built. RHYME - assert_equal expected, House.recite + assert_equal expected, House.recite(1, 12) end end diff --git a/exercises/practice/isbn-verifier/.meta/test_template.erb b/exercises/practice/isbn-verifier/.meta/test_template.erb new file mode 100644 index 0000000000..1bd6239e22 --- /dev/null +++ b/exercises/practice/isbn-verifier/.meta/test_template.erb @@ -0,0 +1,12 @@ +require 'minitest/autorun' +require_relative 'isbn_verifier' + +class IsbnVerifierTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + string = '<%= cases["input"]["isbn"] %>' + <%= cases["expected"] ? "assert" : "refute" %> IsbnVerifier.valid?(string), "Expected <%= cases["expected"] %>, '#{string}' is<%= cases["expected"] ? "" : " not" %> a valid isbn" + end + <% end %> +end diff --git a/exercises/practice/isbn-verifier/isbn_verifier_test.rb b/exercises/practice/isbn-verifier/isbn_verifier_test.rb index 857f5f7b77..9644cf6a36 100644 --- a/exercises/practice/isbn-verifier/isbn_verifier_test.rb +++ b/exercises/practice/isbn-verifier/isbn_verifier_test.rb @@ -4,115 +4,115 @@ class IsbnVerifierTest < Minitest::Test def test_valid_isbn # skip - string = "3-598-21508-8" + string = '3-598-21508-8' assert IsbnVerifier.valid?(string), "Expected true, '#{string}' is a valid isbn" end def test_invalid_isbn_check_digit skip - string = "3-598-21508-9" + string = '3-598-21508-9' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_valid_isbn_with_a_check_digit_of_10 skip - string = "3-598-21507-X" + string = '3-598-21507-X' assert IsbnVerifier.valid?(string), "Expected true, '#{string}' is a valid isbn" end def test_check_digit_is_a_character_other_than_x skip - string = "3-598-21507-A" + string = '3-598-21507-A' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_invalid_check_digit_in_isbn_is_not_treated_as_zero skip - string = "4-598-21507-B" + string = '4-598-21507-B' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_invalid_character_in_isbn_is_not_treated_as_zero skip - string = "3-598-P1581-X" + string = '3-598-P1581-X' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_x_is_only_valid_as_a_check_digit skip - string = "3-598-2X507-9" + string = '3-598-2X507-9' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_valid_isbn_without_separating_dashes skip - string = "3598215088" + string = '3598215088' assert IsbnVerifier.valid?(string), "Expected true, '#{string}' is a valid isbn" end def test_isbn_without_separating_dashes_and_x_as_check_digit skip - string = "359821507X" + string = '359821507X' assert IsbnVerifier.valid?(string), "Expected true, '#{string}' is a valid isbn" end def test_isbn_without_check_digit_and_dashes skip - string = "359821507" + string = '359821507' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_too_long_isbn_and_no_dashes skip - string = "3598215078X" + string = '3598215078X' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_too_short_isbn skip - string = "00" + string = '00' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_isbn_without_check_digit skip - string = "3-598-21507" + string = '3-598-21507' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_check_digit_of_x_should_not_be_used_for_0 skip - string = "3-598-21515-X" + string = '3-598-21515-X' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_empty_isbn skip - string = "" + string = '' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_input_is_9_characters skip - string = "134456729" + string = '134456729' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_invalid_characters_are_not_ignored_after_checking_length skip - string = "3132P34035" + string = '3132P34035' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_invalid_characters_are_not_ignored_before_checking_length skip - string = "3598P215088" + string = '3598P215088' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end def test_input_is_too_long_but_contains_a_valid_isbn skip - string = "98245726788" + string = '98245726788' refute IsbnVerifier.valid?(string), "Expected false, '#{string}' is not a valid isbn" end end diff --git a/exercises/practice/isogram/.meta/test_template.erb b/exercises/practice/isogram/.meta/test_template.erb new file mode 100644 index 0000000000..29ce07d941 --- /dev/null +++ b/exercises/practice/isogram/.meta/test_template.erb @@ -0,0 +1,12 @@ +require 'minitest/autorun' +require_relative 'isogram' + +class IsogramTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + input = '<%= cases["input"]["phrase"] %>' + <%= cases["expected"] ? "assert" : "refute" %> Isogram.isogram?(input), "Expected <%= cases["expected"] %>, '#{input}' is<%= cases["expected"] ? "" : " not" %> an isogram" + end + <% end %> +end diff --git a/exercises/practice/isogram/isogram_test.rb b/exercises/practice/isogram/isogram_test.rb index a46d759018..c46ccea2b2 100644 --- a/exercises/practice/isogram/isogram_test.rb +++ b/exercises/practice/isogram/isogram_test.rb @@ -4,85 +4,85 @@ class IsogramTest < Minitest::Test def test_empty_string # skip - input = "" + input = '' assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram" end def test_isogram_with_only_lower_case_characters skip - input = "isogram" + input = 'isogram' assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram" end def test_word_with_one_duplicated_character skip - input = "eleven" + input = 'eleven' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end def test_word_with_one_duplicated_character_from_the_end_of_the_alphabet skip - input = "zzyzx" + input = 'zzyzx' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end def test_longest_reported_english_isogram skip - input = "subdermatoglyphic" + input = 'subdermatoglyphic' assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram" end def test_word_with_duplicated_character_in_mixed_case skip - input = "Alphabet" + input = 'Alphabet' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end def test_word_with_duplicated_character_in_mixed_case_lowercase_first skip - input = "alphAbet" + input = 'alphAbet' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end def test_hypothetical_isogrammic_word_with_hyphen skip - input = "thumbscrew-japingly" + input = 'thumbscrew-japingly' assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram" end def test_hypothetical_word_with_duplicated_character_following_hyphen skip - input = "thumbscrew-jappingly" + input = 'thumbscrew-jappingly' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end def test_isogram_with_duplicated_hyphen skip - input = "six-year-old" + input = 'six-year-old' assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram" end def test_made_up_name_that_is_an_isogram skip - input = "Emily Jung Schwartzkopf" + input = 'Emily Jung Schwartzkopf' assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram" end def test_duplicated_character_in_the_middle skip - input = "accentor" + input = 'accentor' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end def test_same_first_and_last_characters skip - input = "angola" + input = 'angola' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end def test_word_with_duplicated_character_and_with_two_hyphens skip - input = "up-to-date" + input = 'up-to-date' refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram" end end diff --git a/exercises/practice/kindergarten-garden/.meta/test_template.erb b/exercises/practice/kindergarten-garden/.meta/test_template.erb new file mode 100644 index 0000000000..56eb6d72aa --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/test_template.erb @@ -0,0 +1,24 @@ +require 'minitest/autorun' +require_relative 'kindergarten_garden' + +class KindergartenGardenTest < Minitest::Test +<% json["cases"].each do |cases| %> + <% cases["cases"].each do |sub_case| %> + <%- if sub_case.key?("cases") -%> + <% sub_case["cases"].each do |nested_case| %> + def test_<%= underscore(nested_case["description"]) %> + <%= skip? %> + garden = Garden.new(<%= nested_case["input"]["diagram"].inspect %>) + assert_equal %i[<%= nested_case["expected"].join(", ") %>], garden.<%= underscore(nested_case["input"]["student"]) %> + end + <% end %> + <%- else -%> + def test_<%= underscore(sub_case["description"]) %> + <%= skip? %> + garden = Garden.new(<%= sub_case["input"]["diagram"].inspect %>) + assert_equal %i[<%= sub_case["expected"].join(", ") %>], garden.<%= underscore(sub_case["input"]["student"]) %> + end + <%- end -%> + <% end %> +<% end %> +end diff --git a/exercises/practice/kindergarten-garden/kindergarten_garden_test.rb b/exercises/practice/kindergarten-garden/kindergarten_garden_test.rb index 0060280511..cfebf847b1 100644 --- a/exercises/practice/kindergarten-garden/kindergarten_garden_test.rb +++ b/exercises/practice/kindergarten-garden/kindergarten_garden_test.rb @@ -2,103 +2,103 @@ require_relative 'kindergarten_garden' class KindergartenGardenTest < Minitest::Test - def test_partial_garden_garden_with_single_student + def test_garden_with_single_student # skip garden = Garden.new("RC\nGG") assert_equal %i[radishes clover grass grass], garden.alice end - def test_partial_garden_different_garden_with_single_student + def test_different_garden_with_single_student skip garden = Garden.new("VC\nRC") assert_equal %i[violets clover radishes clover], garden.alice end - def test_partial_garden_garden_with_two_students + def test_garden_with_two_students skip garden = Garden.new("VVCG\nVVRC") assert_equal %i[clover grass radishes clover], garden.bob end - def test_partial_garden_multiple_students_for_the_same_garden_with_three_students_second_students_garden + def test_second_students_garden skip garden = Garden.new("VVCCGG\nVVCCGG") assert_equal %i[clover clover clover clover], garden.bob end - def test_partial_garden_multiple_students_for_the_same_garden_with_three_students_third_students_garden + def test_third_students_garden skip garden = Garden.new("VVCCGG\nVVCCGG") assert_equal %i[grass grass grass grass], garden.charlie end - def test_full_garden_for_alice_first_students_garden + def test_for_alice_first_students_garden skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[violets radishes violets radishes], garden.alice end - def test_full_garden_for_bob_second_students_garden + def test_for_bob_second_students_garden skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[clover grass clover clover], garden.bob end - def test_full_garden_for_charlie + def test_for_charlie skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[violets violets clover grass], garden.charlie end - def test_full_garden_for_david + def test_for_david skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[radishes violets clover radishes], garden.david end - def test_full_garden_for_eve + def test_for_eve skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[clover grass radishes grass], garden.eve end - def test_full_garden_for_fred + def test_for_fred skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[grass clover violets clover], garden.fred end - def test_full_garden_for_ginny + def test_for_ginny skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[clover grass grass clover], garden.ginny end - def test_full_garden_for_harriet + def test_for_harriet skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[violets radishes radishes violets], garden.harriet end - def test_full_garden_for_ileana + def test_for_ileana skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[grass clover violets clover], garden.ileana end - def test_full_garden_for_joseph + def test_for_joseph skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[violets clover violets grass], garden.joseph end - def test_full_garden_for_kincaid_second_to_last_students_garden + def test_for_kincaid_second_to_last_students_garden skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[grass clover clover grass], garden.kincaid end - def test_full_garden_for_larry_last_students_garden + def test_for_larry_last_students_garden skip garden = Garden.new("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") assert_equal %i[grass violets clover violets], garden.larry