问题:我有一个求解二次方程的程序。该程序仅提供真正的解决方案。如何执行程序的质量测试?你需要问我一些额外的输入参数吗?
问问题
656 次
2 回答
1
创建测试用例,并根据测试用例中的预期结果(外部计算)检查程序的结果。
测试用例可以涵盖几种普通情况,也可以包括特殊情况,比如当系数为0,或判别式<0,=0,接近0。当你比较结果时,一定要正确处理比较(因为结果是浮点数)。
于 2012-07-09T03:54:03.447 回答
0
# "quadratic-rb.rb" Code by RRB, dated April 2014. email ab_z@yahoo.com
class Quadratic
def input
print "Enter the value of a: "
$a = gets.to_f
print "Enter the value of b: "
$b = gets.to_f
print "Enter the value of c: "
$c = gets.to_f
end
def announcement #Method to display Equation
puts "The formula is " + $a.to_s + "x^2 + " + $b.to_s + "x + " + $c.to_s + "=0"
end
def result #Method to solve the equation and display answer
if ($b**2-4*$a*$c)>0
x1=(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a))
x2=(-(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a)))
puts "The values of x1 and x2 are " +x1.to_s + " and " + x2.to_s
else
puts "x1 and x2 are imaginary numbers"
end
end
Quadratic_solver = Quadratic.new
Quadratic_solver.input
Quadratic_solver.announcement
Quadratic_solver.result
end
于 2014-04-07T16:10:10.693 回答