light refactoring

This commit is contained in:
kifir 2024-06-13 01:51:41 +03:00 committed by rusefillc
parent b4098fed2c
commit 2434f3a14b
1 changed files with 84 additions and 90 deletions

View File

@ -66,27 +66,6 @@ namespace {
setSatisfyActivationSwithSpeedAndTpsConditions(satifySwitchSpeedThresholdAndTpsConditions);
}
static void setUpTestParameters() {
for (int loadIdx = 0; loadIdx < IGN_LOAD_COUNT; loadIdx++) {
config->ignitionTable[loadIdx][0] = TEST_IGNITION_650;
config->ignitionTable[loadIdx][1] = TEST_IGNITION_800;
config->ignitionTable[loadIdx][2] = TEST_IGNITION_1100;
config->ignitionTable[loadIdx][3] = TEST_IGNITION_1400;
config->ignitionTable[loadIdx][4] = TEST_IGNITION_1700;
config->ignitionTable[loadIdx][5] = TEST_IGNITION_2000;
config->ignitionTable[loadIdx][6] = TEST_IGNITION_2300;
config->ignitionTable[loadIdx][7] = TEST_IGNITION_2600;
config->ignitionTable[loadIdx][8] = TEST_IGNITION_2900;
config->ignitionTable[loadIdx][9] = TEST_IGNITION_3200;
config->ignitionTable[loadIdx][10] = TEST_IGNITION_3500;
config->ignitionTable[loadIdx][11] = TEST_IGNITION_3800;
config->ignitionTable[loadIdx][12] = TEST_IGNITION_4100;
config->ignitionTable[loadIdx][13] = TEST_IGNITION_4400;
config->ignitionTable[loadIdx][14] = TEST_IGNITION_4700;
config->ignitionTable[loadIdx][15] = TEST_IGNITION_7000;
}
}
struct IgnitionAngleAdvanceTestData {
const std::string context;
const int rpm;
@ -101,18 +80,16 @@ namespace {
const std::vector<IgnitionAngleAdvanceTestData> &testData
);
/* Checks that angle advance is not affected by `Launch Control` functionality: */
void checkAngleAdvanceWithoutLaunchControl(
const std::optional<bool> launchControlEnabled = {},
const std::optional<bool> enableLaunchRetard = {},
const std::optional<bool> launchSmoothRetard = {}
);
static const std::vector<IgnitionAngleAdvanceTestData> TEST_DATA_WITHOUT_LAUNCH_ANGLE_ADVANCE;
private:
void configureTestIgnitionTable();
};
void IgnitionAngleAdvanceTest::doTest(
const IgnitionAngleAdvanceTestConfig& config,
const std::vector<IgnitionAngleAdvanceTestData> &testData
) {
configureTestIgnitionTable();
setUpTestConfig(config);
for (const IgnitionAngleAdvanceTestData &testDataItem: testData) {
@ -125,21 +102,7 @@ namespace {
}
}
void IgnitionAngleAdvanceTest::checkAngleAdvanceWithoutLaunchControl(
const std::optional<bool> launchControlEnabled,
const std::optional<bool> enableLaunchRetard,
const std::optional<bool> launchSmoothRetard
) {
setUpTestParameters();
doTest(
/* config = */ {
/* launchControlEnabled = */ launchControlEnabled,
/* ignitionRetardEnable = */ enableLaunchRetard,
/* smoothRetardMode = */ launchSmoothRetard,
/* satifySwitchSpeedThresholdAndTpsConditions = */ true
},
/* testData = */ {
const std::vector<IgnitionAngleAdvanceTestData> IgnitionAngleAdvanceTest::TEST_DATA_WITHOUT_LAUNCH_ANGLE_ADVANCE = {
{ "TEST_IGNITION_650", 650, TEST_IGNITION_650 },
{ "TEST_IGNITION_800", 800, TEST_IGNITION_800 },
{ "TEST_IGNITION_1100", 1100, TEST_IGNITION_1100 },
@ -161,17 +124,42 @@ namespace {
{ "TEST_IGNITION_4400", 4400, TEST_IGNITION_4400 },
{ "TEST_IGNITION_4700", 4700, TEST_IGNITION_4700 },
{ "TEST_IGNITION_7000", 7000, TEST_IGNITION_7000 }
};
void IgnitionAngleAdvanceTest::configureTestIgnitionTable() {
for (int loadIdx = 0; loadIdx < IGN_LOAD_COUNT; loadIdx++) {
config->ignitionTable[loadIdx][0] = TEST_IGNITION_650;
config->ignitionTable[loadIdx][1] = TEST_IGNITION_800;
config->ignitionTable[loadIdx][2] = TEST_IGNITION_1100;
config->ignitionTable[loadIdx][3] = TEST_IGNITION_1400;
config->ignitionTable[loadIdx][4] = TEST_IGNITION_1700;
config->ignitionTable[loadIdx][5] = TEST_IGNITION_2000;
config->ignitionTable[loadIdx][6] = TEST_IGNITION_2300;
config->ignitionTable[loadIdx][7] = TEST_IGNITION_2600;
config->ignitionTable[loadIdx][8] = TEST_IGNITION_2900;
config->ignitionTable[loadIdx][9] = TEST_IGNITION_3200;
config->ignitionTable[loadIdx][10] = TEST_IGNITION_3500;
config->ignitionTable[loadIdx][11] = TEST_IGNITION_3800;
config->ignitionTable[loadIdx][12] = TEST_IGNITION_4100;
config->ignitionTable[loadIdx][13] = TEST_IGNITION_4400;
config->ignitionTable[loadIdx][14] = TEST_IGNITION_4700;
config->ignitionTable[loadIdx][15] = TEST_IGNITION_7000;
}
);
}
TEST_F(IgnitionAngleAdvanceTest, withEnabledLaunchControlAndWithoutLaunchRetard) {
checkAngleAdvanceWithoutLaunchControl();
doTest(
/* config = */ {
/* launchControlEnabled = */ {},
/* ignitionRetardEnable = */ {},
/* smoothRetardMode = */ {},
/* satifySwitchSpeedThresholdAndTpsConditions = */ true
},
/* testData = */ TEST_DATA_WITHOUT_LAUNCH_ANGLE_ADVANCE
);
}
TEST_F(IgnitionAngleAdvanceTest, withEnabledLaunchControlAndLaunchRetardWithoutSmooth) {
setUpTestParameters();
doTest(
/* config = */ {
/* launchControlEnabled = */ { true },
@ -206,8 +194,6 @@ namespace {
}
TEST_F(IgnitionAngleAdvanceTest, withEnabledLaunchControlAndLaunchRetardAndLaunchSmoothRetard) {
setUpTestParameters();
doTest(
/* config = */ {
/* launchControlEnabled = */ { true },
@ -258,18 +244,26 @@ namespace {
/* Tests for https://github.com/rusefi/rusefi/issues/6571: */
TEST_F(IgnitionAngleAdvanceTest, withDisabledLaunchControlAndLaunchRetardWithoutSmooth) {
checkAngleAdvanceWithoutLaunchControl(
doTest(
/* config = */ {
/* launchControlEnabled = */ { false },
/* enableLaunchRetard = */ {true},
/* launchSmoothRetard = */ {false}
/* ignitionRetardEnable = */ { true },
/* smoothRetardMode = */ { false },
/* satifySwitchSpeedThresholdAndTpsConditions = */ true
},
/* testData = */ TEST_DATA_WITHOUT_LAUNCH_ANGLE_ADVANCE
);
}
TEST_F(IgnitionAngleAdvanceTest, withDisabledLaunchControlAndLaunchRetardAndSmooth) {
checkAngleAdvanceWithoutLaunchControl(
doTest(
/* config = */ {
/* launchControlEnabled = */ { false },
/* enableLaunchRetard = */ {true},
/* launchSmoothRetard = */ {true}
/* ignitionRetardEnable = */ { true },
/* smoothRetardMode = */ { true },
/* satifySwitchSpeedThresholdAndTpsConditions = */ true
},
/* testData = */ TEST_DATA_WITHOUT_LAUNCH_ANGLE_ADVANCE
);
}
}