-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
test_stft.cpp
93 lines (71 loc) · 2.49 KB
/
test_stft.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "pch.h"
#include "closed_loop_fuel_cell.h"
#include "closed_loop_fuel.h"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
class MockClCell : public ClosedLoopFuelCellBase {
public:
MOCK_METHOD(float, getLambdaError, (), (const));
MOCK_METHOD(float, getMaxAdjustment, (), (const));
MOCK_METHOD(float, getMinAdjustment, (), (const));
MOCK_METHOD(float, getIntegratorGain, (), (const));
};
TEST(ClosedLoopCell, TestDeadband) {
StrictMock<MockClCell> cl;
// Error is more than deadtime, so nothing else should be called
EXPECT_CALL(cl, getLambdaError())
.WillOnce(Return(0.05f));
cl.update(0.1f, true);
// Should be zero adjustment
EXPECT_FLOAT_EQ(cl.getAdjustment(), 1.0f);
}
TEST(ClosedLoopFuelCell, AdjustRate) {
StrictMock<MockClCell> cl;
EXPECT_CALL(cl, getLambdaError())
.WillOnce(Return(0.1f));
EXPECT_CALL(cl, getMinAdjustment())
.WillOnce(Return(-0.2f));
EXPECT_CALL(cl, getMaxAdjustment())
.WillOnce(Return(0.2f));
EXPECT_CALL(cl, getIntegratorGain())
.WillOnce(Return(2.0f));
cl.update(0.0f, false);
// Should have integrated 0.2 * dt
// dt = 1000.0f / FAST_CALLBACK_PERIOD_MS
EXPECT_FLOAT_EQ(cl.getAdjustment(), 1 + (0.2f / (1000.0f / FAST_CALLBACK_PERIOD_MS)));
}
TEST(ClosedLoopFuel, CellSelection) {
stft_s cfg;
// Sensible region config
cfg.maxIdleRegionRpm = 1500;
cfg.minPowerLoad = 80;
cfg.maxOverrunLoad = 30;
// Test idle
EXPECT_EQ(0, computeStftBin(1000, 10, cfg));
EXPECT_EQ(0, computeStftBin(1000, 50, cfg));
EXPECT_EQ(0, computeStftBin(1000, 90, cfg));
// Test overrun
EXPECT_EQ(1, computeStftBin(2000, 10, cfg));
EXPECT_EQ(1, computeStftBin(4000, 10, cfg));
EXPECT_EQ(1, computeStftBin(10000, 10, cfg));
// Test load
EXPECT_EQ(2, computeStftBin(2000, 90, cfg));
EXPECT_EQ(2, computeStftBin(4000, 90, cfg));
EXPECT_EQ(2, computeStftBin(10000, 90, cfg));
// Main cell
EXPECT_EQ(3, computeStftBin(2000, 50, cfg));
EXPECT_EQ(3, computeStftBin(4000, 50, cfg));
EXPECT_EQ(3, computeStftBin(10000, 50, cfg));
}
TEST(ClosedLoopFuel, afrLimits) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
engineConfiguration->stft.minAfr = 10; // 10.0 AFR
engineConfiguration->stft.maxAfr = 18; // 18.0 AFR
Sensor::setMockValue(SensorType::Lambda1, 0.1f);
EXPECT_FALSE(shouldUpdateCorrection(SensorType::Lambda1));
Sensor::setMockValue(SensorType::Lambda1, 1.0f);
EXPECT_TRUE(shouldUpdateCorrection(SensorType::Lambda1));
Sensor::setMockValue(SensorType::Lambda1, 2.0f);
EXPECT_FALSE(shouldUpdateCorrection(SensorType::Lambda1));
}