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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include <ns3/double.h>
10#include <ns3/log.h>
11#include <ns3/parabolic-antenna-model.h>
12#include <ns3/simulator.h>
13#include <ns3/test.h>
14
15#include <cmath>
16#include <iostream>
17#include <sstream>
18#include <string>
19
20using namespace ns3;
21
22NS_LOG_COMPONENT_DEFINE("TestParabolicAntennaModel");
23
24/**
25 * @ingroup antenna-tests
26 *
27 * @brief Test condition (equal to or less than)
28 */
34
35/**
36 * @ingroup antenna-tests
37 *
38 * @brief ParabolicAntennaModel Test
39 */
41{
42 public:
43 /**
44 * Build the test name
45 * @param a Antenna angle
46 * @param b Beamwidth
47 * @param o Orientation
48 * @param g MaxGain
49 * @return the test name
50 */
51 static std::string BuildNameString(Angles a, double b, double o, double g);
52 /**
53 * Constructor
54 * @param a Antenna angle
55 * @param b Beamwidth
56 * @param o Orientation
57 * @param g MaxGain
58 * @param expectedGainDb Expected antenna gain
59 * @param cond Test condition
60 */
62 double b,
63 double o,
64 double g,
65 double expectedGainDb,
67
68 private:
69 void DoRun() override;
70
71 Angles m_a; //!< Antenna angle
72 double m_b; //!< Beamwidth
73 double m_o; //!< Orientation
74 double m_g; //!< MaxGain
75 double m_expectedGain; //!< Expected gain
77};
78
79std::string
81{
82 std::ostringstream oss;
83 oss << "theta=" << a.GetInclination() << " , phi=" << a.GetAzimuth() << ", beamdwidth=" << b
84 << "deg"
85 << ", orientation=" << o << ", maxAttenuation=" << g << " dB";
86 return oss.str();
87}
88
90 Angles a,
91 double b,
92 double o,
93 double g,
94 double expectedGainDb,
96 : TestCase(BuildNameString(a, b, o, g)),
97 m_a(a),
98 m_b(b),
99 m_o(o),
100 m_g(g),
101 m_expectedGain(expectedGainDb),
102 m_cond(cond)
103{
104}
105
106void
108{
110
112 a->SetAttribute("Beamwidth", DoubleValue(m_b));
113 a->SetAttribute("Orientation", DoubleValue(m_o));
114 a->SetAttribute("MaxAttenuation", DoubleValue(m_g));
115 double actualGain = a->GetGainDb(m_a);
116 switch (m_cond)
117 {
118 case EQUAL:
119 NS_TEST_EXPECT_MSG_EQ_TOL(actualGain,
121 0.001,
122 "wrong value of the radiation pattern");
123 break;
124 case LESSTHAN:
125 NS_TEST_EXPECT_MSG_LT(actualGain, m_expectedGain, "gain higher than expected");
126 break;
127 default:
128 break;
129 }
130}
131
132/**
133 * @ingroup antenna-tests
134 *
135 * @brief ParabolicAntennaModel TestSuite
136 */
142
144 : TestSuite("parabolic-antenna-model", Type::UNIT)
145{
146 // with a 60 deg beamwidth, gain is -20dB at +-77.460 degrees from boresight
147 // phi, theta,
148 // beamwidth,
149 // orientation, maxAttn,
150 // expectedGain,
151 // condition
153 60,
154 0,
155 20,
156 0,
157 EQUAL),
158 TestCase::Duration::QUICK);
161 60,
162 0,
163 20,
164 -3,
165 EQUAL),
166 TestCase::Duration::QUICK);
169 60,
170 0,
171 20,
172 -3,
173 EQUAL),
174 TestCase::Duration::QUICK);
177 60,
178 0,
179 20,
180 -20,
181 EQUAL),
182 TestCase::Duration::QUICK);
185 60,
186 0,
187 20,
188 -20,
189 EQUAL),
190 TestCase::Duration::QUICK);
193 60,
194 0,
195 20,
196 -20,
197 EQUAL),
198 TestCase::Duration::QUICK);
201 60,
202 0,
203 20,
204 -20,
205 EQUAL),
206 TestCase::Duration::QUICK);
209 60,
210 0,
211 20,
212 -20,
213 EQUAL),
214 TestCase::Duration::QUICK);
217 60,
218 0,
219 20,
220 -20,
221 EQUAL),
222 TestCase::Duration::QUICK);
225 60,
226 0,
227 20,
228 -20,
229 EQUAL),
230 TestCase::Duration::QUICK);
233 60,
234 0,
235 20,
236 -20,
237 EQUAL),
238 TestCase::Duration::QUICK);
239
240 // with a 60 deg beamwidth, gain is -10dB at +-54.772 degrees from boresight
241 // test positive orientation
244 60,
245 60,
246 10,
247 0,
248 EQUAL),
249 TestCase::Duration::QUICK);
252 60,
253 60,
254 10,
255 -3,
256 EQUAL),
257 TestCase::Duration::QUICK);
260 60,
261 60,
262 10,
263 -3,
264 EQUAL),
265 TestCase::Duration::QUICK);
268 60,
269 60,
270 10,
271 -10,
272 EQUAL),
273 TestCase::Duration::QUICK);
276 60,
277 60,
278 10,
279 -10,
280 EQUAL),
281 TestCase::Duration::QUICK);
284 60,
285 60,
286 10,
287 -10,
288 EQUAL),
289 TestCase::Duration::QUICK);
292 60,
293 60,
294 10,
295 -10,
296 EQUAL),
297 TestCase::Duration::QUICK);
300 60,
301 60,
302 10,
303 -10,
304 EQUAL),
305 TestCase::Duration::QUICK);
308 60,
309 60,
310 10,
311 -10,
312 EQUAL),
313 TestCase::Duration::QUICK);
316 60,
317 60,
318 10,
319 -10,
320 EQUAL),
321 TestCase::Duration::QUICK);
324 60,
325 60,
326 10,
327 -10,
328 EQUAL),
329 TestCase::Duration::QUICK);
330
331 // test negative orientation and different beamwidths
332 // with a 80 deg beamwidth, gain is -20dB at +- 73.030 degrees from boresight
335 80,
336 -150,
337 10,
338 0,
339 EQUAL),
340 TestCase::Duration::QUICK);
343 80,
344 -150,
345 10,
346 -3,
347 EQUAL),
348 TestCase::Duration::QUICK);
351 80,
352 -150,
353 10,
354 -3,
355 EQUAL),
356 TestCase::Duration::QUICK);
359 80,
360 -150,
361 10,
362 -10,
363 EQUAL),
364 TestCase::Duration::QUICK);
367 80,
368 -150,
369 10,
370 -10,
371 EQUAL),
372 TestCase::Duration::QUICK);
375 80,
376 -150,
377 10,
378 -10,
379 EQUAL),
380 TestCase::Duration::QUICK);
382 80,
383 -150,
384 10,
385 -10,
386 EQUAL),
387 TestCase::Duration::QUICK);
390 80,
391 -150,
392 10,
393 -10,
394 EQUAL),
395 TestCase::Duration::QUICK);
398 80,
399 -150,
400 10,
401 -10,
402 EQUAL),
403 TestCase::Duration::QUICK);
406 80,
407 -150,
408 10,
409 -10,
410 EQUAL),
411 TestCase::Duration::QUICK);
412
413 // test elevation angle
415 60,
416 0,
417 20,
418 0,
419 EQUAL),
420 TestCase::Duration::QUICK);
423 60,
424 0,
425 20,
426 -3,
427 EQUAL),
428 TestCase::Duration::QUICK);
431 60,
432 0,
433 20,
434 -3,
435 EQUAL),
436 TestCase::Duration::QUICK);
439 60,
440 0,
441 20,
442 -20,
443 EQUAL),
444 TestCase::Duration::QUICK);
447 60,
448 0,
449 20,
450 -20,
451 EQUAL),
452 TestCase::Duration::QUICK);
455 60,
456 60,
457 20,
458 0,
459 EQUAL),
460 TestCase::Duration::QUICK);
463 60,
464 60,
465 20,
466 -3,
467 EQUAL),
468 TestCase::Duration::QUICK);
471 60,
472 60,
473 20,
474 -3,
475 EQUAL),
476 TestCase::Duration::QUICK);
479 60,
480 60,
481 20,
482 -20,
483 EQUAL),
484 TestCase::Duration::QUICK);
487 100,
488 -150,
489 10,
490 0,
491 EQUAL),
492 TestCase::Duration::QUICK);
495 100,
496 -150,
497 10,
498 -3,
499 EQUAL),
500 TestCase::Duration::QUICK);
503 100,
504 -150,
505 10,
506 -3,
507 EQUAL),
508 TestCase::Duration::QUICK);
511 100,
512 -150,
513 10,
514 -10,
515 EQUAL),
516 TestCase::Duration::QUICK);
519 100,
520 -150,
521 10,
522 -10,
523 EQUAL),
524 TestCase::Duration::QUICK);
527 60,
528 0,
529 20,
530 0,
531 EQUAL),
532 TestCase::Duration::QUICK);
535 60,
536 0,
537 20,
538 -3,
539 EQUAL),
540 TestCase::Duration::QUICK);
543 60,
544 0,
545 20,
546 -3,
547 EQUAL),
548 TestCase::Duration::QUICK);
551 60,
552 0,
553 20,
554 -20,
555 EQUAL),
556 TestCase::Duration::QUICK);
559 100,
560 -150,
561 30,
562 0,
563 EQUAL),
564 TestCase::Duration::QUICK);
567 100,
568 -150,
569 30,
570 -3,
571 EQUAL),
572 TestCase::Duration::QUICK);
575 100,
576 -150,
577 30,
578 -3,
579 EQUAL),
580 TestCase::Duration::QUICK);
581}
582
583/// 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:107
double GetInclination() const
Getter for inclination angle.
Definition angles.cc:236
double GetAzimuth() const
Getter for azimuth angle.
Definition angles.cc:230
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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
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:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:780
#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:500
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition angles.cc:28
static ParabolicAntennaModelTestSuite g_staticParabolicAntennaModelTestSuiteInstance
Static variable for test initialization.