1
#include "com/ubuntu/location/wgs84/coordinate.h"
2
#include "com/ubuntu/location/wgs84/altitude.h"
3
#include "com/ubuntu/location/wgs84/latitude.h"
4
#include "com/ubuntu/location/wgs84/longitude.h"
5
#include "com/ubuntu/location/position.h"
7
#include <gtest/gtest.h>
9
TEST(Latitude, constructing_a_latitude_with_invalid_value_throws)
11
static const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
12
static const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
13
std::default_random_engine rng;
14
std::uniform_real_distribution<double> dist1(
15
-std::numeric_limits<double>::max(),
16
min_value - std::numeric_limits<double>::min());
17
std::uniform_real_distribution<double> dist2(
18
max_value + std::numeric_limits<double>::min(),
19
std::numeric_limits<double>::max());
20
double dl = dist1(rng);
21
double du = dist2(rng);
22
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Latitude l {dl*com::ubuntu::location::units::Degrees};);
23
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Latitude l {du*com::ubuntu::location::units::Degrees};);
26
TEST(Latitude, constructing_a_latitude_with_a_valid_value_does_not_throw)
28
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
29
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
30
std::default_random_engine rng;
31
std::uniform_real_distribution<double> dist(min_value,max_value);
32
EXPECT_NO_THROW(com::ubuntu::location::wgs84::Latitude l {dist(rng)*com::ubuntu::location::units::Degrees};);
35
TEST(Latitude, a_latitude_contains_value_passed_at_construction)
37
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
38
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
39
std::default_random_engine rng;
40
std::uniform_real_distribution<double> dist(min_value,max_value);
42
com::ubuntu::location::wgs84::Latitude l {d* com::ubuntu::location::units::Degrees};
43
EXPECT_EQ(d * com::ubuntu::location::units::Degrees, l.value);
46
TEST(Longitude, constructing_a_longitude_with_invalid_value_throws)
48
static const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
49
static const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
50
std::default_random_engine rng;
51
std::uniform_real_distribution<double> dist1(
52
-std::numeric_limits<double>::max(),
53
min_value - std::numeric_limits<double>::min());
54
std::uniform_real_distribution<double> dist2(
55
max_value + std::numeric_limits<double>::min(),
56
std::numeric_limits<double>::max());
57
double dl = dist1(rng);
58
double du = dist2(rng);
59
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Longitude l {dl*com::ubuntu::location::units::Degrees};);
60
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Longitude l {du*com::ubuntu::location::units::Degrees};);
63
TEST(Longitude, constructing_a_longitude_with_a_valid_value_does_not_throw)
65
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
66
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
67
std::default_random_engine rng;
68
std::uniform_real_distribution<double> dist(min_value,max_value);
69
EXPECT_NO_THROW(com::ubuntu::location::wgs84::Longitude l {dist(rng)*com::ubuntu::location::units::Degrees};);
72
TEST(Longitude, a_longitude_contains_value_passed_at_construction)
74
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
75
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
76
std::default_random_engine rng;
77
std::uniform_real_distribution<double> dist(min_value,max_value);
79
com::ubuntu::location::wgs84::Longitude l {d* com::ubuntu::location::units::Degrees};
80
EXPECT_EQ(d * com::ubuntu::location::units::Degrees, l.value);
83
TEST(Altitude, an_altitude_contains_value_passed_at_construction)
85
const double min_value = -std::numeric_limits<double>::max();
86
const double max_value = std::numeric_limits<double>::max();
87
std::default_random_engine rng;
88
std::uniform_real_distribution<double> dist(min_value,max_value);
90
com::ubuntu::location::wgs84::Altitude a {d* com::ubuntu::location::units::Meters};
91
EXPECT_EQ(d * com::ubuntu::location::units::Meters, a.value);
94
TEST(HaversineDistance, calculating_the_haverstine_distance_yields_correct_values)
96
com::ubuntu::location::wgs84::Latitude lat1 {47.621800*com::ubuntu::location::units::Degrees};
97
com::ubuntu::location::wgs84::Longitude lon1 {-122.350326*com::ubuntu::location::units::Degrees};
99
com::ubuntu::location::wgs84::Latitude lat2 {47.041917*com::ubuntu::location::units::Degrees};
100
com::ubuntu::location::wgs84::Longitude lon2 {-122.893766*com::ubuntu::location::units::Degrees};
102
com::ubuntu::location::Position seattle {lat1, lon1};
103
com::ubuntu::location::Position olympia {lat2, lon2};
105
com::ubuntu::location::units::Quantity<com::ubuntu::location::units::Length> expected_distance
107
76.386615799548693 * com::ubuntu::location::units::kilo* com::ubuntu::location::units::Meters
109
EXPECT_NEAR(expected_distance.value(), com::ubuntu::location::haversine_distance(seattle, olympia).value(), 1E-3);