summaryrefslogtreecommitdiffstats
path: root/test/fill_indicator.c
blob: 071c24546d346bab12aa1afdfd6e8bdaf41b8f86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <math.h>
#include <stddef.h>
#include "ts.h"

bool ts_test_fill_indicator( void )
{
    uint_t k = 3;

    fp_t const o[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
    fp_t const h[] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
    fp_t const l[] = { 8,  10, 10, 11, 12, 13, 14, 15, 16, 17 };
    fp_t const c[] = { 11, 12, 10, 14, 15, 16, 14, 18, 17, 20 };

    fp_t const * const x[] = { o, h, l, c };

    /* fill values:
     * i=0: |11-10|/(12-8)*100 = 1/4*100 = 25
     * i=1: |12-11|/(13-10)*100 = 1/3*100 = 33.333
     * i=2: |10-12|/(14-10)*100 = 2/4*100 = 50
     * i=3: |14-13|/(15-11)*100 = 1/4*100 = 25
     * i=4: |15-14|/(16-12)*100 = 1/4*100 = 25
     * i=5: |16-15|/(17-13)*100 = 1/4*100 = 25
     * i=6: |14-16|/(18-14)*100 = 2/4*100 = 50
     * i=7: |18-17|/(19-15)*100 = 1/4*100 = 25
     * i=8: |17-18|/(20-16)*100 = 1/4*100 = 25
     * i=9: |20-19|/(21-17)*100 = 1/4*100 = 25
     * SMA(3): i=2: (25+33.333+50)/3 = 36.111
     *         i=3: 36.111 + (25-25)/3 = 36.111
     *         i=4: 36.111 + (25-33.333)/3 = 33.333
     *         i=5: 33.333 + (25-50)/3 = 25
     *         i=6: 25 + (50-25)/3 = 33.333
     *         i=7: 33.333 + (25-25)/3 = 33.333
     *         i=8: 33.333 + (25-25)/3 = 33.333
     *         i=9: 33.333 + (25-50)/3 = 25
     */
    fp_t const e[] = { 36.11111, 36.11111, 33.33333, 25, 33.33333, 33.33333, 33.33333, 25 };
    fp_t const * const exp[1] = { e };

    return ts_test(ts_fill_indicator, ts_fill_indicator_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)&k, &ts_fill_indicator_p);
}