Skip to content

Commit

Permalink
Merge pull request #853 from Insti/bundled_regenerated_tests
Browse files Browse the repository at this point in the history
All exercises: Update generators and regenerate tests
  • Loading branch information
Insti authored Sep 9, 2018
2 parents 908ee77 + a29491c commit da99101
Show file tree
Hide file tree
Showing 119 changed files with 2,018 additions and 2,001 deletions.
4 changes: 1 addition & 3 deletions exercises/acronym/.meta/generator/acronym_case.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'generator/exercise_case'

class AcronymCase < Generator::ExerciseCase

def workload
assert_equal { "Acronym.abbreviate('#{phrase}')" }
assert_equal(expected, "Acronym.abbreviate('#{phrase}')")
end

end
14 changes: 7 additions & 7 deletions exercises/acronym/acronym_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require_relative 'acronym'

# Common test data version: 1.1.0 cae7ae1
# Common test data version: 1.4.0 dc9a5af
class AcronymTest < Minitest::Test
def test_basic
# skip
Expand All @@ -18,18 +18,18 @@ def test_punctuation
assert_equal "FIFO", Acronym.abbreviate('First In, First Out')
end

def test_all_caps_words
def test_all_caps_word
skip
assert_equal "PHP", Acronym.abbreviate('PHP: Hypertext Preprocessor')
assert_equal "GIMP", Acronym.abbreviate('GNU Image Manipulation Program')
end

def test_non_acronym_all_caps_word
def test_punctuation_without_whitespace
skip
assert_equal "GIMP", Acronym.abbreviate('GNU Image Manipulation Program')
assert_equal "CMOS", Acronym.abbreviate('Complementary metal-oxide semiconductor')
end

def test_hyphenated
def test_very_long_abbreviation
skip
assert_equal "CMOS", Acronym.abbreviate('Complementary metal-oxide semiconductor')
assert_equal "ROTFLSHTMDCOALM", Acronym.abbreviate('Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me')
end
end
49 changes: 17 additions & 32 deletions exercises/affine-cipher/.meta/generator/affine_cipher_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,29 @@ def workload

private

def error_expected?
Hash === expected && expected.key?('error')
end

def key_a
input['key']['a']
end

def key_b
input['key']['b']
end

def encode_workload
indent_lines(
[
"cipher = Affine.new(#{key_a}, #{key_b})",
"plaintext = '#{input['phrase']}'",
"ciphertext = '#{expected}'",
"assert_equal ciphertext, cipher.encode(plaintext)"
], 4
)
[
"cipher = #{new_cipher}\n",
"plaintext = '#{phrase}'\n",
"ciphertext = '#{expected}'\n",
"assert_equal ciphertext, cipher.encode(plaintext)\n"
].join
end

def decode_workload
indent_lines(
[
"cipher = Affine.new(#{key_a}, #{key_b})",
"ciphertext = '#{input['phrase']}'",
"plaintext = '#{expected}'",
"assert_equal plaintext, cipher.decode(ciphertext)"
], 4
)
[
"cipher = #{new_cipher}\n",
"ciphertext = '#{phrase}'\n",
"plaintext = '#{expected}'\n",
"assert_equal plaintext, cipher.decode(ciphertext)\n"
].join
end

def error_workload
indent_text(
4,
"assert_raises(ArgumentError) { Affine.new(#{key_a}, #{key_b}) }"
)
"assert_raises(ArgumentError) { #{new_cipher} }\n"
end

def new_cipher
"Affine.new(#{key['a']}, #{key['b']})"
end
end
75 changes: 25 additions & 50 deletions exercises/all-your-base/.meta/generator/all_your_base_case.rb
Original file line number Diff line number Diff line change
@@ -1,73 +1,48 @@
require 'generator/exercise_case'

class AllYourBaseCase < Generator::ExerciseCase

def workload
indent_text(4, (assignments + assertion).join("\n"))
assignments + assertion
end

private

def assignments
[
"digits = #{input_digits}",
"input_base = #{input_base}",
"output_base = #{output_base}",
]
end

def assertion
return error_assertion unless expected_value

[
"expected = #{expected_value}",
"",
"converted = BaseConverter.convert(input_base, digits, output_base)",
"",
"assert_equal expected, converted,",
indent_text(13, error_message),
]
end

def error_assertion
[
"",
"assert_raises ArgumentError do",
" BaseConverter.convert(input_base, digits, output_base)",
"end",
"digits = #{input_digits}",
"input_base = #{input_base}",
"output_base = #{output_base}"
]
end

def error_message
%q( "Input base: #{input_base}, output base #{output_base}. " \\) \
"\n" + %q("Expected #{expected} but got #{converted}.")
end

def expected_value
return expected if expected

case
when invalid_input_digits? || invalid_bases? then nil
when input_digits.empty? then []
when input_of_zero? then [0]
def assertion
if error_expected?
[error_assertion]
else
handle_special_cases
standard_assertion
end
end

def invalid_input_digits?
input_digits.any? { |x| x < 0 || x >= input_base }
end

def invalid_bases?
input_base <= 1 || output_base <= 1
def standard_assertion
[
"expected = #{expected}",
'',
'converted = BaseConverter.convert(input_base, digits, output_base)',
'',
"hint = #{hint}",
'',
'assert_equal expected, converted, hint',
]
end

def input_of_zero?
input_digits.all? { |x| x == 0 }
def hint
[
"\"Input base: #{input_base}, output base #{output_base}. \" +\n",
indent_by(7, %q("Expected #{expected} but got #{converted}.") + "\n")
].join
end

def handle_special_cases
[4, 2] if input_digits == [0, 6, 0]
def error_assertion
assert_raises(ArgumentError, 'BaseConverter.convert(input_base, digits, output_base)')
end
end
2 changes: 1 addition & 1 deletion exercises/all-your-base/.meta/solutions/all_your_base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class BaseConverter
def self.convert(base_from, number_array, base_to)
fail ArgumentError if invalid_inputs?(base_from, number_array, base_to)
return [] unless number_array.any?
return [0] unless number_array.any?
number_in_canonical_base = convert_to_canonical_base(number_array, base_from)
convert_from_canonical_base(number_in_canonical_base, base_to)
end
Expand Down
Loading

0 comments on commit da99101

Please sign in to comment.