질문 : 저는 2 차 방정식을 풀 수있는 프로그램을 가지고 있습니다. 이 프로그램은 실제 솔루션 만 제공합니다. 프로그램의 품질 테스트는 어떻게 수행합니까? 몇 가지 추가 입력 매개 변수에 대해 묻고 싶습니까?2 차 방정식
Q
2 차 방정식
-1
A
답변
0
테스트 케이스를 작성하고 테스트 케이스에서 예상 결과 (외부 적으로 계산 됨)에 대해 프로그램 결과를 점검하십시오.
테스트 사례는 계수가 0이거나 판별자가 < 0 = 0 인 0과 같은 특수한 경우와 함께 여러 가지 일반적인 경우를 포함 할 수 있습니다. 결과를 비교할 때 (결과가 부동 소수점 수이기 때문에) 비교가 적절하다.
0
# "quadratic-rb.rb" Code by RRB, dated April 2014. email [email protected]
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
스택 오버플로에 오신 것을 환영합니다. 당신이 여기서 무엇을 요구하고 있는지 분명하지 않습니다. 질문을 명확하고 구체적으로하기 위해 시간을 할애하면 답을 얻을 수있는 더 좋은 기회가 될 것입니다. – FatalError