A Discrete-Event Network Simulator
API
rand-cart-around-geo-test.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014 University of Washington
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
19 */
20
21#include <ns3/test.h>
22#include <ns3/log.h>
23#include <cmath>
24#include <ns3/geographic-positions.h>
25
45NS_LOG_COMPONENT_DEFINE ("RandCartAroundGeoTest");
46
47using namespace ns3;
48
53const double TOLERANCE = 0.1;
54
56static const double EARTH_RADIUS = 6371e3;
57
65{
66public:
77 RandCartAroundGeoTestCase (double originLatitude,
78 double originLongitude,
79 double maxAltitude,
80 int numPoints,
81 double maxDistFromOrigin,
84
85private:
86 virtual void DoRun (void);
94 static std::string Name (double originLatitude,
95 double originLongitude,
96 double maxDistFromOrigin);
103};
104
105std::string
106RandCartAroundGeoTestCase::Name (double originLatitude,
107 double originLongitude,
108 double maxDistFromOrigin)
109{
110 std::ostringstream oss;
111 oss << "origin latitude = " << originLatitude << " degrees, "
112 << "origin longitude = " << originLongitude << " degrees, "
113 << "max distance from origin = " << maxDistFromOrigin;
114 return oss.str();
115}
116
118 double originLongitude,
119 double maxAltitude,
120 int numPoints,
121 double maxDistFromOrigin,
123 : TestCase (Name (originLatitude, originLongitude, maxDistFromOrigin)),
124 m_originLatitude (originLatitude),
125 m_originLongitude (originLongitude),
126 m_maxAltitude (maxAltitude),
127 m_numPoints (numPoints),
128 m_maxDistFromOrigin (maxDistFromOrigin),
129 m_uniRand (uniRand)
130{
131}
132
134{
135}
136
137void
139{
140 std::list<Vector> points = GeographicPositions::RandCartesianPointsAroundGeographicPoint (m_originLatitude,
145 m_uniRand);
146 Vector origin = GeographicPositions::GeographicToCartesianCoordinates (m_originLatitude,
149 GeographicPositions::SPHERE);
150 Vector randPoint;
151 while (!points.empty ())
152 {
153 randPoint = points.front ();
154 points.pop_front ();
155
156 // pythagorean distance between random point and origin, not distance on surface of earth
157 double straightDistFromOrigin = sqrt (pow (randPoint.x - origin.x, 2) +
158 pow (randPoint.y - origin.y, 2) +
159 pow (randPoint.z - origin.z, 2));
160
161 // arc length distance between random point and origin, on surface of earth
162 double arcDistFromOrigin = 2 * EARTH_RADIUS * asin (straightDistFromOrigin / (2 * EARTH_RADIUS));
163
164 NS_TEST_ASSERT_MSG_LT (arcDistFromOrigin,
166 "random point (" << randPoint.x << ", " << randPoint.y
167 << ", " << randPoint.z << ") is outside of max radius from origin");
168 }
169}
170
178{
179public:
181};
182
184 : TestSuite ("rand-cart-around-geo", UNIT)
185{
186 NS_LOG_INFO ("creating RandCartAroundGeoTestSuite");
187 Ptr<UniformRandomVariable> uniRand = CreateObject<UniformRandomVariable> ();
188 uniRand->SetStream (5);
189 for (double originLatitude = -89.9; originLatitude <= 89.9; originLatitude += 35.96)
190 {
191 for (double originLongitude = 0; originLongitude <= 360; originLongitude += 72)
192 {
193 for (double maxDistFromOrigin = 1000; maxDistFromOrigin <= 1000000; maxDistFromOrigin *= 10)
194 {
195 AddTestCase (new RandCartAroundGeoTestCase (originLatitude,
196 originLongitude,
197 0, // on earth's surface
198 50, // 50 points generated
199 maxDistFromOrigin,
200 uniRand),
201 TestCase::QUICK);
202 }
203 }
204 }
205}
206
Rand Cart Around Geo Test Case.
double m_maxAltitude
maximum altitude
double m_originLongitude
origin longitude
virtual void DoRun(void)
Implementation to actually run this TestCase.
double m_originLatitude
origin latitude
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.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#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:675
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static RandCartAroundGeoTestSuite g_RandCartAroundGeoTestSuite
the test suite
static const double EARTH_RADIUS
earth's radius in meters if modeled as a perfect sphere
const double TOLERANCE
0.1 meter tolerance for testing, which is very small compared to the maximum distances from origin be...
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:166