diff --git a/.gitignore b/.gitignore index 1e969baca04cb3ba3ec5e427e1993da28da2ba41..4cdb46707f622e46a93208d5e20fe4a9d2161a74 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ src/quad_solver *.o *.out *.tar.gz +*.tmp # Ignore spike compiled files. spikes/ieee_floating_point/float diff --git a/readme.md b/readme.md index 65097b2a31e65f5f45e984d766b7383889372d24..76d2ce587ec2a7128960062b3b68af29d4a638fe 100644 --- a/readme.md +++ b/readme.md @@ -11,13 +11,13 @@ A console program to solve quadratic equations. See program help for more detail ## Building and Running -To build, change to the `src` directory and run: +To build run: $ make Now you can run the program and see the help text: - $ ./quad_solver -h + $ src/quad_solver -h For development, you should use valgrind. First install valgrind if not installed: @@ -29,4 +29,16 @@ Then to build and run valgrind on the executable, run: Valgrind will report pointers that were allocated but not freed. -TODO: Finish writing the source files in the src directory. +## Distributing + +To create a .tar.gz of source files run: + + $ make distribute + +The file will be named quad-solver-<VERSION>.tar.gz + +## Testing + +To run all the tests: + + $ make test \ No newline at end of file diff --git a/src/compute.c b/src/compute.c index 0cd7d8d530052d8f569f0b4dd833d289b9fa4cb7..03acbdcad049548046d0bc0e303dcbcf9a2d2d6a 100644 --- a/src/compute.c +++ b/src/compute.c @@ -70,7 +70,7 @@ int calculate_roots(double a, double b, double c, COMPUTATION_STRUCT **root1, CO r1 = (-b - rooted) / (2 * a); r2 = c / (a * r1); } else { - if (my_sqrt(c / a, &r1) != 0) { + if (my_sqrt(-(c / a), &r1) != 0) { code_error_quit("Invalid parameters"); } r2 = -r1; diff --git a/tests/integration_tests/Makefile b/tests/integration_tests/Makefile index a9cbc78e791e341f32341fca0d251993ae482c6b..b4f8789d0b485fb4d0fbe6b7e6d202dfeffef17a 100644 --- a/tests/integration_tests/Makefile +++ b/tests/integration_tests/Makefile @@ -7,11 +7,12 @@ all: default # This will always run make in src quad_solver: - cd $(SRC_DIR); make + make -C $(SRC_DIR) test_int_all: quad_solver ./test_ranges.sh $(SRC_DIR) + ./test_examples.sh $(SRC_DIR) # Clean does nothing for now clean: - @: + rm -f *.tmp diff --git a/tests/integration_tests/expected_1_-3_-4.txt b/tests/integration_tests/expected_1_-3_-4.txt new file mode 100644 index 0000000000000000000000000000000000000000..f6dff0c8f1644409d6fbd625802218b1a09b85a0 --- /dev/null +++ b/tests/integration_tests/expected_1_-3_-4.txt @@ -0,0 +1,15 @@ + +Please enter A B C. +: Received floats: +A: 1.0000000000E+00 +B: -3.0000000000E+00 +C: -4.0000000000E+00 +Calculating 1.0E+00x^2 + -3.0E+00x + -4.0E+00 = 0. +Results: + r1: 4.0000000000E+00 + + r2: -1.0000000000E+00 + + Inexact: No + +Exiting program with code of 0. diff --git a/tests/integration_tests/expected_1_-7_0.txt b/tests/integration_tests/expected_1_-7_0.txt new file mode 100644 index 0000000000000000000000000000000000000000..54999ae710ebf7cd90218492f0c0acc84dfb67a4 --- /dev/null +++ b/tests/integration_tests/expected_1_-7_0.txt @@ -0,0 +1,15 @@ + +Please enter A B C. +: Received floats: +A: 1.0000000000E+00 +B: -7.0000000000E+00 +C: 0.0000000000E+00 +Calculating 1.0E+00x^2 + -7.0E+00x + 0.0E+00 = 0. +Results: + r1: 7.0000000000E+00 + + r2: 0.0000000000E+00 + + Inexact: No + +Exiting program with code of 0. diff --git a/tests/integration_tests/expected_1_0_-4.txt b/tests/integration_tests/expected_1_0_-4.txt new file mode 100644 index 0000000000000000000000000000000000000000..a1defa61544060c3b5ab405e4aca71eb1ad2a22b --- /dev/null +++ b/tests/integration_tests/expected_1_0_-4.txt @@ -0,0 +1,15 @@ + +Please enter A B C. +: Received floats: +A: 1.0000000000E+00 +B: 0.0000000000E+00 +C: -4.0000000000E+00 +Calculating 1.0E+00x^2 + 0.0E+00x + -4.0E+00 = 0. +Results: + r1: 2.0000000000E+00 + + r2: -2.0000000000E+00 + + Inexact: No + +Exiting program with code of 0. diff --git a/tests/integration_tests/expected_1_0_-48.txt b/tests/integration_tests/expected_1_0_-48.txt new file mode 100644 index 0000000000000000000000000000000000000000..be0f3d17cad47962175438f0b06184a9bfe0679a --- /dev/null +++ b/tests/integration_tests/expected_1_0_-48.txt @@ -0,0 +1,15 @@ + +Please enter A B C. +: Received floats: +A: 1.0000000000E+00 +B: 0.0000000000E+00 +C: -4.8000000000E+01 +Calculating 1.0E+00x^2 + 0.0E+00x + -4.8E+01 = 0. +Results: + r1: 6.9282032303E+00 + + r2: -6.9282032303E+00 + + Inexact: Yes + +Exiting program with code of 0. diff --git a/tests/integration_tests/expected_1_0_4.txt b/tests/integration_tests/expected_1_0_4.txt new file mode 100644 index 0000000000000000000000000000000000000000..ad3b94aa04b4453eefdc177bd44fd3557167b386 --- /dev/null +++ b/tests/integration_tests/expected_1_0_4.txt @@ -0,0 +1,15 @@ + +Please enter A B C. +: Received floats: +A: 1.0000000000E+00 +B: 0.0000000000E+00 +C: 4.0000000000E+00 +Calculating 1.0E+00x^2 + 0.0E+00x + 4.0E+00 = 0. +Results: + r1: Imaginary + + r2: Imaginary + + Inexact: No + +Exiting program with code of 0. diff --git a/tests/integration_tests/expected_5_6_1.txt b/tests/integration_tests/expected_5_6_1.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f44a5563ce3e006d3b96ccdc4100b9d48b916cb --- /dev/null +++ b/tests/integration_tests/expected_5_6_1.txt @@ -0,0 +1,15 @@ + +Please enter A B C. +: Received floats: +A: 5.0000000000E+00 +B: 6.0000000000E+00 +C: 1.0000000000E+00 +Calculating 5.0E+00x^2 + 6.0E+00x + 1.0E+00 = 0. +Results: + r1: -1.0000000000E+00 + + r2: -2.0000000000E-01 + + Inexact: Yes + +Exiting program with code of 0. diff --git a/tests/integration_tests/expected_6_11_-35.txt b/tests/integration_tests/expected_6_11_-35.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d8668227c4b4a521ea8ce60571456ea4a684b88 --- /dev/null +++ b/tests/integration_tests/expected_6_11_-35.txt @@ -0,0 +1,15 @@ + +Please enter A B C. +: Received floats: +A: 6.0000000000E+00 +B: 1.1000000000E+01 +C: -3.5000000000E+01 +Calculating 6.0E+00x^2 + 1.1E+01x + -3.5E+01 = 0. +Results: + r1: -3.5000000000E+00 + + r2: 1.6666666667E+00 + + Inexact: Yes + +Exiting program with code of 0. diff --git a/tests/integration_tests/test_examples.sh b/tests/integration_tests/test_examples.sh new file mode 100755 index 0000000000000000000000000000000000000000..666ba26a0793c1ab3c9e5dcb1410e0a12770acc3 --- /dev/null +++ b/tests/integration_tests/test_examples.sh @@ -0,0 +1,52 @@ +#!/bin/bash +SRC_DIR="$1" + + +$SRC_DIR/quad_solver <<< "5 6 1" > out.tmp && \ +diff out.tmp expected_5_6_1.txt + +if [ $? != 0 ]; then + echo "Failed on: 5 6 1" +fi + +$SRC_DIR/quad_solver <<< "1 -3 -4" > out.tmp && \ +diff out.tmp expected_1_-3_-4.txt + +if [ $? != 0 ]; then + echo "Failed on: 1 -3 -4" +fi + +$SRC_DIR/quad_solver <<< "1 0 -4" > out.tmp && \ +diff out.tmp expected_1_0_-4.txt + +if [ $? != 0 ]; then + echo "Failed on: 1 0 -4" +fi + +$SRC_DIR/quad_solver <<< "1 0 4" > out.tmp && \ +diff out.tmp expected_1_0_4.txt + +if [ $? != 0 ]; then + echo "Failed on: 1 0 4" +fi + +$SRC_DIR/quad_solver <<< "6 11 -35" > out.tmp && \ +diff out.tmp expected_6_11_-35.txt + +if [ $? != 0 ]; then + echo "Failed on: 6 11 -35" +fi + +$SRC_DIR/quad_solver <<< "1 0 -48" > out.tmp && \ +diff out.tmp expected_1_0_-48.txt + +if [ $? != 0 ]; then + echo "Failed on: 1 0 -48" +fi + +$SRC_DIR/quad_solver <<< "1 -7 0" > out.tmp && \ +diff out.tmp expected_1_-7_0.txt + +if [ $? != 0 ]; then + echo "Failed on: 1 -7 0" +fi \ No newline at end of file diff --git a/tests/readme.md b/tests/readme.md index ae55afffb5b416f2187f4673c948ce0bf0baf2ee..24bc06a043c587ee2d5f308e0622752fe7543435 100644 --- a/tests/readme.md +++ b/tests/readme.md @@ -2,6 +2,11 @@ # C - Quadratic Solver > Tests ## Description -Unit tests go here. +Unit Tests go in the unit_tests folder. +Integration Tests go in the integration_tests folder. + +You can run the following to run all tests: + + $ make test NOTE: Valgrind doesn't support floating point errors. If used with cunit, it may causes tests to fail.