A Discrete-Event Network Simulator
API
test-isotropic-antenna.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 CTTC
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include <ns3/log.h>
22 #include <ns3/test.h>
23 #include <ns3/isotropic-antenna-model.h>
24 #include <cmath>
25 #include <string>
26 #include <iostream>
27 #include <sstream>
28 
29 using namespace ns3;
30 
37 {
38 public:
44  static std::string BuildNameString (Angles a);
50  IsotropicAntennaModelTestCase (Angles a, double expectedGainDb);
51 
52 
53 private:
54  virtual void DoRun (void);
55 
57  double m_expectedGain;
58 };
59 
61 {
62  std::ostringstream oss;
63  oss << "theta=" << a.GetInclination () << " , phi=" << a.GetAzimuth ();
64  return oss.str ();
65 }
66 
67 
69  : TestCase (BuildNameString (a)),
70  m_a (a),
71  m_expectedGain (expectedGainDb)
72 {
73 }
74 
75 void
77 {
78  Ptr<IsotropicAntennaModel> a = CreateObject<IsotropicAntennaModel> ();
79  double actualGain = a->GetGainDb (m_a);
80  NS_TEST_EXPECT_MSG_EQ_TOL (actualGain, m_expectedGain, 0.01, "wrong value of the radiation pattern");
81 }
82 
83 
84 
85 
92 {
93 public:
95 };
96 
98  : TestSuite ("isotropic-antenna-model", UNIT)
99 {
100  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, 0), 0.0), TestCase::QUICK);
101  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, M_PI), 0.0), TestCase::QUICK);
102  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, M_PI_2), 0.0), TestCase::QUICK);
103  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, 0), 0.0), TestCase::QUICK);
104  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, M_PI), 0.0), TestCase::QUICK);
105  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, M_PI_2), 0.0), TestCase::QUICK);
106  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, 0), 0.0), TestCase::QUICK);
107  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, M_PI), 0.0), TestCase::QUICK);
108  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, M_PI_2), 0.0), TestCase::QUICK);
109 
110 };
111 
IsotropicAntennaModel Test.
IsotropicAntennaModelTestCase(Angles a, double expectedGainDb)
Constructor.
static std::string BuildNameString(Angles a)
Build the test name.
virtual void DoRun(void)
Implementation to actually run this TestCase.
IsotropicAntennaModel TestSuite.
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:119
double GetInclination(void) const
Getter for inclination angle.
Definition: angles.cc:231
double GetAzimuth(void) const
Getter for azimuth angle.
Definition: angles.cc:224
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
#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:491
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static IsotropicAntennaModelTestSuite g_staticIsotropicAntennaModelTestSuiteInstance
Static variable for test initialization.