Skip to content

Commit

Permalink
Merge pull request #483 from Insti/panagram_failure_messages
Browse files Browse the repository at this point in the history
Pangram: Add failure messages to tests
  • Loading branch information
kotp authored Nov 21, 2016
2 parents d05dc36 + 34df08f commit 2a359c0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 39 deletions.
2 changes: 1 addition & 1 deletion exercises/pangram/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2
3
4 changes: 2 additions & 2 deletions exercises/pangram/example.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module BookKeeping
VERSION = 2
VERSION = 3
end

class Pangram
def self.is_pangram?(str)
def self.pangram?(str)
downcased_str = str.downcase
('a'..'z').all? { |letter| downcased_str.include?(letter) }
end
Expand Down
12 changes: 5 additions & 7 deletions exercises/pangram/example.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'pangram'

# Test data version:
# <%= sha1 %>
# 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 %>
def <%= test_case.name %>
<%= test_case.skipped? %>
<%= test_case.workload %>
end
<% end %>
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
def test_bookkeeping
skip
Expand Down
55 changes: 30 additions & 25 deletions exercises/pangram/pangram_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,66 @@
require 'minitest/autorun'
require_relative 'pangram'

# Test data version:
# deb225e Implement canonical dataset for scrabble-score problem (#255)

# Test data version: # 2adfe21
class PangramTest < Minitest::Test
def test_sentence_empty
str = ''
refute Pangram.is_pangram?(str)
# skip
phrase = ''
refute Pangram.pangram?(phrase), "#{phrase.inspect} is NOT a pangram"
end

def test_pangram_with_only_lower_case
skip
str = 'the quick brown fox jumps over the lazy dog'
assert Pangram.is_pangram?(str)
phrase = 'the quick brown fox jumps over the lazy dog'
assert Pangram.pangram?(phrase), "#{phrase.inspect} IS a pangram"
end

def test_missing_character_x
skip
str = 'a quick movement of the enemy will jeopardize five gunboats'
refute Pangram.is_pangram?(str)
phrase = 'a quick movement of the enemy will jeopardize five gunboats'
refute Pangram.pangram?(phrase), "#{phrase.inspect} is NOT a pangram"
end

def test_another_missing_character_x
skip
str = 'the quick brown fish jumps over the lazy dog'
refute Pangram.is_pangram?(str)
phrase = 'the quick brown fish jumps over the lazy dog'
refute Pangram.pangram?(phrase), "#{phrase.inspect} is NOT a pangram"
end

def test_pangram_with_underscores
skip
str = 'the_quick_brown_fox_jumps_over_the_lazy_dog'
assert Pangram.is_pangram?(str)
phrase = 'the_quick_brown_fox_jumps_over_the_lazy_dog'
assert Pangram.pangram?(phrase), "#{phrase.inspect} IS a pangram"
end

def test_pangram_with_numbers
skip
str = 'the 1 quick brown fox jumps over the 2 lazy dogs'
assert Pangram.is_pangram?(str)
phrase = 'the 1 quick brown fox jumps over the 2 lazy dogs'
assert Pangram.pangram?(phrase), "#{phrase.inspect} IS a pangram"
end

def test_missing_letters_replaced_by_numbers
skip
str = '7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog'
refute Pangram.is_pangram?(str)
phrase = '7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog'
refute Pangram.pangram?(phrase), "#{phrase.inspect} is NOT a pangram"
end

def test_pangram_with_mixed_case_and_punctuation
skip
str = '"Five quacking Zephyrs jolt my wax bed."'
assert Pangram.is_pangram?(str)
phrase = '"Five quacking Zephyrs jolt my wax bed."'
assert Pangram.pangram?(phrase), "#{phrase.inspect} IS a pangram"
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)
phrase = 'Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.'
assert Pangram.pangram?(phrase), "#{phrase.inspect} IS a pangram"
end

def test_panagram_in_alphabet_other_than_ascii
skip
phrase = 'Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства.'
refute Pangram.pangram?(phrase), "#{phrase.inspect} is NOT a pangram"
end

# Problems in exercism evolve over time, as we find better ways to ask
Expand All @@ -67,18 +72,18 @@ def test_pangram_with_non_ascii_characters
# not your solution.
#
# Define a constant named VERSION inside of the top level BookKeeping
# module.
# In your file, it will look like this:
# module, which may be placed near the end of your file.
#
# In your file, it will look like this:
#
# module BookKeeping
# VERSION = 1 # Where the version number matches the one in the test.
# end
#
# 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 2, BookKeeping::VERSION
assert_equal 3, BookKeeping::VERSION
end
end
23 changes: 19 additions & 4 deletions lib/pangram_cases.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
class PangramCase < OpenStruct
def name
'test_%s' % description.delete("'").gsub(/[ -]/, '_')
'test_%s' % description.downcase.tr_s(" -'", '_').sub(/_$/,'')
end

def do
'Pangram.is_pangram?(str)'
def workload
[
"phrase = '#{input}'\n",
" #{assertion} Pangram.pangram?(phrase), \"#{message}\""
].join
end

def message
"\#{phrase.inspect} #{is_or_isnt} a pangram"
end

def is_or_isnt
expected ? 'IS' : 'is NOT'
end

def assertion
expected ? 'assert' : 'refute'
end

def skipped?
index > 0
index.zero? ? '# skip' : 'skip'
end
end

Expand Down

0 comments on commit 2a359c0

Please sign in to comment.