LCOV - code coverage report
Current view: top level - src/restriction - RestrictionOperation.cpp (source / functions) Hit Total Coverage
Test: ad_map_access Lines: 30 32 93.8 %
Date: 2022-10-04 09:48:07 Functions: 3 3 100.0 %
Branches: 31 40 77.5 %

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2018-2021 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: MIT
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : 
       9                 :            : #include "ad/map/restriction/RestrictionOperation.hpp"
      10                 :            : 
      11                 :            : #include <algorithm>
      12                 :            : 
      13                 :            : namespace ad {
      14                 :            : namespace map {
      15                 :            : namespace restriction {
      16                 :            : 
      17                 :         28 : bool isAccessOk(Restriction const &restriction, VehicleDescriptor const &vehicle)
      18                 :            : {
      19         [ +  + ]:         28 :   if (!isValid(vehicle))
      20                 :            :   {
      21         [ +  - ]:          1 :     throw std::runtime_error("isAccessOk: vehicle invalid");
      22                 :            :   }
      23                 :            :   //* \todo Full implementation.
      24         [ +  + ]:         27 :   if (vehicle.passengers < restriction.passengersMin)
      25                 :            :   {
      26                 :          2 :     return restriction.negated;
      27                 :            :   }
      28         [ +  + ]:         25 :   if (restriction.roadUserTypes.empty())
      29                 :            :   {
      30                 :          1 :     return !restriction.negated;
      31                 :            :   }
      32                 :            :   else
      33                 :            :   {
      34         [ +  - ]:         24 :     auto it = std::find(restriction.roadUserTypes.begin(), restriction.roadUserTypes.end(), vehicle.type);
      35         [ +  + ]:         24 :     if (it != restriction.roadUserTypes.end())
      36                 :            :     {
      37                 :         10 :       return !restriction.negated;
      38                 :            :     }
      39                 :            :     else
      40                 :            :     {
      41                 :         14 :       return restriction.negated;
      42                 :            :     }
      43                 :            :   }
      44                 :            : }
      45                 :            : 
      46                 :         26 : bool isAccessOk(Restrictions const &restrictions, VehicleDescriptor const &vehicle)
      47                 :            : {
      48                 :            :   //* \todo Improve implenentation based on more complex rules.
      49   [ +  +  +  +  :         26 :   if (restrictions.conjunctions.empty() && restrictions.disjunctions.empty())
                   +  + ]
      50                 :            :   {
      51                 :          1 :     return true;
      52                 :            :   }
      53         [ +  + ]:         25 :   else if (!restrictions.conjunctions.empty())
      54                 :            :   {
      55         [ +  + ]:         34 :     for (auto const &restriction : restrictions.conjunctions)
      56                 :            :     {
      57   [ +  -  +  + ]:         24 :       if (!isAccessOk(restriction, vehicle))
      58                 :            :       {
      59                 :         14 :         return false;
      60                 :            :       }
      61                 :            :     }
      62                 :         10 :     return true;
      63                 :            :   }
      64         [ +  - ]:          1 :   else if (!restrictions.disjunctions.empty())
      65                 :            :   {
      66         [ +  - ]:          1 :     for (auto const &restriction : restrictions.disjunctions)
      67                 :            :     {
      68   [ +  -  +  - ]:          1 :       if (isAccessOk(restriction, vehicle))
      69                 :            :       {
      70                 :          1 :         return true;
      71                 :            :       }
      72                 :            :     }
      73                 :          0 :     return false;
      74                 :            :   }
      75                 :            :   else
      76                 :            :   {
      77         [ #  # ]:          0 :     throw std::runtime_error("IsAccessOk: conjunctions and disjunctions invalid");
      78                 :            :   }
      79                 :            : }
      80                 :            : 
      81                 :          6 : PassengerCount getHOV(Restrictions const &restrictions)
      82                 :            : {
      83                 :          6 :   PassengerCount hov(0);
      84         [ +  + ]:          7 :   for (auto const &conjunction : restrictions.conjunctions)
      85                 :            :   {
      86                 :          1 :     hov = std::max(hov, conjunction.passengersMin);
      87                 :            :   }
      88         [ +  + ]:          7 :   for (auto const &disjunction : restrictions.disjunctions)
      89                 :            :   {
      90                 :          1 :     hov = std::max(hov, disjunction.passengersMin);
      91                 :            :   }
      92                 :          6 :   return hov;
      93                 :            : }
      94                 :            : 
      95                 :            : } // namespace restriction
      96                 :            : } // namespace map
      97                 :            : } // namespace ad

Generated by: LCOV version 1.14