A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
test-isotropic-antenna.cc
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 namespace ns3 {
30 
32 {
33 public:
34  static std::string BuildNameString (Angles a);
35  IsotropicAntennaModelTestCase (Angles a, double expectedGainDb);
36 
37 
38 private:
39  virtual void DoRun (void);
40 
41  Angles m_a;
42  double m_expectedGain;
43 };
44 
45 std::string IsotropicAntennaModelTestCase::BuildNameString (Angles a)
46 {
47  std::ostringstream oss;
48  oss << "theta=" << a.theta << " , phi=" << a.phi;
49  return oss.str ();
50 }
51 
52 
53 IsotropicAntennaModelTestCase::IsotropicAntennaModelTestCase (Angles a, double expectedGainDb)
54  : TestCase (BuildNameString (a)),
55  m_a (a),
56  m_expectedGain (expectedGainDb)
57 {
58 }
59 
60 void
62 {
63  Ptr<IsotropicAntennaModel> a = Create<IsotropicAntennaModel> ();
64  double actualGain = a->GetGainDb (m_a);
65  NS_TEST_EXPECT_MSG_EQ_TOL (actualGain, m_expectedGain, 0.01, "wrong value of the radiation pattern");
66 }
67 
68 
69 
70 
72 {
73 public:
75 };
76 
77 IsotropicAntennaModelTestSuite::IsotropicAntennaModelTestSuite ()
78  : TestSuite ("isotropic-antenna-model", UNIT)
79 {
80  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, 0), 0.0), TestCase::QUICK);
81  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, M_PI), 0.0), TestCase::QUICK);
82  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, M_PI_2), 0.0), TestCase::QUICK);
83  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, 0), 0.0), TestCase::QUICK);
84  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, M_PI), 0.0), TestCase::QUICK);
85  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, M_PI_2), 0.0), TestCase::QUICK);
86  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, 0), 0.0), TestCase::QUICK);
87  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, M_PI), 0.0), TestCase::QUICK);
88  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, M_PI_2), 0.0), TestCase::QUICK);
89 
90 };
91 
92 static IsotropicAntennaModelTestSuite staticIsotropicAntennaModelTestSuiteInstance;
93 
94 
95 
96 
97 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
A suite of tests to run.
Definition: test.h:962
double theta
Definition: angles.h:117
encapsulates test code
Definition: test.h:834
virtual void DoRun(void)
Implementation to actually run this test case.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
double phi
Definition: angles.h:111