diff --git a/bin/generate-pangram b/bin/generate-pangram new file mode 100755 index 0000000000..0b41a81e68 --- /dev/null +++ b/bin/generate-pangram @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby + +require_relative '../lib/generator' +require_relative '../lib/pangram_cases' + +Generator.new('pangram', PangramCases).generate diff --git a/config.json b/config.json index b129b69fdd..b5d7cc2ad4 100644 --- a/config.json +++ b/config.json @@ -10,6 +10,7 @@ "rna-transcription", "raindrops", "difference-of-squares", + "pangram", "roman-numerals", "robot-name", "nth-prime", diff --git a/exercises/pangram/.version b/exercises/pangram/.version new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/exercises/pangram/.version @@ -0,0 +1 @@ +1 diff --git a/exercises/pangram/example.rb b/exercises/pangram/example.rb new file mode 100644 index 0000000000..fabe316606 --- /dev/null +++ b/exercises/pangram/example.rb @@ -0,0 +1,8 @@ +class Pangram + VERSION = 1 + + def self.is_pangram?(str) + downcased_str = str.downcase + ('a'..'z').all? { |letter| downcased_str.include?(letter) } + end +end diff --git a/exercises/pangram/example.tt b/exercises/pangram/example.tt new file mode 100644 index 0000000000..3efb678461 --- /dev/null +++ b/exercises/pangram/example.tt @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby +gem 'minitest', '>= 5.0.0' +require 'minitest/autorun' +require_relative 'pangram' + +# Test data version: +# <%= sha1 %> +class PangramTest < Minitest::Test<% test_cases.each do |test_case| %> + def <%= test_case.name %><% if test_case.skipped? %> + skip<% end %> + str = '<%= test_case.input %>'<% if test_case.expected %> + assert<% else %> + refute<% end %> <%= test_case.do %> + end +<% end %> + # Problems in exercism evolve over time, + # as we find better ways to ask questions. + # The version number refers to the version of the problem you solved, + # not your solution. + # + # Define a constant named VERSION inside of Pangram. + # If you are curious, read more about constants on RubyDoc: + # http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html + def test_bookkeeping + skip + assert_equal <%= version+1 %>, Pangram::VERSION + end +end diff --git a/exercises/pangram/pangram_test.rb b/exercises/pangram/pangram_test.rb new file mode 100755 index 0000000000..3daf2d4399 --- /dev/null +++ b/exercises/pangram/pangram_test.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby +gem 'minitest', '>= 5.0.0' +require 'minitest/autorun' +require_relative 'pangram' + +# Test data version: +# 180638f Merge pull request #217 from ErikSchierboom/patch-2 + +class PangramTest < Minitest::Test + def test_sentence_empty + str = '' + refute Pangram.is_pangram?(str) + end + + def test_pangram_with_only_lower_case + skip + str = 'the quick brown fox jumps over the lazy dog' + assert Pangram.is_pangram?(str) + end + + def test_missing_character_x + skip + str = 'a quick movement of the enemy will jeopardize five gunboats' + refute Pangram.is_pangram?(str) + end + + def test_pangram_with_mixed_case_and_punctuation + skip + str = '"Five quacking Zephyrs jolt my wax bed."' + assert Pangram.is_pangram?(str) + end + + def test_pangram_with_non_ascii_characters + skip + str = 'Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.' + assert Pangram.is_pangram?(str) + end + + # Problems in exercism evolve over time, + # as we find better ways to ask questions. + # The version number refers to the version of the problem you solved, + # not your solution. + # + # Define a constant named VERSION inside of Pangram. + # If you are curious, read more about constants on RubyDoc: + # http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html + def test_bookkeeping + skip + assert_equal 1, Pangram::VERSION + end +end diff --git a/lib/pangram_cases.rb b/lib/pangram_cases.rb new file mode 100644 index 0000000000..4e6ebd7549 --- /dev/null +++ b/lib/pangram_cases.rb @@ -0,0 +1,19 @@ +class PangramCase < OpenStruct + def name + 'test_%s' % description.delete("'").gsub(/[ -]/, '_') + end + + def do + 'Pangram.is_pangram?(str)' + end + + def skipped? + index > 0 + end +end + +PangramCases = proc do |data| + JSON.parse(data)['cases'].map.with_index do |row, i| + PangramCase.new(row.merge('index' => i)) + end +end