diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-18 12:49:39 -0600 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-18 12:49:39 -0600 |
commit | 9e7166a52e94d8e15bf2dbfe00026f21f76630a9 (patch) | |
tree | bb4d7114d5f91fa128375347ab4249a4c35408f2 /test/roots.t.c | |
parent | 1b4d91e623a083690ac6554d1aeaa38b75469908 (diff) | |
download | cmath-9e7166a52e94d8e15bf2dbfe00026f21f76630a9.tar.gz cmath-9e7166a52e94d8e15bf2dbfe00026f21f76630a9.zip |
oct 16, 18 notes. add unit tests with utest, and bisection root finding methods
Diffstat (limited to 'test/roots.t.c')
-rw-r--r-- | test/roots.t.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/roots.t.c b/test/roots.t.c new file mode 100644 index 0000000..632832a --- /dev/null +++ b/test/roots.t.c @@ -0,0 +1,17 @@ +#include "lizfcm.test.h" +#include <stdio.h> + +double g(double x) { return x * x - 9; } + +UTEST(ivt, find_interval) { + double *range = find_ivt_range(&g, -100.0, 1.0, 200); + EXPECT_LT(g(range[0]) * g(range[1]), 0); + + free(range); +} + +UTEST(root, bisection_with_error_assumption) { + double root = bisect_find_root_with_error_assumption(&g, -5, 0, 0.01); + + EXPECT_NEAR(-3, root, 0.01); +} |