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

          Line data    Source code
       1             : #include "pch.h"
       2             : 
       3             : #include "boost_control.h"
       4             : 
       5             : using ::testing::_;
       6             : using ::testing::StrictMock;
       7             : 
       8           4 : TEST(ScaledChannel, Basic) {
       9             :         {
      10           1 :                 scaled_channel<int16_t, 10> i1;
      11           1 :                 i1 = 10;    EXPECT_FLOAT_EQ(i1, 10);
      12           1 :                 i1 =  1;    EXPECT_FLOAT_EQ(i1,  1);
      13           1 :                 i1 =  0.11; EXPECT_FLOAT_EQ(i1,  0.1); // round
      14           1 :                 i1 =  0.1;  EXPECT_FLOAT_EQ(i1,  0.1);
      15           1 :                 i1 =  0.09; EXPECT_FLOAT_EQ(i1,  0.1); // round
      16           1 :                 i1 =  0.01; EXPECT_FLOAT_EQ(i1,  0.); // out of range
      17           1 :                 i1 = -0.09; EXPECT_FLOAT_EQ(i1, -0.1); // round
      18           1 :                 i1 = -0.1;  EXPECT_FLOAT_EQ(i1, -0.1);
      19           1 :                 i1 = -0.11; EXPECT_FLOAT_EQ(i1, -0.1); // round
      20             :         }
      21             : 
      22             :         {
      23           1 :                 scaled_channel<int16_t, 1, 10> i2;
      24           1 :                 i2 = 1000; EXPECT_FLOAT_EQ(i2, 1000);
      25           1 :                 i2 =  100; EXPECT_FLOAT_EQ(i2,  100);
      26           1 :                 i2 =   11; EXPECT_FLOAT_EQ(i2,   10); // round
      27           1 :                 i2 =   10; EXPECT_FLOAT_EQ(i2,   10);
      28           1 :                 i2 =    9; EXPECT_FLOAT_EQ(i2,   10); // round
      29           1 :                 i2 =    1; EXPECT_FLOAT_EQ(i2,    0); // out of range
      30           1 :                 i2 =   -9; EXPECT_FLOAT_EQ(i2,  -10); // round
      31           1 :                 i2 =  -10; EXPECT_FLOAT_EQ(i2,  -10);
      32           1 :                 i2 =  -11; EXPECT_FLOAT_EQ(i2,  -10); // round
      33             :         }
      34           1 : }
      35             : 
      36           4 : TEST(ScaledChannel, IntegerBehavior) {
      37           1 :         scaled_channel<uint32_t, 1, 1> test;
      38             : 
      39             :         // Check that a round trip thru scaled_channel gets us back the same integer
      40           1 :         uint32_t a = 20210311;
      41           1 :         test = a;
      42           1 :         uint32_t b = test;
      43             : 
      44           1 :         EXPECT_EQ(a, b);
      45           1 : }
      46             : 
      47           4 : TEST(ScaledChannel, IntegerUnsigned8Behavior) {
      48           1 :         scaled_channel<uint8_t, 1, 1> test;
      49             : 
      50           1 :         uint32_t a = 140;
      51           1 :         test = a;
      52           1 :         uint32_t b = test;
      53           1 :         EXPECT_EQ(a, b) << a << " unsigned8 " << b;
      54           1 : }

Generated by: LCOV version 1.14