A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
test-parabolic-antenna.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011,12 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#include <ns3/double.h>
21#include <ns3/log.h>
22#include <ns3/parabolic-antenna-model.h>
23#include <ns3/simulator.h>
24#include <ns3/test.h>
25
26#include <cmath>
27#include <iostream>
28#include <sstream>
29#include <string>
30
31using namespace ns3;
32
33NS_LOG_COMPONENT_DEFINE("TestParabolicAntennaModel");
34
41{
42 EQUAL = 0,
43 LESSTHAN = 1
44};
45
52{
53 public:
62 static std::string BuildNameString(Angles a, double b, double o, double g);
73 double b,
74 double o,
75 double g,
76 double expectedGainDb,
78
79 private:
80 void DoRun() override;
81
83 double m_b;
84 double m_o;
85 double m_g;
88};
89
90std::string
92{
93 std::ostringstream oss;
94 oss << "theta=" << a.GetInclination() << " , phi=" << a.GetAzimuth() << ", beamdwidth=" << b
95 << "deg"
96 << ", orientation=" << o << ", maxAttenuation=" << g << " dB";
97 return oss.str();
98}
99
101 Angles a,
102 double b,
103 double o,
104 double g,
105 double expectedGainDb,
107 : TestCase(BuildNameString(a, b, o, g)),
108 m_a(a),
109 m_b(b),
110 m_o(o),
111 m_g(g),
112 m_expectedGain(expectedGainDb),
113 m_cond(cond)
114{
115}
116
117void
119{
121
122 Ptr<ParabolicAntennaModel> a = CreateObject<ParabolicAntennaModel>();
123 a->SetAttribute("Beamwidth", DoubleValue(m_b));
124 a->SetAttribute("Orientation", DoubleValue(m_o));
125 a->SetAttribute("MaxAttenuation", DoubleValue(m_g));
126 double actualGain = a->GetGainDb(m_a);
127 switch (m_cond)
128 {
129 case EQUAL:
130 NS_TEST_EXPECT_MSG_EQ_TOL(actualGain,
132 0.001,
133 "wrong value of the radiation pattern");
134 break;
135 case LESSTHAN:
136 NS_TEST_EXPECT_MSG_LT(actualGain, m_expectedGain, "gain higher than expected");
137 break;
138 default:
139 break;
140 }
141}
142
149{
150 public:
152};
153
155 : TestSuite("parabolic-antenna-model", UNIT)
156{
157 // with a 60 deg beamwidth, gain is -20dB at +-77.460 degrees from boresight
158 // phi, theta,
159 // beamwidth,
160 // orientation, maxAttn,
161 // expectedGain,
162 // condition
164 60,
165 0,
166 20,
167 0,
168 EQUAL),
172 60,
173 0,
174 20,
175 -3,
176 EQUAL),
180 60,
181 0,
182 20,
183 -3,
184 EQUAL),
188 60,
189 0,
190 20,
191 -20,
192 EQUAL),
196 60,
197 0,
198 20,
199 -20,
200 EQUAL),
204 60,
205 0,
206 20,
207 -20,
208 EQUAL),
212 60,
213 0,
214 20,
215 -20,
216 EQUAL),
220 60,
221 0,
222 20,
223 -20,
224 EQUAL),
228 60,
229 0,
230 20,
231 -20,
232 EQUAL),
236 60,
237 0,
238 20,
239 -20,
240 EQUAL),
244 60,
245 0,
246 20,
247 -20,
248 EQUAL),
250
251 // with a 60 deg beamwidth, gain is -10dB at +-54.772 degrees from boresight
252 // test positive orientation
255 60,
256 60,
257 10,
258 0,
259 EQUAL),
263 60,
264 60,
265 10,
266 -3,
267 EQUAL),
271 60,
272 60,
273 10,
274 -3,
275 EQUAL),
279 60,
280 60,
281 10,
282 -10,
283 EQUAL),
287 60,
288 60,
289 10,
290 -10,
291 EQUAL),
295 60,
296 60,
297 10,
298 -10,
299 EQUAL),
303 60,
304 60,
305 10,
306 -10,
307 EQUAL),
311 60,
312 60,
313 10,
314 -10,
315 EQUAL),
319 60,
320 60,
321 10,
322 -10,
323 EQUAL),
327 60,
328 60,
329 10,
330 -10,
331 EQUAL),
335 60,
336 60,
337 10,
338 -10,
339 EQUAL),
341
342 // test negative orientation and different beamwidths
343 // with a 80 deg beamwidth, gain is -20dB at +- 73.030 degrees from boresight
346 80,
347 -150,
348 10,
349 0,
350 EQUAL),
354 80,
355 -150,
356 10,
357 -3,
358 EQUAL),
362 80,
363 -150,
364 10,
365 -3,
366 EQUAL),
370 80,
371 -150,
372 10,
373 -10,
374 EQUAL),
378 80,
379 -150,
380 10,
381 -10,
382 EQUAL),
386 80,
387 -150,
388 10,
389 -10,
390 EQUAL),
393 80,
394 -150,
395 10,
396 -10,
397 EQUAL),
401 80,
402 -150,
403 10,
404 -10,
405 EQUAL),
409 80,
410 -150,
411 10,
412 -10,
413 EQUAL),
417 80,
418 -150,
419 10,
420 -10,
421 EQUAL),
423
424 // test elevation angle
426 60,
427 0,
428 20,
429 0,
430 EQUAL),
434 60,
435 0,
436 20,
437 -3,
438 EQUAL),
442 60,
443 0,
444 20,
445 -3,
446 EQUAL),
450 60,
451 0,
452 20,
453 -20,
454 EQUAL),
458 60,
459 0,
460 20,
461 -20,
462 EQUAL),
466 60,
467 60,
468 20,
469 0,
470 EQUAL),
474 60,
475 60,
476 20,
477 -3,
478 EQUAL),
482 60,
483 60,
484 20,
485 -3,
486 EQUAL),
490 60,
491 60,
492 20,
493 -20,
494 EQUAL),
498 100,
499 -150,
500 10,
501 0,
502 EQUAL),
506 100,
507 -150,
508 10,
509 -3,
510 EQUAL),
514 100,
515 -150,
516 10,
517 -3,
518 EQUAL),
522 100,
523 -150,
524 10,
525 -10,
526 EQUAL),
530 100,
531 -150,
532 10,
533 -10,
534 EQUAL),
538 60,
539 0,
540 20,
541 0,
542 EQUAL),
546 60,
547 0,
548 20,
549 -3,
550 EQUAL),
554 60,
555 0,
556 20,
557 -3,
558 EQUAL),
562 60,
563 0,
564 20,
565 -20,
566 EQUAL),
570 100,
571 -150,
572 30,
573 0,
574 EQUAL),
578 100,
579 -150,
580 30,
581 -3,
582 EQUAL),
586 100,
587 -150,
588 30,
589 -3,
590 EQUAL),
592}
593
ParabolicAntennaModel Test.
static std::string BuildNameString(Angles a, double b, double o, double g)
Build the test name.
void DoRun() override
Implementation to actually run this TestCase.
ParabolicAntennaModelGainTestCondition m_cond
Test condition.
ParabolicAntennaModelTestCase(Angles a, double b, double o, double g, double expectedGainDb, ParabolicAntennaModelGainTestCondition cond)
Constructor.
ParabolicAntennaModel TestSuite.
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:246
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
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:202
#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:790
#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:510
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
static ParabolicAntennaModelTestSuite g_staticParabolicAntennaModelTestSuiteInstance
Static variable for test initialization.