mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 00:05:33 +03:00
Adding the first unit test to verify battery voltage calculations based
on expected ADC readings.
This commit is contained in:
parent
b0cc4df73f
commit
f268c9c4f2
5 changed files with 29834 additions and 0 deletions
60
test/battery_unittest.cc
Normal file
60
test/battery_unittest.cc
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include "battery.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
typedef struct batteryAdcToVoltageExpectation_s {
|
||||
uint16_t adcReading;
|
||||
uint16_t expectedVoltageInDeciVoltSteps;
|
||||
} batteryAdcToVoltageExpectation_t;
|
||||
|
||||
#define ELEVEN_TO_ONE_VOLTAGE_DIVIDER 110 // (10k:1k) * 10 for 0.1V
|
||||
|
||||
TEST(BatteryTest, BatteryADCToVoltage)
|
||||
{
|
||||
// given
|
||||
|
||||
batteryConfig_t batteryConfig;
|
||||
batteryConfig.vbatscale = ELEVEN_TO_ONE_VOLTAGE_DIVIDER;
|
||||
|
||||
batteryInit(&batteryConfig);
|
||||
|
||||
batteryAdcToVoltageExpectation_t batteryAdcToVoltageExpectations[] = {
|
||||
{1420, 125},
|
||||
{1430, 126},
|
||||
{1440, 127},
|
||||
{1890, 167},
|
||||
{1900, 168},
|
||||
{1910, 169}
|
||||
};
|
||||
uint8_t testIterationCount = sizeof(batteryAdcToVoltageExpectations) / sizeof(batteryAdcToVoltageExpectation_t);
|
||||
|
||||
// expect
|
||||
|
||||
for (uint8_t index = 0; index < testIterationCount; index ++) {
|
||||
batteryAdcToVoltageExpectation_t *batteryAdcToVoltageExpectation = &batteryAdcToVoltageExpectations[index];
|
||||
printf("adcReading: %d\n", batteryAdcToVoltageExpectation->adcReading);
|
||||
|
||||
uint16_t pointOneVoltSteps = batteryAdcToVoltage(batteryAdcToVoltageExpectation->adcReading);
|
||||
|
||||
EXPECT_EQ(pointOneVoltSteps, batteryAdcToVoltageExpectation->expectedVoltageInDeciVoltSteps);
|
||||
}
|
||||
}
|
||||
|
||||
// STUBS
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
|
||||
uint16_t adcGetChannel(uint8_t channel)
|
||||
{
|
||||
UNUSED(channel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void delay(uint32_t ms)
|
||||
{
|
||||
UNUSED(ms);
|
||||
return;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue