LCOV - code coverage report
Current view: top level - tests/core - RssCheckTimeIndexTests.cpp (source / functions) Hit Total Coverage
Test: ad_rss Lines: 33 33 100.0 %
Date: 2024-04-16 14:13:10 Functions: 6 6 100.0 %
Branches: 34 100 34.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 "RssCheckTestBaseT.hpp"
      10                 :            : 
      11                 :            : namespace ad {
      12                 :            : namespace rss {
      13                 :            : namespace core {
      14                 :            : 
      15                 :            : class RssCheckTimeIndexTests : public RssCheckTestBaseT<testing::Test>
      16                 :            : {
      17                 :            : };
      18                 :            : 
      19                 :          2 : TEST_F(RssCheckTimeIndexTests, ZeroTimeIndex)
      20                 :            : {
      21                 :          1 :   state::ProperResponse properResponse;
      22         [ +  - ]:          1 :   core::RssCheck rssCheck;
      23                 :            : 
      24                 :          1 :   world::TimeIndex timeIndexArray[] = {0u, 1u, 0u, 0u, 3u};
      25         [ +  + ]:          6 :   for (size_t i = 0; i < ARRAYLEN(timeIndexArray); ++i)
      26                 :            :   {
      27                 :          5 :     worldModel.timeIndex = timeIndexArray[i];
      28         [ +  + ]:          5 :     if (worldModel.timeIndex != 0u)
      29                 :            :     {
      30   [ +  -  -  +  :          2 :       ASSERT_TRUE(rssCheck.calculateProperResponse(worldModel, properResponse));
          -  -  -  -  -  
                -  -  - ]
      31         [ +  - ]:          2 :       testRestrictions(properResponse.accelerationRestrictions);
      32                 :            :     }
      33                 :            :     else
      34                 :            :     {
      35   [ +  -  -  +  :          3 :       ASSERT_FALSE(rssCheck.calculateProperResponse(worldModel, properResponse));
          -  -  -  -  -  
                -  -  - ]
      36                 :            :     }
      37                 :            :   }
      38                 :            : }
      39                 :            : 
      40                 :          2 : TEST_F(RssCheckTimeIndexTests, TimeIndexIncrementValidity)
      41                 :            : {
      42                 :          1 :   state::ProperResponse properResponse;
      43         [ +  - ]:          1 :   core::RssCheck rssCheck;
      44                 :            : 
      45                 :          1 :   world::TimeIndex timeIndexArray[] = {1u,
      46                 :            :                                        2u,
      47                 :            :                                        3u,
      48                 :            :                                        4u,
      49                 :            :                                        5u,
      50                 :            :                                        100u,
      51                 :            :                                        100000u,
      52                 :            :                                        (std::numeric_limits<world::TimeIndex>::max() / 4),
      53                 :            :                                        2 * (std::numeric_limits<world::TimeIndex>::max() / 4),
      54                 :            :                                        3 * (std::numeric_limits<world::TimeIndex>::max() / 4),
      55                 :            :                                        4 * (std::numeric_limits<world::TimeIndex>::max() / 4)};
      56         [ +  + ]:          3 :   for (auto j : {1, 2})
      57                 :            :   {
      58                 :            :     // increment with overflow
      59                 :            :     (void)j;
      60         [ +  + ]:         24 :     for (size_t i = 0; i < ARRAYLEN(timeIndexArray); ++i)
      61                 :            :     {
      62                 :         22 :       worldModel.timeIndex = timeIndexArray[i];
      63   [ +  -  -  +  :         22 :       ASSERT_TRUE(rssCheck.calculateProperResponse(worldModel, properResponse));
          -  -  -  -  -  
                -  -  - ]
      64         [ +  - ]:         22 :       testRestrictions(properResponse.accelerationRestrictions);
      65                 :            :     }
      66                 :            :   }
      67         [ +  + ]:          3 :   for (auto j : {1, 2})
      68                 :            :   {
      69                 :            :     // decrement with overflow
      70                 :            :     (void)j;
      71         [ +  + ]:         24 :     for (size_t i = 0; i < ARRAYLEN(timeIndexArray); ++i)
      72                 :            :     {
      73                 :         22 :       worldModel.timeIndex = timeIndexArray[ARRAYLEN(timeIndexArray) - i - 1];
      74   [ +  -  -  +  :         22 :       ASSERT_FALSE(rssCheck.calculateProperResponse(worldModel, properResponse));
          -  -  -  -  -  
                -  -  - ]
      75                 :            :     }
      76                 :            :   }
      77                 :            : }
      78                 :            : 
      79                 :          2 : TEST_F(RssCheckTimeIndexTests, FixedTimeIndexValidity)
      80                 :            : {
      81                 :          1 :   state::ProperResponse properResponse;
      82         [ +  - ]:          1 :   core::RssCheck rssCheck;
      83                 :            : 
      84                 :          1 :   world::TimeIndex timeIndexArray[] = {1u, 1u, 2u, 2u, 3u, 3u};
      85         [ +  + ]:          7 :   for (size_t i = 0; i < ARRAYLEN(timeIndexArray); ++i)
      86                 :            :   {
      87                 :            :     {
      88                 :          6 :       worldModel.timeIndex = timeIndexArray[i];
      89         [ +  + ]:          6 :       if ((i % 2) == 0)
      90                 :            :       {
      91   [ +  -  -  +  :          3 :         ASSERT_TRUE(rssCheck.calculateProperResponse(worldModel, properResponse));
          -  -  -  -  -  
                -  -  - ]
      92         [ +  - ]:          3 :         testRestrictions(properResponse.accelerationRestrictions);
      93                 :            :       }
      94                 :            :       else
      95                 :            :       {
      96   [ +  -  -  +  :          3 :         ASSERT_FALSE(rssCheck.calculateProperResponse(worldModel, properResponse));
          -  -  -  -  -  
                -  -  - ]
      97                 :            :       }
      98                 :            :     }
      99                 :            :   }
     100                 :            : }
     101                 :            : 
     102                 :            : } // namespace core
     103                 :            : } // namespace rss
     104                 :            : } // namespace ad

Generated by: LCOV version 1.14