From 18c96ea6631df1eedd5809b1b7d2003bb250c323 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 12:23:48 -0700 Subject: [PATCH 01/11] move ExerciseCase under Generator --- .../acronym/.meta/generator/acronym_cases.rb | 2 +- .../.meta/generator/all_your_base_cases.rb | 2 +- .../.meta/generator/alphametics_cases.rb | 2 +- .../anagram/.meta/generator/anagram_cases.rb | 2 +- .../.meta/generator/beer_song_cases.rb | 2 +- .../binary/.meta/generator/binary_cases.rb | 2 +- .../bowling/.meta/generator/bowling_cases.rb | 2 +- .../.meta/generator/bracket_push_cases.rb | 2 +- .../clock/.meta/generator/clock_cases.rb | 2 +- .../connect/.meta/generator/connect_cases.rb | 2 +- .../.meta/generator/custom_set_cases.rb | 2 +- .../generator/difference_of_squares_cases.rb | 2 +- .../.meta/generator/dominoes_cases.rb | 2 +- exercises/etl/.meta/generator/etl_cases.rb | 2 +- .../.meta/generator/gigasecond_cases.rb | 2 +- .../grains/.meta/generator/grains_cases.rb | 2 +- .../hamming/.meta/generator/hamming_cases.rb | 2 +- .../.meta/generator/hello_world_cases.rb | 2 +- .../isogram/.meta/generator/isogram_cases.rb | 2 +- .../generator/largest_series_product_cases.rb | 2 +- exercises/leap/.meta/generator/leap_cases.rb | 2 +- exercises/luhn/.meta/generator/luhn_cases.rb | 2 +- .../.meta/generator/nth_prime_cases.rb | 2 +- .../.meta/generator/ocr_numbers_cases.rb | 2 +- .../pangram/.meta/generator/pangram_cases.rb | 2 +- .../.meta/generator/pig_latin_cases.rb | 2 +- .../.meta/generator/queen_attack_cases.rb | 2 +- .../.meta/generator/raindrops_cases.rb | 2 +- .../generator/rna_transcription_cases.rb | 2 +- .../.meta/generator/roman_numerals_cases.rb | 2 +- .../generator/run_length_encoding_cases.rb | 2 +- exercises/say/.meta/generator/say_cases.rb | 2 +- .../sieve/.meta/generator/sieve_cases.rb | 2 +- .../.meta/generator/tournament_cases.rb | 2 +- .../.meta/generator/transpose_cases.rb | 2 +- .../.meta/generator/triangle_cases.rb | 2 +- .../.meta/generator/two_bucket_cases.rb | 2 +- .../.meta/generator/word_count_cases.rb | 2 +- .../wordy/.meta/generator/wordy_cases.rb | 2 +- lib/generator/exercise_cases.rb | 104 +++++++++++------- .../beta/.meta/generator/beta_cases.rb | 2 +- test/generator/case_values_test.rb | 10 +- 42 files changed, 108 insertions(+), 86 deletions(-) diff --git a/exercises/acronym/.meta/generator/acronym_cases.rb b/exercises/acronym/.meta/generator/acronym_cases.rb index 342f48862c..b9524e4d56 100644 --- a/exercises/acronym/.meta/generator/acronym_cases.rb +++ b/exercises/acronym/.meta/generator/acronym_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class AcronymCase < ExerciseCase +class AcronymCase < Generator::ExerciseCase def workload assert_equal { "Acronym.abbreviate('#{phrase}')" } diff --git a/exercises/all-your-base/.meta/generator/all_your_base_cases.rb b/exercises/all-your-base/.meta/generator/all_your_base_cases.rb index 26d72ef7ae..f2f867e4e5 100644 --- a/exercises/all-your-base/.meta/generator/all_your_base_cases.rb +++ b/exercises/all-your-base/.meta/generator/all_your_base_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class AllYourBaseCase < ExerciseCase +class AllYourBaseCase < Generator::ExerciseCase def workload indent(4, (assignments + assertion).join("\n")) + "\n" diff --git a/exercises/alphametics/.meta/generator/alphametics_cases.rb b/exercises/alphametics/.meta/generator/alphametics_cases.rb index a5e77a138c..ed8f341c1a 100644 --- a/exercises/alphametics/.meta/generator/alphametics_cases.rb +++ b/exercises/alphametics/.meta/generator/alphametics_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class AlphameticsCase < ExerciseCase +class AlphameticsCase < Generator::ExerciseCase def workload body = "input = %s\n" % input, diff --git a/exercises/anagram/.meta/generator/anagram_cases.rb b/exercises/anagram/.meta/generator/anagram_cases.rb index e6c0500538..eb512e885e 100644 --- a/exercises/anagram/.meta/generator/anagram_cases.rb +++ b/exercises/anagram/.meta/generator/anagram_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class AnagramCase < ExerciseCase +class AnagramCase < Generator::ExerciseCase def workload indent_lines([show_comment, detector, anagram, wanted, assert].compact) diff --git a/exercises/beer-song/.meta/generator/beer_song_cases.rb b/exercises/beer-song/.meta/generator/beer_song_cases.rb index 8ae7494141..25f8365e2d 100644 --- a/exercises/beer-song/.meta/generator/beer_song_cases.rb +++ b/exercises/beer-song/.meta/generator/beer_song_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class BeerSongCase < ExerciseCase +class BeerSongCase < Generator::ExerciseCase def workload "assert_equal expected, #{beer_song}" diff --git a/exercises/binary/.meta/generator/binary_cases.rb b/exercises/binary/.meta/generator/binary_cases.rb index 277944999a..e23cf526ca 100644 --- a/exercises/binary/.meta/generator/binary_cases.rb +++ b/exercises/binary/.meta/generator/binary_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class BinaryCase < ExerciseCase +class BinaryCase < Generator::ExerciseCase def workload raises_error? ? error_assertion : equality_assertion diff --git a/exercises/bowling/.meta/generator/bowling_cases.rb b/exercises/bowling/.meta/generator/bowling_cases.rb index 5e38a24fcd..9fb0c677c6 100644 --- a/exercises/bowling/.meta/generator/bowling_cases.rb +++ b/exercises/bowling/.meta/generator/bowling_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class BowlingCase < ExerciseCase +class BowlingCase < Generator::ExerciseCase def workload indent_lines(assert) diff --git a/exercises/bracket-push/.meta/generator/bracket_push_cases.rb b/exercises/bracket-push/.meta/generator/bracket_push_cases.rb index 18b5b665b0..62d854a6b6 100644 --- a/exercises/bracket-push/.meta/generator/bracket_push_cases.rb +++ b/exercises/bracket-push/.meta/generator/bracket_push_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class BracketPushCase < ExerciseCase +class BracketPushCase < Generator::ExerciseCase def workload long_input? ? split_test : simple_test diff --git a/exercises/clock/.meta/generator/clock_cases.rb b/exercises/clock/.meta/generator/clock_cases.rb index deaec62e90..b198ba40f8 100644 --- a/exercises/clock/.meta/generator/clock_cases.rb +++ b/exercises/clock/.meta/generator/clock_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class ClockCase < ExerciseCase +class ClockCase < Generator::ExerciseCase def name 'test_%s' % description .gsub(/[() -]/, '_') diff --git a/exercises/connect/.meta/generator/connect_cases.rb b/exercises/connect/.meta/generator/connect_cases.rb index cfa4036cdb..e7f4efeb69 100644 --- a/exercises/connect/.meta/generator/connect_cases.rb +++ b/exercises/connect/.meta/generator/connect_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class ConnectCase < ExerciseCase +class ConnectCase < Generator::ExerciseCase def test_body [ diff --git a/exercises/custom-set/.meta/generator/custom_set_cases.rb b/exercises/custom-set/.meta/generator/custom_set_cases.rb index 3388120272..f13458d316 100644 --- a/exercises/custom-set/.meta/generator/custom_set_cases.rb +++ b/exercises/custom-set/.meta/generator/custom_set_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class CustomSetCase < ExerciseCase +class CustomSetCase < Generator::ExerciseCase def workload send property diff --git a/exercises/difference-of-squares/.meta/generator/difference_of_squares_cases.rb b/exercises/difference-of-squares/.meta/generator/difference_of_squares_cases.rb index ab2a5bb789..a496b523c2 100644 --- a/exercises/difference-of-squares/.meta/generator/difference_of_squares_cases.rb +++ b/exercises/difference-of-squares/.meta/generator/difference_of_squares_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class DifferenceOfSquaresCase < ExerciseCase +class DifferenceOfSquaresCase < Generator::ExerciseCase def workload %Q(assert_equal #{expected_formatted}, Squares.new(#{number}).#{action}) diff --git a/exercises/dominoes/.meta/generator/dominoes_cases.rb b/exercises/dominoes/.meta/generator/dominoes_cases.rb index 921fd5f880..e7d585eb00 100644 --- a/exercises/dominoes/.meta/generator/dominoes_cases.rb +++ b/exercises/dominoes/.meta/generator/dominoes_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class DominoesCase < ExerciseCase +class DominoesCase < Generator::ExerciseCase def name 'test_%s' % description.gsub("can't", 'can not').gsub(/[= -]+/, '_') end diff --git a/exercises/etl/.meta/generator/etl_cases.rb b/exercises/etl/.meta/generator/etl_cases.rb index f348281dde..b1d19994c7 100644 --- a/exercises/etl/.meta/generator/etl_cases.rb +++ b/exercises/etl/.meta/generator/etl_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class EtlCase < ExerciseCase +class EtlCase < Generator::ExerciseCase def workload indent_lines([ "old = {\n #{format(input)}\n }", diff --git a/exercises/gigasecond/.meta/generator/gigasecond_cases.rb b/exercises/gigasecond/.meta/generator/gigasecond_cases.rb index 9dd57e32e0..07110358db 100644 --- a/exercises/gigasecond/.meta/generator/gigasecond_cases.rb +++ b/exercises/gigasecond/.meta/generator/gigasecond_cases.rb @@ -1,7 +1,7 @@ require 'generator/exercise_cases' require 'time' -class GigasecondCase < ExerciseCase +class GigasecondCase < Generator::ExerciseCase def workload %Q(assert_equal #{want}, Gigasecond.from(#{got})) end diff --git a/exercises/grains/.meta/generator/grains_cases.rb b/exercises/grains/.meta/generator/grains_cases.rb index 26c9ab9452..266efa591c 100644 --- a/exercises/grains/.meta/generator/grains_cases.rb +++ b/exercises/grains/.meta/generator/grains_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class GrainsCase < ExerciseCase +class GrainsCase < Generator::ExerciseCase def workload send("#{property}_workload") diff --git a/exercises/hamming/.meta/generator/hamming_cases.rb b/exercises/hamming/.meta/generator/hamming_cases.rb index 94b753d4ca..b44c90219b 100644 --- a/exercises/hamming/.meta/generator/hamming_cases.rb +++ b/exercises/hamming/.meta/generator/hamming_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class HammingCase < ExerciseCase +class HammingCase < Generator::ExerciseCase def workload if raises_error? assert_raises(ArgumentError) { test_case } diff --git a/exercises/hello-world/.meta/generator/hello_world_cases.rb b/exercises/hello-world/.meta/generator/hello_world_cases.rb index df3f92495b..b75107c7d9 100644 --- a/exercises/hello-world/.meta/generator/hello_world_cases.rb +++ b/exercises/hello-world/.meta/generator/hello_world_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class HelloWorldCase < ExerciseCase +class HelloWorldCase < Generator::ExerciseCase def workload assert_equal { "HelloWorld.hello" } diff --git a/exercises/isogram/.meta/generator/isogram_cases.rb b/exercises/isogram/.meta/generator/isogram_cases.rb index d7bc10940d..3221b224b9 100644 --- a/exercises/isogram/.meta/generator/isogram_cases.rb +++ b/exercises/isogram/.meta/generator/isogram_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class IsogramCase < ExerciseCase +class IsogramCase < Generator::ExerciseCase def workload indent_lines( diff --git a/exercises/largest-series-product/.meta/generator/largest_series_product_cases.rb b/exercises/largest-series-product/.meta/generator/largest_series_product_cases.rb index cccae6f8b1..9423b3eda6 100644 --- a/exercises/largest-series-product/.meta/generator/largest_series_product_cases.rb +++ b/exercises/largest-series-product/.meta/generator/largest_series_product_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class LargestSeriesProductCase < ExerciseCase +class LargestSeriesProductCase < Generator::ExerciseCase def workload if raises_error? diff --git a/exercises/leap/.meta/generator/leap_cases.rb b/exercises/leap/.meta/generator/leap_cases.rb index 99ebcd7fa1..76689c2e5d 100644 --- a/exercises/leap/.meta/generator/leap_cases.rb +++ b/exercises/leap/.meta/generator/leap_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class LeapCase < ExerciseCase +class LeapCase < Generator::ExerciseCase def workload "#{assert} Year.leap?(#{input.inspect})" diff --git a/exercises/luhn/.meta/generator/luhn_cases.rb b/exercises/luhn/.meta/generator/luhn_cases.rb index 1e2e1a190c..ffaa263a05 100644 --- a/exercises/luhn/.meta/generator/luhn_cases.rb +++ b/exercises/luhn/.meta/generator/luhn_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class LuhnCase < ExerciseCase +class LuhnCase < Generator::ExerciseCase def workload "#{assert} Luhn.valid?(#{input.inspect})" end diff --git a/exercises/nth-prime/.meta/generator/nth_prime_cases.rb b/exercises/nth-prime/.meta/generator/nth_prime_cases.rb index 79d66c08d0..7612d5ccd0 100644 --- a/exercises/nth-prime/.meta/generator/nth_prime_cases.rb +++ b/exercises/nth-prime/.meta/generator/nth_prime_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class NthPrimeCase < ExerciseCase +class NthPrimeCase < Generator::ExerciseCase def workload if raises_error? diff --git a/exercises/ocr-numbers/.meta/generator/ocr_numbers_cases.rb b/exercises/ocr-numbers/.meta/generator/ocr_numbers_cases.rb index 238b5e3e96..c646297290 100644 --- a/exercises/ocr-numbers/.meta/generator/ocr_numbers_cases.rb +++ b/exercises/ocr-numbers/.meta/generator/ocr_numbers_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class OcrNumbersCase < ExerciseCase +class OcrNumbersCase < Generator::ExerciseCase def workload if raises_error? assert_raises(ArgumentError) { test_case } diff --git a/exercises/pangram/.meta/generator/pangram_cases.rb b/exercises/pangram/.meta/generator/pangram_cases.rb index 1dcc1b7f50..0819acc240 100644 --- a/exercises/pangram/.meta/generator/pangram_cases.rb +++ b/exercises/pangram/.meta/generator/pangram_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class PangramCase < ExerciseCase +class PangramCase < Generator::ExerciseCase def workload [ "phrase = '#{input}'", diff --git a/exercises/pig-latin/.meta/generator/pig_latin_cases.rb b/exercises/pig-latin/.meta/generator/pig_latin_cases.rb index 515e0a3fd3..3b153c2714 100644 --- a/exercises/pig-latin/.meta/generator/pig_latin_cases.rb +++ b/exercises/pig-latin/.meta/generator/pig_latin_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class PigLatinCase < ExerciseCase +class PigLatinCase < Generator::ExerciseCase def workload assert_equal { "PigLatin.translate(#{input.inspect})" } end diff --git a/exercises/queen-attack/.meta/generator/queen_attack_cases.rb b/exercises/queen-attack/.meta/generator/queen_attack_cases.rb index f1b3d4ca1a..31d233b622 100644 --- a/exercises/queen-attack/.meta/generator/queen_attack_cases.rb +++ b/exercises/queen-attack/.meta/generator/queen_attack_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class QueenAttackCase < ExerciseCase +class QueenAttackCase < Generator::ExerciseCase def workload property == 'create' ? create_workload : attack_workload diff --git a/exercises/raindrops/.meta/generator/raindrops_cases.rb b/exercises/raindrops/.meta/generator/raindrops_cases.rb index e7e6634c3b..4ec14f09e6 100644 --- a/exercises/raindrops/.meta/generator/raindrops_cases.rb +++ b/exercises/raindrops/.meta/generator/raindrops_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class RaindropsCase < ExerciseCase +class RaindropsCase < Generator::ExerciseCase def workload assert_equal { "Raindrops.convert(#{number})" } diff --git a/exercises/rna-transcription/.meta/generator/rna_transcription_cases.rb b/exercises/rna-transcription/.meta/generator/rna_transcription_cases.rb index 2964b8941b..3867114c57 100644 --- a/exercises/rna-transcription/.meta/generator/rna_transcription_cases.rb +++ b/exercises/rna-transcription/.meta/generator/rna_transcription_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class RnaTranscriptionCase < ExerciseCase +class RnaTranscriptionCase < Generator::ExerciseCase def workload "assert_equal '#{expected}', Complement.of_dna('#{dna}')" diff --git a/exercises/roman-numerals/.meta/generator/roman_numerals_cases.rb b/exercises/roman-numerals/.meta/generator/roman_numerals_cases.rb index 542c52b911..0ec4587f68 100644 --- a/exercises/roman-numerals/.meta/generator/roman_numerals_cases.rb +++ b/exercises/roman-numerals/.meta/generator/roman_numerals_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class RomanNumeralsCase < ExerciseCase +class RomanNumeralsCase < Generator::ExerciseCase def name 'test_%s' % number.to_s end diff --git a/exercises/run-length-encoding/.meta/generator/run_length_encoding_cases.rb b/exercises/run-length-encoding/.meta/generator/run_length_encoding_cases.rb index f548500716..a1e692c6d4 100644 --- a/exercises/run-length-encoding/.meta/generator/run_length_encoding_cases.rb +++ b/exercises/run-length-encoding/.meta/generator/run_length_encoding_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class RunLengthEncodingCase < ExerciseCase +class RunLengthEncodingCase < Generator::ExerciseCase def workload indent_lines([ diff --git a/exercises/say/.meta/generator/say_cases.rb b/exercises/say/.meta/generator/say_cases.rb index 07ac05db1a..d0a1ae1852 100644 --- a/exercises/say/.meta/generator/say_cases.rb +++ b/exercises/say/.meta/generator/say_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class SayCase < ExerciseCase +class SayCase < Generator::ExerciseCase def workload [ diff --git a/exercises/sieve/.meta/generator/sieve_cases.rb b/exercises/sieve/.meta/generator/sieve_cases.rb index 11d980973a..5455ef37e1 100644 --- a/exercises/sieve/.meta/generator/sieve_cases.rb +++ b/exercises/sieve/.meta/generator/sieve_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class SieveCase < ExerciseCase +class SieveCase < Generator::ExerciseCase OPEN_ARRAY = "[\n\s\s\s\s\s\s".freeze CLOSE_ARRAY = "\n\s\s\s\s]".freeze NEW_ARRAY_ROW = ",\n\s\s\s\s\s\s".freeze diff --git a/exercises/tournament/.meta/generator/tournament_cases.rb b/exercises/tournament/.meta/generator/tournament_cases.rb index 6a297aa9c4..1949e34da8 100644 --- a/exercises/tournament/.meta/generator/tournament_cases.rb +++ b/exercises/tournament/.meta/generator/tournament_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class TournamentCase < ExerciseCase +class TournamentCase < Generator::ExerciseCase def workload 'Tournament.tally(input)' diff --git a/exercises/transpose/.meta/generator/transpose_cases.rb b/exercises/transpose/.meta/generator/transpose_cases.rb index d78bec1e00..3b6dc0af29 100644 --- a/exercises/transpose/.meta/generator/transpose_cases.rb +++ b/exercises/transpose/.meta/generator/transpose_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class TransposeCase < ExerciseCase +class TransposeCase < Generator::ExerciseCase def workload 'Transpose.transpose(input)' diff --git a/exercises/triangle/.meta/generator/triangle_cases.rb b/exercises/triangle/.meta/generator/triangle_cases.rb index 5491712ad4..7bef141187 100644 --- a/exercises/triangle/.meta/generator/triangle_cases.rb +++ b/exercises/triangle/.meta/generator/triangle_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class TriangleCase < ExerciseCase +class TriangleCase < Generator::ExerciseCase def name initial = description.downcase replaced = initial.gsub(/(true|false)/, expected_type) diff --git a/exercises/two-bucket/.meta/generator/two_bucket_cases.rb b/exercises/two-bucket/.meta/generator/two_bucket_cases.rb index ad4f6be8d1..93edec54de 100644 --- a/exercises/two-bucket/.meta/generator/two_bucket_cases.rb +++ b/exercises/two-bucket/.meta/generator/two_bucket_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class TwoBucketCase < ExerciseCase +class TwoBucketCase < Generator::ExerciseCase def name "test_bucket_one_size_#{bucket_one}_bucket_two_"\ "size_#{bucket_two}_goal_#{goal}_start_with_bucket_#{start_bucket}" diff --git a/exercises/word-count/.meta/generator/word_count_cases.rb b/exercises/word-count/.meta/generator/word_count_cases.rb index 0c0b29e4e7..0e57b24bcc 100644 --- a/exercises/word-count/.meta/generator/word_count_cases.rb +++ b/exercises/word-count/.meta/generator/word_count_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class WordCountCase < ExerciseCase +class WordCountCase < Generator::ExerciseCase def workload indent_lines([ diff --git a/exercises/wordy/.meta/generator/wordy_cases.rb b/exercises/wordy/.meta/generator/wordy_cases.rb index d99100591e..e1d46199da 100644 --- a/exercises/wordy/.meta/generator/wordy_cases.rb +++ b/exercises/wordy/.meta/generator/wordy_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class WordyCase < ExerciseCase +class WordyCase < Generator::ExerciseCase def workload [ diff --git a/lib/generator/exercise_cases.rb b/lib/generator/exercise_cases.rb index 07c4e8a1f8..f58cdba50e 100644 --- a/lib/generator/exercise_cases.rb +++ b/lib/generator/exercise_cases.rb @@ -1,54 +1,76 @@ require 'ostruct' require 'json' -class ExerciseCase < OpenStruct - using Generator::Underscore +module Generator + class ExerciseCase < OpenStruct + using Generator::Underscore - def name - 'test_%s' % description.underscore - end + def name + 'test_%s' % description.underscore + end - def skipped - index.zero? ? '# skip' : 'skip' - end + def skipped + index.zero? ? '# skip' : 'skip' + end - protected - - # used to indent multi line workloads, as - # indent_lines( - # [ - # "string = #{input.inspect}", - # "#{assert} Isogram.is_isogram?(string)" - # ], 4 - # ) - def indent_lines(code, depth, separator = "\n") - code.join(separator + ' ' * depth) - end + protected - # used in workload, for example, as - # "#{assert} Luhn.valid?(#{input.inspect})" - def assert - expected ? 'assert' : 'refute' - end + # indent multi line workloads + # + # indent_lines( + # [ + # "string = #{input.inspect}", + # "#{assert} Isogram.is_isogram?(string)" + # ], 4 + # ) + def indent_lines(code, depth, separator = "\n") + code.join(separator + ' ' * depth) + end - # used in workload, for example, as - # assert_equal { "PigLatin.translate(#{input.inspect})" } - def assert_equal - "assert_equal #{expected.inspect}, #{yield}" - end + # indent multi line workloads with blank lines + # + # indent_text(4, lines.join("\n")) + def indent_text(depth, text) + text.lines.reduce do |obj, line| + obj << (line == "\n" ? line : ' ' * depth + line) + end + end - # used in workload, for example, as - # if raises_error? - # assert_raises(ArgumentError) { test_case } - # else - # assert_equal { test_case } - # end + # generate heredoc (as part of workload) with optional indentation + def indented_heredoc(lines, delimiter, depth = 0, delimiter_method = nil) + [ + "<<-#{delimiter}#{delimiter_method}", + lines.map { |line| ' ' * depth + line }.join("\n"), + delimiter + ].join("\n") + end - def raises_error? - expected.to_i == -1 - end + # e.g., + # "#{assert} Luhn.valid?(#{input.inspect})" + def assert + expected ? 'assert' : 'refute' + end + + # e.g., + # assert_equal { "PigLatin.translate(#{input.inspect})" } + def assert_equal + "assert_equal #{expected.inspect}, #{yield}" + end + + # e.g., + # if raises_error? + # assert_raises(ArgumentError) { test_case } + # else + # assert_equal { test_case } + # end + def raises_error? + expected.to_i == -1 + end - def assert_raises(error) - "assert_raises(#{error}) { #{yield} }" + # e.g., + # assert_raises(ArgumentError) { test_case } + def assert_raises(error) + "assert_raises(#{error}) { #{yield} }" + end end end diff --git a/test/fixtures/xruby/exercises/beta/.meta/generator/beta_cases.rb b/test/fixtures/xruby/exercises/beta/.meta/generator/beta_cases.rb index d6bebff85c..c27e3a9b24 100644 --- a/test/fixtures/xruby/exercises/beta/.meta/generator/beta_cases.rb +++ b/test/fixtures/xruby/exercises/beta/.meta/generator/beta_cases.rb @@ -1,6 +1,6 @@ require 'generator/exercise_cases' -class BetaCase < ExerciseCase +class BetaCase < Generator::ExerciseCase def workload assert_equal { "Beta.call('#{input}')" } end diff --git a/test/generator/case_values_test.rb b/test/generator/case_values_test.rb index 9fbcf7d0b2..7dfb8aea62 100644 --- a/test/generator/case_values_test.rb +++ b/test/generator/case_values_test.rb @@ -1,12 +1,12 @@ require_relative '../test_helper' -class ComplexCase < ExerciseCase - def workload - assert { Complex.foo(bar) } +module Generator + class ComplexCase < ExerciseCase + def workload + assert { Complex.foo(bar) } + end end -end -module Generator module CaseValues class ExtractorTest < Minitest::Test def test_multi_level_auto_extraction From c2d75c6d4d3961bf94ce1e93d456c49bd4ba6668 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 12:30:24 -0700 Subject: [PATCH 02/11] test public methods in ExerciseCase --- test/generator/exercise_cases_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/generator/exercise_cases_test.rb diff --git a/test/generator/exercise_cases_test.rb b/test/generator/exercise_cases_test.rb new file mode 100644 index 0000000000..19a61cbce3 --- /dev/null +++ b/test/generator/exercise_cases_test.rb @@ -0,0 +1,17 @@ +require_relative '../test_helper' + +module Generator + class ExerciseCaseTest < Minitest::Test + def test_name + assert_equal 'test_foo', ExerciseCase.new(description: 'foo').name + end + + def test_skipped_index_zero + assert_equal '# skip', ExerciseCase.new(index: 0).skipped + end + + def test_skipped_index_nonzero + assert_equal 'skip', ExerciseCase.new(index: 12).skipped + end + end +end From 0a9fe83da9da1eda2c2bc1fc948f832819d36328 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 12:47:34 -0700 Subject: [PATCH 03/11] test indenting lines --- test/generator/exercise_cases_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/generator/exercise_cases_test.rb b/test/generator/exercise_cases_test.rb index 19a61cbce3..e1268f6519 100644 --- a/test/generator/exercise_cases_test.rb +++ b/test/generator/exercise_cases_test.rb @@ -13,5 +13,15 @@ def test_skipped_index_zero def test_skipped_index_nonzero assert_equal 'skip', ExerciseCase.new(index: 12).skipped end + + class MyCase < ExerciseCase + def workload + indent_lines(['foo','bar'], 1) + end + end + def test_indent_multiline_workloads + expected = "foo\n bar" + assert_equal expected, MyCase.new.workload + end end end From 2e5f410b28638085bde13ff0c2d2ebe4674d870f Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:12:21 -0700 Subject: [PATCH 04/11] test multiline workloads with blank lines --- lib/generator/exercise_cases.rb | 8 ++++---- test/generator/exercise_cases_test.rb | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/generator/exercise_cases.rb b/lib/generator/exercise_cases.rb index f58cdba50e..ba0b58f746 100644 --- a/lib/generator/exercise_cases.rb +++ b/lib/generator/exercise_cases.rb @@ -27,11 +27,11 @@ def indent_lines(code, depth, separator = "\n") code.join(separator + ' ' * depth) end - # indent multi line workloads with blank lines + # indent multi line workloads with (unindented) blank lines # - # indent_text(4, lines.join("\n")) - def indent_text(depth, text) - text.lines.reduce do |obj, line| + # indent_text(4, lines) + def indent_text(depth, lines) + lines.reduce do |obj, line| obj << (line == "\n" ? line : ' ' * depth + line) end end diff --git a/test/generator/exercise_cases_test.rb b/test/generator/exercise_cases_test.rb index e1268f6519..e2e865f48c 100644 --- a/test/generator/exercise_cases_test.rb +++ b/test/generator/exercise_cases_test.rb @@ -14,14 +14,24 @@ def test_skipped_index_nonzero assert_equal 'skip', ExerciseCase.new(index: 12).skipped end - class MyCase < ExerciseCase + class MultiLineCase < ExerciseCase def workload indent_lines(['foo','bar'], 1) end end def test_indent_multiline_workloads expected = "foo\n bar" - assert_equal expected, MyCase.new.workload + assert_equal expected, MultiLineCase.new.workload + end + + class BlankLineCase < ExerciseCase + def workload + indent_text(2, ["foo\n", "\n", "bar\n"]) + end + end + def test_indent_multiline_workloads_with_blank_lines + expected = "foo\n\n bar\n" + assert_equal expected, BlankLineCase.new.workload end end end From 0b465155152ff9338673c8f9fa0ee28761233a09 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:36:39 -0700 Subject: [PATCH 05/11] test generating and indenting heredocs --- lib/generator/exercise_cases.rb | 4 +++- test/generator/exercise_cases_test.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/generator/exercise_cases.rb b/lib/generator/exercise_cases.rb index ba0b58f746..22380aa0ab 100644 --- a/lib/generator/exercise_cases.rb +++ b/lib/generator/exercise_cases.rb @@ -37,7 +37,9 @@ def indent_text(depth, lines) end # generate heredoc (as part of workload) with optional indentation - def indented_heredoc(lines, delimiter, depth = 0, delimiter_method = nil) + # + # indent_heredoc(["foo", "bar"], 'TEXT', 1) + def indent_heredoc(lines, delimiter, depth = 0, delimiter_method = nil) [ "<<-#{delimiter}#{delimiter_method}", lines.map { |line| ' ' * depth + line }.join("\n"), diff --git a/test/generator/exercise_cases_test.rb b/test/generator/exercise_cases_test.rb index e2e865f48c..ededfe39e8 100644 --- a/test/generator/exercise_cases_test.rb +++ b/test/generator/exercise_cases_test.rb @@ -33,5 +33,15 @@ def test_indent_multiline_workloads_with_blank_lines expected = "foo\n\n bar\n" assert_equal expected, BlankLineCase.new.workload end + + class HeredocCase < ExerciseCase + def workload + indent_heredoc(["foo", "bar"], 'TEXT', 1) + end + end + def test_heredoc + expected = "<<-TEXT\n foo\n bar\nTEXT" + assert_equal expected, HeredocCase.new.workload + end end end From 361e425543b7113be312b162cbda0c5ca9cb3646 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:38:50 -0700 Subject: [PATCH 06/11] move assertions to their own module --- lib/generator/exercise_case/assertion.rb | 33 +++++++++++++++++++ lib/generator/exercise_cases.rb | 28 ---------------- .../generator/exercise_case/assertion_test.rb | 13 ++++++++ 3 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 lib/generator/exercise_case/assertion.rb create mode 100644 test/generator/exercise_case/assertion_test.rb diff --git a/lib/generator/exercise_case/assertion.rb b/lib/generator/exercise_case/assertion.rb new file mode 100644 index 0000000000..1231485f72 --- /dev/null +++ b/lib/generator/exercise_case/assertion.rb @@ -0,0 +1,33 @@ +module Generator + class ExerciseCase < OpenStruct + module Assertion + # e.g., + # "#{assert} Luhn.valid?(#{input.inspect})" + def assert + expected ? 'assert' : 'refute' + end + + # e.g., + # assert_equal { "PigLatin.translate(#{input.inspect})" } + def assert_equal + "assert_equal #{expected.inspect}, #{yield}" + end + + # e.g., + # if raises_error? + # assert_raises(ArgumentError) { test_case } + # else + # assert_equal { test_case } + # end + def raises_error? + expected.to_i == -1 + end + + # e.g., + # assert_raises(ArgumentError) { test_case } + def assert_raises(error) + "assert_raises(#{error}) { #{yield} }" + end + end + end +end diff --git a/lib/generator/exercise_cases.rb b/lib/generator/exercise_cases.rb index 22380aa0ab..72b271eb7f 100644 --- a/lib/generator/exercise_cases.rb +++ b/lib/generator/exercise_cases.rb @@ -46,33 +46,5 @@ def indent_heredoc(lines, delimiter, depth = 0, delimiter_method = nil) delimiter ].join("\n") end - - # e.g., - # "#{assert} Luhn.valid?(#{input.inspect})" - def assert - expected ? 'assert' : 'refute' - end - - # e.g., - # assert_equal { "PigLatin.translate(#{input.inspect})" } - def assert_equal - "assert_equal #{expected.inspect}, #{yield}" - end - - # e.g., - # if raises_error? - # assert_raises(ArgumentError) { test_case } - # else - # assert_equal { test_case } - # end - def raises_error? - expected.to_i == -1 - end - - # e.g., - # assert_raises(ArgumentError) { test_case } - def assert_raises(error) - "assert_raises(#{error}) { #{yield} }" - end end end diff --git a/test/generator/exercise_case/assertion_test.rb b/test/generator/exercise_case/assertion_test.rb new file mode 100644 index 0000000000..499154b7f3 --- /dev/null +++ b/test/generator/exercise_case/assertion_test.rb @@ -0,0 +1,13 @@ +require_relative '../../test_helper' + +module Generator + class ExerciseCase + class AssertionTest < Minitest::Test + def test_assert + test_case = OpenStruct.new(expected: true) + test_case.extend(Assertion) + assert_equal 'assert', test_case.assert + end + end + end +end From 61560db969d37430472965942d104714f17c4984 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:45:51 -0700 Subject: [PATCH 07/11] test refute --- lib/generator/exercise_case/assertion.rb | 4 ++-- test/generator/exercise_case/assertion_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/generator/exercise_case/assertion.rb b/lib/generator/exercise_case/assertion.rb index 1231485f72..7016ea9fa2 100644 --- a/lib/generator/exercise_case/assertion.rb +++ b/lib/generator/exercise_case/assertion.rb @@ -1,8 +1,8 @@ module Generator class ExerciseCase < OpenStruct module Assertion - # e.g., - # "#{assert} Luhn.valid?(#{input.inspect})" + + # "#{assert} Luhn.valid?(#{input.inspect})" def assert expected ? 'assert' : 'refute' end diff --git a/test/generator/exercise_case/assertion_test.rb b/test/generator/exercise_case/assertion_test.rb index 499154b7f3..6244050c15 100644 --- a/test/generator/exercise_case/assertion_test.rb +++ b/test/generator/exercise_case/assertion_test.rb @@ -8,6 +8,13 @@ def test_assert test_case.extend(Assertion) assert_equal 'assert', test_case.assert end + + def test_refute + test_case = OpenStruct.new(expected: false) + test_case.extend(Assertion) + assert_equal 'refute', test_case.assert + end + end end end From cf5b9d5378d8fc8c3e93c6e11b8e937a2dcde60c Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:46:26 -0700 Subject: [PATCH 08/11] test assert_equal --- test/generator/exercise_case/assertion_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/generator/exercise_case/assertion_test.rb b/test/generator/exercise_case/assertion_test.rb index 6244050c15..99b92b0f28 100644 --- a/test/generator/exercise_case/assertion_test.rb +++ b/test/generator/exercise_case/assertion_test.rb @@ -15,6 +15,12 @@ def test_refute assert_equal 'refute', test_case.assert end + def test_assert_equal + test_case = OpenStruct.new(expected: 2) + test_case.extend(Assertion) + assert_equal "assert_equal 2, 4", test_case.assert_equal { 1 + 3 } + end + end end end From 458b6f6af0aa73156762b6fe88e5b40f6ff2978c Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:46:46 -0700 Subject: [PATCH 09/11] assert raises_error? --- test/generator/exercise_case/assertion_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/generator/exercise_case/assertion_test.rb b/test/generator/exercise_case/assertion_test.rb index 99b92b0f28..8cbcb4e3ed 100644 --- a/test/generator/exercise_case/assertion_test.rb +++ b/test/generator/exercise_case/assertion_test.rb @@ -21,6 +21,17 @@ def test_assert_equal assert_equal "assert_equal 2, 4", test_case.assert_equal { 1 + 3 } end + def test_raises_error + test_case = OpenStruct.new(expected: -1) + test_case.extend(Assertion) + assert test_case.raises_error? + end + + def test_does_not_raise_error + test_case = OpenStruct.new(expected: 'cute kitties') + test_case.extend(Assertion) + refute test_case.raises_error? + end end end end From 8b43cfcfb6b6919501ab51621f5bc3f46ebe53a0 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:49:18 -0700 Subject: [PATCH 10/11] test assert_raises --- test/generator/exercise_case/assertion_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/generator/exercise_case/assertion_test.rb b/test/generator/exercise_case/assertion_test.rb index 8cbcb4e3ed..f0a3f35384 100644 --- a/test/generator/exercise_case/assertion_test.rb +++ b/test/generator/exercise_case/assertion_test.rb @@ -32,6 +32,15 @@ def test_does_not_raise_error test_case.extend(Assertion) refute test_case.raises_error? end + + def test_assert_raises + test_case = OpenStruct.new + test_case.extend(Assertion) + assert_equal( + "assert_raises(ArgumentError) { 4 }", + test_case.assert_raises(ArgumentError) { 2 + 2 } + ) + end end end end From ea4721cf8c1b8f57c8f7d9074f39e3d0e74ab3e8 Mon Sep 17 00:00:00 2001 From: Hilary Holz Date: Tue, 2 May 2017 13:50:53 -0700 Subject: [PATCH 11/11] fix style issue --- test/generator/exercise_cases_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/generator/exercise_cases_test.rb b/test/generator/exercise_cases_test.rb index ededfe39e8..116bb398d4 100644 --- a/test/generator/exercise_cases_test.rb +++ b/test/generator/exercise_cases_test.rb @@ -16,7 +16,7 @@ def test_skipped_index_nonzero class MultiLineCase < ExerciseCase def workload - indent_lines(['foo','bar'], 1) + indent_lines(['foo', 'bar'], 1) end end def test_indent_multiline_workloads