| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | ||||
| 2 | #include "pch.h" | |||
| 3 | // todo: should we unify code with deadband.h? | |||
| 4 | ||||
| 5 | template <typename T> | |||
| 6 | class StickyValue { | |||
| 7 | public: | |||
| 8 | 6 | T get(T currentValue, T deadbandThreshold) { | ||
| 9 | // If we're within the deadband, be "sticky" with the previous value | |||
| 10 | 6 | T absError = absF(currentValue - m_lastValue); | ||
| 11 | ||||
| 12 | if (std::is_same<T,float>::value) { | |||
| 13 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 5 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 5 times.
|
6 | if (std::isnan(currentValue)) |
| 14 | 1 | return currentValue; | ||
| 15 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 5 times.
|
5 | if (std::isnan(m_lastValue)) |
| 16 | ✗ | m_lastValue = currentValue; | ||
| 17 | } | |||
| 18 | ||||
| 19 | // use current value if there's enough error | |||
| 20 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
2/2✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 2 times.
|
5 | if (absError > deadbandThreshold) { |
| 21 | 3 | m_lastValue = currentValue; | ||
| 22 | } | |||
| 23 | ||||
| 24 | 5 | return m_lastValue; | ||
| 25 | } | |||
| 26 | ||||
| 27 | private: | |||
| 28 | T m_lastValue = 0; | |||
| 29 | }; | |||
| 30 | ||||
| 31 | ||||
| 32 | 4 | TEST(Sticky, PPS) { | ||
| 33 | 1 | StickyValue<float> pps; | ||
| 34 | ||||
| 35 | 1 | float threshold = 0.5; | ||
| 36 | ||||
| 37 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(1, pps.get(1, threshold)); | |
| 38 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(1, pps.get(1.2, threshold)); | |
| 39 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(1, pps.get(0.8, threshold)); | |
| 40 |
2/6✓ Branch 3 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
|
1 | EXPECT_NEAR(2.2, pps.get(2.2, threshold), EPS4D); | |
| 41 | ||||
| 42 | 1 | float expectedNaN = pps.get(NAN, threshold); | ||
| 43 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(std::isnan(expectedNaN)); | |
| 44 | ||||
| 45 |
2/6✓ Branch 3 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
|
1 | EXPECT_NEAR(33, pps.get(33, threshold), EPS4D); | |
| 46 | 1 | } | ||
| 47 |