Skip to content

Instantly share code, notes, and snippets.

@artkirienko
Last active July 7, 2020 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artkirienko/cf57d6b5764d5cb3c87d18535dd41a79 to your computer and use it in GitHub Desktop.
Save artkirienko/cf57d6b5764d5cb3c87d18535dd41a79 to your computer and use it in GitHub Desktop.
# coderpad test
# https://coderpad.io/
# click Try Sandbox
# choose Ruby
# paste:
# Determine if a word or phrase is an isogram.
# An isogram (also known as a "nonpattern word") is a word or phrase
# without a repeating letter, however spaces and hyphens are allowed
# to appear multiple times.
# Examples of isograms:
# lumberjacks
# background
# downstream
# six-year-old
# The word isograms, however, is not an isogram, because the s repeats.
class Isogram
end
require 'minitest/autorun'
class IsogramTest < Minitest::Test
def test_empty_string
# skip
input = ""
assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram"
end
def test_isogram_with_only_lower_case_characters
skip
input = "isogram"
assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram"
end
def test_word_with_one_duplicated_character
skip
input = "eleven"
refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram"
end
def test_word_with_one_duplicated_character_from_the_end_of_the_alphabet
skip
input = "zzyzx"
refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram"
end
def test_longest_reported_english_isogram
skip
input = "subdermatoglyphic"
assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram"
end
def test_word_with_duplicated_character_in_mixed_case
skip
input = "Alphabet"
refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram"
end
def test_word_with_duplicated_character_in_mixed_case_lowercase_first
skip
input = "alphAbet"
refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram"
end
def test_hypothetical_isogrammic_word_with_hyphen
skip
input = "thumbscrew-japingly"
assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram"
end
def test_hypothetical_word_with_duplicated_character_following_hyphen
skip
input = "thumbscrew-jappingly"
refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram"
end
def test_isogram_with_duplicated_hyphen
skip
input = "six-year-old"
assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram"
end
def test_made_up_name_that_is_an_isogram
skip
input = "Emily Jung Schwartzkopf"
assert Isogram.isogram?(input), "Expected true, '#{input}' is an isogram"
end
def test_duplicated_character_in_the_middle
skip
input = "accentor"
refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram"
end
def test_same_first_and_last_characters
skip
input = "angola"
refute Isogram.isogram?(input), "Expected false, '#{input}' is not an isogram"
end
end
class Isogram
class << self
# @param phrase [String] a word or phrase
# @return [Boolean] if a word or phrase is an isogram
def isogram?(phrase)
base = phrase.downcase.tr(' -', '')
base.chars.count == base.chars.uniq.count
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment