Hi i am learning to write test-cases, I started small test-cases for small programs.Iam trying a program
require 'test/unit'
class YearTest < Test::Unit::TestCase
def test_hours(m)
p = Year.new
assert_equal(p.hours,开发者_C百科m)
# assert_equal(p.hours,8784)
end
end
class Year
def hours(a)
d = 24
if (a%400 == 0)
return h = d * 366
else
return h = d * 365
end
puts h
end
end
puts "enter a year"
n = gets.to_i
y = Year.new
y.hours(n)
and when i run this program in netbeans am getting error in test-case..can anybody help in solving this??
Your test case needs to specify a particular case; it's not intended to be done interactively as you are trying to do.
Something like this would do:
require 'test/unit'
class YearTest < Test::Unit::TestCase
def test_hours
y = Year.new
assert_equal 8760, y.hours(2001)
assert_equal 8784, y.hours(1996)
end
end
精彩评论