ruby - pangram
This commit is contained in:
parent
0e1e6a0d9c
commit
d16fe6a02a
39
ruby/pangram/README.md
Normal file
39
ruby/pangram/README.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# Pangram
|
||||||
|
|
||||||
|
Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma,
|
||||||
|
"every letter") is a sentence using every letter of the alphabet at least once.
|
||||||
|
The best known English pangram is:
|
||||||
|
> The quick brown fox jumps over the lazy dog.
|
||||||
|
|
||||||
|
The alphabet used consists of ASCII letters `a` to `z`, inclusive, and is case
|
||||||
|
insensitive. Input will not contain non-ASCII symbols.
|
||||||
|
|
||||||
|
* * * *
|
||||||
|
|
||||||
|
For installation and learning resources, refer to the
|
||||||
|
[Ruby resources page](http://exercism.io/languages/ruby/resources).
|
||||||
|
|
||||||
|
For running the tests provided, you will need the Minitest gem. Open a
|
||||||
|
terminal window and run the following command to install minitest:
|
||||||
|
|
||||||
|
gem install minitest
|
||||||
|
|
||||||
|
If you would like color output, you can `require 'minitest/pride'` in
|
||||||
|
the test file, or note the alternative instruction, below, for running
|
||||||
|
the test file.
|
||||||
|
|
||||||
|
Run the tests from the exercise directory using the following command:
|
||||||
|
|
||||||
|
ruby pangram_test.rb
|
||||||
|
|
||||||
|
To include color from the command line:
|
||||||
|
|
||||||
|
ruby -r minitest/pride pangram_test.rb
|
||||||
|
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
Wikipedia [https://en.wikipedia.org/wiki/Pangram](https://en.wikipedia.org/wiki/Pangram)
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
8
ruby/pangram/pangram.rb
Normal file
8
ruby/pangram/pangram.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Pangram class
|
||||||
|
class Pangram
|
||||||
|
def self.pangram?(sentence)
|
||||||
|
sentence.downcase!
|
||||||
|
('a'..'z').each { |char| return false unless sentence.include?(char) }
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
75
ruby/pangram/pangram_test.rb
Normal file
75
ruby/pangram/pangram_test.rb
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
require 'minitest/autorun'
|
||||||
|
require_relative 'pangram'
|
||||||
|
|
||||||
|
# Common test data version: 1.4.1 2c020bc
|
||||||
|
class PangramTest < Minitest::Test
|
||||||
|
def test_sentence_empty
|
||||||
|
# skip
|
||||||
|
sentence = ''
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
refute result, "Expected false, got: #{result.inspect}. #{sentence.inspect} is NOT a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_recognizes_a_perfect_lower_case_pangram
|
||||||
|
# skip
|
||||||
|
sentence = 'abcdefghijklmnopqrstuvwxyz'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
assert result, "Expected true, got: #{result.inspect}. #{sentence.inspect} IS a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pangram_with_only_lower_case
|
||||||
|
# skip
|
||||||
|
sentence = 'the quick brown fox jumps over the lazy dog'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
assert result, "Expected true, got: #{result.inspect}. #{sentence.inspect} IS a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_missing_character_x
|
||||||
|
# skip
|
||||||
|
sentence = 'a quick movement of the enemy will jeopardize five gunboats'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
refute result, "Expected false, got: #{result.inspect}. #{sentence.inspect} is NOT a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_missing_character_h
|
||||||
|
# skip
|
||||||
|
sentence = 'five boxing wizards jump quickly at it'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
refute result, "Expected false, got: #{result.inspect}. #{sentence.inspect} is NOT a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pangram_with_underscores
|
||||||
|
# skip
|
||||||
|
sentence = 'the_quick_brown_fox_jumps_over_the_lazy_dog'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
assert result, "Expected true, got: #{result.inspect}. #{sentence.inspect} IS a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pangram_with_numbers
|
||||||
|
# skip
|
||||||
|
sentence = 'the 1 quick brown fox jumps over the 2 lazy dogs'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
assert result, "Expected true, got: #{result.inspect}. #{sentence.inspect} IS a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_missing_letters_replaced_by_numbers
|
||||||
|
# skip
|
||||||
|
sentence = '7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
refute result, "Expected false, got: #{result.inspect}. #{sentence.inspect} is NOT a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pangram_with_mixed_case_and_punctuation
|
||||||
|
# skip
|
||||||
|
sentence = '"Five quacking Zephyrs jolt my wax bed."'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
assert result, "Expected true, got: #{result.inspect}. #{sentence.inspect} IS a pangram"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_upper_and_lower_case_versions_of_the_same_character_should_not_be_counted_separately
|
||||||
|
# skip
|
||||||
|
sentence = 'the quick brown fox jumps over with lazy FX'
|
||||||
|
result = Pangram.pangram?(sentence)
|
||||||
|
refute result, "Expected false, got: #{result.inspect}. #{sentence.inspect} is NOT a pangram"
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user