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"
84 << ", orientation=" << o << ", maxGain=" << g << " dB";
85 return oss.str();
86}
87
89 double b,
90 double o,
91 double g,
92 double expectedGainDb,
94 : TestCase(BuildNameString(a, b, o, g)),
95 m_a(a),
96 m_b(b),
97 m_o(o),
98 m_g(g),
99 m_expectedGain(expectedGainDb),
100 m_cond(cond)
101{
102}
103
104void
106{
108
110 a->SetAttribute("HorizontalBeamwidth", DoubleValue(m_b));
111 a->SetAttribute("VerticalBeamwidth", DoubleValue(m_b));
112 a->SetAttribute("Orientation", DoubleValue(m_o));
113 a->SetAttribute("MaxGain", 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 CosineAntennaModel TestSuite
135 */
137{
138 public:
140};
141
143 : TestSuite("cosine-antenna-model", Type::UNIT)
144{
145 // to calculate the azimut angle offset for a given gain in db:
146 // phideg = (2*acos(10^(targetgaindb/(20*n))))*180/pi
147 // e.g., with a 60 deg beamwidth, gain is -20dB at +- 74.945 degrees from boresight
148
149 // phi, theta, beamwidth,
150 // orientation, maxGain,
151 // expectedGain, condition
153 60,
154 0,
155 0,
156 0,
157 EQUAL),
158 TestCase::Duration::QUICK);
160 60,
161 0,
162 0,
163 -3,
164 EQUAL),
165 TestCase::Duration::QUICK);
167 60,
168 0,
169 0,
170 -3,
171 EQUAL),
172 TestCase::Duration::QUICK);
174 60,
175 0,
176 0,
177 -20,
178 LESSTHAN),
179 TestCase::Duration::QUICK);
181 60,
182 0,
183 0,
184 -20,
185 LESSTHAN),
186 TestCase::Duration::QUICK);
188 60,
189 0,
190 0,
191 -20,
192 LESSTHAN),
193 TestCase::Duration::QUICK);
195 60,
196 0,
197 0,
198 -20,
199 LESSTHAN),
200 TestCase::Duration::QUICK);
202 60,
203 0,
204 0,
205 -20,
206 LESSTHAN),
207 TestCase::Duration::QUICK);
209 60,
210 0,
211 0,
212 -20,
213 LESSTHAN),
214 TestCase::Duration::QUICK);
216 60,
217 0,
218 0,
219 -20,
220 LESSTHAN),
221 TestCase::Duration::QUICK);
223 60,
224 0,
225 0,
226 -20,
227 LESSTHAN),
228 TestCase::Duration::QUICK);
229
230 // test positive orientation
232 60,
233 60,
234 0,
235 0,
236 EQUAL),
237 TestCase::Duration::QUICK);
239 60,
240 60,
241 0,
242 -3,
243 EQUAL),
244 TestCase::Duration::QUICK);
246 60,
247 60,
248 0,
249 -3,
250 EQUAL),
251 TestCase::Duration::QUICK);
253 60,
254 60,
255 0,
256 -20,
257 LESSTHAN),
258 TestCase::Duration::QUICK);
260 60,
261 60,
262 0,
263 -20,
264 LESSTHAN),
265 TestCase::Duration::QUICK);
267 60,
268 60,
269 0,
270 -20,
271 LESSTHAN),
272 TestCase::Duration::QUICK);
274 60,
275 60,
276 0,
277 -20,
278 LESSTHAN),
279 TestCase::Duration::QUICK);
281 60,
282 60,
283 0,
284 -20,
285 LESSTHAN),
286 TestCase::Duration::QUICK);
288 60,
289 60,
290 0,
291 -20,
292 LESSTHAN),
293 TestCase::Duration::QUICK);
295 60,
296 60,
297 0,
298 -20,
299 LESSTHAN),
300 TestCase::Duration::QUICK);
302 60,
303 60,
304 0,
305 -20,
306 LESSTHAN),
307 TestCase::Duration::QUICK);
308
309 // test negative orientation and different beamwidths
310 // with a 100 deg beamwidth, gain is -20dB at +- 117.47 degrees from boresight
312 100,
313 -150,
314 0,
315 0,
316 EQUAL),
317 TestCase::Duration::QUICK);
319 100,
320 -150,
321 0,
322 -3,
323 EQUAL),
324 TestCase::Duration::QUICK);
326 100,
327 -150,
328 0,
329 -3,
330 EQUAL),
331 TestCase::Duration::QUICK);
334 100,
335 -150,
336 0,
337 -20,
338 EQUAL),
339 TestCase::Duration::QUICK);
342 100,
343 -150,
344 0,
345 -20,
346 EQUAL),
347 TestCase::Duration::QUICK);
349 100,
350 -150,
351 0,
352 -20,
353 LESSTHAN),
354 TestCase::Duration::QUICK);
356 100,
357 -150,
358 0,
359 -20,
360 LESSTHAN),
361 TestCase::Duration::QUICK);
363 100,
364 -150,
365 0,
366 -20,
367 LESSTHAN),
368 TestCase::Duration::QUICK);
370 100,
371 -150,
372 0,
373 -20,
374 LESSTHAN),
375 TestCase::Duration::QUICK);
377 100,
378 -150,
379 0,
380 -20,
381 LESSTHAN),
382 TestCase::Duration::QUICK);
383 // with a 150 deg beamwidth, gain is -10dB at +- 124.93 degrees from boresight, and -20dB at +-
384 // 155.32 degrees from boresight
386 150,
387 -150,
388 0,
389 0,
390 EQUAL),
391 TestCase::Duration::QUICK);
393 150,
394 -150,
395 0,
396 -3,
397 EQUAL),
398 TestCase::Duration::QUICK);
400 150,
401 -150,
402 0,
403 -3,
404 EQUAL),
405 TestCase::Duration::QUICK);
408 150,
409 -150,
410 0,
411 -10,
412 EQUAL),
413 TestCase::Duration::QUICK);
416 150,
417 -150,
418 0,
419 -10,
420 EQUAL),
421 TestCase::Duration::QUICK);
424 150,
425 -150,
426 0,
427 -20,
428 EQUAL),
429 TestCase::Duration::QUICK);
432 150,
433 -150,
434 0,
435 -20,
436 EQUAL),
437 TestCase::Duration::QUICK);
439 150,
440 -150,
441 0,
442 -20,
443 LESSTHAN),
444 TestCase::Duration::QUICK);
446 150,
447 -150,
448 0,
449 -20,
450 LESSTHAN),
451 TestCase::Duration::QUICK);
452 // test flat beam, with beamwidth=360 deg
454 360,
455 0,
456 0,
457 0,
458 EQUAL),
459 TestCase::Duration::QUICK);
461 360,
462 0,
463 0,
464 0,
465 EQUAL),
466 TestCase::Duration::QUICK);
468 360,
469 0,
470 0,
471 0,
472 EQUAL),
473 TestCase::Duration::QUICK);
475 360,
476 0,
477 0,
478 0,
479 EQUAL),
480 TestCase::Duration::QUICK);
482 360,
483 0,
484 0,
485 0,
486 EQUAL),
487 TestCase::Duration::QUICK);
488
489 // test maxGain
491 60,
492 0,
493 10,
494 10,
495 EQUAL),
496 TestCase::Duration::QUICK);
498 60,
499 0,
500 22,
501 19,
502 EQUAL),
503 TestCase::Duration::QUICK);
505 60,
506 0,
507 -4,
508 -7,
509 EQUAL),
510 TestCase::Duration::QUICK);
512 60,
513 0,
514 10,
515 -10,
516 LESSTHAN),
517 TestCase::Duration::QUICK);
519 60,
520 0,
521 -20,
522 -40,
523 LESSTHAN),
524 TestCase::Duration::QUICK);
526 60,
527 0,
528 40,
529 20,
530 LESSTHAN),
531 TestCase::Duration::QUICK);
533 100,
534 -150,
535 2,
536 2,
537 EQUAL),
538 TestCase::Duration::QUICK);
540 100,
541 -150,
542 4,
543 1,
544 EQUAL),
545 TestCase::Duration::QUICK);
547 100,
548 -150,
549 -1,
550 -4,
551 EQUAL),
552 TestCase::Duration::QUICK);
553
554 // test elevation angle
556 60,
557 0,
558 0,
559 -3,
560 EQUAL),
561 TestCase::Duration::QUICK);
563 60,
564 0,
565 0,
566 -6,
567 EQUAL),
568 TestCase::Duration::QUICK);
570 60,
571 0,
572 0,
573 -6,
574 EQUAL),
575 TestCase::Duration::QUICK);
577 60,
578 0,
579 0,
580 -20,
581 LESSTHAN),
582 TestCase::Duration::QUICK);
584 60,
585 0,
586 0,
587 -20,
588 LESSTHAN),
589 TestCase::Duration::QUICK);
591 60,
592 60,
593 0,
594 -3,
595 EQUAL),
596 TestCase::Duration::QUICK);
598 60,
599 60,
600 0,
601 -6,
602 EQUAL),
603 TestCase::Duration::QUICK);
605 60,
606 60,
607 0,
608 -6,
609 EQUAL),
610 TestCase::Duration::QUICK);
613 60,
614 60,
615 0,
616 -20,
617 LESSTHAN),
618 TestCase::Duration::QUICK);
621 100,
622 -150,
623 0,
624 -3,
625 EQUAL),
626 TestCase::Duration::QUICK);
629 100,
630 -150,
631 0,
632 -6,
633 EQUAL),
634 TestCase::Duration::QUICK);
637 100,
638 -150,
639 0,
640 -6,
641 EQUAL),
642 TestCase::Duration::QUICK);
644 100,
645 -150,
646 0,
647 -20,
648 LESSTHAN),
649 TestCase::Duration::QUICK);
651 60,
652 0,
653 10,
654 7,
655 EQUAL),
656 TestCase::Duration::QUICK);
658 60,
659 0,
660 22,
661 16,
662 EQUAL),
663 TestCase::Duration::QUICK);
665 60,
666 0,
667 -4,
668 -10,
669 EQUAL),
670 TestCase::Duration::QUICK);
672 60,
673 0,
674 10,
675 -13,
676 LESSTHAN),
677 TestCase::Duration::QUICK);
679 60,
680 0,
681 -20,
682 -43,
683 LESSTHAN),
684 TestCase::Duration::QUICK);
686 60,
687 0,
688 40,
689 17,
690 LESSTHAN),
691 TestCase::Duration::QUICK);
693 100,
694 -150,
695 2,
696 -1,
697 EQUAL),
698 TestCase::Duration::QUICK);
700 100,
701 -150,
702 4,
703 -2,
704 EQUAL),
705 TestCase::Duration::QUICK);
707 100,
708 -150,
709 -1,
710 -7,
711 EQUAL),
712 TestCase::Duration::QUICK);
713}
714
715/// 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.