~thomas-voss/location-service/fix-settings-not-being-applied

« back to all changes in this revision

Viewing changes to tests/wgs84_test.cpp

  • Committer: Thomas Voß
  • Date: 2013-05-28 14:20:45 UTC
  • Revision ID: thomas.voss@canonical.com-20130528142045-kq5umqdmm4o53vwk
Initial push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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"
 
6
 
 
7
#include <gtest/gtest.h>
 
8
 
 
9
TEST(Latitude, constructing_a_latitude_with_invalid_value_throws)
 
10
{
 
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};);
 
24
}
 
25
 
 
26
TEST(Latitude, constructing_a_latitude_with_a_valid_value_does_not_throw)
 
27
{
 
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};);
 
33
}
 
34
 
 
35
TEST(Latitude, a_latitude_contains_value_passed_at_construction)
 
36
{
 
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);
 
41
    double d = dist(rng);
 
42
    com::ubuntu::location::wgs84::Latitude l {d* com::ubuntu::location::units::Degrees};
 
43
    EXPECT_EQ(d * com::ubuntu::location::units::Degrees, l.value);
 
44
}
 
45
 
 
46
TEST(Longitude, constructing_a_longitude_with_invalid_value_throws)
 
47
{
 
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};);
 
61
}
 
62
 
 
63
TEST(Longitude, constructing_a_longitude_with_a_valid_value_does_not_throw)
 
64
{
 
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};);
 
70
}
 
71
 
 
72
TEST(Longitude, a_longitude_contains_value_passed_at_construction)
 
73
{
 
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);
 
78
    double d = dist(rng);
 
79
    com::ubuntu::location::wgs84::Longitude l {d* com::ubuntu::location::units::Degrees};
 
80
    EXPECT_EQ(d * com::ubuntu::location::units::Degrees, l.value);
 
81
}
 
82
 
 
83
TEST(Altitude, an_altitude_contains_value_passed_at_construction)
 
84
{
 
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);
 
89
    double d = dist(rng);
 
90
    com::ubuntu::location::wgs84::Altitude a {d* com::ubuntu::location::units::Meters};
 
91
    EXPECT_EQ(d * com::ubuntu::location::units::Meters, a.value);
 
92
}
 
93
 
 
94
TEST(HaversineDistance, calculating_the_haverstine_distance_yields_correct_values)
 
95
{
 
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};
 
98
 
 
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};
 
101
 
 
102
    com::ubuntu::location::Position seattle {lat1, lon1};
 
103
    com::ubuntu::location::Position olympia {lat2, lon2};
 
104
 
 
105
    com::ubuntu::location::units::Quantity<com::ubuntu::location::units::Length> expected_distance
 
106
    {
 
107
        76.386615799548693 * com::ubuntu::location::units::kilo* com::ubuntu::location::units::Meters
 
108
    };
 
109
    EXPECT_NEAR(expected_distance.value(), com::ubuntu::location::haversine_distance(seattle, olympia).value(), 1E-3);
 
110
}