A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rand-cart-around-geo-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
7 */
8
9#include <ns3/geographic-positions.h>
10#include <ns3/log.h>
11#include <ns3/test.h>
12
13#include <cmath>
14
15/**
16 * This test verifies the accuracy of the RandCartesianPointsAroundGeographicPoint()
17 * method in the GeographicPositions class, which generates uniformly
18 * distributed random points (in ECEF Cartesian coordinates) within a given
19 * altitude above earth's surface centered around a given origin point (on
20 * earth's surface, in geographic/geodetic coordinates) within a given distance
21 * radius (using arc length of earth's surface, not pythagorean distance).
22 * Distance radius is measured as if all generated points are on earth's
23 * surface (with altitude = 0). Assumes earth is a perfect sphere. To verify the
24 * method, this test checks that the generated points are within the given
25 * maximum distance radius from the origin. Since this is testing the distance
26 * radius from the origin, all points generated in this test are on earth's
27 * surface (altitude = 0), since the distance radius has been defined as if all
28 * points are on earth's surface. The pythagorean (straight-line) distance
29 * between each generated point and the origin is first calculated, and then
30 * using this distance and the radius of the earth, the distance radius to the
31 * origin (arc length) is calculated. This distance radius is compared to the
32 * max distance radius to ensure that it is less than the maximum.
33 */
34NS_LOG_COMPONENT_DEFINE("RandCartAroundGeoTest");
35
36using namespace ns3;
37
38/**
39 * 0.1 meter tolerance for testing, which is very small compared to the maximum
40 * distances from origin being tested
41 */
42const double TOLERANCE = 0.1;
43
44/// earth's radius in meters if modeled as a perfect sphere
45static const double EARTH_RADIUS = 6371e3;
46
47/**
48 * \ingroup mobility-test
49 *
50 * \brief Rand Cart Around Geo Test Case
51 */
53{
54 public:
55 /**
56 * Constructor
57 *
58 * \param originLatitude origin latitude
59 * \param originLongitude origin longitude
60 * \param maxAltitude maximum altitude
61 * \param numPoints number of points
62 * \param maxDistFromOrigin maximum distance from origin
63 * \param uniRand random variable
64 */
65 RandCartAroundGeoTestCase(double originLatitude,
66 double originLongitude,
67 double maxAltitude,
68 int numPoints,
69 double maxDistFromOrigin,
72
73 private:
74 void DoRun() override;
75 /**
76 * name function
77 * \param originLatitude the origin latitude
78 * \param originLongitude the origin longitude
79 * \param maxDistFromOrigin the maximum distance from the origin
80 * \returns the name string
81 */
82 static std::string Name(double originLatitude,
83 double originLongitude,
84 double maxDistFromOrigin);
85 double m_originLatitude; ///< origin latitude
86 double m_originLongitude; ///< origin longitude
87 double m_maxAltitude; ///< maximum altitude
88 int m_numPoints; ///< number of points
89 double m_maxDistFromOrigin; ///< maximum distance from origin
91};
92
93std::string
94RandCartAroundGeoTestCase::Name(double originLatitude,
95 double originLongitude,
96 double maxDistFromOrigin)
97{
98 std::ostringstream oss;
99 oss << "origin latitude = " << originLatitude << " degrees, "
100 << "origin longitude = " << originLongitude << " degrees, "
101 << "max distance from origin = " << maxDistFromOrigin;
102 return oss.str();
103}
104
106 double originLongitude,
107 double maxAltitude,
108 int numPoints,
109 double maxDistFromOrigin,
111 : TestCase(Name(originLatitude, originLongitude, maxDistFromOrigin)),
112 m_originLatitude(originLatitude),
113 m_originLongitude(originLongitude),
114 m_maxAltitude(maxAltitude),
115 m_numPoints(numPoints),
116 m_maxDistFromOrigin(maxDistFromOrigin),
117 m_uniRand(uniRand)
118{
119}
120
124
125void
127{
128 std::list<Vector> points =
134 m_uniRand);
135 Vector origin =
140 Vector randPoint;
141 while (!points.empty())
142 {
143 randPoint = points.front();
144 points.pop_front();
145
146 // pythagorean distance between random point and origin, not distance on surface of earth
147 double straightDistFromOrigin =
148 sqrt(pow(randPoint.x - origin.x, 2) + pow(randPoint.y - origin.y, 2) +
149 pow(randPoint.z - origin.z, 2));
150
151 // arc length distance between random point and origin, on surface of earth
152 double arcDistFromOrigin =
153 2 * EARTH_RADIUS * asin(straightDistFromOrigin / (2 * EARTH_RADIUS));
154
155 NS_TEST_ASSERT_MSG_LT(arcDistFromOrigin,
157 "random point (" << randPoint.x << ", " << randPoint.y << ", "
158 << randPoint.z
159 << ") is outside of max radius from origin");
160 }
161}
162
163/**
164 * \ingroup mobility-test
165 *
166 * \brief Rand Cart Around Geo Test Suite
167 */
169{
170 public:
172};
173
175 : TestSuite("rand-cart-around-geo", Type::UNIT)
176{
177 NS_LOG_INFO("creating RandCartAroundGeoTestSuite");
179 uniRand->SetStream(5);
180 for (double originLatitude = -89.9; originLatitude <= 89.9; originLatitude += 35.96)
181 {
182 for (double originLongitude = 0; originLongitude <= 360; originLongitude += 72)
183 {
184 for (double maxDistFromOrigin = 1000; maxDistFromOrigin <= 1000000;
185 maxDistFromOrigin *= 10)
186 {
187 AddTestCase(new RandCartAroundGeoTestCase(originLatitude,
188 originLongitude,
189 0, // on earth's surface
190 50, // 50 points generated
191 maxDistFromOrigin,
192 uniRand),
193 TestCase::Duration::QUICK);
194 }
195 }
196 }
197}
198
199/**
200 * \ingroup mobility-test
201 * Static variable for test initialization
202 */
Rand Cart Around Geo Test Case.
void DoRun() override
Implementation to actually run this TestCase.
double m_originLongitude
origin longitude
static std::string Name(double originLatitude, double originLongitude, double maxDistFromOrigin)
name function
RandCartAroundGeoTestCase(double originLatitude, double originLongitude, double maxAltitude, int numPoints, double maxDistFromOrigin, Ptr< UniformRandomVariable > uniRand)
Constructor.
double m_maxDistFromOrigin
maximum distance from origin
Ptr< UniformRandomVariable > m_uniRand
random number
Rand Cart Around Geo Test Suite.
static std::list< Vector > RandCartesianPointsAroundGeographicPoint(double originLatitude, double originLongitude, double maxAltitude, int numPoints, double maxDistFromOrigin, Ptr< UniformRandomVariable > uniRand)
Generates uniformly distributed random points (in ECEF Cartesian coordinates) within a given altitude...
static Vector GeographicToCartesianCoordinates(double latitude, double longitude, double altitude, EarthSpheroidType sphType)
Converts earth geographic/geodetic coordinates (latitude and longitude in degrees) with a given altit...
Smart pointer class similar to boost::intrusive_ptr.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
static RandCartAroundGeoTestSuite g_RandCartAroundGeoTestSuite
Static variable for test initialization.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition test.h:699
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const double TOLERANCE
Tolerance used to check reciprocal of two numbers.
static const double EARTH_RADIUS
earth's radius in meters if modeled as a perfect sphere
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
Definition tcp-test.cc:155