Created
December 2, 2013 18:09
-
-
Save wjessop/7753737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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