summaryrefslogtreecommitdiffstats
path: root/test/linear_weighted_ma.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
committerEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
commit07e18043145f3d91c8ea7ec3ad41b3c905585277 (patch)
tree2bdeae46973f4bdfce263679a4008ac768011f28 /test/linear_weighted_ma.c
initial commit: ts time series analysis library v0.1.0
- 354 financial and mathematical time-series indicators - Uniform C11 API with consistent function signatures - 349 passing tests with -Werror - Static and shared library builds - pkg-config integration - Python bindings - Fuzzing and sanitizer support - Security hardening flags
Diffstat (limited to 'test/linear_weighted_ma.c')
-rw-r--r--test/linear_weighted_ma.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/linear_weighted_ma.c b/test/linear_weighted_ma.c
new file mode 100644
index 0000000..5c7b212
--- /dev/null
+++ b/test/linear_weighted_ma.c
@@ -0,0 +1,23 @@
+#include <stddef.h>
+#include "ts.h"
+
+bool ts_test_linear_weighted_ma( void )
+{
+ fp_t const x0[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+
+ fp_t const * const x[] = { x0 };
+
+ /* LMA with k=5: weights 1..5, sum_weights = 15
+ * y[4] = (1*1 + 2*2 + 3*3 + 4*4 + 5*5) / 15 = (1+4+9+16+25)/15 = 55/15 = 3.666667
+ * y[5] = (1*2 + 2*3 + 3*4 + 4*5 + 5*6) / 15 = (2+6+12+20+30)/15 = 70/15 = 4.666667
+ * y[6] = (1*3 + 2*4 + 3*5 + 4*6 + 5*7) / 15 = (3+8+15+24+35)/15 = 85/15 = 5.666667
+ * y[7] = (1*4 + 2*5 + 3*6 + 4*7 + 5*8) / 15 = (4+10+18+28+40)/15 = 100/15 = 6.666667
+ * y[8] = (1*5 + 2*6 + 3*7 + 4*8 + 5*9) / 15 = (5+12+21+32+45)/15 = 115/15 = 7.666667
+ * y[9] = (1*6 + 2*7 + 3*8 + 4*9 + 5*10) / 15 = (6+14+24+36+50)/15 = 130/15 = 8.666667
+ */
+ fp_t const e[] = { 3.666667, 4.666667, 5.666667, 6.666667, 7.666667, 8.666667 };
+ fp_t const * const exp[] = { e };
+
+ uint_t c = 5;
+ return ts_test(ts_linear_weighted_ma, ts_linear_weighted_ma_offset, x, exp, 10, (ts_constant_t *)&c, &ts_linear_weighted_ma_p);
+}