超级初学者容易点红宝石问题。我试图通过编程Project Euler问题来学习一些红宝石。所以我有一个测试
class ProjectEuler_tests < Test::Unit::TestCase
@solution = 123456 # Not the answer so as not to be a spoiler
def test_problem_1
assert_equal(@solution, ProjectEuler1.new.solve)
end
end
但这不起作用,@ solution在测试运行时为零。在课程范围内分配它的正确方法是什么?
答案 0 :(得分:6)
Class constants以大写字母开头:
class ProjectEuler_tests < Test::Unit::TestCase
SOLUTION = 123456 # Not the answer so as not to be a spoiler
def test_problem_1
assert_equal(SOLUTION, ProjectEuler1.new.solve)
end
end