问题:我有一个解决二次方程的程序。该计划仅提供真正的解决方案。如何执行程序的质量测试?你需要问我一些额外的输入参数吗?
答案 0 :(得分:0)
创建测试用例,并根据测试用例中的预期结果(在外部计算)检查程序的结果。
测试用例可以包括几种普通情况,以及特殊情况,例如当系数为0或判别式<1时。 0,= 0,接近0.比较结果时,请确保正确处理比较(因为结果是浮点数)。
答案 1 :(得分: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