【发布时间】:2016-02-07 08:35:57
【问题描述】:
我正在尝试完成一个 exercism.io 测试文件,该文件比较两个字符串并在每次两个字符串之间存在差异时将一个添加到计数器中。我已经编写了我的课程,但由于某种原因它不会在终端中运行。我已经将我的代码与几个在线语法示例进行了比较,但不明白为什么它不会运行。任何帮助将不胜感激。
这是我的课:
class Hamming
def compute(str1, str2)
distance = 0
length = str1.length
for i in 0..length
if str1[i] != str2[i] then
distance++
end
end
return distance
end
end
这是一个相关的测试文件:
class HammingTest < Minitest::Test
def test_identical_strands
assert_equal 0, Hamming.compute('A', 'A')
end
end
最后,这是我得到的错误:
hamming_test.rb:4:in `require_relative': /Users/Jack/exercism/ruby/hamming/hamming.rb:8: syntax error, unexpected keyword_end (SyntaxError)
/Users/Jack/exercism/ruby/hamming/hamming.rb:12: syntax error, unexpected end-of-input, expecting keyword_end
from hamming_test.rb:4:in `<main>'
【问题讨论】:
-
试过了。没有骰子!
标签: ruby string function class compare