A Discrete-Event Network Simulator
API
test-parabolic-antenna.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011,12 CTTC
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Nicola Baldo <nbaldo@cttc.es>
18  */
19 
20 #include <ns3/double.h>
21 #include <ns3/log.h>
22 #include <ns3/parabolic-antenna-model.h>
23 #include <ns3/simulator.h>
24 #include <ns3/test.h>
25 
26 #include <cmath>
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 
31 using namespace ns3;
32 
33 NS_LOG_COMPONENT_DEFINE("TestParabolicAntennaModel");
34 
41 {
42  EQUAL = 0,
43  LESSTHAN = 1
44 };
45 
52 {
53  public:
62  static std::string BuildNameString(Angles a, double b, double o, double g);
73  double b,
74  double o,
75  double g,
76  double expectedGainDb,
78 
79  private:
80  void DoRun() override;
81 
83  double m_b;
84  double m_o;
85  double m_g;
86  double m_expectedGain;
88 };
89 
90 std::string
92 {
93  std::ostringstream oss;
94  oss << "theta=" << a.GetInclination() << " , phi=" << a.GetAzimuth() << ", beamdwidth=" << b
95  << "deg"
96  << ", orientation=" << o << ", maxAttenuation=" << g << " dB";
97  return oss.str();
98 }
99 
101  Angles a,
102  double b,
103  double o,
104  double g,
105  double expectedGainDb,
107  : TestCase(BuildNameString(a, b, o, g)),
108  m_a(a),
109  m_b(b),
110  m_o(o),
111  m_g(g),
112  m_expectedGain(expectedGainDb),
113  m_cond(cond)
114 {
115 }
116 
117 void
119 {
121 
122  Ptr<ParabolicAntennaModel> a = CreateObject<ParabolicAntennaModel>();
123  a->SetAttribute("Beamwidth", DoubleValue(m_b));
124  a->SetAttribute("Orientation", DoubleValue(m_o));
125  a->SetAttribute("MaxAttenuation", DoubleValue(m_g));
126  double actualGain = a->GetGainDb(m_a);
127  switch (m_cond)
128  {
129  case EQUAL:
130  NS_TEST_EXPECT_MSG_EQ_TOL(actualGain,
132  0.001,
133  "wrong value of the radiation pattern");
134  break;
135  case LESSTHAN:
136  NS_TEST_EXPECT_MSG_LT(actualGain, m_expectedGain, "gain higher than expected");
137  break;
138  default:
139  break;
140  }
141 }
142 
149 {
150  public:
152 };
153 
155  : TestSuite("parabolic-antenna-model", UNIT)
156 {
157  // with a 60 deg beamwidth, gain is -20dB at +-77.460 degrees from boresight
158  // phi, theta,
159  // beamwidth,
160  // orientation, maxAttn,
161  // expectedGain,
162  // condition
164  60,
165  0,
166  20,
167  0,
168  EQUAL),
169  TestCase::QUICK);
170  AddTestCase(
172  60,
173  0,
174  20,
175  -3,
176  EQUAL),
177  TestCase::QUICK);
178  AddTestCase(
180  60,
181  0,
182  20,
183  -3,
184  EQUAL),
185  TestCase::QUICK);
186  AddTestCase(
188  60,
189  0,
190  20,
191  -20,
192  EQUAL),
193  TestCase::QUICK);
194  AddTestCase(
196  60,
197  0,
198  20,
199  -20,
200  EQUAL),
201  TestCase::QUICK);
202  AddTestCase(
204  60,
205  0,
206  20,
207  -20,
208  EQUAL),
209  TestCase::QUICK);
210  AddTestCase(
212  60,
213  0,
214  20,
215  -20,
216  EQUAL),
217  TestCase::QUICK);
218  AddTestCase(
220  60,
221  0,
222  20,
223  -20,
224  EQUAL),
225  TestCase::QUICK);
226  AddTestCase(
228  60,
229  0,
230  20,
231  -20,
232  EQUAL),
233  TestCase::QUICK);
234  AddTestCase(
236  60,
237  0,
238  20,
239  -20,
240  EQUAL),
241  TestCase::QUICK);
242  AddTestCase(
244  60,
245  0,
246  20,
247  -20,
248  EQUAL),
249  TestCase::QUICK);
250 
251  // with a 60 deg beamwidth, gain is -10dB at +-54.772 degrees from boresight
252  // test positive orientation
253  AddTestCase(
255  60,
256  60,
257  10,
258  0,
259  EQUAL),
260  TestCase::QUICK);
261  AddTestCase(
263  60,
264  60,
265  10,
266  -3,
267  EQUAL),
268  TestCase::QUICK);
269  AddTestCase(
271  60,
272  60,
273  10,
274  -3,
275  EQUAL),
276  TestCase::QUICK);
277  AddTestCase(
279  60,
280  60,
281  10,
282  -10,
283  EQUAL),
284  TestCase::QUICK);
285  AddTestCase(
287  60,
288  60,
289  10,
290  -10,
291  EQUAL),
292  TestCase::QUICK);
293  AddTestCase(
295  60,
296  60,
297  10,
298  -10,
299  EQUAL),
300  TestCase::QUICK);
301  AddTestCase(
303  60,
304  60,
305  10,
306  -10,
307  EQUAL),
308  TestCase::QUICK);
309  AddTestCase(
311  60,
312  60,
313  10,
314  -10,
315  EQUAL),
316  TestCase::QUICK);
317  AddTestCase(
319  60,
320  60,
321  10,
322  -10,
323  EQUAL),
324  TestCase::QUICK);
325  AddTestCase(
327  60,
328  60,
329  10,
330  -10,
331  EQUAL),
332  TestCase::QUICK);
333  AddTestCase(
335  60,
336  60,
337  10,
338  -10,
339  EQUAL),
340  TestCase::QUICK);
341 
342  // test negative orientation and different beamwidths
343  // with a 80 deg beamwidth, gain is -20dB at +- 73.030 degrees from boresight
344  AddTestCase(
346  80,
347  -150,
348  10,
349  0,
350  EQUAL),
351  TestCase::QUICK);
352  AddTestCase(
354  80,
355  -150,
356  10,
357  -3,
358  EQUAL),
359  TestCase::QUICK);
360  AddTestCase(
362  80,
363  -150,
364  10,
365  -3,
366  EQUAL),
367  TestCase::QUICK);
368  AddTestCase(
370  80,
371  -150,
372  10,
373  -10,
374  EQUAL),
375  TestCase::QUICK);
376  AddTestCase(
378  80,
379  -150,
380  10,
381  -10,
382  EQUAL),
383  TestCase::QUICK);
384  AddTestCase(
386  80,
387  -150,
388  10,
389  -10,
390  EQUAL),
391  TestCase::QUICK);
393  80,
394  -150,
395  10,
396  -10,
397  EQUAL),
398  TestCase::QUICK);
399  AddTestCase(
401  80,
402  -150,
403  10,
404  -10,
405  EQUAL),
406  TestCase::QUICK);
407  AddTestCase(
409  80,
410  -150,
411  10,
412  -10,
413  EQUAL),
414  TestCase::QUICK);
415  AddTestCase(
417  80,
418  -150,
419  10,
420  -10,
421  EQUAL),
422  TestCase::QUICK);
423 
424  // test elevation angle
426  60,
427  0,
428  20,
429  0,
430  EQUAL),
431  TestCase::QUICK);
432  AddTestCase(
434  60,
435  0,
436  20,
437  -3,
438  EQUAL),
439  TestCase::QUICK);
440  AddTestCase(
442  60,
443  0,
444  20,
445  -3,
446  EQUAL),
447  TestCase::QUICK);
448  AddTestCase(
450  60,
451  0,
452  20,
453  -20,
454  EQUAL),
455  TestCase::QUICK);
456  AddTestCase(
458  60,
459  0,
460  20,
461  -20,
462  EQUAL),
463  TestCase::QUICK);
464  AddTestCase(
466  60,
467  60,
468  20,
469  0,
470  EQUAL),
471  TestCase::QUICK);
472  AddTestCase(
474  60,
475  60,
476  20,
477  -3,
478  EQUAL),
479  TestCase::QUICK);
480  AddTestCase(
482  60,
483  60,
484  20,
485  -3,
486  EQUAL),
487  TestCase::QUICK);
488  AddTestCase(
490  60,
491  60,
492  20,
493  -20,
494  EQUAL),
495  TestCase::QUICK);
496  AddTestCase(
498  100,
499  -150,
500  10,
501  0,
502  EQUAL),
503  TestCase::QUICK);
504  AddTestCase(
506  100,
507  -150,
508  10,
509  -3,
510  EQUAL),
511  TestCase::QUICK);
512  AddTestCase(
514  100,
515  -150,
516  10,
517  -3,
518  EQUAL),
519  TestCase::QUICK);
520  AddTestCase(
522  100,
523  -150,
524  10,
525  -10,
526  EQUAL),
527  TestCase::QUICK);
528  AddTestCase(
530  100,
531  -150,
532  10,
533  -10,
534  EQUAL),
535  TestCase::QUICK);
536  AddTestCase(
538  60,
539  0,
540  20,
541  0,
542  EQUAL),
543  TestCase::QUICK);
544  AddTestCase(
546  60,
547  0,
548  20,
549  -3,
550  EQUAL),
551  TestCase::QUICK);
552  AddTestCase(
554  60,
555  0,
556  20,
557  -3,
558  EQUAL),
559  TestCase::QUICK);
560  AddTestCase(
562  60,
563  0,
564  20,
565  -20,
566  EQUAL),
567  TestCase::QUICK);
568  AddTestCase(
570  100,
571  -150,
572  30,
573  0,
574  EQUAL),
575  TestCase::QUICK);
576  AddTestCase(
578  100,
579  -150,
580  30,
581  -3,
582  EQUAL),
583  TestCase::QUICK);
584  AddTestCase(
586  100,
587  -150,
588  30,
589  -3,
590  EQUAL),
591  TestCase::QUICK);
592 }
593 
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:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:246
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
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:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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:790
#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:510
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
static ParabolicAntennaModelTestSuite g_staticParabolicAntennaModelTestSuiteInstance
Static variable for test initialization.