add quadratic tests
This commit is contained in:
parent
4b54877ee9
commit
53914aebfa
|
|
@ -119,8 +119,14 @@ UTEST_F_TEARDOWN(InterpreterTestFile) {
|
|||
|
||||
UTEST_F(InterpreterTestFile, helloworld) {
|
||||
utest_fixture->test_file = "samples/hello-world.cbl";
|
||||
utest_fixture->print_file = "samples/hello-world_print.txt";
|
||||
utest_fixture->evaluated_file = "samples/hello-world_evaluate.txt";
|
||||
utest_fixture->print_file = "samples/outputs/hello-world_print.txt";
|
||||
utest_fixture->evaluated_file = "samples/outputs/hello-world_evaluate.txt";
|
||||
}
|
||||
|
||||
UTEST_F(InterpreterTestFile, quadratic) {
|
||||
utest_fixture->test_file = "samples/quadratic-snippet.cbl";
|
||||
utest_fixture->print_file = "samples/outputs/quadratic_print.txt";
|
||||
utest_fixture->evaluated_file = "samples/outputs/quadratic_evaluate.txt";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
EQUATION: (1x^2) + 5x + 6 = 0
|
||||
The equation has two distinct real roots:
|
||||
Root 1: -2
|
||||
Root 2: -3
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
section
|
||||
section
|
||||
section
|
||||
section
|
||||
a = ();
|
||||
b = ();
|
||||
c = ();
|
||||
discriminant = ();
|
||||
root1 = ();
|
||||
root2 = ();
|
||||
square-root-discriminant = ();
|
||||
section
|
||||
print EQUATION: (1x^2) + 5x + 6 = 0;
|
||||
compute discriminant = ((b**2)-(4*(a*c)));
|
||||
if (discriminant>0) then
|
||||
compute square-root-discriminant = FUNCTION SQRT discriminant;
|
||||
compute root1 = ((-b+square-root-discriminant)/(2*a));
|
||||
compute root2 = ((-b-square-root-discriminant)/(2*a));
|
||||
print The equation has two distinct real roots: ;
|
||||
print Root 1: root1;
|
||||
print Root 2: root2;
|
||||
endif
|
||||
else if then
|
||||
if (discriminant==0) then
|
||||
compute root1 = (-b/(2*a));
|
||||
print The equation has one real root: ;
|
||||
print Root: root1;
|
||||
endif
|
||||
else if then
|
||||
print The equation has no real roots.;
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
stop run
|
||||
Loading…
Reference in New Issue