From 74f4f992802b7c92749675f4ee7e2059ffceab90 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Tue, 1 Jul 2014 15:38:19 +0200 Subject: [PATCH] Added regresion test for FrskyValueWithMin averaging algorithm --- radio/src/tests/gtests.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/radio/src/tests/gtests.cpp b/radio/src/tests/gtests.cpp index da6230ad8..02c800a9a 100644 --- a/radio/src/tests/gtests.cpp +++ b/radio/src/tests/gtests.cpp @@ -334,6 +334,36 @@ TEST(FrSkySPORT, checkCrc) } #endif + +#if defined(FRSKY) && defined(CPUARM) +TEST(FrSky, FrskyValueWithMinAveraging) +{ + /* + The following expected[] array is filled + with values that correspond to 4 elements + long averaging buffer. + If length of averaging buffer is changed, this + values must be adjusted + */ + uint8_t expected[] = { 10, 12, 17, 25, 35, 45, 55, 65, 75, 85, 92, 97, 100, 100, 100, 100, 100}; + int testPos = 0; + //test of averaging + FrskyValueWithMin testVal; + testVal.value = 0; + testVal.set(10); + EXPECT_EQ(testVal.value, expected[testPos++]); + for(int n=2; n<10; ++n) { + testVal.set(n*10); + EXPECT_EQ(testVal.value, expected[testPos++]); + } + for(int n=2; n<10; ++n) { + testVal.set(100); + EXPECT_EQ(testVal.value, expected[testPos++]); + } +} +#endif + + #if !defined(PCBTARANIS) TEST(getSwitch, undefCSW) {