문제

I am trying to create a Minitest test that tests for an instance of Infinity being returned in an array. However I am getting an uninitialized constant error. How do I check for Infinity in an array?

This is the test:

def test_lgamma
   x = 0
   z = Math.lgamma(x)
   puts z
   assert_equal [Infinity, 1], z
end

This is the error:

NameError: uninitialized constant Tests::Infinity
    .../CORE_MATH.rb:131:in `test_lgamma'
도움이 되었습니까?

해결책

It's a constant of the Float class:

assert_equal [Float::INFINITY, 1], z

If you're using a version before 1.9.2, try:

assert_equal [1.0 / 0, 1], z
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top