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/approx_derivative.t.c | |
| parent | 1b4d91e623a083690ac6554d1aeaa38b75469908 (diff) | |
| download | math-4610-9e7166a52e94d8e15bf2dbfe00026f21f76630a9.tar.gz math-4610-9e7166a52e94d8e15bf2dbfe00026f21f76630a9.zip | |
oct 16, 18 notes. add unit tests with utest, and bisection root finding methods
Diffstat (limited to 'test/approx_derivative.t.c')
| -rw-r--r-- | test/approx_derivative.t.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/approx_derivative.t.c b/test/approx_derivative.t.c new file mode 100644 index 0000000..6bcac79 --- /dev/null +++ b/test/approx_derivative.t.c @@ -0,0 +1,32 @@ +#include "lizfcm.test.h" + +double f(double x) { return x * x; } + +double f_prime(double x) { return 2 * x; } + +double H = 0.0001; +double ACCEPTED_DERIVATIVE_ERROR = 0.0001; + +UTEST(derivative, central) { + double a = 3.0; + double expected = f_prime(a); + double f_prime_x = central_derivative_at(&f, a, H); + + EXPECT_NEAR(expected, f_prime_x, ACCEPTED_DERIVATIVE_ERROR); +} + +UTEST(derivative, forward) { + double a = 3.0; + double expected = f_prime(a); + double f_prime_x = forward_derivative_at(&f, a, H); + + EXPECT_NEAR(expected, f_prime_x, ACCEPTED_DERIVATIVE_ERROR); +} + +UTEST(derivative, backward) { + double a = 3.0; + double expected = f_prime(a); + double f_prime_x = backward_derivative_at(&f, a, H); + + EXPECT_NEAR(expected, f_prime_x, ACCEPTED_DERIVATIVE_ERROR); +} |
