LCOV - code coverage report
Current view: top level - tests/situation - PhysicsUnitTestsTimeToCoverDistance.cpp (source / functions) Hit Total Coverage
Test: ad_rss Lines: 53 53 100.0 %
Date: 2024-12-17 12:06:18 Functions: 16 16 100.0 %
Branches: 49 232 21.1 %

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2018-2021 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: LGPL-2.1-only
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : 
       9                 :            : #include "TestSupport.hpp"
      10                 :            : #include "ad/rss/situation/Physics.hpp"
      11                 :            : 
      12                 :            : namespace ad {
      13                 :            : namespace rss {
      14                 :            : namespace situation {
      15                 :            : 
      16                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, no_brake_required_2_brake_required_is_continuous)
      17                 :            : {
      18         [ +  + ]:         12 :   for (size_t i = 0; i <= 10u; ++i)
      19                 :            :   {
      20                 :         11 :     Speed speed(1 - (static_cast<double>(i) - 5.) * 0.01);
      21                 :         11 :     Duration requiredTime(0.);
      22                 :         11 :     double expectedDuration = 1. / static_cast<double>(speed);
      23   [ +  -  -  +  :         11 :     EXPECT_TRUE(calculateTimeToCoverDistance(
          -  -  -  -  -  
                -  -  - ]
      24                 :            :       speed, cMaxSpeedOnAcceleration, Duration(1.), Acceleration(0.), Acceleration(-1.), Distance(1.), requiredTime));
      25   [ +  -  -  +  :         11 :     EXPECT_NEAR(expectedDuration, static_cast<double>(requiredTime), cDoubleNear);
          -  -  -  -  -  
                      - ]
      26                 :            :   }
      27                 :          1 : }
      28                 :            : 
      29                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, no_brake_required_zero_acceleration_zero_speed)
      30                 :            : {
      31                 :          1 :   Duration requiredTime(0.);
      32   [ +  -  -  +  :          1 :   EXPECT_TRUE(calculateTimeToCoverDistance(
          -  -  -  -  -  
                -  -  - ]
      33                 :            :     Speed(0.), cMaxSpeedOnAcceleration, Duration(1.), Acceleration(0.), Acceleration(-1.), Distance(1.), requiredTime));
      34   [ +  -  -  +  :          1 :   EXPECT_EQ(requiredTime, std::numeric_limits<Duration>::max());
          -  -  -  -  -  
                      - ]
      35                 :          1 : }
      36                 :            : 
      37                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, no_brake_required_zero_acceleration_is_continuous)
      38                 :            : {
      39         [ +  + ]:         11 :   for (size_t i = 0; i < 10u; ++i)
      40                 :            :   {
      41                 :         10 :     Acceleration acceleration((static_cast<double>(i) - 5.)
      42                 :         10 :                               * static_cast<double>(std::numeric_limits<Acceleration>::epsilon()) * 0.9);
      43                 :         10 :     Duration requiredTime(0.);
      44   [ +  -  -  +  :         10 :     EXPECT_TRUE(calculateTimeToCoverDistance(
          -  -  -  -  -  
                -  -  - ]
      45                 :            :       Speed(2.), cMaxSpeedOnAcceleration, Duration(1.), acceleration, Acceleration(-1.), Distance(1.), requiredTime));
      46   [ +  -  -  +  :         10 :     EXPECT_NEAR(.5, static_cast<double>(requiredTime), cDoubleNear);
          -  -  -  -  -  
                      - ]
      47                 :            :   }
      48                 :          1 : }
      49                 :            : 
      50                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, brake_required_negative_or_zero_deceleration)
      51                 :            : {
      52                 :          1 :   Acceleration decelerationValue(1.);
      53                 :          1 :   Duration requiredTime(0.);
      54         [ +  + ]:         11 :   for (size_t i = 0u; i < 10u; ++i)
      55                 :            :   {
      56         [ +  - ]:         10 :     decelerationValue = decelerationValue * 0.1;
      57   [ +  -  -  +  :         10 :     EXPECT_TRUE(calculateTimeToCoverDistance(Speed(0.),
          -  -  -  -  -  
                -  -  - ]
      58                 :            :                                              cMaxSpeedOnAcceleration,
      59                 :            :                                              Duration(0.),
      60                 :            :                                              Acceleration(0.),
      61                 :            :                                              decelerationValue,
      62                 :            :                                              Distance(1.),
      63                 :            :                                              requiredTime));
      64   [ +  -  -  +  :         10 :     EXPECT_EQ(requiredTime, std::numeric_limits<Duration>::max());
          -  -  -  -  -  
                      - ]
      65                 :            :   }
      66   [ +  -  -  +  :          1 :   EXPECT_TRUE(calculateTimeToCoverDistance(
          -  -  -  -  -  
                -  -  - ]
      67                 :            :     Speed(0.), cMaxSpeedOnAcceleration, Duration(0.), Acceleration(0.), Acceleration(0.), Distance(1.), requiredTime));
      68   [ +  -  -  +  :          1 :   EXPECT_EQ(requiredTime, std::numeric_limits<Duration>::max());
          -  -  -  -  -  
                      - ]
      69   [ +  -  +  -  :          1 :   EXPECT_TRUE(calculateTimeToCoverDistance(Speed(0.),
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      70                 :            :                                            cMaxSpeedOnAcceleration,
      71                 :            :                                            Duration(0.),
      72                 :            :                                            Acceleration(0.),
      73                 :            :                                            std::numeric_limits<Acceleration>::epsilon() * 0.99,
      74                 :            :                                            Distance(1.),
      75                 :            :                                            requiredTime));
      76   [ +  -  -  +  :          1 :   EXPECT_EQ(requiredTime, std::numeric_limits<Duration>::max());
          -  -  -  -  -  
                      - ]
      77                 :          1 : }
      78                 :            : 
      79                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, brake_required_positive_deceleration)
      80                 :            : {
      81                 :          1 :   Duration requiredTime(0.);
      82   [ +  -  +  -  :          1 :   EXPECT_TRUE(calculateTimeToCoverDistance(Speed(0.),
          -  +  -  -  -  
             -  -  -  -  
                      - ]
      83                 :            :                                            cMaxSpeedOnAcceleration,
      84                 :            :                                            Duration(0.),
      85                 :            :                                            Acceleration(0.),
      86                 :            :                                            -std::numeric_limits<Acceleration>::epsilon(),
      87                 :            :                                            Distance(1.),
      88                 :            :                                            requiredTime));
      89   [ +  -  -  +  :          1 :   EXPECT_EQ(requiredTime, std::numeric_limits<Duration>::max());
          -  -  -  -  -  
                      - ]
      90                 :          1 : }
      91                 :            : 
      92                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, test_zero_distance)
      93                 :            : {
      94                 :          1 :   Duration requiredTime(0.);
      95   [ +  -  -  +  :          1 :   EXPECT_TRUE(calculateTimeToCoverDistance(
          -  -  -  -  -  
                -  -  - ]
      96                 :            :     Speed(1.), cMaxSpeedOnAcceleration, Duration(1.), Acceleration(1.), Acceleration(-1.), Distance(0.), requiredTime));
      97   [ +  -  -  +  :          1 :   EXPECT_EQ(requiredTime, Duration(0.));
          -  -  -  -  -  
                      - ]
      98                 :          1 : }
      99                 :            : 
     100                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, max_speed_reached_before_response_time)
     101                 :            : {
     102                 :          1 :   Duration requiredTime(0.);
     103   [ +  -  -  +  :          1 :   EXPECT_TRUE(calculateTimeToCoverDistance(
          -  -  -  -  -  
                -  -  - ]
     104                 :            :     Speed(1.0), Speed(2.0), Duration(1.5), Acceleration(2.), Acceleration(-0.5), Distance(1.75), requiredTime));
     105   [ +  -  -  +  :          1 :   EXPECT_NEAR(1.0, static_cast<double>(requiredTime), cDoubleNear);
          -  -  -  -  -  
                      - ]
     106                 :          1 : }
     107                 :            : 
     108                 :          2 : TEST(PhysicsUnitTestsTimeToCoverDistance, max_speed_still_exceeded_after_response_time)
     109                 :            : {
     110                 :          1 :   Duration requiredTime(0.);
     111   [ +  -  -  +  :          1 :   EXPECT_TRUE(calculateTimeToCoverDistance(
          -  -  -  -  -  
                -  -  - ]
     112                 :            :     Speed(2.0), Speed(1.0), Duration(1.), Acceleration(1.), Acceleration(-1.), Distance(3.), requiredTime));
     113   [ +  -  -  +  :          1 :   EXPECT_NEAR(1.585786, static_cast<double>(requiredTime), cDoubleNear);
          -  -  -  -  -  
                      - ]
     114                 :          1 : }
     115                 :            : 
     116                 :            : } // namespace situation
     117                 :            : } // namespace rss
     118                 :            : } // namespace ad

Generated by: LCOV version 1.14