26
26
TEST(Latitude, constructing_a_latitude_with_invalid_value_throws)
28
static const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
29
static const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
28
static const double min_value =
29
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
30
static const double max_value =
31
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
30
32
std::default_random_engine rng;
31
std::uniform_real_distribution<double> dist1(
32
-std::numeric_limits<double>::max(),
33
min_value - std::numeric_limits<double>::min());
34
std::uniform_real_distribution<double> dist2(
35
max_value + std::numeric_limits<double>::min(),
36
std::numeric_limits<double>::max());
33
std::uniform_real_distribution<double> dist1(-std::numeric_limits<double>::max(),
34
min_value - std::numeric_limits<double>::min());
35
std::uniform_real_distribution<double> dist2(max_value + std::numeric_limits<double>::min(),
36
std::numeric_limits<double>::max());
37
37
double dl = dist1(rng);
38
38
double du = dist2(rng);
39
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Latitude l {dl*com::ubuntu::location::units::Degrees};);
40
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Latitude l {du*com::ubuntu::location::units::Degrees};);
39
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Latitude l{dl * com::ubuntu::location::units::Degrees};);
40
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Latitude l{du * com::ubuntu::location::units::Degrees};);
43
43
TEST(Latitude, constructing_a_latitude_with_a_valid_value_does_not_throw)
45
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
46
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
45
const double min_value =
46
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
47
const double max_value =
48
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
47
49
std::default_random_engine rng;
48
std::uniform_real_distribution<double> dist(min_value,max_value);
49
EXPECT_NO_THROW(com::ubuntu::location::wgs84::Latitude l {dist(rng)*com::ubuntu::location::units::Degrees};);
50
std::uniform_real_distribution<double> dist(min_value, max_value);
51
EXPECT_NO_THROW(com::ubuntu::location::wgs84::Latitude l{dist(rng) * com::ubuntu::location::units::Degrees};);
52
54
TEST(Latitude, a_latitude_contains_value_passed_at_construction)
54
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
55
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
56
const double min_value =
57
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::min();
58
const double max_value =
59
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Latitude>::max();
56
60
std::default_random_engine rng;
57
std::uniform_real_distribution<double> dist(min_value,max_value);
61
std::uniform_real_distribution<double> dist(min_value, max_value);
58
62
double d = dist(rng);
59
com::ubuntu::location::wgs84::Latitude l {d* com::ubuntu::location::units::Degrees};
63
com::ubuntu::location::wgs84::Latitude l{d * com::ubuntu::location::units::Degrees};
60
64
EXPECT_EQ(d * com::ubuntu::location::units::Degrees, l.value);
63
67
TEST(Longitude, constructing_a_longitude_with_invalid_value_throws)
65
static const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
66
static const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
69
static const double min_value =
70
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
71
static const double max_value =
72
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
67
73
std::default_random_engine rng;
68
std::uniform_real_distribution<double> dist1(
69
-std::numeric_limits<double>::max(),
70
min_value - std::numeric_limits<double>::min());
71
std::uniform_real_distribution<double> dist2(
72
max_value + std::numeric_limits<double>::min(),
73
std::numeric_limits<double>::max());
74
std::uniform_real_distribution<double> dist1(-std::numeric_limits<double>::max(),
75
min_value - std::numeric_limits<double>::min());
76
std::uniform_real_distribution<double> dist2(max_value + std::numeric_limits<double>::min(),
77
std::numeric_limits<double>::max());
74
78
double dl = dist1(rng);
75
79
double du = dist2(rng);
76
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Longitude l {dl*com::ubuntu::location::units::Degrees};);
77
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Longitude l {du*com::ubuntu::location::units::Degrees};);
80
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Longitude l{dl * com::ubuntu::location::units::Degrees};);
81
EXPECT_ANY_THROW(com::ubuntu::location::wgs84::Longitude l{du * com::ubuntu::location::units::Degrees};);
80
84
TEST(Longitude, constructing_a_longitude_with_a_valid_value_does_not_throw)
82
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
83
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
86
const double min_value =
87
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
88
const double max_value =
89
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
84
90
std::default_random_engine rng;
85
std::uniform_real_distribution<double> dist(min_value,max_value);
86
EXPECT_NO_THROW(com::ubuntu::location::wgs84::Longitude l {dist(rng)*com::ubuntu::location::units::Degrees};);
91
std::uniform_real_distribution<double> dist(min_value, max_value);
92
EXPECT_NO_THROW(com::ubuntu::location::wgs84::Longitude l{dist(rng) * com::ubuntu::location::units::Degrees};);
89
95
TEST(Longitude, a_longitude_contains_value_passed_at_construction)
91
const double min_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
92
const double max_value = com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
97
const double min_value =
98
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::min();
99
const double max_value =
100
com::ubuntu::location::wgs84::CoordinateTraits<com::ubuntu::location::wgs84::Longitude>::max();
93
101
std::default_random_engine rng;
94
std::uniform_real_distribution<double> dist(min_value,max_value);
102
std::uniform_real_distribution<double> dist(min_value, max_value);
95
103
double d = dist(rng);
96
com::ubuntu::location::wgs84::Longitude l {d* com::ubuntu::location::units::Degrees};
104
com::ubuntu::location::wgs84::Longitude l{d * com::ubuntu::location::units::Degrees};
97
105
EXPECT_EQ(d * com::ubuntu::location::units::Degrees, l.value);
102
110
const double min_value = -std::numeric_limits<double>::max();
103
111
const double max_value = std::numeric_limits<double>::max();
104
112
std::default_random_engine rng;
105
std::uniform_real_distribution<double> dist(min_value,max_value);
113
std::uniform_real_distribution<double> dist(min_value, max_value);
106
114
double d = dist(rng);
107
com::ubuntu::location::wgs84::Altitude a {d* com::ubuntu::location::units::Meters};
115
com::ubuntu::location::wgs84::Altitude a{d * com::ubuntu::location::units::Meters};
108
116
EXPECT_EQ(d * com::ubuntu::location::units::Meters, a.value);
111
119
TEST(HaversineDistance, calculating_the_haverstine_distance_yields_correct_values)
113
com::ubuntu::location::wgs84::Latitude lat1 {47.621800*com::ubuntu::location::units::Degrees};
114
com::ubuntu::location::wgs84::Longitude lon1 {-122.350326*com::ubuntu::location::units::Degrees};
116
com::ubuntu::location::wgs84::Latitude lat2 {47.041917*com::ubuntu::location::units::Degrees};
117
com::ubuntu::location::wgs84::Longitude lon2 {-122.893766*com::ubuntu::location::units::Degrees};
119
com::ubuntu::location::Position seattle {lat1, lon1};
120
com::ubuntu::location::Position olympia {lat2, lon2};
122
com::ubuntu::location::units::Quantity<com::ubuntu::location::units::Length> expected_distance
124
76.386615799548693 * com::ubuntu::location::units::kilo* com::ubuntu::location::units::Meters
121
com::ubuntu::location::wgs84::Latitude lat1{47.621800 * com::ubuntu::location::units::Degrees};
122
com::ubuntu::location::wgs84::Longitude lon1{-122.350326 * com::ubuntu::location::units::Degrees};
124
com::ubuntu::location::wgs84::Latitude lat2{47.041917 * com::ubuntu::location::units::Degrees};
125
com::ubuntu::location::wgs84::Longitude lon2{-122.893766 * com::ubuntu::location::units::Degrees};
127
com::ubuntu::location::Position seattle{lat1, lon1};
128
com::ubuntu::location::Position olympia{lat2, lon2};
130
com::ubuntu::location::units::Quantity<com::ubuntu::location::units::Length> expected_distance{
131
76.386615799548693 * com::ubuntu::location::units::kilo * com::ubuntu::location::units::Meters};
126
132
EXPECT_NEAR(expected_distance.value(), com::ubuntu::location::haversine_distance(seattle, olympia).value(), 1E-3);