LCOV - code coverage report
Current view: top level - unit_tests/tests/sensor - test_vehicle_speed_converter.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 20 100.0 %
Date: 2024-04-25 02:23:43 Functions: 9 9 100.0 %

          Line data    Source code
       1             : #include "pch.h"
       2             : #include "vehicle_speed_converter.h"
       3             : 
       4             : 
       5           8 : float GetVssFor(float revPerKm, float axle, float teeth, float hz) {
       6           8 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
       7             : 
       8           8 :         VehicleSpeedConverter dut;
       9             : 
      10           8 :         engineConfiguration->driveWheelRevPerKm = revPerKm;
      11           8 :         engineConfiguration->vssGearRatio = axle;
      12           8 :         engineConfiguration->vssToothCount = teeth;
      13             : 
      14          16 :         return dut.convert(hz).value_or(-1);
      15           8 : }
      16             : 
      17           4 : TEST(VehicleSpeed, FakeCases) {
      18             :         // 0hz -> 0kph
      19           1 :         EXPECT_NEAR_M3(0, GetVssFor(500, 5, 10, 0));
      20             : 
      21             :         // 1000hz -> 144 kph
      22           1 :         EXPECT_NEAR_M3(144, GetVssFor(500, 5, 10, 1000));
      23             : 
      24             :         // Half size tires -> half speed
      25           1 :         EXPECT_NEAR_M3(72, GetVssFor(1000, 5, 10, 1000));
      26             : 
      27             :         // Double the axle ratio -> half the speed
      28           1 :         EXPECT_NEAR_M3(72, GetVssFor(500, 10, 10, 1000));
      29             : 
      30             :         // Twice as many teeth -> half speed
      31           1 :         EXPECT_NEAR_M3(72, GetVssFor(500, 5, 20, 1000));
      32           1 : }
      33             : 
      34           4 : TEST(VehicleSpeed, RealCases) {
      35             :         // V8 Volvo
      36             :         // 205/50R16 tire -> 521 rev/km
      37             :         // 3.73 axle ratio
      38             :         // 17 tooth speedo gear
      39           1 :         EXPECT_NEAR_M3(108.970f, GetVssFor(521, 3.73, 17, 1000));
      40             : 
      41             :         // NB miata
      42             :         // 205/50R15 tire -> 544 rev/km
      43             :         // 4.3 axle ratio
      44             :         // 21 tooth speedo gear
      45           1 :         EXPECT_NEAR_M3(73.285f, GetVssFor(544, 4.3, 21, 1000));
      46             : 
      47             :         // Some truck with ABS sensors
      48             :         // 265/65R18 tire -> 391 rev/km
      49             :         // 1.0 ratio because ABS sensors are hub mounted
      50             :         // 48 tooth abs sensor
      51           1 :         EXPECT_NEAR_M3(191.816f, GetVssFor(391, 1, 48, 1000));
      52           1 : }

Generated by: LCOV version 1.14