Version 0.8.0
[marnav.git] / test / geo / Test_geo_cpa.cpp
blob047db6b5499c4faf522578d4516a21ad02bab297
1 #include <gtest/gtest.h>
2 #include <marnav/geo/cpa.hpp>
4 using namespace marnav::geo;
6 namespace
9 class Test_geo_cpa : public ::testing::Test
13 TEST_F(Test_geo_cpa, collision_on_equator_eastwards_westwards)
15 const vessel vessel1 = {{0.0, 1.0}, 1.0, 90.0}; // being west, going east
16 const vessel vessel2 = {{0.0, -1.0}, 1.0, 270.0}; // being east, going west
18 // 2 degrees appart = 120nm, closing in at each 1kn => 60h
19 const position expected_vessels_pos{0.0, 0.0};
20 const std::chrono::seconds expected_time{60 * 3600};
22 position p1;
23 position p2;
24 std::chrono::seconds tcpa;
25 bool cpa_exists;
26 std::tie(p1, p2, tcpa, cpa_exists) = cpa(vessel1, vessel2);
28 EXPECT_NEAR(expected_vessels_pos.lat(), p1.lat(), 1e-5);
29 EXPECT_NEAR(expected_vessels_pos.lon(), p1.lon(), 1e-5);
30 EXPECT_NEAR(expected_vessels_pos.lat(), p2.lat(), 1e-5);
31 EXPECT_NEAR(expected_vessels_pos.lon(), p2.lon(), 1e-5);
32 EXPECT_NEAR(p1.lat(), p2.lat(), 1e-5);
33 EXPECT_NEAR(p1.lon(), p2.lon(), 1e-5);
34 EXPECT_EQ(expected_time, tcpa);
35 EXPECT_TRUE(cpa_exists);
38 TEST_F(Test_geo_cpa, collision_on_equator_eastwards_northwards)
40 const vessel vessel1 = {{0.0, 1.0}, 1.0, 90.0}; // being west, going east
41 const vessel vessel2 = {{-1.0, 0.0}, 1.0, 0.0}; // being south, going north
43 // each vessel 1 degree appart from CPA = 60nm, closing in at 1kn => 60h
44 const position expected_vessels_pos{0.0, 0.0};
45 const std::chrono::seconds expected_time{60 * 3600};
47 position p1;
48 position p2;
49 std::chrono::seconds tcpa;
50 bool cpa_exists;
51 std::tie(p1, p2, tcpa, cpa_exists) = cpa(vessel1, vessel2);
53 EXPECT_NEAR(expected_vessels_pos.lat(), p1.lat(), 1e-5);
54 EXPECT_NEAR(expected_vessels_pos.lon(), p1.lon(), 1e-5);
55 EXPECT_NEAR(expected_vessels_pos.lat(), p2.lat(), 1e-5);
56 EXPECT_NEAR(expected_vessels_pos.lon(), p2.lon(), 1e-5);
57 EXPECT_NEAR(p1.lat(), p2.lat(), 1e-5);
58 EXPECT_NEAR(p1.lon(), p2.lon(), 1e-5);
59 EXPECT_EQ(expected_time, tcpa);
60 EXPECT_EQ(std::chrono::minutes(60 * 60), tcpa);
61 EXPECT_EQ(std::chrono::hours(60), tcpa);
62 EXPECT_TRUE(cpa_exists);