LCOV - code coverage report
Current view: top level - tests/point - GeoOperationTests.cpp (source / functions) Hit Total Coverage
Test: ad_map_access Lines: 114 114 100.0 %
Date: 2022-10-04 09:48:07 Functions: 9 9 100.0 %
Branches: 75 248 30.2 %

           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/access/Operation.hpp>
      10                 :            : #include <ad/map/point/Operation.hpp>
      11                 :            : #include <gtest/gtest.h>
      12                 :            : 
      13                 :            : using namespace ::ad;
      14                 :            : using namespace ::ad::map;
      15                 :            : using namespace ::ad::map::point;
      16                 :            : 
      17                 :            : struct GeoOperationTest : ::testing::Test
      18                 :            : {
      19                 :          3 :   GeoOperationTest()
      20                 :          3 :   {
      21                 :          3 :   }
      22                 :            : 
      23                 :          3 :   virtual void SetUp()
      24                 :            :   {
      25                 :          3 :   }
      26                 :            : 
      27                 :          3 :   virtual void TearDown()
      28                 :            :   {
      29                 :          3 :     access::cleanup();
      30                 :          3 :   }
      31                 :            : };
      32                 :            : 
      33                 :          2 : TEST_F(GeoOperationTest, geoPointapproxAltitude)
      34                 :            : {
      35                 :          1 :   Longitude ul_lon(10.123456);
      36                 :          1 :   Longitude lr_lon(10.234567);
      37                 :          1 :   Latitude ul_lat(-20.22222);
      38                 :          1 :   Latitude lr_lat(-20.33333);
      39                 :          1 :   Altitude ul_alt(100);
      40                 :          1 :   Altitude ur_alt(200);
      41                 :          1 :   Altitude ll_alt(300);
      42                 :          1 :   Altitude lr_alt(400);
      43                 :            :   //
      44                 :          1 :   GeoEdge pts;
      45                 :          1 :   GeoPoint pt_ul = createGeoPoint(ul_lon, ul_lat, ul_alt);
      46                 :          1 :   GeoPoint pt_ur = createGeoPoint(ul_lon, lr_lat, ur_alt);
      47                 :          1 :   GeoPoint pt_ll = createGeoPoint(lr_lon, ul_lat, ll_alt);
      48                 :          1 :   GeoPoint pt_lr = createGeoPoint(lr_lon, lr_lat, lr_alt);
      49         [ +  - ]:          1 :   pts.push_back(pt_ul);
      50         [ +  - ]:          1 :   pts.push_back(pt_ur);
      51         [ +  - ]:          1 :   pts.push_back(pt_ll);
      52         [ +  - ]:          1 :   pts.push_back(pt_lr);
      53                 :            :   //
      54                 :            :   {
      55                 :          1 :     GeoPoint ptX = createGeoPoint(ul_lon, ul_lat, AltitudeUnknown);
      56         [ +  - ]:          1 :     GeoPoint pt = approxAltitude(ptX, pts);
      57   [ +  -  -  +  :          1 :     ASSERT_EQ(pt, pt_ul);
          -  -  -  -  -  
                      - ]
      58                 :            :   }
      59                 :            :   {
      60                 :          1 :     GeoPoint ptX = createGeoPoint(ul_lon, lr_lat, AltitudeUnknown);
      61         [ +  - ]:          1 :     GeoPoint pt = approxAltitude(ptX, pts);
      62   [ +  -  -  +  :          1 :     ASSERT_EQ(pt, pt_ur);
          -  -  -  -  -  
                      - ]
      63                 :            :   }
      64                 :            :   {
      65                 :          1 :     GeoPoint ptX = createGeoPoint(lr_lon, ul_lat, AltitudeUnknown);
      66         [ +  - ]:          1 :     GeoPoint pt = approxAltitude(ptX, pts);
      67   [ +  -  -  +  :          1 :     ASSERT_EQ(pt, pt_ll);
          -  -  -  -  -  
                      - ]
      68                 :            :   }
      69                 :            :   {
      70                 :          1 :     GeoPoint ptX = createGeoPoint(lr_lon, lr_lat, AltitudeUnknown);
      71         [ +  - ]:          1 :     GeoPoint pt = approxAltitude(ptX, pts);
      72   [ +  -  -  +  :          1 :     ASSERT_EQ(pt, pt_lr);
          -  -  -  -  -  
                      - ]
      73                 :            :   }
      74                 :            :   {
      75         [ +  - ]:          1 :     GeoPoint ptY = vectorInterpolate(pt_ul, pt_ur, physics::ParametricValue(0.3));
      76         [ +  - ]:          1 :     GeoPoint ptX = zeroAltitude(ptY);
      77         [ +  - ]:          1 :     GeoPoint pt = approxAltitude(ptX, pts);
      78   [ +  -  -  +  :          1 :     ASSERT_EQ(pt, ptY);
          -  -  -  -  -  
                      - ]
      79                 :            :   }
      80                 :            :   {
      81         [ +  - ]:          1 :     GeoPoint ptY = vectorInterpolate(pt_ur, pt_lr, physics::ParametricValue(0.7));
      82         [ +  - ]:          1 :     GeoPoint ptX = zeroAltitude(ptY);
      83         [ +  - ]:          1 :     GeoPoint pt = approxAltitude(ptX, pts);
      84   [ +  -  -  +  :          1 :     ASSERT_EQ(pt, ptY);
          -  -  -  -  -  
                      - ]
      85                 :            :   }
      86                 :            :   {
      87                 :          1 :     const Altitude h(123.456);  // Invented altitude.
      88                 :          1 :     const Altitude dh(100.123); // Invented altitude difference.
      89                 :            :     // Position of Intel Office
      90                 :          1 :     GeoPoint pt1_geo = createGeoPoint(Longitude(-121.935549), Latitude(37.401336), h);
      91                 :            :     // Position of San Jose Fire Department Station 29 + altitude difference
      92         [ +  - ]:          1 :     GeoPoint pt2_geo = createGeoPoint(Longitude(-121.933886), Latitude(37.401112), h + dh);
      93                 :            : 
      94                 :          1 :     GeoEdge edge1_geo;
      95         [ +  - ]:          1 :     edge1_geo.push_back(pt2_geo);
      96                 :          1 :     GeoPoint ret;
      97         [ +  - ]:          1 :     ret = approxAltitude(pt1_geo, edge1_geo);
      98   [ +  -  +  -  :          1 :     ASSERT_EQ(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), h + dh), ret);
          -  +  -  -  -  
                -  -  - ]
      99                 :            :   }
     100                 :            : }
     101                 :            : 
     102                 :          2 : TEST_F(GeoOperationTest, Orientation)
     103                 :            : {
     104                 :          1 :   const Altitude h(123.456);  // Invented altitude.
     105                 :          1 :   const Altitude dh(100.123); // Invented altitude difference.
     106                 :            :   // Position of Intel Office
     107                 :          1 :   GeoPoint pt1_geo = createGeoPoint(Longitude(-121.935549), Latitude(37.401336), h);
     108                 :            :   // Position of San Jose Fire Department Station 29
     109                 :          1 :   GeoPoint pt2_geo = createGeoPoint(Longitude(-121.933886), Latitude(37.401112), h);
     110                 :            :   // Position of San Jose Fire Department Station 29 + altitude difference
     111         [ +  - ]:          1 :   GeoPoint pt3_geo = createGeoPoint(Longitude(-121.933886), Latitude(37.401112), h + dh);
     112                 :            : 
     113                 :          1 :   GeoEdge edge2_geo;
     114                 :          1 :   GeoEdge edge3_geo;
     115         [ +  - ]:          1 :   edge2_geo.push_back(pt1_geo);
     116         [ +  - ]:          1 :   edge2_geo.push_back(pt2_geo);
     117         [ +  - ]:          1 :   edge3_geo.push_back(pt1_geo);
     118         [ +  - ]:          1 :   edge3_geo.push_back(pt3_geo);
     119   [ +  -  -  +  :          1 :   ASSERT_TRUE(haveSameOrientation(edge2_geo, edge3_geo));
          -  -  -  -  -  
                -  -  - ]
     120                 :            : }
     121                 :            : 
     122                 :          2 : TEST_F(GeoOperationTest, isOnTheLeft)
     123                 :            : {
     124                 :          1 :   GeoEdge edge2_geo;
     125                 :          1 :   GeoEdge edge3_geo;
     126                 :          1 :   const double diff = 3.534679;
     127                 :          1 :   edge2_geo.clear();
     128         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549 - diff), Latitude(37.401336), Altitude(123.456)));
     129         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 + diff), Altitude(123.456)));
     130                 :          1 :   edge3_geo.clear();
     131         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     132         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 + diff), Altitude(123.456)));
     133   [ +  -  -  +  :          1 :   ASSERT_TRUE(isOnTheLeft(edge2_geo, edge3_geo));
          -  -  -  -  -  
                -  -  - ]
     134                 :            : 
     135                 :          1 :   edge2_geo.clear();
     136         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549 + diff), Latitude(37.401336), Altitude(123.456)));
     137         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 + diff), Altitude(123.456)));
     138                 :          1 :   edge3_geo.clear();
     139         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 + diff), Altitude(123.456)));
     140         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     141   [ +  -  -  +  :          1 :   ASSERT_TRUE(isOnTheLeft(edge2_geo, edge3_geo));
          -  -  -  -  -  
                -  -  - ]
     142                 :            : 
     143                 :          1 :   edge2_geo.clear();
     144         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 - diff), Altitude(123.456)));
     145         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     146                 :          1 :   edge3_geo.clear();
     147         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     148         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549 + diff), Latitude(37.401336), Altitude(123.456)));
     149   [ +  -  -  +  :          1 :   ASSERT_FALSE(isOnTheLeft(edge2_geo, edge3_geo));
          -  -  -  -  -  
                -  -  - ]
     150                 :            : 
     151                 :          1 :   edge2_geo.clear();
     152         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 + diff), Altitude(123.456)));
     153         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     154                 :          1 :   edge3_geo.clear();
     155         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     156         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549 + diff), Latitude(37.401336), Altitude(123.456)));
     157   [ +  -  -  +  :          1 :   ASSERT_TRUE(isOnTheLeft(edge2_geo, edge3_geo));
          -  -  -  -  -  
                -  -  - ]
     158                 :            : 
     159                 :          1 :   edge2_geo.clear();
     160         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 + diff), Altitude(123.456)));
     161         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     162                 :          1 :   edge3_geo.clear();
     163         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     164         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549 + diff), Latitude(37.401336 + diff), Altitude(123.456)));
     165   [ +  -  -  +  :          1 :   ASSERT_TRUE(isOnTheLeft(edge2_geo, edge3_geo));
          -  -  -  -  -  
                -  -  - ]
     166                 :            : 
     167                 :          1 :   edge2_geo.clear();
     168         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336 - diff), Altitude(123.456)));
     169         [ +  - ]:          1 :   edge2_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     170                 :          1 :   edge3_geo.clear();
     171         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549), Latitude(37.401336), Altitude(123.456)));
     172         [ +  - ]:          1 :   edge3_geo.push_back(createGeoPoint(Longitude(-121.935549 + diff), Latitude(37.401336 + diff), Altitude(123.456)));
     173   [ +  -  -  +  :          1 :   ASSERT_FALSE(isOnTheLeft(edge2_geo, edge3_geo));
          -  -  -  -  -  
                -  -  - ]
     174                 :            : }

Generated by: LCOV version 1.14