From 9e7166a52e94d8e15bf2dbfe00026f21f76630a9 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Wed, 18 Oct 2023 12:49:39 -0600 Subject: oct 16, 18 notes. add unit tests with utest, and bisection root finding methods --- test/lin.t.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/lin.t.c (limited to 'test/lin.t.c') diff --git a/test/lin.t.c b/test/lin.t.c new file mode 100644 index 0000000..6ad1613 --- /dev/null +++ b/test/lin.t.c @@ -0,0 +1,20 @@ +#include "lizfcm.test.h" + +UTEST(Lin, least_squares_lin_reg_perfect) { + Array_double *x = InitArray(double, {0, 1, 2, 3, 4}); + Array_double *y = InitArray(double, {1, 2, 3, 4, 5}); + + Line *line = least_squares_lin_reg(x, y); + + EXPECT_EQ(line->m, 1.0); + EXPECT_EQ(line->a, 1.0); +} + +UTEST(Lin, least_squares_lin_reg_estimate) { + Array_double *x = InitArray(double, {1, 2, 3, 4, 5, 6, 7}); + Array_double *y = InitArray(double, {0.5, 3, 2, 3.5, 5, 6, 7.5}); + + Line *line = least_squares_lin_reg(x, y); + + EXPECT_NEAR(line->m, 1.0, 0.2); +} -- cgit v1.2.3-70-g09d2