LCOV - code coverage report
Current view: top level - firmware/libfirmware/util/test - test_math.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 16 100.0 %
Date: 2024-04-25 02:23:43 Functions: 12 12 100.0 %

          Line data    Source code
       1             : #include <rusefi/math.h>
       2             : 
       3             : #include <gtest/gtest.h>
       4             : #include <math.h>
       5             : 
       6           4 : TEST(Util_Math, ExpTaylor)
       7             : {
       8             :     // test from -2 < x < 0
       9          42 :     for(float x = -2; x < 0; x += 0.05)
      10             :     {
      11             :         // Compare taylor to libc implementation
      12          41 :         EXPECT_NEAR(expf_taylor(x), expf(x), 0.01f);
      13             :     }
      14           1 : }
      15             : 
      16           4 : TEST(Util_Math, clampf) {
      17             :         // off scale low
      18           1 :         EXPECT_EQ(clampF(10, 5, 20), 10);
      19           1 :         EXPECT_EQ(clampF(-10, -50, 10), -10);
      20             : 
      21             :         // in range (unclamped)
      22           1 :         EXPECT_EQ(clampF(10, 15, 20), 15);
      23           1 :         EXPECT_EQ(clampF(-10, -5, 10), -5);
      24             : 
      25             :         // off scale high
      26           1 :         EXPECT_EQ(clampF(10, 25, 20), 20);
      27           1 :         EXPECT_EQ(clampF(-10, 50, 10), 10);
      28           1 : }
      29             : 
      30           4 : TEST(Util_Math, tanf_taylor) {
      31             :         // Function is only specified from [0, pi/2) ish, so test that range
      32          16 :         for (float i = 0; i < 1.5; i += 0.1f)
      33             :         {
      34             :                 // Compare to libc implementation
      35          15 :                 EXPECT_NEAR(tanf_taylor(i), tanf(i), 0.05f) << "I = " << i;
      36             :         }
      37           1 : }

Generated by: LCOV version 1.14