Skip to content

Instantly share code, notes, and snippets.

@wjessop
Created December 2, 2013 18:09
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 wjessop/7753737 to your computer and use it in GitHub Desktop.
Save wjessop/7753737 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
class TestWords < Minitest::Test
def test_that_similar_words_are_found
assert_equal one_off_words("moor", ["door", "moot", "boot", "boots"]), ["door", "moot"]
end
def test_fake_failure
assert_equal one_off_words("moor", ["door", "moot", "boot", "boots"]), ["door", "moot", "fuckers"]
end
end
def one_off_words(str, word_list)
word_list.select do |word|
if word.size == str.size
compare_chars = (0...word.size).map {|i| word[i] == str[i]}
compare_chars.count(false) == 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment