Super-beginner easy points ruby question. I'm trying to learn some ruby by programming the Project Euler problems. So I have a test
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
But this doesn't work, @solution is nil when the test runs. What is the proper way to assign it at the class scope?
Class constants in ruby start with an uppercase char:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With