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
35/**
36 * \ingroup antenna-tests
37 *
38 * \brief Test condition (equal to or less than)
39 */
41{
42 EQUAL = 0,
43 LESSTHAN = 1
44};
45
46/**
47 * \ingroup antenna-tests
48 *
49 * \brief ParabolicAntennaModel Test
50 */
52{
53 public:
54 /**
55 * Build the test name
56 * \param a Antenna angle
57 * \param b Beamwidth
58 * \param o Orientation
59 * \param g MaxGain
60 * \return the test name
61 */
62 static std::string BuildNameString(Angles a, double b, double o, double g);
63 /**
64 * Constructor
65 * \param a Antenna angle
66 * \param b Beamwidth
67 * \param o Orientation
68 * \param g MaxGain
69 * \param expectedGainDb Expected antenna gain
70 * \param cond Test condition
71 */
73 double b,
74 double o,
75 double g,
76 double expectedGainDb,
78
79 private:
80 void DoRun() override;
81
82 Angles m_a; //!< Antenna angle
83 double m_b; //!< Beamwidth
84 double m_o; //!< Orientation
85 double m_g; //!< MaxGain
86 double m_expectedGain; //!< Expected gain
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
143/**
144 * \ingroup antenna-tests
145 *
146 * \brief ParabolicAntennaModel TestSuite
147 */
149{
150 public:
152};
153
155 : TestSuite("parabolic-antenna-model", Type::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),
169 TestCase::Duration::QUICK);
172 60,
173 0,
174 20,
175 -3,
176 EQUAL),
177 TestCase::Duration::QUICK);
180 60,
181 0,
182 20,
183 -3,
184 EQUAL),
185 TestCase::Duration::QUICK);
188 60,
189 0,
190 20,
191 -20,
192 EQUAL),
193 TestCase::Duration::QUICK);
196 60,
197 0,
198 20,
199 -20,
200 EQUAL),
201 TestCase::Duration::QUICK);
204 60,
205 0,
206 20,
207 -20,
208 EQUAL),
209 TestCase::Duration::QUICK);
212 60,
213 0,
214 20,
215 -20,
216 EQUAL),
217 TestCase::Duration::QUICK);
220 60,
221 0,
222 20,
223 -20,
224 EQUAL),
225 TestCase::Duration::QUICK);
228 60,
229 0,
230 20,
231 -20,
232 EQUAL),
233 TestCase::Duration::QUICK);
236 60,
237 0,
238 20,
239 -20,
240 EQUAL),
241 TestCase::Duration::QUICK);
244 60,
245 0,
246 20,
247 -20,
248 EQUAL),
249 TestCase::Duration::QUICK);
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),
260 TestCase::Duration::QUICK);
263 60,
264 60,
265 10,
266 -3,
267 EQUAL),
268 TestCase::Duration::QUICK);
271 60,
272 60,
273 10,
274 -3,
275 EQUAL),
276 TestCase::Duration::QUICK);
279 60,
280 60,
281 10,
282 -10,
283 EQUAL),
284 TestCase::Duration::QUICK);
287 60,
288 60,
289 10,
290 -10,
291 EQUAL),
292 TestCase::Duration::QUICK);
295 60,
296 60,
297 10,
298 -10,
299 EQUAL),
300 TestCase::Duration::QUICK);
303 60,
304 60,
305 10,
306 -10,
307 EQUAL),
308 TestCase::Duration::QUICK);
311 60,
312 60,
313 10,
314 -10,
315 EQUAL),
316 TestCase::Duration::QUICK);
319 60,
320 60,
321 10,
322 -10,
323 EQUAL),
324 TestCase::Duration::QUICK);
327 60,
328 60,
329 10,
330 -10,
331 EQUAL),
332 TestCase::Duration::QUICK);
335 60,
336 60,
337 10,
338 -10,
339 EQUAL),
340 TestCase::Duration::QUICK);
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),
351 TestCase::Duration::QUICK);
354 80,
355 -150,
356 10,
357 -3,
358 EQUAL),
359 TestCase::Duration::QUICK);
362 80,
363 -150,
364 10,
365 -3,
366 EQUAL),
367 TestCase::Duration::QUICK);
370 80,
371 -150,
372 10,
373 -10,
374 EQUAL),
375 TestCase::Duration::QUICK);
378 80,
379 -150,
380 10,
381 -10,
382 EQUAL),
383 TestCase::Duration::QUICK);
386 80,
387 -150,
388 10,
389 -10,
390 EQUAL),
391 TestCase::Duration::QUICK);
393 80,
394 -150,
395 10,
396 -10,
397 EQUAL),
398 TestCase::Duration::QUICK);
401 80,
402 -150,
403 10,
404 -10,
405 EQUAL),
406 TestCase::Duration::QUICK);
409 80,
410 -150,
411 10,
412 -10,
413 EQUAL),
414 TestCase::Duration::QUICK);
417 80,
418 -150,
419 10,
420 -10,
421 EQUAL),
422 TestCase::Duration::QUICK);
423
424 // test elevation angle
426 60,
427 0,
428 20,
429 0,
430 EQUAL),
431 TestCase::Duration::QUICK);
434 60,
435 0,
436 20,
437 -3,
438 EQUAL),
439 TestCase::Duration::QUICK);
442 60,
443 0,
444 20,
445 -3,
446 EQUAL),
447 TestCase::Duration::QUICK);
450 60,
451 0,
452 20,
453 -20,
454 EQUAL),
455 TestCase::Duration::QUICK);
458 60,
459 0,
460 20,
461 -20,
462 EQUAL),
463 TestCase::Duration::QUICK);
466 60,
467 60,
468 20,
469 0,
470 EQUAL),
471 TestCase::Duration::QUICK);
474 60,
475 60,
476 20,
477 -3,
478 EQUAL),
479 TestCase::Duration::QUICK);
482 60,
483 60,
484 20,
485 -3,
486 EQUAL),
487 TestCase::Duration::QUICK);
490 60,
491 60,
492 20,
493 -20,
494 EQUAL),
495 TestCase::Duration::QUICK);
498 100,
499 -150,
500 10,
501 0,
502 EQUAL),
503 TestCase::Duration::QUICK);
506 100,
507 -150,
508 10,
509 -3,
510 EQUAL),
511 TestCase::Duration::QUICK);
514 100,
515 -150,
516 10,
517 -3,
518 EQUAL),
519 TestCase::Duration::QUICK);
522 100,
523 -150,
524 10,
525 -10,
526 EQUAL),
527 TestCase::Duration::QUICK);
530 100,
531 -150,
532 10,
533 -10,
534 EQUAL),
535 TestCase::Duration::QUICK);
538 60,
539 0,
540 20,
541 0,
542 EQUAL),
543 TestCase::Duration::QUICK);
546 60,
547 0,
548 20,
549 -3,
550 EQUAL),
551 TestCase::Duration::QUICK);
554 60,
555 0,
556 20,
557 -3,
558 EQUAL),
559 TestCase::Duration::QUICK);
562 60,
563 0,
564 20,
565 -20,
566 EQUAL),
567 TestCase::Duration::QUICK);
570 100,
571 -150,
572 30,
573 0,
574 EQUAL),
575 TestCase::Duration::QUICK);
578 100,
579 -150,
580 30,
581 -3,
582 EQUAL),
583 TestCase::Duration::QUICK);
586 100,
587 -150,
588 30,
589 -3,
590 EQUAL),
591 TestCase::Duration::QUICK);
592}
593
594/// Static variable for test initialization
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:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
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:791
#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:511
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.