rusefi-1/unit_tests/tests/trigger/test_map_cam.cpp

72 lines
1.6 KiB
C++
Raw Normal View History

2021-11-24 18:53:32 -08:00
#include "pch.h"
2021-11-24 19:36:36 -08:00
#include "trigger_central.h"
2021-11-24 18:53:32 -08:00
static int getZigZag(int index) {
index = index % 1000;
if (index < 400) {
// going up from 0 to 400
return index;
}
if (index < 500) {
// going down from 400 to 300
return 800 - index;
}
if (index < 600) {
// going up from 300 to 400
return index - 200;
}
// going down from 400 to 0
return 1000 - index;
}
TEST(trigger, map_cam) {
EngineTestHelper eth(TEST_ENGINE);
2021-11-24 18:53:32 -08:00
engineConfiguration->mapCamAveragingLength = 8;
2021-11-24 18:53:32 -08:00
MapState state;
int i = 0;
for (;i<403;i++) {
2021-11-24 18:53:32 -08:00
state.add(getZigZag(i));
if (state.mapBuffer.getCount() > engineConfiguration->mapCamAveragingLength) {
ASSERT_FALSE(state.isPeak(false)) << "high At " << i;
ASSERT_FALSE(state.isPeak(true)) << "low At " << i;
2021-11-24 18:53:32 -08:00
}
}
state.add(getZigZag(i));
ASSERT_FALSE(state.isPeak(false)) << "high At " << i;
ASSERT_FALSE(state.isPeak(true)) << "low At " << i;
i++;
state.add(getZigZag(i));
ASSERT_TRUE(state.isPeak(false)) << "high At " << i;
ASSERT_FALSE(state.isPeak(true)) << "low At " << i;
for (;i<504;i++) {
state.add(getZigZag(i));
ASSERT_FALSE(state.isPeak(false)) << "high At " << i;
ASSERT_FALSE(state.isPeak(true)) << "low At " << i;
}
state.add(getZigZag(i));
ASSERT_FALSE(state.isPeak(false)) << "high At " << i;
ASSERT_TRUE(state.isPeak(true)) << "low At " << i;
i++;
2021-11-24 18:53:32 -08:00
for (;i<604;i++) {
state.add(getZigZag(i));
ASSERT_FALSE(state.isPeak(false)) << "high At " << i;
ASSERT_FALSE(state.isPeak(true)) << "low At " << i;
2021-11-24 18:53:32 -08:00
}
state.add(getZigZag(i));
ASSERT_TRUE(state.isPeak(false)) << "high At " << i;
ASSERT_TRUE(state.isPeak(false)) << "low At " << i;
2021-11-24 18:53:32 -08:00
}