A Discrete-Event Network Simulator
API
test-isotropic-antenna.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 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/isotropic-antenna-model.h>
21 #include <ns3/log.h>
22 #include <ns3/test.h>
23 
24 #include <cmath>
25 #include <iostream>
26 #include <sstream>
27 #include <string>
28 
29 using namespace ns3;
30 
37 {
38  public:
44  static std::string BuildNameString(Angles a);
50  IsotropicAntennaModelTestCase(Angles a, double expectedGainDb);
51 
52  private:
53  void DoRun() override;
54 
56  double m_expectedGain;
57 };
58 
59 std::string
61 {
62  std::ostringstream oss;
63  oss << "theta=" << a.GetInclination() << " , phi=" << a.GetAzimuth();
64  return oss.str();
65 }
66 
68  : TestCase(BuildNameString(a)),
69  m_a(a),
70  m_expectedGain(expectedGainDb)
71 {
72 }
73 
74 void
76 {
77  Ptr<IsotropicAntennaModel> a = CreateObject<IsotropicAntennaModel>();
78  double actualGain = a->GetGainDb(m_a);
79  NS_TEST_EXPECT_MSG_EQ_TOL(actualGain,
81  0.01,
82  "wrong value of the radiation pattern");
83 }
84 
91 {
92  public:
94 };
95 
97  : TestSuite("isotropic-antenna-model", UNIT)
98 {
99  AddTestCase(new IsotropicAntennaModelTestCase(Angles(0, 0), 0.0), TestCase::QUICK);
100  AddTestCase(new IsotropicAntennaModelTestCase(Angles(0, M_PI), 0.0), TestCase::QUICK);
101  AddTestCase(new IsotropicAntennaModelTestCase(Angles(0, M_PI_2), 0.0), TestCase::QUICK);
102  AddTestCase(new IsotropicAntennaModelTestCase(Angles(M_PI, 0), 0.0), TestCase::QUICK);
103  AddTestCase(new IsotropicAntennaModelTestCase(Angles(M_PI, M_PI), 0.0), TestCase::QUICK);
104  AddTestCase(new IsotropicAntennaModelTestCase(Angles(M_PI, M_PI_2), 0.0), TestCase::QUICK);
105  AddTestCase(new IsotropicAntennaModelTestCase(Angles(M_PI_2, 0), 0.0), TestCase::QUICK);
106  AddTestCase(new IsotropicAntennaModelTestCase(Angles(M_PI_2, M_PI), 0.0), TestCase::QUICK);
107  AddTestCase(new IsotropicAntennaModelTestCase(Angles(M_PI_2, M_PI_2), 0.0), TestCase::QUICK);
108 }
109 
IsotropicAntennaModel Test.
IsotropicAntennaModelTestCase(Angles a, double expectedGainDb)
Constructor.
static std::string BuildNameString(Angles a)
Build the test name.
void DoRun() override
Implementation to actually run this TestCase.
IsotropicAntennaModel 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
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
#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.
static IsotropicAntennaModelTestSuite g_staticIsotropicAntennaModelTestSuiteInstance
Static variable for test initialization.