Host C Specs


Directory: src/c/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 26 / 0 / 26
Functions: 100.0% 2 / 0 / 2
Branches: 100.0% 18 / 0 / 18

core/math/series.c
Line Branch Exec Source
1 /**
2 * @file series.c
3 * @brief Reducing a run of samples to the few numbers a chart draws from.
4 *
5 * @ingroup lib_core
6 */
7 #include "math/series.h"
8
9 4 int series_range(const uint8_t *samples, int count, uint8_t no_sample,
10 int *lo, int *hi, int *last)
11 {
12 4 int lo_val = 0;
13 4 int hi_val = 0;
14 4 int last_val = 0;
15 4 int valid = 0;
16
17
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 4 times.
19 for (int i = 0; i < count; i++)
18 {
19 15 int value = samples[i];
20
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 7 times.
15 if (value == no_sample)
21 {
22 8 continue;
23 }
24
25
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 3 times.
7 if (valid == 0 || value < lo_val)
26 {
27 4 lo_val = value;
28 }
29
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
7 if (valid == 0 || value > hi_val)
30 {
31 6 hi_val = value;
32 }
33 7 last_val = value; // slots run oldest to newest, so the last real one is the most recent
34 7 valid++;
35 }
36
37
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
4 if (valid > 0)
38 {
39 3 *lo = lo_val;
40 3 *hi = hi_val;
41 3 *last = last_val;
42 }
43 4 return valid;
44 }
45
46 2 int series_max_u16(const uint16_t *values, int count)
47 {
48 2 int hi = 0;
49
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int i = 0; i < count; i++)
50 {
51
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (values[i] > hi)
52 {
53 2 hi = values[i];
54 }
55 }
56 2 return hi;
57 }
58