diff options
| author | Ethan Werner <mail@ethanwerner.com> | 2026-07-01 09:42:39 +0400 |
|---|---|---|
| committer | Ethan Werner <mail@ethanwerner.com> | 2026-07-01 09:42:39 +0400 |
| commit | 07e18043145f3d91c8ea7ec3ad41b3c905585277 (patch) | |
| tree | 2bdeae46973f4bdfce263679a4008ac768011f28 /test/zigzag.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/zigzag.c')
| -rw-r--r-- | test/zigzag.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/zigzag.c b/test/zigzag.c new file mode 100644 index 0000000..890a1f0 --- /dev/null +++ b/test/zigzag.c @@ -0,0 +1,29 @@ +#include <math.h> +#include <stddef.h> +#include "ts.h" + +bool ts_test_zigzag( void ) +{ + /* threshold=5% */ + /* Prices: 100, 102, 104, 108, 110, 105, 95, 90, 94, 98 */ + fp_t const x[] = { 100, 102, 104, 108, 110, 105, 95, 90, 94, 98 }; + + fp_t const * const inp[1] = { x }; + + /* i=0: zz=100, dir=0 */ + /* i=1: change=(102-100)/100*100=2% < 5%, no change */ + /* i=2: change=4% < 5%, no change */ + /* i=3: change=8% >= 5%, zz=108, dir=1 */ + /* i=4: change=(110-108)/108*100=1.85% < 5%, no change */ + /* i=5: change=(105-108)/108*100=-2.78% > -5%, no change */ + /* i=6: change=(95-108)/108*100=-12.04% <= -5%, zz=95, dir=-1 */ + /* i=7: change=(90-95)/95*100=-5.26% <= -5%, zz=90, dir=-1 */ + /* i=8: change=(94-90)/90*100=4.44% < 5%, no change */ + /* i=9: change=(98-90)/90*100=8.89% >= 5%, zz=98, dir=1 */ + fp_t const ezz[] = { 100, 100, 100, 108, 108, 108, 95, 95, 95, 95 }; + fp_t const ed[] = { 0, 0, 0, 1, 1, 1, -1, -1, -1, -1 }; + fp_t const * const exp[2] = { ezz, ed }; + + fp_t threshold = 5; + return ts_test(ts_zigzag, ts_zigzag_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&threshold, &ts_zigzag_p); +} |