質問: 二次方程式を解くプログラムがあります。プログラムは実際のソリューションのみを提供します。プログラムの品質テストを実行するにはどうすればよいですか? 追加の入力パラメータについて私に尋ねる必要がありますか?
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   に答える