【发布时间】:2014-04-08 00:10:10
【问题描述】:
问题:我有一个求解二次方程的程序。该程序仅提供真正的解决方案。如何执行程序的质量测试?你需要问我一些额外的输入参数吗?
【问题讨论】:
-
欢迎来到 Stack Overflow。目前还不清楚你在这里问什么。如果您花一些时间使问题更加清晰和具体,您的问题将更有可能得到回答。
问题:我有一个求解二次方程的程序。该程序仅提供真正的解决方案。如何执行程序的质量测试?你需要问我一些额外的输入参数吗?
【问题讨论】:
创建测试用例,并根据测试用例中的预期结果(外部计算)检查程序的结果。
测试用例可以涵盖几种普通情况,也可以包括特殊情况,比如当系数为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
【讨论】: