A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
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
31
class
IsotropicAntennaModelTestCase
:
public
TestCase
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.
GetInclination
() <<
" , phi="
<< a.
GetAzimuth
();
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
61
IsotropicAntennaModelTestCase::DoRun
()
62
{
63
Ptr<IsotropicAntennaModel>
a = CreateObject<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
71
class
IsotropicAntennaModelTestSuite
:
public
TestSuite
72
{
73
public
:
74
IsotropicAntennaModelTestSuite
();
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
;
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::Angles::GetInclination
double GetInclination(void) const
Getter for inclination angle.
Definition:
angles.cc:229
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IsotropicAntennaModelTestCase::BuildNameString
static std::string BuildNameString(Angles a)
Definition:
test-isotropic-antenna.cc:45
IsotropicAntennaModelTestSuite::IsotropicAntennaModelTestSuite
IsotropicAntennaModelTestSuite()
Definition:
test-isotropic-antenna.cc:77
IsotropicAntennaModelTestCase::m_expectedGain
double m_expectedGain
Definition:
test-isotropic-antenna.cc:42
staticIsotropicAntennaModelTestSuiteInstance
static IsotropicAntennaModelTestSuite staticIsotropicAntennaModelTestSuiteInstance
Definition:
test-isotropic-antenna.cc:90
IsotropicAntennaModelTestCase::IsotropicAntennaModelTestCase
IsotropicAntennaModelTestCase(Angles a, double expectedGainDb)
Definition:
test-isotropic-antenna.cc:53
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
NS_TEST_EXPECT_MSG_EQ_TOL
#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:563
IsotropicAntennaModelTestCase
Definition:
test-isotropic-antenna.cc:32
IsotropicAntennaModelTestCase::m_a
Angles m_a
Definition:
test-isotropic-antenna.cc:41
IsotropicAntennaModelTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
test-isotropic-antenna.cc:61
ns3::IsotropicAntennaModel::GetGainDb
virtual double GetGainDb(Angles a)
this method is expected to be re-implemented by each antenna model
Definition:
isotropic-antenna-model.cc:59
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
ns3::Angles
Class holding the azimuth and inclination angles of spherical coordinates.
Definition:
angles.h:119
ns3::Angles::GetAzimuth
double GetAzimuth(void) const
Getter for azimuth angle.
Definition:
angles.cc:222
IsotropicAntennaModelTestSuite
Definition:
test-isotropic-antenna.cc:72
src
antenna
test
test-isotropic-antenna.cc
Generated on Fri Oct 1 2021 17:02:53 for ns-3 by
1.8.20