From 3e82c0db745fa1cae34d994cc196c636b784cc56 Mon Sep 17 00:00:00 2001 From: meatball Date: Sun, 14 Sep 2025 22:32:28 +0200 Subject: [PATCH 1/2] Add templates for exercises batch 8 --- .../pig-latin/.meta/test_template.erb | 13 +++ .../practice/pig-latin/pig_latin_test.rb | 49 ++++---- .../practice/poker/.meta/test_template.erb | 12 ++ exercises/practice/poker/poker_test.rb | 18 ++- .../prime-factors/.meta/test_template.erb | 11 ++ .../.meta/test_template.erb | 19 +++ .../protein_translation_test.rb | 109 ++++++++++-------- .../.meta/test_template.erb | 12 ++ .../queen-attack/.meta/test_template.erb | 23 ++++ .../queen-attack/queen_attack_test.rb | 26 ++--- .../rail-fence-cipher/.meta/test_template.erb | 13 +++ .../rail_fence_cipher_test.rb | 44 ++----- 12 files changed, 225 insertions(+), 124 deletions(-) create mode 100644 exercises/practice/pig-latin/.meta/test_template.erb create mode 100644 exercises/practice/poker/.meta/test_template.erb create mode 100644 exercises/practice/prime-factors/.meta/test_template.erb create mode 100644 exercises/practice/protein-translation/.meta/test_template.erb create mode 100644 exercises/practice/pythagorean-triplet/.meta/test_template.erb create mode 100644 exercises/practice/queen-attack/.meta/test_template.erb create mode 100644 exercises/practice/rail-fence-cipher/.meta/test_template.erb diff --git a/exercises/practice/pig-latin/.meta/test_template.erb b/exercises/practice/pig-latin/.meta/test_template.erb new file mode 100644 index 0000000000..ef5639e8ef --- /dev/null +++ b/exercises/practice/pig-latin/.meta/test_template.erb @@ -0,0 +1,13 @@ +require 'minitest/autorun' +require_relative 'pig_latin' + +class PigLatinTest < Minitest::Test +<% json["cases"].each do |cases| %> + <% cases["cases"].each do |sub_case|%> + def test_<%= underscore(sub_case["description"]) %> + <%= skip? %> + assert_equal '<%= sub_case["expected"] %>', PigLatin.translate('<%= sub_case["input"]["phrase"] %>') + end + <% end%> +<% end %> +end diff --git a/exercises/practice/pig-latin/pig_latin_test.rb b/exercises/practice/pig-latin/pig_latin_test.rb index 7540532b76..74463441cf 100644 --- a/exercises/practice/pig-latin/pig_latin_test.rb +++ b/exercises/practice/pig-latin/pig_latin_test.rb @@ -4,111 +4,116 @@ class PigLatinTest < Minitest::Test def test_word_beginning_with_a # skip - assert_equal "appleay", PigLatin.translate("apple") + assert_equal 'appleay', PigLatin.translate('apple') end def test_word_beginning_with_e skip - assert_equal "earay", PigLatin.translate("ear") + assert_equal 'earay', PigLatin.translate('ear') end def test_word_beginning_with_i skip - assert_equal "iglooay", PigLatin.translate("igloo") + assert_equal 'iglooay', PigLatin.translate('igloo') end def test_word_beginning_with_o skip - assert_equal "objectay", PigLatin.translate("object") + assert_equal 'objectay', PigLatin.translate('object') end def test_word_beginning_with_u skip - assert_equal "underay", PigLatin.translate("under") + assert_equal 'underay', PigLatin.translate('under') end def test_word_beginning_with_a_vowel_and_followed_by_a_qu skip - assert_equal "equalay", PigLatin.translate("equal") + assert_equal 'equalay', PigLatin.translate('equal') end def test_word_beginning_with_p skip - assert_equal "igpay", PigLatin.translate("pig") + assert_equal 'igpay', PigLatin.translate('pig') end def test_word_beginning_with_k skip - assert_equal "oalakay", PigLatin.translate("koala") + assert_equal 'oalakay', PigLatin.translate('koala') end def test_word_beginning_with_x skip - assert_equal "enonxay", PigLatin.translate("xenon") + assert_equal 'enonxay', PigLatin.translate('xenon') end def test_word_beginning_with_q_without_a_following_u skip - assert_equal "atqay", PigLatin.translate("qat") + assert_equal 'atqay', PigLatin.translate('qat') + end + + def test_word_beginning_with_consonant_and_vowel_containing_qu + skip + assert_equal 'iquidlay', PigLatin.translate('liquid') end def test_word_beginning_with_ch skip - assert_equal "airchay", PigLatin.translate("chair") + assert_equal 'airchay', PigLatin.translate('chair') end def test_word_beginning_with_qu skip - assert_equal "eenquay", PigLatin.translate("queen") + assert_equal 'eenquay', PigLatin.translate('queen') end def test_word_beginning_with_qu_and_a_preceding_consonant skip - assert_equal "aresquay", PigLatin.translate("square") + assert_equal 'aresquay', PigLatin.translate('square') end def test_word_beginning_with_th skip - assert_equal "erapythay", PigLatin.translate("therapy") + assert_equal 'erapythay', PigLatin.translate('therapy') end def test_word_beginning_with_thr skip - assert_equal "ushthray", PigLatin.translate("thrush") + assert_equal 'ushthray', PigLatin.translate('thrush') end def test_word_beginning_with_sch skip - assert_equal "oolschay", PigLatin.translate("school") + assert_equal 'oolschay', PigLatin.translate('school') end def test_word_beginning_with_yt skip - assert_equal "yttriaay", PigLatin.translate("yttria") + assert_equal 'yttriaay', PigLatin.translate('yttria') end def test_word_beginning_with_xr skip - assert_equal "xrayay", PigLatin.translate("xray") + assert_equal 'xrayay', PigLatin.translate('xray') end def test_y_is_treated_like_a_consonant_at_the_beginning_of_a_word skip - assert_equal "ellowyay", PigLatin.translate("yellow") + assert_equal 'ellowyay', PigLatin.translate('yellow') end def test_y_is_treated_like_a_vowel_at_the_end_of_a_consonant_cluster skip - assert_equal "ythmrhay", PigLatin.translate("rhythm") + assert_equal 'ythmrhay', PigLatin.translate('rhythm') end def test_y_as_second_letter_in_two_letter_word skip - assert_equal "ymay", PigLatin.translate("my") + assert_equal 'ymay', PigLatin.translate('my') end def test_a_whole_phrase skip - assert_equal "ickquay astfay unray", PigLatin.translate("quick fast run") + assert_equal 'ickquay astfay unray', PigLatin.translate('quick fast run') end end diff --git a/exercises/practice/poker/.meta/test_template.erb b/exercises/practice/poker/.meta/test_template.erb new file mode 100644 index 0000000000..0651024c5c --- /dev/null +++ b/exercises/practice/poker/.meta/test_template.erb @@ -0,0 +1,12 @@ +require 'minitest/autorun' +require_relative 'poker' + +class PokerTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + hands = [<%= cases["input"]["hands"].map{ |hand| "%w[#{hand}]"}.join(", ") %>] + assert_equal [<%= cases["expected"].map{ |hand| "%w[#{hand}]"}.join(", ") %>], Poker.new(hands).best_hand + end +<% end %> +end diff --git a/exercises/practice/poker/poker_test.rb b/exercises/practice/poker/poker_test.rb index e02d23433e..7c2d99a2d6 100644 --- a/exercises/practice/poker/poker_test.rb +++ b/exercises/practice/poker/poker_test.rb @@ -26,6 +26,12 @@ def test_multiple_hands_with_the_same_high_cards_tie_compares_next_highest_ranke assert_equal [%w[3S 5H 6S 8D 7H]], Poker.new(hands).best_hand end + def test_winning_high_card_hand_also_has_the_lowest_card + skip + hands = [%w[2S 5H 6S 8D 7H], %w[3S 4D 6D 8C 7S]] + assert_equal [%w[2S 5H 6S 8D 7H]], Poker.new(hands).best_hand + end + def test_one_pair_beats_high_card skip hands = [%w[4S 5H 6C 8D KH], %w[2S 4H 6S 4D JH]] @@ -38,6 +44,12 @@ def test_highest_pair_wins assert_equal [%w[2S 4H 6C 4D JD]], Poker.new(hands).best_hand end + def test_both_hands_have_the_same_pair_high_card_wins + skip + hands = [%w[4H 4S AH JC 3D], %w[4C 4D AS 5D 6C]] + assert_equal [%w[4H 4S AH JC 3D]], Poker.new(hands).best_hand + end + def test_two_pairs_beats_one_pair skip hands = [%w[2S 8H 6S 8D JH], %w[4S 5H 4C 8C 5C]] @@ -88,7 +100,7 @@ def test_both_hands_have_three_of_a_kind_tie_goes_to_highest_ranked_triplet def test_with_multiple_decks_two_players_can_have_same_three_of_a_kind_ties_go_to_highest_remaining_cards skip - hands = [%w[4S AH AS 7C AD], %w[4S AH AS 8C AD]] + hands = [%w[5S AH AS 7C AD], %w[4S AH AS 8C AD]] assert_equal [%w[4S AH AS 8C AD]], Poker.new(hands).best_hand end @@ -136,8 +148,8 @@ def test_flush_beats_a_straight def test_both_hands_have_a_flush_tie_goes_to_high_card_down_to_the_last_one_if_necessary skip - hands = [%w[4H 7H 8H 9H 6H], %w[2S 4S 5S 6S 7S]] - assert_equal [%w[4H 7H 8H 9H 6H]], Poker.new(hands).best_hand + hands = [%w[2H 7H 8H 9H 6H], %w[3S 5S 6S 7S 8S]] + assert_equal [%w[2H 7H 8H 9H 6H]], Poker.new(hands).best_hand end def test_full_house_beats_a_flush diff --git a/exercises/practice/prime-factors/.meta/test_template.erb b/exercises/practice/prime-factors/.meta/test_template.erb new file mode 100644 index 0000000000..d08e3d46c9 --- /dev/null +++ b/exercises/practice/prime-factors/.meta/test_template.erb @@ -0,0 +1,11 @@ +require 'minitest/autorun' +require_relative 'prime_factors' + +class PrimeFactorsTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + assert_equal <%= cases["expected"] %>, PrimeFactors.of(<%= cases["input"]["value"] %>) + end +<% end %> +end diff --git a/exercises/practice/protein-translation/.meta/test_template.erb b/exercises/practice/protein-translation/.meta/test_template.erb new file mode 100644 index 0000000000..6ccb42dd77 --- /dev/null +++ b/exercises/practice/protein-translation/.meta/test_template.erb @@ -0,0 +1,19 @@ +require 'minitest/autorun' +require_relative 'protein_translation' + +class ProteinTranslationTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + strand = '<%= cases["input"]["strand"] %>' + <%- if cases["expected"].is_a?(Hash) && cases["expected"].key?("error") -%> + assert_raises(InvalidCodonError) do + Translation.of_rna(strand) + end + <%- else -%> + expected = %w[<%= cases["expected"].join(" ") %>] + assert_equal expected, Translation.of_rna(strand) + <%- end -%> + end +<% end %> +end diff --git a/exercises/practice/protein-translation/protein_translation_test.rb b/exercises/practice/protein-translation/protein_translation_test.rb index 9dfaadc331..8d92da4422 100644 --- a/exercises/practice/protein-translation/protein_translation_test.rb +++ b/exercises/practice/protein-translation/protein_translation_test.rb @@ -4,189 +4,196 @@ class ProteinTranslationTest < Minitest::Test def test_empty_rna_sequence_results_in_no_proteins # skip - strand = "" - expected = [] + strand = '' + expected = %w[] assert_equal expected, Translation.of_rna(strand) end def test_methionine_rna_sequence skip - strand = "AUG" - expected = ["Methionine"] + strand = 'AUG' + expected = %w[Methionine] assert_equal expected, Translation.of_rna(strand) end def test_phenylalanine_rna_sequence_1 skip - strand = "UUU" - expected = ["Phenylalanine"] + strand = 'UUU' + expected = %w[Phenylalanine] assert_equal expected, Translation.of_rna(strand) end def test_phenylalanine_rna_sequence_2 skip - strand = "UUC" - expected = ["Phenylalanine"] + strand = 'UUC' + expected = %w[Phenylalanine] assert_equal expected, Translation.of_rna(strand) end def test_leucine_rna_sequence_1 skip - strand = "UUA" - expected = ["Leucine"] + strand = 'UUA' + expected = %w[Leucine] assert_equal expected, Translation.of_rna(strand) end def test_leucine_rna_sequence_2 skip - strand = "UUG" - expected = ["Leucine"] + strand = 'UUG' + expected = %w[Leucine] assert_equal expected, Translation.of_rna(strand) end def test_serine_rna_sequence_1 skip - strand = "UCU" - expected = ["Serine"] + strand = 'UCU' + expected = %w[Serine] assert_equal expected, Translation.of_rna(strand) end def test_serine_rna_sequence_2 skip - strand = "UCC" - expected = ["Serine"] + strand = 'UCC' + expected = %w[Serine] assert_equal expected, Translation.of_rna(strand) end def test_serine_rna_sequence_3 skip - strand = "UCA" - expected = ["Serine"] + strand = 'UCA' + expected = %w[Serine] assert_equal expected, Translation.of_rna(strand) end def test_serine_rna_sequence_4 skip - strand = "UCG" - expected = ["Serine"] + strand = 'UCG' + expected = %w[Serine] assert_equal expected, Translation.of_rna(strand) end def test_tyrosine_rna_sequence_1 skip - strand = "UAU" - expected = ["Tyrosine"] + strand = 'UAU' + expected = %w[Tyrosine] assert_equal expected, Translation.of_rna(strand) end def test_tyrosine_rna_sequence_2 skip - strand = "UAC" - expected = ["Tyrosine"] + strand = 'UAC' + expected = %w[Tyrosine] assert_equal expected, Translation.of_rna(strand) end def test_cysteine_rna_sequence_1 skip - strand = "UGU" - expected = ["Cysteine"] + strand = 'UGU' + expected = %w[Cysteine] assert_equal expected, Translation.of_rna(strand) end def test_cysteine_rna_sequence_2 skip - strand = "UGC" - expected = ["Cysteine"] + strand = 'UGC' + expected = %w[Cysteine] assert_equal expected, Translation.of_rna(strand) end def test_tryptophan_rna_sequence skip - strand = "UGG" - expected = ["Tryptophan"] + strand = 'UGG' + expected = %w[Tryptophan] assert_equal expected, Translation.of_rna(strand) end def test_stop_codon_rna_sequence_1 skip - strand = "UAA" - expected = [] + strand = 'UAA' + expected = %w[] assert_equal expected, Translation.of_rna(strand) end def test_stop_codon_rna_sequence_2 skip - strand = "UAG" - expected = [] + strand = 'UAG' + expected = %w[] assert_equal expected, Translation.of_rna(strand) end def test_stop_codon_rna_sequence_3 skip - strand = "UGA" - expected = [] + strand = 'UGA' + expected = %w[] assert_equal expected, Translation.of_rna(strand) end def test_sequence_of_two_protein_codons_translates_into_proteins skip - strand = "UUUUUU" + strand = 'UUUUUU' expected = %w[Phenylalanine Phenylalanine] assert_equal expected, Translation.of_rna(strand) end def test_sequence_of_two_different_protein_codons_translates_into_proteins skip - strand = "UUAUUG" + strand = 'UUAUUG' expected = %w[Leucine Leucine] assert_equal expected, Translation.of_rna(strand) end def test_translate_rna_strand_into_correct_protein_list skip - strand = "AUGUUUUGG" + strand = 'AUGUUUUGG' expected = %w[Methionine Phenylalanine Tryptophan] assert_equal expected, Translation.of_rna(strand) end def test_translation_stops_if_stop_codon_at_beginning_of_sequence skip - strand = "UAGUGG" - expected = [] + strand = 'UAGUGG' + expected = %w[] assert_equal expected, Translation.of_rna(strand) end def test_translation_stops_if_stop_codon_at_end_of_two_codon_sequence skip - strand = "UGGUAG" - expected = ["Tryptophan"] + strand = 'UGGUAG' + expected = %w[Tryptophan] assert_equal expected, Translation.of_rna(strand) end def test_translation_stops_if_stop_codon_at_end_of_three_codon_sequence skip - strand = "AUGUUUUAA" + strand = 'AUGUUUUAA' expected = %w[Methionine Phenylalanine] assert_equal expected, Translation.of_rna(strand) end def test_translation_stops_if_stop_codon_in_middle_of_three_codon_sequence skip - strand = "UGGUAGUGG" - expected = ["Tryptophan"] + strand = 'UGGUAGUGG' + expected = %w[Tryptophan] assert_equal expected, Translation.of_rna(strand) end def test_translation_stops_if_stop_codon_in_middle_of_six_codon_sequence skip - strand = "UGGUGUUAUUAAUGGUUU" + strand = 'UGGUGUUAUUAAUGGUUU' expected = %w[Tryptophan Cysteine Tyrosine] assert_equal expected, Translation.of_rna(strand) end + def test_sequence_of_two_non_stop_codons_does_not_translate_to_a_stop_codon + skip + strand = 'AUGAUG' + expected = %w[Methionine Methionine] + assert_equal expected, Translation.of_rna(strand) + end + def test_non_existing_codon_cant_translate skip - strand = "AAA" + strand = 'AAA' assert_raises(InvalidCodonError) do Translation.of_rna(strand) end @@ -194,7 +201,7 @@ def test_non_existing_codon_cant_translate def test_unknown_amino_acids_not_part_of_a_codon_cant_translate skip - strand = "XYZ" + strand = 'XYZ' assert_raises(InvalidCodonError) do Translation.of_rna(strand) end @@ -202,7 +209,7 @@ def test_unknown_amino_acids_not_part_of_a_codon_cant_translate def test_incomplete_rna_sequence_cant_translate skip - strand = "AUGU" + strand = 'AUGU' assert_raises(InvalidCodonError) do Translation.of_rna(strand) end @@ -210,7 +217,7 @@ def test_incomplete_rna_sequence_cant_translate def test_incomplete_rna_sequence_can_translate_if_valid_until_a_stop_codon skip - strand = "UUCUUCUAAUGGU" + strand = 'UUCUUCUAAUGGU' expected = %w[Phenylalanine Phenylalanine] assert_equal expected, Translation.of_rna(strand) end diff --git a/exercises/practice/pythagorean-triplet/.meta/test_template.erb b/exercises/practice/pythagorean-triplet/.meta/test_template.erb new file mode 100644 index 0000000000..9bb153133f --- /dev/null +++ b/exercises/practice/pythagorean-triplet/.meta/test_template.erb @@ -0,0 +1,12 @@ +require 'minitest/autorun' +require_relative 'pythagorean_triplet' + +class PythagoreanTripletTest < Minitest::Test +<% json["cases"].each do |cases| %> + def test_<%= underscore(cases["description"]) %> + <%= skip? %> + expected = <%= cases["expected"] %> + assert_equal expected, PythagoreanTriplet.triplets_with_sum(<%= cases["input"]["n"] %>) + end +<% end %> +end diff --git a/exercises/practice/queen-attack/.meta/test_template.erb b/exercises/practice/queen-attack/.meta/test_template.erb new file mode 100644 index 0000000000..27d82eafb3 --- /dev/null +++ b/exercises/practice/queen-attack/.meta/test_template.erb @@ -0,0 +1,23 @@ +require 'minitest/autorun' +require_relative 'queen_attack' + +class QueenAttackTest < Minitest::Test +<% json["cases"].each do |cases| %> + <% cases["cases"].each do |sub_case| %> + def test_<%= underscore(sub_case["description"]) %> + <%= skip? %> + <%- if sub_case["property"] == "create" -%> + <%- if sub_case["expected"].is_a?(Hash) && sub_case["expected"].key?("error") -%> + assert_raises(ArgumentError) do + Queens.new(white: [<%= sub_case["input"]["queen"]["position"]["row"] %>, <%= sub_case["input"]["queen"]["position"]["column"] %>]) + end + <%- else -%> + assert Queens.new(white: [<%= sub_case["input"]["queen"]["position"]["row"] %>, <%= sub_case["input"]["queen"]["position"]["column"] %>]) + <%- end -%> + <%- elsif sub_case["property"] == "canAttack" -%> + <%= sub_case["expected"] ? "assert" : "refute" %> Queens.new(white: [<%= sub_case["input"]["white_queen"]["position"]["row"] %>, <%= sub_case["input"]["white_queen"]["position"]["column"] %>], black: [<%= sub_case["input"]["black_queen"]["position"]["row"] %>, <%= sub_case["input"]["black_queen"]["position"]["column"] %>]).attack? + <%- end -%> + end + <% end %> +<% end %> +end diff --git a/exercises/practice/queen-attack/queen_attack_test.rb b/exercises/practice/queen-attack/queen_attack_test.rb index 61d55c21fa..0688102f85 100644 --- a/exercises/practice/queen-attack/queen_attack_test.rb +++ b/exercises/practice/queen-attack/queen_attack_test.rb @@ -2,75 +2,75 @@ require_relative 'queen_attack' class QueenAttackTest < Minitest::Test - def test_new_queen_with_a_valid_position + def test_queen_with_a_valid_position # skip assert Queens.new(white: [2, 2]) end - def test_new_queen_must_have_positive_row + def test_queen_must_have_positive_row skip assert_raises(ArgumentError) do Queens.new(white: [-2, 2]) end end - def test_new_queen_must_have_row_on_board + def test_queen_must_have_row_on_board skip assert_raises(ArgumentError) do Queens.new(white: [8, 4]) end end - def test_new_queen_must_have_positive_column + def test_queen_must_have_positive_column skip assert_raises(ArgumentError) do Queens.new(white: [2, -2]) end end - def test_new_queen_must_have_column_on_board + def test_queen_must_have_column_on_board skip assert_raises(ArgumentError) do Queens.new(white: [4, 8]) end end - def test_queens_cannot_attack + def test_cannot_attack skip refute Queens.new(white: [2, 4], black: [6, 6]).attack? end - def test_queens_can_attack_on_same_row + def test_can_attack_on_same_row skip assert Queens.new(white: [2, 4], black: [2, 6]).attack? end - def test_queens_can_attack_on_same_column + def test_can_attack_on_same_column skip assert Queens.new(white: [4, 5], black: [2, 5]).attack? end - def test_queens_can_attack_on_first_diagonal + def test_can_attack_on_first_diagonal skip assert Queens.new(white: [2, 2], black: [0, 4]).attack? end - def test_queens_can_attack_on_second_diagonal + def test_can_attack_on_second_diagonal skip assert Queens.new(white: [2, 2], black: [3, 1]).attack? end - def test_queens_can_attack_on_third_diagonal + def test_can_attack_on_third_diagonal skip assert Queens.new(white: [2, 2], black: [1, 1]).attack? end - def test_queens_can_attack_on_fourth_diagonal + def test_can_attack_on_fourth_diagonal skip assert Queens.new(white: [1, 7], black: [0, 6]).attack? end - def test_queens_cannot_attack_if_falling_diagonals_are_only_the_same_when_reflected_across_the_longest_falling_diagonal + def test_cannot_attack_if_falling_diagonals_are_only_the_same_when_reflected_across_the_longest_falling_diagonal skip refute Queens.new(white: [4, 1], black: [2, 5]).attack? end diff --git a/exercises/practice/rail-fence-cipher/.meta/test_template.erb b/exercises/practice/rail-fence-cipher/.meta/test_template.erb new file mode 100644 index 0000000000..22b892211f --- /dev/null +++ b/exercises/practice/rail-fence-cipher/.meta/test_template.erb @@ -0,0 +1,13 @@ +require 'minitest/autorun' +require_relative 'rail_fence_cipher' + +class RailFenceCipherTest < Minitest::Test +<% json["cases"].each do |cases| %> + <% cases["cases"].each do |sub_case| %> + def test_<%= underscore(sub_case["description"]) %> + <%= skip? %> + assert_equal '<%= sub_case["expected"] %>', RailFenceCipher.<%= sub_case["property"] %>('<%= sub_case["input"]["msg"] %>', <%= sub_case["input"]["rails"] %>) + end + <% end %> +<% end %> +end diff --git a/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb b/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb index 92bf5ef15c..e0089622f4 100644 --- a/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb +++ b/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb @@ -2,26 +2,14 @@ require_relative 'rail_fence_cipher' class RailFenceCipherTest < Minitest::Test - def test_encode_with_empty_string - assert_equal '', RailFenceCipher.encode('', 4) - end - - def test_encode_with_one_rail - skip - assert_equal 'One rail, only one rail', - RailFenceCipher.encode('One rail, only one rail', 1) - end - def test_encode_with_two_rails - skip - assert_equal 'XXXXXXXXXOOOOOOOOO', - RailFenceCipher.encode('XOXOXOXOXOXOXOXOXO', 2) + # skip + assert_equal 'XXXXXXXXXOOOOOOOOO', RailFenceCipher.encode('XOXOXOXOXOXOXOXOXO', 2) end def test_encode_with_three_rails skip - assert_equal 'WECRLTEERDSOEEFEAOCAIVDEN', - RailFenceCipher.encode('WEAREDISCOVEREDFLEEATONCE', 3) + assert_equal 'WECRLTEERDSOEEFEAOCAIVDEN', RailFenceCipher.encode('WEAREDISCOVEREDFLEEATONCE', 3) end def test_encode_with_ending_in_the_middle @@ -29,32 +17,18 @@ def test_encode_with_ending_in_the_middle assert_equal 'ESXIEECSR', RailFenceCipher.encode('EXERCISES', 4) end - def test_encode_with_less_letters_than_rails - skip - assert_equal 'More rails than letters', - RailFenceCipher.encode('More rails than letters', 24) - end - - def test_decode_with_empty_string - skip - assert_equal '', RailFenceCipher.decode('', 4) - end - - def test_decode_with_one_rail + def test_decode_with_three_rails skip - assert_equal 'ABCDEFGHIJKLMNOP', - RailFenceCipher.decode('ABCDEFGHIJKLMNOP', 1) + assert_equal 'THEDEVILISINTHEDETAILS', RailFenceCipher.decode('TEITELHDVLSNHDTISEIIEA', 3) end - def test_decode_with_two_rails + def test_decode_with_five_rails skip - assert_equal 'XOXOXOXOXOXOXOXOXO', - RailFenceCipher.decode(+'XXXXXXXXXOOOOOOOOO', 2) + assert_equal 'EXERCISMISAWESOME', RailFenceCipher.decode('EIEXMSMESAORIWSCE', 5) end - def test_decode_with_three_rails + def test_decode_with_six_rails skip - assert_equal 'THEDEVILISINTHEDETAILS', - RailFenceCipher.decode(+'TEITELHDVLSNHDTISEIIEA', 3) + assert_equal '112358132134558914423337761098715972584418167651094617711286', RailFenceCipher.decode('133714114238148966225439541018335470986172518171757571896261', 6) end end From 4854585a06bc1db962c178a1e4e02cfb4fbb7761 Mon Sep 17 00:00:00 2001 From: meatball Date: Tue, 23 Sep 2025 21:57:57 +0200 Subject: [PATCH 2/2] Change to actual and expected format --- .../pig-latin/.meta/test_template.erb | 4 +- .../practice/pig-latin/pig_latin_test.rb | 92 ++++++++--- .../practice/poker/.meta/test_template.erb | 4 +- exercises/practice/poker/poker_test.rb | 148 +++++++++++++----- .../prime-factors/.meta/test_template.erb | 4 +- .../prime-factors/prime_factors_test.rb | 48 ++++-- .../.meta/test_template.erb | 3 +- .../protein_translation_test.rb | 84 ++++++---- .../.meta/test_template.erb | 3 +- .../pythagorean_triplet_test.rb | 21 ++- .../rail-fence-cipher/.meta/test_template.erb | 4 +- .../rail_fence_cipher_test.rb | 24 ++- 12 files changed, 320 insertions(+), 119 deletions(-) diff --git a/exercises/practice/pig-latin/.meta/test_template.erb b/exercises/practice/pig-latin/.meta/test_template.erb index ef5639e8ef..2056d280d4 100644 --- a/exercises/practice/pig-latin/.meta/test_template.erb +++ b/exercises/practice/pig-latin/.meta/test_template.erb @@ -6,7 +6,9 @@ class PigLatinTest < Minitest::Test <% cases["cases"].each do |sub_case|%> def test_<%= underscore(sub_case["description"]) %> <%= skip? %> - assert_equal '<%= sub_case["expected"] %>', PigLatin.translate('<%= sub_case["input"]["phrase"] %>') + actual = PigLatin.translate('<%= sub_case["input"]["phrase"] %>') + expected = '<%= sub_case["expected"] %>' + assert_equal expected, actual end <% end%> <% end %> diff --git a/exercises/practice/pig-latin/pig_latin_test.rb b/exercises/practice/pig-latin/pig_latin_test.rb index 74463441cf..a46102aca5 100644 --- a/exercises/practice/pig-latin/pig_latin_test.rb +++ b/exercises/practice/pig-latin/pig_latin_test.rb @@ -4,116 +4,162 @@ class PigLatinTest < Minitest::Test def test_word_beginning_with_a # skip - assert_equal 'appleay', PigLatin.translate('apple') + actual = PigLatin.translate('apple') + expected = 'appleay' + assert_equal expected, actual end def test_word_beginning_with_e skip - assert_equal 'earay', PigLatin.translate('ear') + actual = PigLatin.translate('ear') + expected = 'earay' + assert_equal expected, actual end def test_word_beginning_with_i skip - assert_equal 'iglooay', PigLatin.translate('igloo') + actual = PigLatin.translate('igloo') + expected = 'iglooay' + assert_equal expected, actual end def test_word_beginning_with_o skip - assert_equal 'objectay', PigLatin.translate('object') + actual = PigLatin.translate('object') + expected = 'objectay' + assert_equal expected, actual end def test_word_beginning_with_u skip - assert_equal 'underay', PigLatin.translate('under') + actual = PigLatin.translate('under') + expected = 'underay' + assert_equal expected, actual end def test_word_beginning_with_a_vowel_and_followed_by_a_qu skip - assert_equal 'equalay', PigLatin.translate('equal') + actual = PigLatin.translate('equal') + expected = 'equalay' + assert_equal expected, actual end def test_word_beginning_with_p skip - assert_equal 'igpay', PigLatin.translate('pig') + actual = PigLatin.translate('pig') + expected = 'igpay' + assert_equal expected, actual end def test_word_beginning_with_k skip - assert_equal 'oalakay', PigLatin.translate('koala') + actual = PigLatin.translate('koala') + expected = 'oalakay' + assert_equal expected, actual end def test_word_beginning_with_x skip - assert_equal 'enonxay', PigLatin.translate('xenon') + actual = PigLatin.translate('xenon') + expected = 'enonxay' + assert_equal expected, actual end def test_word_beginning_with_q_without_a_following_u skip - assert_equal 'atqay', PigLatin.translate('qat') + actual = PigLatin.translate('qat') + expected = 'atqay' + assert_equal expected, actual end def test_word_beginning_with_consonant_and_vowel_containing_qu skip - assert_equal 'iquidlay', PigLatin.translate('liquid') + actual = PigLatin.translate('liquid') + expected = 'iquidlay' + assert_equal expected, actual end def test_word_beginning_with_ch skip - assert_equal 'airchay', PigLatin.translate('chair') + actual = PigLatin.translate('chair') + expected = 'airchay' + assert_equal expected, actual end def test_word_beginning_with_qu skip - assert_equal 'eenquay', PigLatin.translate('queen') + actual = PigLatin.translate('queen') + expected = 'eenquay' + assert_equal expected, actual end def test_word_beginning_with_qu_and_a_preceding_consonant skip - assert_equal 'aresquay', PigLatin.translate('square') + actual = PigLatin.translate('square') + expected = 'aresquay' + assert_equal expected, actual end def test_word_beginning_with_th skip - assert_equal 'erapythay', PigLatin.translate('therapy') + actual = PigLatin.translate('therapy') + expected = 'erapythay' + assert_equal expected, actual end def test_word_beginning_with_thr skip - assert_equal 'ushthray', PigLatin.translate('thrush') + actual = PigLatin.translate('thrush') + expected = 'ushthray' + assert_equal expected, actual end def test_word_beginning_with_sch skip - assert_equal 'oolschay', PigLatin.translate('school') + actual = PigLatin.translate('school') + expected = 'oolschay' + assert_equal expected, actual end def test_word_beginning_with_yt skip - assert_equal 'yttriaay', PigLatin.translate('yttria') + actual = PigLatin.translate('yttria') + expected = 'yttriaay' + assert_equal expected, actual end def test_word_beginning_with_xr skip - assert_equal 'xrayay', PigLatin.translate('xray') + actual = PigLatin.translate('xray') + expected = 'xrayay' + assert_equal expected, actual end def test_y_is_treated_like_a_consonant_at_the_beginning_of_a_word skip - assert_equal 'ellowyay', PigLatin.translate('yellow') + actual = PigLatin.translate('yellow') + expected = 'ellowyay' + assert_equal expected, actual end def test_y_is_treated_like_a_vowel_at_the_end_of_a_consonant_cluster skip - assert_equal 'ythmrhay', PigLatin.translate('rhythm') + actual = PigLatin.translate('rhythm') + expected = 'ythmrhay' + assert_equal expected, actual end def test_y_as_second_letter_in_two_letter_word skip - assert_equal 'ymay', PigLatin.translate('my') + actual = PigLatin.translate('my') + expected = 'ymay' + assert_equal expected, actual end def test_a_whole_phrase skip - assert_equal 'ickquay astfay unray', PigLatin.translate('quick fast run') + actual = PigLatin.translate('quick fast run') + expected = 'ickquay astfay unray' + assert_equal expected, actual end end diff --git a/exercises/practice/poker/.meta/test_template.erb b/exercises/practice/poker/.meta/test_template.erb index 0651024c5c..6730df6be0 100644 --- a/exercises/practice/poker/.meta/test_template.erb +++ b/exercises/practice/poker/.meta/test_template.erb @@ -6,7 +6,9 @@ class PokerTest < Minitest::Test def test_<%= underscore(cases["description"]) %> <%= skip? %> hands = [<%= cases["input"]["hands"].map{ |hand| "%w[#{hand}]"}.join(", ") %>] - assert_equal [<%= cases["expected"].map{ |hand| "%w[#{hand}]"}.join(", ") %>], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [<%= cases["expected"].map{ |hand| "%w[#{hand}]"}.join(", ") %>] + assert_equal expected, actual end <% end %> end diff --git a/exercises/practice/poker/poker_test.rb b/exercises/practice/poker/poker_test.rb index 7c2d99a2d6..fe71dca0c3 100644 --- a/exercises/practice/poker/poker_test.rb +++ b/exercises/practice/poker/poker_test.rb @@ -5,222 +5,296 @@ class PokerTest < Minitest::Test def test_single_hand_always_wins # skip hands = [%w[4S 5S 7H 8D JC]] - assert_equal [%w[4S 5S 7H 8D JC]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4S 5S 7H 8D JC]] + assert_equal expected, actual end def test_highest_card_out_of_all_hands_wins skip hands = [%w[4D 5S 6S 8D 3C], %w[2S 4C 7S 9H 10H], %w[3S 4S 5D 6H JH]] - assert_equal [%w[3S 4S 5D 6H JH]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[3S 4S 5D 6H JH]] + assert_equal expected, actual end def test_a_tie_has_multiple_winners skip hands = [%w[4D 5S 6S 8D 3C], %w[2S 4C 7S 9H 10H], %w[3S 4S 5D 6H JH], %w[3H 4H 5C 6C JD]] - assert_equal [%w[3S 4S 5D 6H JH], %w[3H 4H 5C 6C JD]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[3S 4S 5D 6H JH], %w[3H 4H 5C 6C JD]] + assert_equal expected, actual end def test_multiple_hands_with_the_same_high_cards_tie_compares_next_highest_ranked_down_to_last_card skip hands = [%w[3S 5H 6S 8D 7H], %w[2S 5D 6D 8C 7S]] - assert_equal [%w[3S 5H 6S 8D 7H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[3S 5H 6S 8D 7H]] + assert_equal expected, actual end def test_winning_high_card_hand_also_has_the_lowest_card skip hands = [%w[2S 5H 6S 8D 7H], %w[3S 4D 6D 8C 7S]] - assert_equal [%w[2S 5H 6S 8D 7H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2S 5H 6S 8D 7H]] + assert_equal expected, actual end def test_one_pair_beats_high_card skip hands = [%w[4S 5H 6C 8D KH], %w[2S 4H 6S 4D JH]] - assert_equal [%w[2S 4H 6S 4D JH]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2S 4H 6S 4D JH]] + assert_equal expected, actual end def test_highest_pair_wins skip hands = [%w[4S 2H 6S 2D JH], %w[2S 4H 6C 4D JD]] - assert_equal [%w[2S 4H 6C 4D JD]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2S 4H 6C 4D JD]] + assert_equal expected, actual end def test_both_hands_have_the_same_pair_high_card_wins skip hands = [%w[4H 4S AH JC 3D], %w[4C 4D AS 5D 6C]] - assert_equal [%w[4H 4S AH JC 3D]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4H 4S AH JC 3D]] + assert_equal expected, actual end def test_two_pairs_beats_one_pair skip hands = [%w[2S 8H 6S 8D JH], %w[4S 5H 4C 8C 5C]] - assert_equal [%w[4S 5H 4C 8C 5C]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4S 5H 4C 8C 5C]] + assert_equal expected, actual end def test_both_hands_have_two_pairs_highest_ranked_pair_wins skip hands = [%w[2S 8H 2D 8D 3H], %w[4S 5H 4C 8S 5D]] - assert_equal [%w[2S 8H 2D 8D 3H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2S 8H 2D 8D 3H]] + assert_equal expected, actual end def test_both_hands_have_two_pairs_with_the_same_highest_ranked_pair_tie_goes_to_low_pair skip hands = [%w[2S QS 2C QD JH], %w[JD QH JS 8D QC]] - assert_equal [%w[JD QH JS 8D QC]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[JD QH JS 8D QC]] + assert_equal expected, actual end def test_both_hands_have_two_identically_ranked_pairs_tie_goes_to_remaining_card_kicker skip hands = [%w[JD QH JS 8D QC], %w[JS QS JC 2D QD]] - assert_equal [%w[JD QH JS 8D QC]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[JD QH JS 8D QC]] + assert_equal expected, actual end def test_both_hands_have_two_pairs_that_add_to_the_same_value_win_goes_to_highest_pair skip hands = [%w[6S 6H 3S 3H AS], %w[7H 7S 2H 2S AC]] - assert_equal [%w[7H 7S 2H 2S AC]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[7H 7S 2H 2S AC]] + assert_equal expected, actual end def test_two_pairs_first_ranked_by_largest_pair skip hands = [%w[5C 2S 5S 4H 4C], %w[6S 2S 6H 7C 2C]] - assert_equal [%w[6S 2S 6H 7C 2C]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[6S 2S 6H 7C 2C]] + assert_equal expected, actual end def test_three_of_a_kind_beats_two_pair skip hands = [%w[2S 8H 2H 8D JH], %w[4S 5H 4C 8S 4H]] - assert_equal [%w[4S 5H 4C 8S 4H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4S 5H 4C 8S 4H]] + assert_equal expected, actual end def test_both_hands_have_three_of_a_kind_tie_goes_to_highest_ranked_triplet skip hands = [%w[2S 2H 2C 8D JH], %w[4S AH AS 8C AD]] - assert_equal [%w[4S AH AS 8C AD]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4S AH AS 8C AD]] + assert_equal expected, actual end def test_with_multiple_decks_two_players_can_have_same_three_of_a_kind_ties_go_to_highest_remaining_cards skip hands = [%w[5S AH AS 7C AD], %w[4S AH AS 8C AD]] - assert_equal [%w[4S AH AS 8C AD]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4S AH AS 8C AD]] + assert_equal expected, actual end def test_a_straight_beats_three_of_a_kind skip hands = [%w[4S 5H 4C 8D 4H], %w[3S 4D 2S 6D 5C]] - assert_equal [%w[3S 4D 2S 6D 5C]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[3S 4D 2S 6D 5C]] + assert_equal expected, actual end def test_aces_can_end_a_straight_10_j_q_k_a skip hands = [%w[4S 5H 4C 8D 4H], %w[10D JH QS KD AC]] - assert_equal [%w[10D JH QS KD AC]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[10D JH QS KD AC]] + assert_equal expected, actual end def test_aces_can_start_a_straight_a_2_3_4_5 skip hands = [%w[4S 5H 4C 8D 4H], %w[4D AH 3S 2D 5C]] - assert_equal [%w[4D AH 3S 2D 5C]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4D AH 3S 2D 5C]] + assert_equal expected, actual end def test_aces_cannot_be_in_the_middle_of_a_straight_q_k_a_2_3 skip hands = [%w[2C 3D 7H 5H 2S], %w[QS KH AC 2D 3S]] - assert_equal [%w[2C 3D 7H 5H 2S]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2C 3D 7H 5H 2S]] + assert_equal expected, actual end def test_both_hands_with_a_straight_tie_goes_to_highest_ranked_card skip hands = [%w[4S 6C 7S 8D 5H], %w[5S 7H 8S 9D 6H]] - assert_equal [%w[5S 7H 8S 9D 6H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[5S 7H 8S 9D 6H]] + assert_equal expected, actual end def test_even_though_an_ace_is_usually_high_a_5_high_straight_is_the_lowest_scoring_straight skip hands = [%w[2H 3C 4D 5D 6H], %w[4S AH 3S 2D 5H]] - assert_equal [%w[2H 3C 4D 5D 6H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2H 3C 4D 5D 6H]] + assert_equal expected, actual end def test_flush_beats_a_straight skip hands = [%w[4C 6H 7D 8D 5H], %w[2S 4S 5S 6S 7S]] - assert_equal [%w[2S 4S 5S 6S 7S]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2S 4S 5S 6S 7S]] + assert_equal expected, actual end def test_both_hands_have_a_flush_tie_goes_to_high_card_down_to_the_last_one_if_necessary skip hands = [%w[2H 7H 8H 9H 6H], %w[3S 5S 6S 7S 8S]] - assert_equal [%w[2H 7H 8H 9H 6H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2H 7H 8H 9H 6H]] + assert_equal expected, actual end def test_full_house_beats_a_flush skip hands = [%w[3H 6H 7H 8H 5H], %w[4S 5H 4C 5D 4H]] - assert_equal [%w[4S 5H 4C 5D 4H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4S 5H 4C 5D 4H]] + assert_equal expected, actual end def test_both_hands_have_a_full_house_tie_goes_to_highest_ranked_triplet skip hands = [%w[4H 4S 4D 9S 9D], %w[5H 5S 5D 8S 8D]] - assert_equal [%w[5H 5S 5D 8S 8D]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[5H 5S 5D 8S 8D]] + assert_equal expected, actual end def test_with_multiple_decks_both_hands_have_a_full_house_with_the_same_triplet_tie_goes_to_the_pair skip hands = [%w[5H 5S 5D 9S 9D], %w[5H 5S 5D 8S 8D]] - assert_equal [%w[5H 5S 5D 9S 9D]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[5H 5S 5D 9S 9D]] + assert_equal expected, actual end def test_four_of_a_kind_beats_a_full_house skip hands = [%w[4S 5H 4D 5D 4H], %w[3S 3H 2S 3D 3C]] - assert_equal [%w[3S 3H 2S 3D 3C]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[3S 3H 2S 3D 3C]] + assert_equal expected, actual end def test_both_hands_have_four_of_a_kind_tie_goes_to_high_quad skip hands = [%w[2S 2H 2C 8D 2D], %w[4S 5H 5S 5D 5C]] - assert_equal [%w[4S 5H 5S 5D 5C]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4S 5H 5S 5D 5C]] + assert_equal expected, actual end def test_with_multiple_decks_both_hands_with_identical_four_of_a_kind_tie_determined_by_kicker skip hands = [%w[3S 3H 2S 3D 3C], %w[3S 3H 4S 3D 3C]] - assert_equal [%w[3S 3H 4S 3D 3C]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[3S 3H 4S 3D 3C]] + assert_equal expected, actual end def test_straight_flush_beats_four_of_a_kind skip hands = [%w[4S 5H 5S 5D 5C], %w[7S 8S 9S 6S 10S]] - assert_equal [%w[7S 8S 9S 6S 10S]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[7S 8S 9S 6S 10S]] + assert_equal expected, actual end def test_aces_can_end_a_straight_flush_10_j_q_k_a skip hands = [%w[KC AH AS AD AC], %w[10C JC QC KC AC]] - assert_equal [%w[10C JC QC KC AC]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[10C JC QC KC AC]] + assert_equal expected, actual end def test_aces_can_start_a_straight_flush_a_2_3_4_5 skip hands = [%w[KS AH AS AD AC], %w[4H AH 3H 2H 5H]] - assert_equal [%w[4H AH 3H 2H 5H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[4H AH 3H 2H 5H]] + assert_equal expected, actual end def test_aces_cannot_be_in_the_middle_of_a_straight_flush_q_k_a_2_3 skip hands = [%w[2C AC QC 10C KC], %w[QH KH AH 2H 3H]] - assert_equal [%w[2C AC QC 10C KC]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2C AC QC 10C KC]] + assert_equal expected, actual end def test_both_hands_have_a_straight_flush_tie_goes_to_highest_ranked_card skip hands = [%w[4H 6H 7H 8H 5H], %w[5S 7S 8S 9S 6S]] - assert_equal [%w[5S 7S 8S 9S 6S]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[5S 7S 8S 9S 6S]] + assert_equal expected, actual end def test_even_though_an_ace_is_usually_high_a_5_high_straight_flush_is_the_lowest_scoring_straight_flush skip hands = [%w[2H 3H 4H 5H 6H], %w[4D AD 3D 2D 5D]] - assert_equal [%w[2H 3H 4H 5H 6H]], Poker.new(hands).best_hand + actual = Poker.new(hands).best_hand + expected = [%w[2H 3H 4H 5H 6H]] + assert_equal expected, actual end end diff --git a/exercises/practice/prime-factors/.meta/test_template.erb b/exercises/practice/prime-factors/.meta/test_template.erb index d08e3d46c9..76ec31178c 100644 --- a/exercises/practice/prime-factors/.meta/test_template.erb +++ b/exercises/practice/prime-factors/.meta/test_template.erb @@ -5,7 +5,9 @@ class PrimeFactorsTest < Minitest::Test <% json["cases"].each do |cases| %> def test_<%= underscore(cases["description"]) %> <%= skip? %> - assert_equal <%= cases["expected"] %>, PrimeFactors.of(<%= cases["input"]["value"] %>) + actual = PrimeFactors.of(<%= cases["input"]["value"] %>) + expected = <%= cases["expected"] %> + assert_equal expected, actual end <% end %> end diff --git a/exercises/practice/prime-factors/prime_factors_test.rb b/exercises/practice/prime-factors/prime_factors_test.rb index cb8735c2f5..6fad14b83a 100644 --- a/exercises/practice/prime-factors/prime_factors_test.rb +++ b/exercises/practice/prime-factors/prime_factors_test.rb @@ -4,61 +4,85 @@ class PrimeFactorsTest < Minitest::Test def test_no_factors # skip - assert_empty PrimeFactors.of(1) + actual = PrimeFactors.of(1) + expected = [] + assert_equal expected, actual end def test_prime_number skip - assert_equal [2], PrimeFactors.of(2) + actual = PrimeFactors.of(2) + expected = [2] + assert_equal expected, actual end def test_another_prime_number skip - assert_equal [3], PrimeFactors.of(3) + actual = PrimeFactors.of(3) + expected = [3] + assert_equal expected, actual end def test_square_of_a_prime skip - assert_equal [3, 3], PrimeFactors.of(9) + actual = PrimeFactors.of(9) + expected = [3, 3] + assert_equal expected, actual end def test_product_of_first_prime skip - assert_equal [2, 2], PrimeFactors.of(4) + actual = PrimeFactors.of(4) + expected = [2, 2] + assert_equal expected, actual end def test_cube_of_a_prime skip - assert_equal [2, 2, 2], PrimeFactors.of(8) + actual = PrimeFactors.of(8) + expected = [2, 2, 2] + assert_equal expected, actual end def test_product_of_second_prime skip - assert_equal [3, 3, 3], PrimeFactors.of(27) + actual = PrimeFactors.of(27) + expected = [3, 3, 3] + assert_equal expected, actual end def test_product_of_third_prime skip - assert_equal [5, 5, 5, 5], PrimeFactors.of(625) + actual = PrimeFactors.of(625) + expected = [5, 5, 5, 5] + assert_equal expected, actual end def test_product_of_first_and_second_prime skip - assert_equal [2, 3], PrimeFactors.of(6) + actual = PrimeFactors.of(6) + expected = [2, 3] + assert_equal expected, actual end def test_product_of_primes_and_non_primes skip - assert_equal [2, 2, 3], PrimeFactors.of(12) + actual = PrimeFactors.of(12) + expected = [2, 2, 3] + assert_equal expected, actual end def test_product_of_primes skip - assert_equal [5, 17, 23, 461], PrimeFactors.of(901_255) + actual = PrimeFactors.of(901_255) + expected = [5, 17, 23, 461] + assert_equal expected, actual end def test_factors_include_a_large_prime skip - assert_equal [11, 9539, 894_119], PrimeFactors.of(93_819_012_551) + actual = PrimeFactors.of(93_819_012_551) + expected = [11, 9539, 894_119] + assert_equal expected, actual end end diff --git a/exercises/practice/protein-translation/.meta/test_template.erb b/exercises/practice/protein-translation/.meta/test_template.erb index 6ccb42dd77..b3dc16a1e9 100644 --- a/exercises/practice/protein-translation/.meta/test_template.erb +++ b/exercises/practice/protein-translation/.meta/test_template.erb @@ -11,8 +11,9 @@ class ProteinTranslationTest < Minitest::Test Translation.of_rna(strand) end <%- else -%> + actual = Translation.of_rna(strand) expected = %w[<%= cases["expected"].join(" ") %>] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual <%- end -%> end <% end %> diff --git a/exercises/practice/protein-translation/protein_translation_test.rb b/exercises/practice/protein-translation/protein_translation_test.rb index 8d92da4422..b3417eeca1 100644 --- a/exercises/practice/protein-translation/protein_translation_test.rb +++ b/exercises/practice/protein-translation/protein_translation_test.rb @@ -5,190 +5,217 @@ class ProteinTranslationTest < Minitest::Test def test_empty_rna_sequence_results_in_no_proteins # skip strand = '' + actual = Translation.of_rna(strand) expected = %w[] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_methionine_rna_sequence skip strand = 'AUG' + actual = Translation.of_rna(strand) expected = %w[Methionine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_phenylalanine_rna_sequence_1 skip strand = 'UUU' + actual = Translation.of_rna(strand) expected = %w[Phenylalanine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_phenylalanine_rna_sequence_2 skip strand = 'UUC' + actual = Translation.of_rna(strand) expected = %w[Phenylalanine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_leucine_rna_sequence_1 skip strand = 'UUA' + actual = Translation.of_rna(strand) expected = %w[Leucine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_leucine_rna_sequence_2 skip strand = 'UUG' + actual = Translation.of_rna(strand) expected = %w[Leucine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_serine_rna_sequence_1 skip strand = 'UCU' + actual = Translation.of_rna(strand) expected = %w[Serine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_serine_rna_sequence_2 skip strand = 'UCC' + actual = Translation.of_rna(strand) expected = %w[Serine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_serine_rna_sequence_3 skip strand = 'UCA' + actual = Translation.of_rna(strand) expected = %w[Serine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_serine_rna_sequence_4 skip strand = 'UCG' + actual = Translation.of_rna(strand) expected = %w[Serine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_tyrosine_rna_sequence_1 skip strand = 'UAU' + actual = Translation.of_rna(strand) expected = %w[Tyrosine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_tyrosine_rna_sequence_2 skip strand = 'UAC' + actual = Translation.of_rna(strand) expected = %w[Tyrosine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_cysteine_rna_sequence_1 skip strand = 'UGU' + actual = Translation.of_rna(strand) expected = %w[Cysteine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_cysteine_rna_sequence_2 skip strand = 'UGC' + actual = Translation.of_rna(strand) expected = %w[Cysteine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_tryptophan_rna_sequence skip strand = 'UGG' + actual = Translation.of_rna(strand) expected = %w[Tryptophan] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_stop_codon_rna_sequence_1 skip strand = 'UAA' + actual = Translation.of_rna(strand) expected = %w[] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_stop_codon_rna_sequence_2 skip strand = 'UAG' + actual = Translation.of_rna(strand) expected = %w[] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_stop_codon_rna_sequence_3 skip strand = 'UGA' + actual = Translation.of_rna(strand) expected = %w[] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_sequence_of_two_protein_codons_translates_into_proteins skip strand = 'UUUUUU' + actual = Translation.of_rna(strand) expected = %w[Phenylalanine Phenylalanine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_sequence_of_two_different_protein_codons_translates_into_proteins skip strand = 'UUAUUG' + actual = Translation.of_rna(strand) expected = %w[Leucine Leucine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_translate_rna_strand_into_correct_protein_list skip strand = 'AUGUUUUGG' + actual = Translation.of_rna(strand) expected = %w[Methionine Phenylalanine Tryptophan] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_translation_stops_if_stop_codon_at_beginning_of_sequence skip strand = 'UAGUGG' + actual = Translation.of_rna(strand) expected = %w[] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_translation_stops_if_stop_codon_at_end_of_two_codon_sequence skip strand = 'UGGUAG' + actual = Translation.of_rna(strand) expected = %w[Tryptophan] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_translation_stops_if_stop_codon_at_end_of_three_codon_sequence skip strand = 'AUGUUUUAA' + actual = Translation.of_rna(strand) expected = %w[Methionine Phenylalanine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_translation_stops_if_stop_codon_in_middle_of_three_codon_sequence skip strand = 'UGGUAGUGG' + actual = Translation.of_rna(strand) expected = %w[Tryptophan] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_translation_stops_if_stop_codon_in_middle_of_six_codon_sequence skip strand = 'UGGUGUUAUUAAUGGUUU' + actual = Translation.of_rna(strand) expected = %w[Tryptophan Cysteine Tyrosine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_sequence_of_two_non_stop_codons_does_not_translate_to_a_stop_codon skip strand = 'AUGAUG' + actual = Translation.of_rna(strand) expected = %w[Methionine Methionine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end def test_non_existing_codon_cant_translate @@ -218,7 +245,8 @@ def test_incomplete_rna_sequence_cant_translate def test_incomplete_rna_sequence_can_translate_if_valid_until_a_stop_codon skip strand = 'UUCUUCUAAUGGU' + actual = Translation.of_rna(strand) expected = %w[Phenylalanine Phenylalanine] - assert_equal expected, Translation.of_rna(strand) + assert_equal expected, actual end end diff --git a/exercises/practice/pythagorean-triplet/.meta/test_template.erb b/exercises/practice/pythagorean-triplet/.meta/test_template.erb index 9bb153133f..ebfe763662 100644 --- a/exercises/practice/pythagorean-triplet/.meta/test_template.erb +++ b/exercises/practice/pythagorean-triplet/.meta/test_template.erb @@ -5,8 +5,9 @@ class PythagoreanTripletTest < Minitest::Test <% json["cases"].each do |cases| %> def test_<%= underscore(cases["description"]) %> <%= skip? %> + actual = PythagoreanTriplet.triplets_with_sum(<%= cases["input"]["n"] %>) expected = <%= cases["expected"] %> - assert_equal expected, PythagoreanTriplet.triplets_with_sum(<%= cases["input"]["n"] %>) + assert_equal expected, actual end <% end %> end diff --git a/exercises/practice/pythagorean-triplet/pythagorean_triplet_test.rb b/exercises/practice/pythagorean-triplet/pythagorean_triplet_test.rb index 26168bf5af..3659e30250 100644 --- a/exercises/practice/pythagorean-triplet/pythagorean_triplet_test.rb +++ b/exercises/practice/pythagorean-triplet/pythagorean_triplet_test.rb @@ -4,43 +4,50 @@ class PythagoreanTripletTest < Minitest::Test def test_triplets_whose_sum_is_12 # skip + actual = PythagoreanTriplet.triplets_with_sum(12) expected = [[3, 4, 5]] - assert_equal expected, PythagoreanTriplet.triplets_with_sum(12) + assert_equal expected, actual end def test_triplets_whose_sum_is_108 skip + actual = PythagoreanTriplet.triplets_with_sum(108) expected = [[27, 36, 45]] - assert_equal expected, PythagoreanTriplet.triplets_with_sum(108) + assert_equal expected, actual end def test_triplets_whose_sum_is_1000 skip + actual = PythagoreanTriplet.triplets_with_sum(1000) expected = [[200, 375, 425]] - assert_equal expected, PythagoreanTriplet.triplets_with_sum(1000) + assert_equal expected, actual end def test_no_matching_triplets_for_1001 skip + actual = PythagoreanTriplet.triplets_with_sum(1001) expected = [] - assert_equal expected, PythagoreanTriplet.triplets_with_sum(1001) + assert_equal expected, actual end def test_returns_all_matching_triplets skip + actual = PythagoreanTriplet.triplets_with_sum(90) expected = [[9, 40, 41], [15, 36, 39]] - assert_equal expected, PythagoreanTriplet.triplets_with_sum(90) + assert_equal expected, actual end def test_several_matching_triplets skip + actual = PythagoreanTriplet.triplets_with_sum(840) expected = [[40, 399, 401], [56, 390, 394], [105, 360, 375], [120, 350, 370], [140, 336, 364], [168, 315, 357], [210, 280, 350], [240, 252, 348]] - assert_equal expected, PythagoreanTriplet.triplets_with_sum(840) + assert_equal expected, actual end def test_triplets_for_large_number skip + actual = PythagoreanTriplet.triplets_with_sum(30_000) expected = [[1200, 14_375, 14_425], [1875, 14_000, 14_125], [5000, 12_000, 13_000], [6000, 11_250, 12_750], [7500, 10_000, 12_500]] - assert_equal expected, PythagoreanTriplet.triplets_with_sum(30_000) + assert_equal expected, actual end end diff --git a/exercises/practice/rail-fence-cipher/.meta/test_template.erb b/exercises/practice/rail-fence-cipher/.meta/test_template.erb index 22b892211f..fe28fab33b 100644 --- a/exercises/practice/rail-fence-cipher/.meta/test_template.erb +++ b/exercises/practice/rail-fence-cipher/.meta/test_template.erb @@ -6,7 +6,9 @@ class RailFenceCipherTest < Minitest::Test <% cases["cases"].each do |sub_case| %> def test_<%= underscore(sub_case["description"]) %> <%= skip? %> - assert_equal '<%= sub_case["expected"] %>', RailFenceCipher.<%= sub_case["property"] %>('<%= sub_case["input"]["msg"] %>', <%= sub_case["input"]["rails"] %>) + actual = RailFenceCipher.<%= sub_case["property"] %>('<%= sub_case["input"]["msg"] %>', <%= sub_case["input"]["rails"] %>) + expected = '<%= sub_case["expected"] %>' + assert_equal expected, actual end <% end %> <% end %> diff --git a/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb b/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb index e0089622f4..352ebc95e4 100644 --- a/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb +++ b/exercises/practice/rail-fence-cipher/rail_fence_cipher_test.rb @@ -4,31 +4,43 @@ class RailFenceCipherTest < Minitest::Test def test_encode_with_two_rails # skip - assert_equal 'XXXXXXXXXOOOOOOOOO', RailFenceCipher.encode('XOXOXOXOXOXOXOXOXO', 2) + actual = RailFenceCipher.encode('XOXOXOXOXOXOXOXOXO', 2) + expected = 'XXXXXXXXXOOOOOOOOO' + assert_equal expected, actual end def test_encode_with_three_rails skip - assert_equal 'WECRLTEERDSOEEFEAOCAIVDEN', RailFenceCipher.encode('WEAREDISCOVEREDFLEEATONCE', 3) + actual = RailFenceCipher.encode('WEAREDISCOVEREDFLEEATONCE', 3) + expected = 'WECRLTEERDSOEEFEAOCAIVDEN' + assert_equal expected, actual end def test_encode_with_ending_in_the_middle skip - assert_equal 'ESXIEECSR', RailFenceCipher.encode('EXERCISES', 4) + actual = RailFenceCipher.encode('EXERCISES', 4) + expected = 'ESXIEECSR' + assert_equal expected, actual end def test_decode_with_three_rails skip - assert_equal 'THEDEVILISINTHEDETAILS', RailFenceCipher.decode('TEITELHDVLSNHDTISEIIEA', 3) + actual = RailFenceCipher.decode('TEITELHDVLSNHDTISEIIEA', 3) + expected = 'THEDEVILISINTHEDETAILS' + assert_equal expected, actual end def test_decode_with_five_rails skip - assert_equal 'EXERCISMISAWESOME', RailFenceCipher.decode('EIEXMSMESAORIWSCE', 5) + actual = RailFenceCipher.decode('EIEXMSMESAORIWSCE', 5) + expected = 'EXERCISMISAWESOME' + assert_equal expected, actual end def test_decode_with_six_rails skip - assert_equal '112358132134558914423337761098715972584418167651094617711286', RailFenceCipher.decode('133714114238148966225439541018335470986172518171757571896261', 6) + actual = RailFenceCipher.decode('133714114238148966225439541018335470986172518171757571896261', 6) + expected = '112358132134558914423337761098715972584418167651094617711286' + assert_equal expected, actual end end