A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
test-cosine-antenna.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include "ns3/cosine-antenna-model.h"
10#include "ns3/double.h"
11#include "ns3/log.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("TestCosineAntennaModel");
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 CosineAntennaModel Test
39 */
41{
42 public:
43 /**
44 * Build the test name
45 * @param a Antenna angle
46 * @param b Horizontal and Vertical 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 Horizontal and Vertical 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 Angles m_a; //!< Antenna angle
71 double m_b; //!< Horizontal and Vertical Beamwidth
72 double m_o; //!< Orientation
73 double m_g; //!< MaxGain
74 double m_expectedGain; //!< Expected gain
76};
77
78std::string
80{
81 std::ostringstream oss;
82 oss << "theta=" << a.GetInclination() << " , phi=" << a.GetAzimuth() << ", beamdwidth=" << b
83 << "deg, orientation=" << o << ", maxGain=" << g << " dB";
84 return oss.str();
85}
86
88 double b,
89 double o,
90 double g,
91 double expectedGainDb,
93 : TestCase(BuildNameString(a, b, o, g)),
94 m_a(a),
95 m_b(b),
96 m_o(o),
97 m_g(g),
98 m_expectedGain(expectedGainDb),
99 m_cond(cond)
100{
101}
102
103void
105{
107
109 a->SetAttribute("HorizontalBeamwidth", DoubleValue(m_b));
110 a->SetAttribute("VerticalBeamwidth", DoubleValue(m_b));
111 a->SetAttribute("Orientation", DoubleValue(m_o));
112 a->SetAttribute("MaxGain", DoubleValue(m_g));
113 double actualGain = a->GetGainDb(m_a);
114 switch (m_cond)
115 {
116 case EQUAL:
117 NS_TEST_EXPECT_MSG_EQ_TOL(actualGain,
119 0.001,
120 "wrong value of the radiation pattern");
121 break;
122 case LESSTHAN:
123 NS_TEST_EXPECT_MSG_LT(actualGain, m_expectedGain, "gain higher than expected");
124 break;
125 default:
126 break;
127 }
128}
129
130/**
131 * @ingroup antenna-tests
132 *
133 * @brief CosineAntennaModel TestSuite
134 */
136{
137 public:
139};
140
142 : TestSuite("cosine-antenna-model", Type::UNIT)
143{
144 // to calculate the azimut angle offset for a given gain in db:
145 // phideg = (2*acos(10^(targetgaindb/(20*n))))*180/pi
146 // e.g., with a 60 deg beamwidth, gain is -20dB at +- 74.945 degrees from boresight
147
148 // phi, theta, beamwidth,
149 // orientation, maxGain,
150 // expectedGain, condition
152 60,
153 0,
154 0,
155 0,
156 EQUAL),
159 60,
160 0,
161 0,
162 -3,
163 EQUAL),
166 60,
167 0,
168 0,
169 -3,
170 EQUAL),
173 60,
174 0,
175 0,
176 -20,
177 LESSTHAN),
180 60,
181 0,
182 0,
183 -20,
184 LESSTHAN),
187 60,
188 0,
189 0,
190 -20,
191 LESSTHAN),
194 60,
195 0,
196 0,
197 -20,
198 LESSTHAN),
201 60,
202 0,
203 0,
204 -20,
205 LESSTHAN),
208 60,
209 0,
210 0,
211 -20,
212 LESSTHAN),
215 60,
216 0,
217 0,
218 -20,
219 LESSTHAN),
222 60,
223 0,
224 0,
225 -20,
226 LESSTHAN),
228
229 // test positive orientation
231 60,
232 60,
233 0,
234 0,
235 EQUAL),
238 60,
239 60,
240 0,
241 -3,
242 EQUAL),
245 60,
246 60,
247 0,
248 -3,
249 EQUAL),
252 60,
253 60,
254 0,
255 -20,
256 LESSTHAN),
259 60,
260 60,
261 0,
262 -20,
263 LESSTHAN),
266 60,
267 60,
268 0,
269 -20,
270 LESSTHAN),
273 60,
274 60,
275 0,
276 -20,
277 LESSTHAN),
280 60,
281 60,
282 0,
283 -20,
284 LESSTHAN),
287 60,
288 60,
289 0,
290 -20,
291 LESSTHAN),
294 60,
295 60,
296 0,
297 -20,
298 LESSTHAN),
301 60,
302 60,
303 0,
304 -20,
305 LESSTHAN),
307
308 // test negative orientation and different beamwidths
309 // with a 100 deg beamwidth, gain is -20dB at +- 117.47 degrees from boresight
311 100,
312 -150,
313 0,
314 0,
315 EQUAL),
318 100,
319 -150,
320 0,
321 -3,
322 EQUAL),
325 100,
326 -150,
327 0,
328 -3,
329 EQUAL),
333 100,
334 -150,
335 0,
336 -20,
337 EQUAL),
341 100,
342 -150,
343 0,
344 -20,
345 EQUAL),
348 100,
349 -150,
350 0,
351 -20,
352 LESSTHAN),
355 100,
356 -150,
357 0,
358 -20,
359 LESSTHAN),
362 100,
363 -150,
364 0,
365 -20,
366 LESSTHAN),
369 100,
370 -150,
371 0,
372 -20,
373 LESSTHAN),
376 100,
377 -150,
378 0,
379 -20,
380 LESSTHAN),
382 // with a 150 deg beamwidth, gain is -10dB at +- 124.93 degrees from boresight, and -20dB at +-
383 // 155.32 degrees from boresight
385 150,
386 -150,
387 0,
388 0,
389 EQUAL),
392 150,
393 -150,
394 0,
395 -3,
396 EQUAL),
399 150,
400 -150,
401 0,
402 -3,
403 EQUAL),
407 150,
408 -150,
409 0,
410 -10,
411 EQUAL),
415 150,
416 -150,
417 0,
418 -10,
419 EQUAL),
423 150,
424 -150,
425 0,
426 -20,
427 EQUAL),
431 150,
432 -150,
433 0,
434 -20,
435 EQUAL),
438 150,
439 -150,
440 0,
441 -20,
442 LESSTHAN),
445 150,
446 -150,
447 0,
448 -20,
449 LESSTHAN),
451 // test flat beam, with beamwidth=360 deg
453 360,
454 0,
455 0,
456 0,
457 EQUAL),
460 360,
461 0,
462 0,
463 0,
464 EQUAL),
467 360,
468 0,
469 0,
470 0,
471 EQUAL),
474 360,
475 0,
476 0,
477 0,
478 EQUAL),
481 360,
482 0,
483 0,
484 0,
485 EQUAL),
487
488 // test maxGain
490 60,
491 0,
492 10,
493 10,
494 EQUAL),
497 60,
498 0,
499 22,
500 19,
501 EQUAL),
504 60,
505 0,
506 -4,
507 -7,
508 EQUAL),
511 60,
512 0,
513 10,
514 -10,
515 LESSTHAN),
518 60,
519 0,
520 -20,
521 -40,
522 LESSTHAN),
525 60,
526 0,
527 40,
528 20,
529 LESSTHAN),
532 100,
533 -150,
534 2,
535 2,
536 EQUAL),
539 100,
540 -150,
541 4,
542 1,
543 EQUAL),
546 100,
547 -150,
548 -1,
549 -4,
550 EQUAL),
552
553 // test elevation angle
555 60,
556 0,
557 0,
558 -3,
559 EQUAL),
562 60,
563 0,
564 0,
565 -6,
566 EQUAL),
569 60,
570 0,
571 0,
572 -6,
573 EQUAL),
576 60,
577 0,
578 0,
579 -20,
580 LESSTHAN),
583 60,
584 0,
585 0,
586 -20,
587 LESSTHAN),
590 60,
591 60,
592 0,
593 -3,
594 EQUAL),
597 60,
598 60,
599 0,
600 -6,
601 EQUAL),
604 60,
605 60,
606 0,
607 -6,
608 EQUAL),
612 60,
613 60,
614 0,
615 -20,
616 LESSTHAN),
620 100,
621 -150,
622 0,
623 -3,
624 EQUAL),
628 100,
629 -150,
630 0,
631 -6,
632 EQUAL),
636 100,
637 -150,
638 0,
639 -6,
640 EQUAL),
643 100,
644 -150,
645 0,
646 -20,
647 LESSTHAN),
650 60,
651 0,
652 10,
653 7,
654 EQUAL),
657 60,
658 0,
659 22,
660 16,
661 EQUAL),
664 60,
665 0,
666 -4,
667 -10,
668 EQUAL),
671 60,
672 0,
673 10,
674 -13,
675 LESSTHAN),
678 60,
679 0,
680 -20,
681 -43,
682 LESSTHAN),
685 60,
686 0,
687 40,
688 17,
689 LESSTHAN),
692 100,
693 -150,
694 2,
695 -1,
696 EQUAL),
699 100,
700 -150,
701 4,
702 -2,
703 EQUAL),
706 100,
707 -150,
708 -1,
709 -7,
710 EQUAL),
712}
713
714/// Static variable for test initialization
CosineAntennaModel Test.
double m_expectedGain
Expected gain.
double m_b
Horizontal and Vertical Beamwidth.
CosineAntennaModelGainTestCondition m_cond
Test condition.
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.
CosineAntennaModelTestCase(Angles a, double b, double o, double g, double expectedGainDb, CosineAntennaModelGainTestCondition cond)
Constructor.
CosineAntennaModel 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.
Definition ptr.h:66
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
@ QUICK
Fast test.
Definition test.h:1055
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1274
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
static constexpr auto UNIT
Definition test.h:1291
CosineAntennaModelGainTestCondition
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 CosineAntennaModelTestSuite g_staticCosineAntennaModelTestSuiteInstance
Static variable for test initialization.