A Discrete-Event Network Simulator
API
test-parabolic-antenna.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011,12 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19 */
20
21#include <ns3/log.h>
22#include <ns3/test.h>
23#include <ns3/double.h>
24#include <ns3/parabolic-antenna-model.h>
25#include <ns3/simulator.h>
26#include <cmath>
27#include <string>
28#include <iostream>
29#include <sstream>
30
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE ("TestParabolicAntennaModel");
35
42 EQUAL = 0,
43 LESSTHAN = 1
44};
45
52{
53public:
62 static std::string BuildNameString (Angles a, double b, double o, double g);
72 ParabolicAntennaModelTestCase (Angles a, double b, double o, double g, double expectedGainDb, ParabolicAntennaModelGainTestCondition cond);
73
74
75private:
76 virtual void DoRun (void);
77
79 double m_b;
80 double m_o;
81 double m_g;
84};
85
86std::string ParabolicAntennaModelTestCase::BuildNameString (Angles a, double b, double o, double g)
87{
88 std::ostringstream oss;
89 oss << "theta=" << a.GetInclination () << " , phi=" << a.GetAzimuth ()
90 << ", beamdwidth=" << b << "deg"
91 << ", orientation=" << o
92 << ", maxAttenuation=" << g << " dB";
93 return oss.str ();
94}
95
96
98 : TestCase (BuildNameString (a, b, o, g)),
99 m_a (a),
100 m_b (b),
101 m_o (o),
102 m_g (g),
103 m_expectedGain (expectedGainDb),
104 m_cond (cond)
105{
106}
107
108void
110{
112
113 Ptr<ParabolicAntennaModel> a = CreateObject<ParabolicAntennaModel> ();
114 a->SetAttribute ("Beamwidth", DoubleValue (m_b));
115 a->SetAttribute ("Orientation", DoubleValue (m_o));
116 a->SetAttribute ("MaxAttenuation", DoubleValue (m_g));
117 double actualGain = a->GetGainDb (m_a);
118 switch (m_cond)
119 {
120 case EQUAL:
121 NS_TEST_EXPECT_MSG_EQ_TOL (actualGain, m_expectedGain, 0.001, "wrong value of the radiation pattern");
122 break;
123 case LESSTHAN:
124 NS_TEST_EXPECT_MSG_LT (actualGain, m_expectedGain, "gain higher than expected");
125 break;
126 default:
127 break;
128 }
129}
130
131
138{
139public:
141};
142
144 : TestSuite ("parabolic-antenna-model", UNIT)
145{
146
147 // with a 60 deg beamwidth, gain is -20dB at +-77.460 degrees from boresight
148 // phi, theta, beamwidth, orientation, maxAttn, expectedGain, condition
149 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (0), DegreesToRadians (90)), 60, 0, 20, 0, EQUAL), TestCase::QUICK);
150 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (30), DegreesToRadians (90)), 60, 0, 20, -3, EQUAL), TestCase::QUICK);
151 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-30), DegreesToRadians (90)), 60, 0, 20, -3, EQUAL), TestCase::QUICK);
152 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-90), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
153 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (90), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
154 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (100), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
155 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (150), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
156 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (180), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
157 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-100), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
158 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-150), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
159 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-180), DegreesToRadians (90)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
160
161 // with a 60 deg beamwidth, gain is -10dB at +-54.772 degrees from boresight
162 // test positive orientation
163 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (60), DegreesToRadians (90)), 60, 60, 10, 0, EQUAL), TestCase::QUICK);
164 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (90), DegreesToRadians (90)), 60, 60, 10, -3, EQUAL), TestCase::QUICK);
165 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (30), DegreesToRadians (90)), 60, 60, 10, -3, EQUAL), TestCase::QUICK);
166 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-30), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
167 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (150), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
168 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (160), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
169 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (210), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
170 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (240), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
171 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-40), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
172 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-90), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
173 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-120), DegreesToRadians (90)), 60, 60, 10, -10, EQUAL), TestCase::QUICK);
174
175 // test negative orientation and different beamwidths
176 // with a 80 deg beamwidth, gain is -20dB at +- 73.030 degrees from boresight
177 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-150), DegreesToRadians (90)), 80, -150, 10, 0, EQUAL), TestCase::QUICK);
178 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-110), DegreesToRadians (90)), 80, -150, 10, -3, EQUAL), TestCase::QUICK);
179 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-190), DegreesToRadians (90)), 80, -150, 10, -3, EQUAL), TestCase::QUICK);
180 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-70), DegreesToRadians (90)), 80, -150, 10, -10, EQUAL), TestCase::QUICK);
181 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (92), DegreesToRadians (90)), 80, -150, 10, -10, EQUAL), TestCase::QUICK);
182 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-30), DegreesToRadians (90)), 80, -150, 10, -10, EQUAL), TestCase::QUICK);
183 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (0), DegreesToRadians (90)), 80, -150, 10, -10, EQUAL), TestCase::QUICK);
184 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (60), DegreesToRadians (90)), 80, -150, 10, -10, EQUAL), TestCase::QUICK);
185 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (90), DegreesToRadians (90)), 80, -150, 10, -10, EQUAL), TestCase::QUICK);
186 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (30), DegreesToRadians (90)), 80, -150, 10, -10, EQUAL), TestCase::QUICK);
187
188
189
190 // test elevation angle
191 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (0), DegreesToRadians (88)), 60, 0, 20, 0, EQUAL), TestCase::QUICK);
192 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (30), DegreesToRadians (88)), 60, 0, 20, -3, EQUAL), TestCase::QUICK);
193 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-30), DegreesToRadians (88)), 60, 0, 20, -3, EQUAL), TestCase::QUICK);
194 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-90), DegreesToRadians (88)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
195 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-180), DegreesToRadians (88)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
196 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (60), DegreesToRadians (93)), 60, 60, 20, 0, EQUAL), TestCase::QUICK);
197 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (90), DegreesToRadians (93)), 60, 60, 20, -3, EQUAL), TestCase::QUICK);
198 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (30), DegreesToRadians (93)), 60, 60, 20, -3, EQUAL), TestCase::QUICK);
199 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-120), DegreesToRadians (93)), 60, 60, 20, -20, EQUAL), TestCase::QUICK);
200 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-150), DegreesToRadians (93)), 100, -150, 10, 0, EQUAL), TestCase::QUICK);
201 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-100), DegreesToRadians (93)), 100, -150, 10, -3, EQUAL), TestCase::QUICK);
202 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-200), DegreesToRadians (93)), 100, -150, 10, -3, EQUAL), TestCase::QUICK);
203 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-30), DegreesToRadians (93)), 100, -150, 10, -10, EQUAL), TestCase::QUICK);
204 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (90), DegreesToRadians (80.5)), 100, -150, 10, -10, EQUAL), TestCase::QUICK);
205 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (0), DegreesToRadians (80.5)), 60, 0, 20, 0, EQUAL), TestCase::QUICK);
206 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (30), DegreesToRadians (80.5)), 60, 0, 20, -3, EQUAL), TestCase::QUICK);
207 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-30), DegreesToRadians (80.5)), 60, 0, 20, -3, EQUAL), TestCase::QUICK);
208 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (100), DegreesToRadians (80.5)), 60, 0, 20, -20, EQUAL), TestCase::QUICK);
209 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-150), DegreesToRadians (80.5)), 100, -150, 30, 0, EQUAL), TestCase::QUICK);
210 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-100), DegreesToRadians (80.5)), 100, -150, 30, -3, EQUAL), TestCase::QUICK);
211 AddTestCase (new ParabolicAntennaModelTestCase (Angles (DegreesToRadians (-200), DegreesToRadians (80.5)), 100, -150, 30, -3, EQUAL), TestCase::QUICK);
212
213};
214
ParabolicAntennaModel Test.
static std::string BuildNameString(Angles a, double b, double o, double g)
Build the test name.
ParabolicAntennaModelGainTestCondition m_cond
Test condition.
ParabolicAntennaModelTestCase(Angles a, double b, double o, double g, double expectedGainDb, ParabolicAntennaModelGainTestCondition cond)
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
ParabolicAntennaModel TestSuite.
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:119
double GetInclination(void) const
Getter for inclination angle.
Definition: angles.cc:231
double GetAzimuth(void) const
Getter for azimuth angle.
Definition: angles.cc:224
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
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
ParabolicAntennaModelGainTestCondition
Test condition (equal to or less than)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
Definition: test.h:748
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition: test.h:491
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:40
static ParabolicAntennaModelTestSuite g_staticParabolicAntennaModelTestSuiteInstance
Static variable for test initialization.