29 lines
947 B
C++
29 lines
947 B
C++
|
#include "pch.h"
|
||
|
|
||
|
float GetGearRatioFor(float revPerKm, float axle, float kph, float rpm) {
|
||
|
EngineTestHelper eth(TEST_ENGINE);
|
||
|
|
||
|
engineConfiguration->driveWheelRevPerKm = revPerKm;
|
||
|
engineConfiguration->finalGearRatio = axle;
|
||
|
|
||
|
Sensor::setMockValue(SensorType::VehicleSpeed, kph);
|
||
|
Sensor::setMockValue(SensorType::Rpm, rpm);
|
||
|
|
||
|
GearDetector dut;
|
||
|
dut.onSlowCallback();
|
||
|
|
||
|
return dut.getGearboxRatio();
|
||
|
}
|
||
|
|
||
|
TEST(GearDetector, ComputeGearRatio) {
|
||
|
// real gears from Volvo racecar
|
||
|
EXPECT_NEAR_M3(3.35f, GetGearRatioFor(507, 4.1, 29.45f / 0.6214f, 5500));
|
||
|
EXPECT_NEAR_M3(1.99f, GetGearRatioFor(507, 4.1, 49.57f / 0.6214f, 5500));
|
||
|
EXPECT_NEAR_M3(1.33f, GetGearRatioFor(507, 4.1, 74.18f / 0.6214f, 5500));
|
||
|
EXPECT_NEAR_M3(1.00f, GetGearRatioFor(507, 4.1, 98.65f / 0.6214f, 5500));
|
||
|
EXPECT_NEAR_M3(0.72f, GetGearRatioFor(507, 4.1, 137.02f / 0.6214f, 5500));
|
||
|
|
||
|
// Idling, car stopped, check no div/0
|
||
|
EXPECT_EQ(0, GetGearRatioFor(507, 4.1, 0, 800));
|
||
|
}
|