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, orientation=" << o << ", maxAttenuation=" << g << " dB";
85 return oss.str();
86}
87
89 Angles a,
90 double b,
91 double o,
92 double g,
93 double expectedGainDb,
95 : TestCase(BuildNameString(a, b, o, g)),
96 m_a(a),
97 m_b(b),
98 m_o(o),
99 m_g(g),
100 m_expectedGain(expectedGainDb),
101 m_cond(cond)
102{
103}
104
105void
107{
109
111 a->SetAttribute("Beamwidth", DoubleValue(m_b));
112 a->SetAttribute("Orientation", DoubleValue(m_o));
113 a->SetAttribute("MaxAttenuation", DoubleValue(m_g));
114 double actualGain = a->GetGainDb(m_a);
115 switch (m_cond)
116 {
117 case EQUAL:
118 NS_TEST_EXPECT_MSG_EQ_TOL(actualGain,
120 0.001,
121 "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/**
132 * @ingroup antenna-tests
133 *
134 * @brief ParabolicAntennaModel TestSuite
135 */
141
143 : TestSuite("parabolic-antenna-model", Type::UNIT)
144{
145 // with a 60 deg beamwidth, gain is -20dB at +-77.460 degrees from boresight
146 // phi, theta,
147 // beamwidth,
148 // orientation, maxAttn,
149 // expectedGain,
150 // condition
152 60,
153 0,
154 20,
155 0,
156 EQUAL),
157 TestCase::Duration::QUICK);
160 60,
161 0,
162 20,
163 -3,
164 EQUAL),
165 TestCase::Duration::QUICK);
168 60,
169 0,
170 20,
171 -3,
172 EQUAL),
173 TestCase::Duration::QUICK);
176 60,
177 0,
178 20,
179 -20,
180 EQUAL),
181 TestCase::Duration::QUICK);
184 60,
185 0,
186 20,
187 -20,
188 EQUAL),
189 TestCase::Duration::QUICK);
192 60,
193 0,
194 20,
195 -20,
196 EQUAL),
197 TestCase::Duration::QUICK);
200 60,
201 0,
202 20,
203 -20,
204 EQUAL),
205 TestCase::Duration::QUICK);
208 60,
209 0,
210 20,
211 -20,
212 EQUAL),
213 TestCase::Duration::QUICK);
216 60,
217 0,
218 20,
219 -20,
220 EQUAL),
221 TestCase::Duration::QUICK);
224 60,
225 0,
226 20,
227 -20,
228 EQUAL),
229 TestCase::Duration::QUICK);
232 60,
233 0,
234 20,
235 -20,
236 EQUAL),
237 TestCase::Duration::QUICK);
238
239 // with a 60 deg beamwidth, gain is -10dB at +-54.772 degrees from boresight
240 // test positive orientation
243 60,
244 60,
245 10,
246 0,
247 EQUAL),
248 TestCase::Duration::QUICK);
251 60,
252 60,
253 10,
254 -3,
255 EQUAL),
256 TestCase::Duration::QUICK);
259 60,
260 60,
261 10,
262 -3,
263 EQUAL),
264 TestCase::Duration::QUICK);
267 60,
268 60,
269 10,
270 -10,
271 EQUAL),
272 TestCase::Duration::QUICK);
275 60,
276 60,
277 10,
278 -10,
279 EQUAL),
280 TestCase::Duration::QUICK);
283 60,
284 60,
285 10,
286 -10,
287 EQUAL),
288 TestCase::Duration::QUICK);
291 60,
292 60,
293 10,
294 -10,
295 EQUAL),
296 TestCase::Duration::QUICK);
299 60,
300 60,
301 10,
302 -10,
303 EQUAL),
304 TestCase::Duration::QUICK);
307 60,
308 60,
309 10,
310 -10,
311 EQUAL),
312 TestCase::Duration::QUICK);
315 60,
316 60,
317 10,
318 -10,
319 EQUAL),
320 TestCase::Duration::QUICK);
323 60,
324 60,
325 10,
326 -10,
327 EQUAL),
328 TestCase::Duration::QUICK);
329
330 // test negative orientation and different beamwidths
331 // with a 80 deg beamwidth, gain is -20dB at +- 73.030 degrees from boresight
334 80,
335 -150,
336 10,
337 0,
338 EQUAL),
339 TestCase::Duration::QUICK);
342 80,
343 -150,
344 10,
345 -3,
346 EQUAL),
347 TestCase::Duration::QUICK);
350 80,
351 -150,
352 10,
353 -3,
354 EQUAL),
355 TestCase::Duration::QUICK);
358 80,
359 -150,
360 10,
361 -10,
362 EQUAL),
363 TestCase::Duration::QUICK);
366 80,
367 -150,
368 10,
369 -10,
370 EQUAL),
371 TestCase::Duration::QUICK);
374 80,
375 -150,
376 10,
377 -10,
378 EQUAL),
379 TestCase::Duration::QUICK);
381 80,
382 -150,
383 10,
384 -10,
385 EQUAL),
386 TestCase::Duration::QUICK);
389 80,
390 -150,
391 10,
392 -10,
393 EQUAL),
394 TestCase::Duration::QUICK);
397 80,
398 -150,
399 10,
400 -10,
401 EQUAL),
402 TestCase::Duration::QUICK);
405 80,
406 -150,
407 10,
408 -10,
409 EQUAL),
410 TestCase::Duration::QUICK);
411
412 // test elevation angle
414 60,
415 0,
416 20,
417 0,
418 EQUAL),
419 TestCase::Duration::QUICK);
422 60,
423 0,
424 20,
425 -3,
426 EQUAL),
427 TestCase::Duration::QUICK);
430 60,
431 0,
432 20,
433 -3,
434 EQUAL),
435 TestCase::Duration::QUICK);
438 60,
439 0,
440 20,
441 -20,
442 EQUAL),
443 TestCase::Duration::QUICK);
446 60,
447 0,
448 20,
449 -20,
450 EQUAL),
451 TestCase::Duration::QUICK);
454 60,
455 60,
456 20,
457 0,
458 EQUAL),
459 TestCase::Duration::QUICK);
462 60,
463 60,
464 20,
465 -3,
466 EQUAL),
467 TestCase::Duration::QUICK);
470 60,
471 60,
472 20,
473 -3,
474 EQUAL),
475 TestCase::Duration::QUICK);
478 60,
479 60,
480 20,
481 -20,
482 EQUAL),
483 TestCase::Duration::QUICK);
486 100,
487 -150,
488 10,
489 0,
490 EQUAL),
491 TestCase::Duration::QUICK);
494 100,
495 -150,
496 10,
497 -3,
498 EQUAL),
499 TestCase::Duration::QUICK);
502 100,
503 -150,
504 10,
505 -3,
506 EQUAL),
507 TestCase::Duration::QUICK);
510 100,
511 -150,
512 10,
513 -10,
514 EQUAL),
515 TestCase::Duration::QUICK);
518 100,
519 -150,
520 10,
521 -10,
522 EQUAL),
523 TestCase::Duration::QUICK);
526 60,
527 0,
528 20,
529 0,
530 EQUAL),
531 TestCase::Duration::QUICK);
534 60,
535 0,
536 20,
537 -3,
538 EQUAL),
539 TestCase::Duration::QUICK);
542 60,
543 0,
544 20,
545 -3,
546 EQUAL),
547 TestCase::Duration::QUICK);
550 60,
551 0,
552 20,
553 -20,
554 EQUAL),
555 TestCase::Duration::QUICK);
558 100,
559 -150,
560 30,
561 0,
562 EQUAL),
563 TestCase::Duration::QUICK);
566 100,
567 -150,
568 30,
569 -3,
570 EQUAL),
571 TestCase::Duration::QUICK);
574 100,
575 -150,
576 30,
577 -3,
578 EQUAL),
579 TestCase::Duration::QUICK);
580}
581
582/// 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.