~thomas-voss/location-service/flatten

« back to all changes in this revision

Viewing changes to tests/wgs84_test.cpp

  • Committer: thomas-voss
  • Date: 2015-02-03 12:21:33 UTC
  • Revision ID: thomas.voss@canonical.com-20150203122133-660kjot28cz7dx6m
Adjust namespace to core::location for all classes not in com::ubuntu::location::connectivity.

Show diffs side-by-side

added added

removed removed

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