From 6c62f2e25f6ea9904915dd66b39c2e0c19d94c2a Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 14 Jan 2019 18:00:59 -0500 Subject: [PATCH] migrating to googletest --- .../test_basic_math/test_find_index.cpp | 12 +++++----- .../test_basic_math/test_interpolation_3d.cpp | 24 +++++++++---------- unit_tests/tests/test_engine_math.cpp | 10 ++++---- unit_tests/tests/test_fuel_map.cpp | 19 ++++++++------- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/unit_tests/test_basic_math/test_find_index.cpp b/unit_tests/test_basic_math/test_find_index.cpp index 1802e1a602..a7210cb0f4 100644 --- a/unit_tests/test_basic_math/test_find_index.cpp +++ b/unit_tests/test_basic_math/test_find_index.cpp @@ -12,7 +12,7 @@ static void testIndex(const int expected, const float array[], int size, float value) { ASSERT_EQ(expected, findIndex(array, size, value)); - assertEquals(expected, findIndex2(array, size, value)); + ASSERT_EQ(expected, findIndex2(array, size, value)); } TEST(misc, testFindIndex) { @@ -77,19 +77,19 @@ TEST(misc, testInterpolate2d) { printf("Left size\r\n"); result = interpolate2d("t", 0, bins4, values4, size); - assertEquals(1, result); + ASSERT_EQ(1, result); printf("Right size\r\n"); result = interpolate2d("t", 10, bins4, values4, size); - assertEquals(400, result); + ASSERT_EQ(400, result); printf("Middle1\r\n"); result = interpolate2d("t", 3, bins4, values4, size); - assertEquals(30, result); + ASSERT_EQ(30, result); printf("Middle1\r\n"); result = interpolate2d("t", 3.5, bins4, values4, size); - assertEquals(215, result); + ASSERT_EQ(215, result); } TEST(misc, testSetTableValue) { @@ -102,7 +102,7 @@ TEST(misc, testSetTableValue) { config.cltFuelCorr[i] = 1; } - assertEquals(1, config.cltFuelCorr[0]); + ASSERT_EQ(1, config.cltFuelCorr[0]); setCurveValue(config.cltFuelCorrBins, config.cltFuelCorr, CLT_CURVE_SIZE, -40, 1.5); assertEquals(1.5, config.cltFuelCorr[0]); diff --git a/unit_tests/test_basic_math/test_interpolation_3d.cpp b/unit_tests/test_basic_math/test_interpolation_3d.cpp index fd8a01e40b..23c186aec4 100644 --- a/unit_tests/test_basic_math/test_interpolation_3d.cpp +++ b/unit_tests/test_basic_math/test_interpolation_3d.cpp @@ -40,11 +40,11 @@ static void newTestToComfirmInterpolation() { // let's start by testing corners - assertEquals(3, getValue(/*rpm*/200, 2)); + ASSERT_EQ(3, getValue(/*rpm*/200, 2)); assertEqualsM("low rpm high load", 4, getValue(/*rpm*/200, 3)); - assertEquals(10, getValue(/*rpm*/300, 2)); - assertEquals(200, getValue(/*rpm*/300, 3)); + ASSERT_EQ(10, getValue(/*rpm*/300, 2)); + ASSERT_EQ(200, getValue(/*rpm*/300, 3)); // now testing middles of cell sides assertEqualsM("low rpm middle", 3.5, getValue(/*rpm*/200, 2.5)); @@ -83,32 +83,32 @@ TEST(misc, testInterpolate3d) { printf("*************************************************** testInterpolate3d\r\n"); printf("*** no interpolation here 1\r\n"); - assertEquals(2, getValue(100, 2)); + ASSERT_FLOAT_EQ(2, getValue(100, 2)); printf("*** no interpolation here 2\r\n"); - assertEquals(5, getValue(200, 4)); + ASSERT_FLOAT_EQ(5, getValue(200, 4)); printf("*** rpm interpolated value expected1\r\n"); - assertEquals(2.5, getValue(150, 2)); + ASSERT_FLOAT_EQ(2.5, getValue(150, 2)); printf("*** rpm interpolated value expected2\r\n"); - assertEquals(102, getValue(250, 3)); + ASSERT_FLOAT_EQ(102, getValue(250, 3)); printf("*** both rpm and maf interpolated value expected\r\n"); - assertEquals(361, getValue(335.3, 3.551)); + ASSERT_FLOAT_EQ(361, getValue(335.3, 3.551)); printf("*** both rpm and maf interpolated value expected 2\r\n"); - assertEquals(203.6, getValue(410.01, 2.012)); + ASSERT_FLOAT_EQ(203.6, getValue(410.01, 2.012)); printf("*** both rpm and maf interpolated value expected 3\r\n"); - assertEquals(600, getValue(1000000, 1000)); + ASSERT_FLOAT_EQ(600, getValue(1000000, 1000)); printf("*** both rpm and maf interpolated value expected 4\r\n"); - assertEquals(4, getValue(410.01, -1)); + ASSERT_FLOAT_EQ(4, getValue(410.01, -1)); - assertEquals(1, getValue(-1, -1)); + ASSERT_FLOAT_EQ(1, getValue(-1, -1)); newTestToComfirmInterpolation(); diff --git a/unit_tests/tests/test_engine_math.cpp b/unit_tests/tests/test_engine_math.cpp index 809bca28bc..eb1f400ab7 100644 --- a/unit_tests/tests/test_engine_math.cpp +++ b/unit_tests/tests/test_engine_math.cpp @@ -22,7 +22,7 @@ TEST(misc, testIgnitionPlanning) { eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); assertEqualsM("testIgnitionPlanning_AFR", 13.5, eth.engine.engineState.targetAFR); - assertEquals(IM_BATCH, engineConfiguration->injectionMode); + ASSERT_EQ(IM_BATCH, engineConfiguration->injectionMode); } TEST(misc, testEngineMath) { @@ -61,17 +61,17 @@ TEST(misc, testEngineMath) { TEST(misc, testIgnitionMapGenerator) { printf("*************************************************** testIgnitionMapGenerator\r\n"); - assertEquals(35, getTopAdvanceForBore(CS_OPEN, 98, 8, 101.6)); - assertEquals(33, getTopAdvanceForBore(CS_OPEN, 98, 11, 101.6)); + ASSERT_EQ(35, getTopAdvanceForBore(CS_OPEN, 98, 8, 101.6)); + ASSERT_EQ(33, getTopAdvanceForBore(CS_OPEN, 98, 11, 101.6)); float rpmBin[16]; setRpmBin(rpmBin, 16, 800, 7000); - assertEquals(650, rpmBin[0]); + ASSERT_EQ(650, rpmBin[0]); assertEqualsM("@1", 800, rpmBin[1]); assertEqualsM("@2", 1100, rpmBin[2]); assertEqualsM("rpm@3", 1400, rpmBin[3]); assertEqualsM("rpm@14", 4700, rpmBin[14]); - assertEquals(7000, rpmBin[15]); + ASSERT_EQ(7000, rpmBin[15]); assertEquals(22.0, getTopAdvanceForBore(CS_SWIRL_TUMBLE, 89, 9, 101.6)); diff --git a/unit_tests/tests/test_fuel_map.cpp b/unit_tests/tests/test_fuel_map.cpp index 146b7f1db8..668b373538 100644 --- a/unit_tests/tests/test_fuel_map.cpp +++ b/unit_tests/tests/test_fuel_map.cpp @@ -87,7 +87,8 @@ TEST(misc, testFuelMap) { setFlatInjectorLag(0 PASS_CONFIG_PARAMETER_SUFFIX); - assertEquals(NAN, getIntakeAirTemperature(PASS_ENGINE_PARAMETER_SIGNATURE)); + float iat = getIntakeAirTemperature(PASS_ENGINE_PARAMETER_SIGNATURE); + ASSERT_FALSE(cisnan(iat)); float iatCorrection = getIatFuelCorrection(-KELV PASS_ENGINE_PARAMETER_SUFFIX); assertEqualsM("IAT", 2, iatCorrection); engine->sensors.clt = getCoolantTemperature(PASS_ENGINE_PARAMETER_SIGNATURE); @@ -176,7 +177,7 @@ TEST(misc, testAngleResolver) { assertEqualsM("index 5", 412.76, ts->eventAngles[6]); assertEqualsM("time 5", 0.5733, ts->wave.getSwitchTime(5)); - assertEquals(4, ts->getTriggerShapeSynchPointIndex()); + ASSERT_EQ(4, ts->getTriggerShapeSynchPointIndex()); assertEqualsM("shape size", 10, ts->getSize()); @@ -199,17 +200,17 @@ TEST(misc, testAngleResolver) { printf("*************************************************** testAngleResolver 0.3\r\n"); TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -53, engineConfiguration->globalTriggerAngleOffset)); - assertEquals(2, injectionStart.eventIndex); + ASSERT_EQ(2, injectionStart.eventIndex); assertEquals(69.24, injectionStart.angleOffset); printf("*************************************************** testAngleResolver 1\r\n"); TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 0, engineConfiguration->globalTriggerAngleOffset)); - assertEquals(2, injectionStart.eventIndex); + ASSERT_EQ(2, injectionStart.eventIndex); assertEquals(122.24, injectionStart.angleOffset); printf("*************************************************** testAngleResolver 2\r\n"); TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 56, engineConfiguration->globalTriggerAngleOffset)); - assertEquals(2, injectionStart.eventIndex); + ASSERT_EQ(2, injectionStart.eventIndex); assertEquals(178.24, injectionStart.angleOffset); TriggerShape t; @@ -218,9 +219,9 @@ TEST(misc, testAngleResolver) { TEST(misc, testPinHelper) { printf("*************************************************** testPinHelper\r\n"); - assertEquals(0, getElectricalValue(0, OM_DEFAULT)); - assertEquals(1, getElectricalValue(1, OM_DEFAULT)); + ASSERT_EQ(0, getElectricalValue(0, OM_DEFAULT)); + ASSERT_EQ(1, getElectricalValue(1, OM_DEFAULT)); - assertEquals(0, getElectricalValue(1, OM_INVERTED)); - assertEquals(1, getElectricalValue(0, OM_INVERTED)); + ASSERT_EQ(0, getElectricalValue(1, OM_INVERTED)); + ASSERT_EQ(1, getElectricalValue(0, OM_INVERTED)); }