| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | ||||
| 3 | #include "error_accumulator.h" | |||
| 4 | ||||
| 5 | 4 | TEST(errorAccumulator, ignoreSmallError) { | ||
| 6 | 1 | ErrorAccumulator dut; | ||
| 7 | 1 | dut.init(5, 0.01); | ||
| 8 | ||||
| 9 |
2/2✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 1000000 times.
✓ Decision 'false' taken 1 time.
|
1000001 | for (size_t i = 0; i < 1'000'000; i++) { |
| 10 | // An error just below the threshold should never trip | |||
| 11 |
4/9✓ Branch 3 taken 1000000 times.
✓ Branch 7 taken 1000000 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1000000 times.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 31 taken 1000000 times.
✗ Branch 32 not taken.
|
1000000 | ASSERT_EQ(0, dut.accumulate(4)); | |
| 12 | } | |||
| 13 | } | |||
| 14 | ||||
| 15 | 4 | TEST(errorAccumulator, integrateError) { | ||
| 16 | 1 | ErrorAccumulator dut; | ||
| 17 | 1 | dut.init(5, 0.01); | ||
| 18 | ||||
| 19 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 100 times.
✓ Decision 'false' taken 1 time.
|
101 | for (size_t i = 0; i < 100; i++) { |
| 20 | // error of 1 over the ignore value | |||
| 21 |
1/1✓ Branch 1 taken 100 times.
|
100 | dut.accumulate(6); | |
| 22 | } | |||
| 23 | ||||
| 24 | // Integral should be 1 * dt * 100 = 1.0 | |||
| 25 |
3/8✓ 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.
✓ Branch 25 taken 1 time.
✗ Branch 26 not taken.
|
1 | ASSERT_NEAR(dut.getAccumulator(), 1, 0.001f); | |
| 26 | } | |||
| 27 | ||||
| 28 | 4 | TEST(errorAccumulator, integrateNegativeError) { | ||
| 29 | 1 | ErrorAccumulator dut; | ||
| 30 | 1 | dut.init(5, 0.01); | ||
| 31 | ||||
| 32 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 100 times.
✓ Decision 'false' taken 1 time.
|
101 | for (size_t i = 0; i < 100; i++) { |
| 33 | // error of 1 over the ignore value, but negative | |||
| 34 |
1/1✓ Branch 1 taken 100 times.
|
100 | dut.accumulate(-6); | |
| 35 | } | |||
| 36 | ||||
| 37 | // Integral should be 1 * dt * 100 = 1.0 | |||
| 38 |
3/8✓ 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.
✓ Branch 25 taken 1 time.
✗ Branch 26 not taken.
|
1 | ASSERT_NEAR(dut.getAccumulator(), 1, 0.001f); | |
| 39 | } | |||
| 40 | ||||
| 41 | TEST(errorAccumulator, integrateErrorBothSigns) { | |||
| 42 | ErrorAccumulator dut; | |||
| 43 | dut.init(5, 0.01); | |||
| 44 | ||||
| 45 | for (size_t i = 0; i < 100; i++) { | |||
| 46 | // These should collectively integrate 1 * dt worth of error | |||
| 47 | dut.accumulate(-5.5); | |||
| 48 | dut.accumulate(5.5); | |||
| 49 | } | |||
| 50 | ||||
| 51 | // Integral should be 2 * 0.5 * dt * 100 = 1.0 | |||
| 52 | ASSERT_NEAR(dut.getAccumulator(), 1, 0.001f); | |||
| 53 | } | |||
| 54 |