2
* Copyright © 2012-2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
18
#include "com/ubuntu/location/velocity.h"
20
#include <gtest/gtest.h>
22
TEST(Velocity, constructing_a_velocity_with_invalid_value_throws)
24
std::default_random_engine rng;
25
std::uniform_real_distribution<double> dist(
26
-std::numeric_limits<double>::max(),
27
com::ubuntu::location::Velocity::min().value() - std::numeric_limits<double>::min());
29
EXPECT_ANY_THROW(com::ubuntu::location::Velocity v {d*com::ubuntu::location::units::MetersPerSecond};);
30
dist = std::uniform_real_distribution<double>(
31
com::ubuntu::location::Velocity::max().value() + std::numeric_limits<double>::min(),
32
std::numeric_limits<double>::max());
34
EXPECT_NO_THROW(com::ubuntu::location::Velocity v {d*com::ubuntu::location::units::MetersPerSecond};);
37
TEST(Velocity, constructing_a_velocity_with_a_valid_value_does_not_throw)
39
std::default_random_engine rng;
40
std::uniform_real_distribution<double> dist(com::ubuntu::location::Velocity::min().value(),
41
com::ubuntu::location::Velocity::max().value());
43
EXPECT_NO_THROW(com::ubuntu::location::Velocity v {dist(rng)*com::ubuntu::location::units::MetersPerSecond};);
46
TEST(Velocity, a_velocity_contains_value_passed_at_construction)
48
std::default_random_engine rng;
49
std::uniform_real_distribution<double> dist(com::ubuntu::location::Velocity::min().value(),
50
com::ubuntu::location::Velocity::max().value());
52
com::ubuntu::location::Velocity v {d* com::ubuntu::location::units::MetersPerSecond};
53
EXPECT_DOUBLE_EQ(d, v.value.value());