LCOV - code coverage report
Current view: top level - tests/situation - RssSituationCheckingTestsLateral.cpp (source / functions) Hit Total Coverage
Test: ad_rss Lines: 126 126 100.0 %
Date: 2024-04-30 13:12:49 Functions: 18 18 100.0 %
Branches: 180 720 25.0 %

           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 "situation/RssStructuredSceneNonIntersectionChecker.hpp"
      11                 :            : 
      12                 :            : namespace ad {
      13                 :            : namespace rss {
      14                 :            : namespace situation {
      15                 :            : 
      16                 :            : class RssSituationCheckingTestsLateral : public testing::Test
      17                 :            : {
      18                 :            : protected:
      19                 :          8 :   virtual void SetUp()
      20                 :            :   {
      21                 :          8 :     situation.situationType = SituationType::SameDirection;
      22                 :          8 :     situation.situationId = SituationId(111);
      23                 :          8 :   }
      24                 :            : 
      25                 :          8 :   virtual void TearDown()
      26                 :            :   {
      27                 :          8 :   }
      28                 :            :   VehicleState leftVehicle;
      29                 :            :   VehicleState rightVehicle;
      30                 :            :   Situation situation;
      31                 :            :   state::RssState rssState;
      32                 :            :   world::TimeIndex timeIndex{1u};
      33                 :            : };
      34                 :            : 
      35                 :          2 : TEST_F(RssSituationCheckingTestsLateral, safe_left)
      36                 :            : {
      37                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
      38         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(1);
      39         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(1);
      40                 :            : 
      41                 :          1 :   situation.egoVehicleState = leftVehicle;
      42                 :          1 :   situation.otherVehicleState = rightVehicle;
      43         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtLeft, Distance(95.));
      44                 :            : 
      45   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
      46                 :            : 
      47   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
      48   [ +  -  -  +  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
      49   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
      50                 :            : }
      51                 :            : 
      52                 :          2 : TEST_F(RssSituationCheckingTestsLateral, not_safe_overlap_left)
      53                 :            : {
      54                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
      55         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(1);
      56         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(1);
      57                 :            : 
      58                 :          1 :   situation.egoVehicleState = leftVehicle;
      59                 :          1 :   situation.otherVehicleState = rightVehicle;
      60         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::OverlapLeft);
      61                 :            : 
      62   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
      63   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
      64   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
      65   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState,
          -  +  -  -  -  
                -  -  - ]
      66                 :            :             TestSupport::stateWithInformation(cTestSupport.cLongitudinalBrakeMin, situation));
      67                 :            : }
      68                 :            : 
      69                 :          2 : TEST_F(RssSituationCheckingTestsLateral, not_safe_overlap)
      70                 :            : {
      71                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
      72         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(1);
      73         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(1);
      74                 :            : 
      75                 :          1 :   situation.egoVehicleState = leftVehicle;
      76                 :          1 :   situation.otherVehicleState = rightVehicle;
      77         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::Overlap);
      78                 :            : 
      79   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
      80   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
      81   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
      82   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState,
          -  +  -  -  -  
                -  -  - ]
      83                 :            :             TestSupport::stateWithInformation(cTestSupport.cLongitudinalBrakeMin, situation));
      84                 :            : }
      85                 :            : 
      86                 :          2 : TEST_F(RssSituationCheckingTestsLateral, not_safe_overlap_right)
      87                 :            : {
      88                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
      89         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(1);
      90         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(1);
      91                 :            : 
      92                 :          1 :   situation.egoVehicleState = leftVehicle;
      93                 :          1 :   situation.otherVehicleState = rightVehicle;
      94         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::OverlapRight);
      95                 :            : 
      96   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
      97   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
      98   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
      99   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState,
          -  +  -  -  -  
                -  -  - ]
     100                 :            :             TestSupport::stateWithInformation(cTestSupport.cLongitudinalBrakeMin, situation));
     101                 :            : }
     102                 :            : 
     103                 :          2 : TEST_F(RssSituationCheckingTestsLateral, safe_right)
     104                 :            : {
     105                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
     106         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(1);
     107         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(1);
     108                 :            : 
     109                 :          1 :   situation.egoVehicleState = leftVehicle;
     110                 :          1 :   situation.otherVehicleState = rightVehicle;
     111         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtRight, Distance(95.));
     112                 :            : 
     113   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     114   [ +  -  -  +  :          1 :   ASSERT_EQ(rssState.lateralStateRight, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
     115   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
     116   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     117                 :            : }
     118                 :            : 
     119                 :          2 : TEST_F(RssSituationCheckingTestsLateral, both_move_right)
     120                 :            : {
     121                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
     122         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(1);
     123         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(1);
     124                 :            : 
     125                 :          1 :   situation.egoVehicleState = leftVehicle;
     126                 :          1 :   situation.otherVehicleState = rightVehicle;
     127         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtLeft, Distance(0.02));
     128                 :            : 
     129   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     130   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     131   [ +  -  -  +  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
     132   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState,
          -  +  -  -  -  
                -  -  - ]
     133                 :            :             TestSupport::stateWithInformation(cTestSupport.cLongitudinalBrakeMin, situation));
     134                 :            : }
     135                 :            : 
     136                 :          2 : TEST_F(RssSituationCheckingTestsLateral, move_towards_each_other)
     137                 :            : {
     138                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
     139         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(1);
     140         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(-1);
     141                 :            : 
     142                 :          1 :   situation.egoVehicleState = leftVehicle;
     143                 :          1 :   situation.otherVehicleState = rightVehicle;
     144         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtLeft, Distance(0.02));
     145                 :            : 
     146   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     147   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     148   [ +  -  -  +  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
     149   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState,
          -  +  -  -  -  
                -  -  - ]
     150                 :            :             TestSupport::stateWithInformation(cTestSupport.cLongitudinalBrakeMin, situation));
     151                 :            : }
     152                 :            : 
     153                 :          2 : TEST_F(RssSituationCheckingTestsLateral, check_input_range)
     154                 :            : {
     155                 :          1 :   RssStructuredSceneNonIntersectionChecker checker;
     156         [ +  - ]:          1 :   leftVehicle = createVehicleStateForLateralMotion(0);
     157         [ +  - ]:          1 :   rightVehicle = createVehicleStateForLateralMotion(0);
     158                 :            : 
     159                 :            :   // ego vehicle "moves" towards right vehicle from left
     160                 :          1 :   situation.egoVehicleState = leftVehicle;
     161                 :          1 :   situation.otherVehicleState = rightVehicle;
     162         [ +  + ]:         10 :   for (uint32_t i = 10; i > 1; i--)
     163                 :            :   {
     164         [ +  - ]:          9 :     situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtLeft, Distance(i));
     165                 :            : 
     166   [ +  -  -  +  :          9 :     ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     167   [ +  -  +  -  :          9 :     ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
     168   [ +  -  -  +  :          9 :     ASSERT_EQ(rssState.lateralStateLeft, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
     169   [ +  -  +  -  :          9 :     ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     170                 :            :   }
     171                 :            : 
     172                 :            :   // near enough: trigger brake
     173         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtLeft, Distance(1));
     174                 :            : 
     175   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     176   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     177   [ +  -  -  +  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
     178   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     179                 :            : 
     180                 :            :   // ego vehicle overlaps on left side
     181         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::OverlapLeft);
     182                 :            : 
     183   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     184   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     185   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
     186   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     187                 :            : 
     188                 :            :   // ego vehicle totally overlaps with other vehicle
     189         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::Overlap);
     190                 :            : 
     191   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     192   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     193   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     194   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     195                 :            : 
     196                 :            :   // ego vehicle overlaps on right side
     197         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::OverlapRight);
     198                 :            : 
     199   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     200   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateRight, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
     201   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     202   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     203                 :            : 
     204                 :            :   // ego vehicle still too near, but on right side
     205         [ +  - ]:          1 :   situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtRight, Distance(1));
     206                 :            : 
     207   [ +  -  -  +  :          1 :   ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     208   [ +  -  -  +  :          1 :   ASSERT_EQ(rssState.lateralStateRight, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
     209   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralBrakeMin, situation));
          -  +  -  -  -  
                -  -  - ]
     210   [ +  -  +  -  :          1 :   ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     211                 :            : 
     212                 :            :   // ego vehicle far enough on right side
     213         [ +  + ]:          9 :   for (uint32_t i = 2; i < 10; i++)
     214                 :            :   {
     215         [ +  - ]:          8 :     situation.relativePosition = createRelativeLateralPosition(LateralRelativePosition::AtRight, Distance(i));
     216   [ +  -  -  +  :          8 :     ASSERT_TRUE(checker.calculateRssStateNonIntersection(timeIndex++, situation, rssState));
          -  -  -  -  -  
                -  -  - ]
     217   [ +  -  -  +  :          8 :     ASSERT_EQ(rssState.lateralStateRight, cTestSupport.cLateralSafe);
          -  -  -  -  -  
                      - ]
     218   [ +  -  +  -  :          8 :     ASSERT_EQ(rssState.lateralStateLeft, TestSupport::stateWithInformation(cTestSupport.cLateralSafe, situation));
          -  +  -  -  -  
                -  -  - ]
     219   [ +  -  +  -  :          8 :     ASSERT_EQ(rssState.longitudinalState, TestSupport::stateWithInformation(cTestSupport.cLongitudinalNone, situation));
          -  +  -  -  -  
                -  -  - ]
     220                 :            :   }
     221                 :            : }
     222                 :            : 
     223                 :            : } // namespace situation
     224                 :            : } // namespace rss
     225                 :            : } // namespace ad

Generated by: LCOV version 1.14