Avatar of PatrickMcSweeny
0
0
Genius
0
0

PatrickMcSweeny's solution

to Isogram in the Ruby Track

0
0
Genius
0
0
Instructions
Test suite
Solution

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.


For installation and learning resources, refer to the Ruby resources page.

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 isogram_test.rb

To include color from the command line:

ruby -r minitest/pride isogram_test.rb

Source

Wikipedia https://en.wikipedia.org/wiki/Isogram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

isogram_test.rb

require 'minitest/autorun'
require_relative 'isogram'

# Common test data version: 1.6.0 7cea153
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_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
  def self.isogram?(input)
    input = input.downcase.scan /\w/
    input.size == input.uniq.size
  end
end

What can you learn from this solution?

A huge amount can be learnt from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that I could read more about to develop my understanding?