Skip to content

Commit

Permalink
generate pangram exercise (#279)
Browse files Browse the repository at this point in the history
* generate pangram exercise
  • Loading branch information
Cohen-Carlisle authored and kotp committed Apr 10, 2016
1 parent 27e7b1d commit ed58807
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/generate-pangram
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

require_relative '../lib/generator'
require_relative '../lib/pangram_cases'

Generator.new('pangram', PangramCases).generate
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"rna-transcription",
"raindrops",
"difference-of-squares",
"pangram",
"roman-numerals",
"robot-name",
"nth-prime",
Expand Down
1 change: 1 addition & 0 deletions exercises/pangram/.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
8 changes: 8 additions & 0 deletions exercises/pangram/example.rb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions exercises/pangram/example.tt
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions exercises/pangram/pangram_test.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions lib/pangram_cases.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ed58807

Please sign in to comment.