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),
157 TestCase::Duration::QUICK);
159 60,
160 0,
161 0,
162 -3,
163 EQUAL),
164 TestCase::Duration::QUICK);
166 60,
167 0,
168 0,
169 -3,
170 EQUAL),
171 TestCase::Duration::QUICK);
173 60,
174 0,
175 0,
176 -20,
177 LESSTHAN),
178 TestCase::Duration::QUICK);
180 60,
181 0,
182 0,
183 -20,
184 LESSTHAN),
185 TestCase::Duration::QUICK);
187 60,
188 0,
189 0,
190 -20,
191 LESSTHAN),
192 TestCase::Duration::QUICK);
194 60,
195 0,
196 0,
197 -20,
198 LESSTHAN),
199 TestCase::Duration::QUICK);
201 60,
202 0,
203 0,
204 -20,
205 LESSTHAN),
206 TestCase::Duration::QUICK);
208 60,
209 0,
210 0,
211 -20,
212 LESSTHAN),
213 TestCase::Duration::QUICK);
215 60,
216 0,
217 0,
218 -20,
219 LESSTHAN),
220 TestCase::Duration::QUICK);
222 60,
223 0,
224 0,
225 -20,
226 LESSTHAN),
227 TestCase::Duration::QUICK);
228
229 // test positive orientation
231 60,
232 60,
233 0,
234 0,
235 EQUAL),
236 TestCase::Duration::QUICK);
238 60,
239 60,
240 0,
241 -3,
242 EQUAL),
243 TestCase::Duration::QUICK);
245 60,
246 60,
247 0,
248 -3,
249 EQUAL),
250 TestCase::Duration::QUICK);
252 60,
253 60,
254 0,
255 -20,
256 LESSTHAN),
257 TestCase::Duration::QUICK);
259 60,
260 60,
261 0,
262 -20,
263 LESSTHAN),
264 TestCase::Duration::QUICK);
266 60,
267 60,
268 0,
269 -20,
270 LESSTHAN),
271 TestCase::Duration::QUICK);
273 60,
274 60,
275 0,
276 -20,
277 LESSTHAN),
278 TestCase::Duration::QUICK);
280 60,
281 60,
282 0,
283 -20,
284 LESSTHAN),
285 TestCase::Duration::QUICK);
287 60,
288 60,
289 0,
290 -20,
291 LESSTHAN),
292 TestCase::Duration::QUICK);
294 60,
295 60,
296 0,
297 -20,
298 LESSTHAN),
299 TestCase::Duration::QUICK);
301 60,
302 60,
303 0,
304 -20,
305 LESSTHAN),
306 TestCase::Duration::QUICK);
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),
316 TestCase::Duration::QUICK);
318 100,
319 -150,
320 0,
321 -3,
322 EQUAL),
323 TestCase::Duration::QUICK);
325 100,
326 -150,
327 0,
328 -3,
329 EQUAL),
330 TestCase::Duration::QUICK);
333 100,
334 -150,
335 0,
336 -20,
337 EQUAL),
338 TestCase::Duration::QUICK);
341 100,
342 -150,
343 0,
344 -20,
345 EQUAL),
346 TestCase::Duration::QUICK);
348 100,
349 -150,
350 0,
351 -20,
352 LESSTHAN),
353 TestCase::Duration::QUICK);
355 100,
356 -150,
357 0,
358 -20,
359 LESSTHAN),
360 TestCase::Duration::QUICK);
362 100,
363 -150,
364 0,
365 -20,
366 LESSTHAN),
367 TestCase::Duration::QUICK);
369 100,
370 -150,
371 0,
372 -20,
373 LESSTHAN),
374 TestCase::Duration::QUICK);
376 100,
377 -150,
378 0,
379 -20,
380 LESSTHAN),
381 TestCase::Duration::QUICK);
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),
390 TestCase::Duration::QUICK);
392 150,
393 -150,
394 0,
395 -3,
396 EQUAL),
397 TestCase::Duration::QUICK);
399 150,
400 -150,
401 0,
402 -3,
403 EQUAL),
404 TestCase::Duration::QUICK);
407 150,
408 -150,
409 0,
410 -10,
411 EQUAL),
412 TestCase::Duration::QUICK);
415 150,
416 -150,
417 0,
418 -10,
419 EQUAL),
420 TestCase::Duration::QUICK);
423 150,
424 -150,
425 0,
426 -20,
427 EQUAL),
428 TestCase::Duration::QUICK);
431 150,
432 -150,
433 0,
434 -20,
435 EQUAL),
436 TestCase::Duration::QUICK);
438 150,
439 -150,
440 0,
441 -20,
442 LESSTHAN),
443 TestCase::Duration::QUICK);
445 150,
446 -150,
447 0,
448 -20,
449 LESSTHAN),
450 TestCase::Duration::QUICK);
451 // test flat beam, with beamwidth=360 deg
453 360,
454 0,
455 0,
456 0,
457 EQUAL),
458 TestCase::Duration::QUICK);
460 360,
461 0,
462 0,
463 0,
464 EQUAL),
465 TestCase::Duration::QUICK);
467 360,
468 0,
469 0,
470 0,
471 EQUAL),
472 TestCase::Duration::QUICK);
474 360,
475 0,
476 0,
477 0,
478 EQUAL),
479 TestCase::Duration::QUICK);
481 360,
482 0,
483 0,
484 0,
485 EQUAL),
486 TestCase::Duration::QUICK);
487
488 // test maxGain
490 60,
491 0,
492 10,
493 10,
494 EQUAL),
495 TestCase::Duration::QUICK);
497 60,
498 0,
499 22,
500 19,
501 EQUAL),
502 TestCase::Duration::QUICK);
504 60,
505 0,
506 -4,
507 -7,
508 EQUAL),
509 TestCase::Duration::QUICK);
511 60,
512 0,
513 10,
514 -10,
515 LESSTHAN),
516 TestCase::Duration::QUICK);
518 60,
519 0,
520 -20,
521 -40,
522 LESSTHAN),
523 TestCase::Duration::QUICK);
525 60,
526 0,
527 40,
528 20,
529 LESSTHAN),
530 TestCase::Duration::QUICK);
532 100,
533 -150,
534 2,
535 2,
536 EQUAL),
537 TestCase::Duration::QUICK);
539 100,
540 -150,
541 4,
542 1,
543 EQUAL),
544 TestCase::Duration::QUICK);
546 100,
547 -150,
548 -1,
549 -4,
550 EQUAL),
551 TestCase::Duration::QUICK);
552
553 // test elevation angle
555 60,
556 0,
557 0,
558 -3,
559 EQUAL),
560 TestCase::Duration::QUICK);
562 60,
563 0,
564 0,
565 -6,
566 EQUAL),
567 TestCase::Duration::QUICK);
569 60,
570 0,
571 0,
572 -6,
573 EQUAL),
574 TestCase::Duration::QUICK);
576 60,
577 0,
578 0,
579 -20,
580 LESSTHAN),
581 TestCase::Duration::QUICK);
583 60,
584 0,
585 0,
586 -20,
587 LESSTHAN),
588 TestCase::Duration::QUICK);
590 60,
591 60,
592 0,
593 -3,
594 EQUAL),
595 TestCase::Duration::QUICK);
597 60,
598 60,
599 0,
600 -6,
601 EQUAL),
602 TestCase::Duration::QUICK);
604 60,
605 60,
606 0,
607 -6,
608 EQUAL),
609 TestCase::Duration::QUICK);
612 60,
613 60,
614 0,
615 -20,
616 LESSTHAN),
617 TestCase::Duration::QUICK);
620 100,
621 -150,
622 0,
623 -3,
624 EQUAL),
625 TestCase::Duration::QUICK);
628 100,
629 -150,
630 0,
631 -6,
632 EQUAL),
633 TestCase::Duration::QUICK);
636 100,
637 -150,
638 0,
639 -6,
640 EQUAL),
641 TestCase::Duration::QUICK);
643 100,
644 -150,
645 0,
646 -20,
647 LESSTHAN),
648 TestCase::Duration::QUICK);
650 60,
651 0,
652 10,
653 7,
654 EQUAL),
655 TestCase::Duration::QUICK);
657 60,
658 0,
659 22,
660 16,
661 EQUAL),
662 TestCase::Duration::QUICK);
664 60,
665 0,
666 -4,
667 -10,
668 EQUAL),
669 TestCase::Duration::QUICK);
671 60,
672 0,
673 10,
674 -13,
675 LESSTHAN),
676 TestCase::Duration::QUICK);
678 60,
679 0,
680 -20,
681 -43,
682 LESSTHAN),
683 TestCase::Duration::QUICK);
685 60,
686 0,
687 40,
688 17,
689 LESSTHAN),
690 TestCase::Duration::QUICK);
692 100,
693 -150,
694 2,
695 -1,
696 EQUAL),
697 TestCase::Duration::QUICK);
699 100,
700 -150,
701 4,
702 -2,
703 EQUAL),
704 TestCase::Duration::QUICK);
706 100,
707 -150,
708 -1,
709 -7,
710 EQUAL),
711 TestCase::Duration::QUICK);
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.
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
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.