A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
test-angles.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/antenna-model.h>
24
#include <cmath>
25
#include <string>
26
#include <iostream>
27
#include <sstream>
28
29
namespace
ns3 {
30
31
class
OneVectorConstructorTestCase
:
public
TestCase
32
{
33
public
:
34
static
std::string
BuildNameString
(
Vector
v);
35
OneVectorConstructorTestCase
(
Vector
v,
Angles
a);
36
37
private
:
38
virtual
void
DoRun
(
void
);
39
40
Vector
m_v
;
41
Angles
m_a
;
42
};
43
44
std::string
OneVectorConstructorTestCase::BuildNameString
(
Vector
v)
45
{
46
std::ostringstream oss;
47
oss <<
" v = "
<< v;
48
return
oss.str ();
49
}
50
51
52
OneVectorConstructorTestCase::OneVectorConstructorTestCase
(
Vector
v,
Angles
a)
53
:
TestCase
(BuildNameString (v)),
54
m_v (v),
55
m_a (a)
56
{
57
}
58
59
void
60
OneVectorConstructorTestCase::DoRun
()
61
{
62
Angles
a (
m_v
);
63
NS_TEST_EXPECT_MSG_EQ_TOL
( a.
phi
,
m_a
.
phi
, 1e-10,
"incorrect phi"
);
64
NS_TEST_EXPECT_MSG_EQ_TOL
( a.
theta
,
m_a
.
theta
, 1e-10,
"incorrect theta"
);
65
}
66
67
68
69
70
71
class
TwoVectorsConstructorTestCase
:
public
TestCase
72
{
73
public
:
74
static
std::string
BuildNameString
(
Vector
v,
Vector
o);
75
TwoVectorsConstructorTestCase
(
Vector
v,
Vector
o,
Angles
a);
76
77
private
:
78
virtual
void
DoRun
(
void
);
79
80
Vector
m_v
;
81
Vector
m_o
;
82
Angles
m_a
;
83
};
84
85
std::string
TwoVectorsConstructorTestCase::BuildNameString
(
Vector
v,
Vector
o)
86
{
87
std::ostringstream oss;
88
oss <<
" v = "
<< v <<
", o = "
<< o;
89
return
oss.str ();
90
}
91
92
93
TwoVectorsConstructorTestCase::TwoVectorsConstructorTestCase
(
Vector
v,
Vector
o,
Angles
a)
94
:
TestCase
(BuildNameString (v, o)),
95
m_v (v),
96
m_o (o),
97
m_a (a)
98
{
99
}
100
101
void
102
TwoVectorsConstructorTestCase::DoRun
()
103
{
104
Angles
a (
m_v
,
m_o
);
105
NS_TEST_EXPECT_MSG_EQ_TOL
( a.
phi
,
m_a
.
phi
, 1e-10,
"incorrect phi"
);
106
NS_TEST_EXPECT_MSG_EQ_TOL
( a.
theta
,
m_a
.
theta
, 1e-10,
"incorrect theta"
);
107
}
108
109
110
111
112
113
114
class
AnglesTestSuite
:
public
TestSuite
115
{
116
public
:
117
AnglesTestSuite
();
118
};
119
120
AnglesTestSuite::AnglesTestSuite
()
121
:
TestSuite
(
"angles"
, UNIT)
122
{
123
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, 0, 0),
Angles
(0, M_PI_2)),
TestCase::QUICK
);
124
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(-1, 0, 0),
Angles
(M_PI, M_PI_2)),
TestCase::QUICK
);
125
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 1, 0),
Angles
(M_PI_2, M_PI_2)),
TestCase::QUICK
);
126
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, -1, 0),
Angles
(-M_PI_2, M_PI_2)),
TestCase::QUICK
);
127
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 0, 1),
Angles
(0, 0)),
TestCase::QUICK
);
128
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 0, -1),
Angles
(0, M_PI)),
TestCase::QUICK
);
129
130
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(2, 0, 0),
Angles
(0, M_PI_2)),
TestCase::QUICK
);
131
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(-2, 0, 0),
Angles
(M_PI, M_PI_2)),
TestCase::QUICK
);
132
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 2, 0),
Angles
(M_PI_2, M_PI_2)),
TestCase::QUICK
);
133
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, -2, 0),
Angles
(-M_PI_2, M_PI_2)),
TestCase::QUICK
);
134
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 0, 2),
Angles
(0, 0)),
TestCase::QUICK
);
135
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 0, -2),
Angles
(0, M_PI)),
TestCase::QUICK
);
136
137
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, 0, 1),
Angles
(0, M_PI_4)),
TestCase::QUICK
);
138
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, 0, -1),
Angles
(0, 3*M_PI_4)),
TestCase::QUICK
);
139
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, 1, 0),
Angles
(M_PI_4, M_PI_2)),
TestCase::QUICK
);
140
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, -1, 0),
Angles
(-M_PI_4, M_PI_2)),
TestCase::QUICK
);
141
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(-1, 0, 1),
Angles
(M_PI, M_PI_4)),
TestCase::QUICK
);
142
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(-1, 0, -1),
Angles
(M_PI, 3*M_PI_4)),
TestCase::QUICK
);
143
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(-1, 1, 0),
Angles
(3*M_PI_4, M_PI_2)),
TestCase::QUICK
);
144
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(-1, -1, 0),
Angles
(-3*M_PI_4, M_PI_2)),
TestCase::QUICK
);
145
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 1, 1),
Angles
(M_PI_2, M_PI_4)),
TestCase::QUICK
);
146
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, 1, -1),
Angles
(M_PI_2, 3*M_PI_4)),
TestCase::QUICK
);
147
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, -1, 1),
Angles
(-M_PI_2, M_PI_4)),
TestCase::QUICK
);
148
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(0, -1, -1),
Angles
(-M_PI_2, 3*M_PI_4)),
TestCase::QUICK
);
149
150
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, 1, std::sqrt (2)),
Angles
(M_PI_4, M_PI_4)),
TestCase::QUICK
);
151
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, 1, -std::sqrt (2)),
Angles
(M_PI_4, 3*M_PI_4)),
TestCase::QUICK
);
152
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(1, -1, std::sqrt (2)),
Angles
(-M_PI_4, M_PI_4)),
TestCase::QUICK
);
153
AddTestCase
(
new
OneVectorConstructorTestCase
(
Vector
(-1, 1, std::sqrt (2)),
Angles
(3*M_PI_4, M_PI_4)),
TestCase::QUICK
);
154
155
156
157
158
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, 0, 0),
Vector
(0, 0, 0),
Angles
(0, M_PI_2)),
TestCase::QUICK
);
159
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, 0, 0),
Vector
(0, 0, 0),
Angles
(M_PI, M_PI_2)),
TestCase::QUICK
);
160
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 1, 0),
Vector
(0, 0, 0),
Angles
(M_PI_2, M_PI_2)),
TestCase::QUICK
);
161
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, -1, 0),
Vector
(0, 0, 0),
Angles
(-M_PI_2, M_PI_2)),
TestCase::QUICK
);
162
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 0, 1),
Vector
(0, 0, 0),
Angles
(0, 0)),
TestCase::QUICK
);
163
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 0, -1),
Vector
(0, 0, 0),
Angles
(0, M_PI)),
TestCase::QUICK
);
164
165
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(2, 0, 0),
Vector
(0, 0, 0),
Angles
(0, M_PI_2)),
TestCase::QUICK
);
166
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-2, 0, 0),
Vector
(0, 0, 0),
Angles
(M_PI, M_PI_2)),
TestCase::QUICK
);
167
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 2, 0),
Vector
(0, 0, 0),
Angles
(M_PI_2, M_PI_2)),
TestCase::QUICK
);
168
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, -2, 0),
Vector
(0, 0, 0),
Angles
(-M_PI_2, M_PI_2)),
TestCase::QUICK
);
169
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 0, 2),
Vector
(0, 0, 0),
Angles
(0, 0)),
TestCase::QUICK
);
170
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 0, -2),
Vector
(0, 0, 0),
Angles
(0, M_PI)),
TestCase::QUICK
);
171
172
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, 0, 1),
Vector
(0, 0, 0),
Angles
(0, M_PI_4)),
TestCase::QUICK
);
173
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, 0, -1),
Vector
(0, 0, 0),
Angles
(0, 3*M_PI_4)),
TestCase::QUICK
);
174
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, 1, 0),
Vector
(0, 0, 0),
Angles
(M_PI_4, M_PI_2)),
TestCase::QUICK
);
175
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, -1, 0),
Vector
(0, 0, 0),
Angles
(-M_PI_4, M_PI_2)),
TestCase::QUICK
);
176
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, 0, 1),
Vector
(0, 0, 0),
Angles
(M_PI, M_PI_4)),
TestCase::QUICK
);
177
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, 0, -1),
Vector
(0, 0, 0),
Angles
(M_PI, 3*M_PI_4)),
TestCase::QUICK
);
178
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, 1, 0),
Vector
(0, 0, 0),
Angles
(3*M_PI_4, M_PI_2)),
TestCase::QUICK
);
179
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, -1, 0),
Vector
(0, 0, 0),
Angles
(-3*M_PI_4, M_PI_2)),
TestCase::QUICK
);
180
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 1, 1),
Vector
(0, 0, 0),
Angles
(M_PI_2, M_PI_4)),
TestCase::QUICK
);
181
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, 1, -1),
Vector
(0, 0, 0),
Angles
(M_PI_2, 3*M_PI_4)),
TestCase::QUICK
);
182
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, -1, 1),
Vector
(0, 0, 0),
Angles
(-M_PI_2, M_PI_4)),
TestCase::QUICK
);
183
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, -1, -1),
Vector
(0, 0, 0),
Angles
(-M_PI_2, 3*M_PI_4)),
TestCase::QUICK
);
184
185
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, 1, std::sqrt (2)),
Vector
(0, 0, 0),
Angles
(M_PI_4, M_PI_4)),
TestCase::QUICK
);
186
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, 1, -std::sqrt (2)),
Vector
(0, 0, 0),
Angles
(M_PI_4, 3*M_PI_4)),
TestCase::QUICK
);
187
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, -1, std::sqrt (2)),
Vector
(0, 0, 0),
Angles
(-M_PI_4, M_PI_4)),
TestCase::QUICK
);
188
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, 1, std::sqrt (2)),
Vector
(0, 0, 0),
Angles
(3*M_PI_4, M_PI_4)),
TestCase::QUICK
);
189
190
191
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(3, 2, 2),
Vector
(2, 2, 2),
Angles
(0, M_PI_2)),
TestCase::QUICK
);
192
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(1, 2, 2),
Vector
(2, 2, 2),
Angles
(M_PI, M_PI_2)),
TestCase::QUICK
);
193
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(2, 3, 2),
Vector
(2, 2, 2),
Angles
(M_PI_2, M_PI_2)),
TestCase::QUICK
);
194
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, 2, 2),
Vector
(-1, 3, 2),
Angles
(-M_PI_2, M_PI_2)),
TestCase::QUICK
);
195
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(4, -2, 7),
Vector
(4, -2, 6),
Angles
(0, 0)),
TestCase::QUICK
);
196
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, -5, -1),
Vector
(0, -5, 0),
Angles
(0, M_PI)),
TestCase::QUICK
);
197
198
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-2, 2, -1),
Vector
(-4, 2, -1),
Angles
(0, M_PI_2)),
TestCase::QUICK
);
199
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(2, 2, 0),
Vector
(4, 2, 0),
Angles
(M_PI, M_PI_2)),
TestCase::QUICK
);
200
201
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(-1, 4, 4),
Vector
(-2, 4, 3),
Angles
(0, M_PI_4)),
TestCase::QUICK
);
202
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0, -2, -6),
Vector
(-1, -2, -5),
Angles
(0, 3*M_PI_4)),
TestCase::QUICK
);
203
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(77, 3, 43),
Vector
(78, 2, 43),
Angles
(3*M_PI_4, M_PI_2)),
TestCase::QUICK
);
204
205
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(24, -2, -6 -std::sqrt (2)),
Vector
(23, -3, -6),
Angles
(M_PI_4, 3*M_PI_4)),
TestCase::QUICK
);
206
AddTestCase
(
new
TwoVectorsConstructorTestCase
(
Vector
(0.5, 11.45, std::sqrt (2)-1),
Vector
(-0.5, 12.45, -1),
Angles
(-M_PI_4, M_PI_4)),
TestCase::QUICK
);
207
208
209
};
210
211
static
AnglesTestSuite
staticAnglesTestSuiteInstance
;
212
213
214
215
216
}
// namespace ns3
ns3::AnglesTestSuite::AnglesTestSuite
AnglesTestSuite()
Definition:
test-angles.cc:120
ns3::staticAnglesTestSuiteInstance
static AnglesTestSuite staticAnglesTestSuiteInstance
Definition:
test-angles.cc:209
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
ns3::TwoVectorsConstructorTestCase::m_o
Vector m_o
Definition:
test-angles.cc:81
ns3::OneVectorConstructorTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
test-angles.cc:60
ns3::Angles::theta
double theta
the inclination angle in radians
Definition:
angles.h:117
ns3::TestCase
encapsulates test code
Definition:
test.h:849
ns3::Vector3D
a 3d vector
Definition:
vector.h:31
ns3::TwoVectorsConstructorTestCase
Definition:
test-angles.cc:71
ns3::TwoVectorsConstructorTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
test-angles.cc:102
ns3::TwoVectorsConstructorTestCase::TwoVectorsConstructorTestCase
TwoVectorsConstructorTestCase(Vector v, Vector o, Angles a)
Definition:
test-angles.cc:93
ns3::AnglesTestSuite
Definition:
test-angles.cc:114
ns3::OneVectorConstructorTestCase
Definition:
test-angles.cc:31
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:485
ns3::OneVectorConstructorTestCase::BuildNameString
static std::string BuildNameString(Vector v)
Definition:
test-angles.cc:44
ns3::OneVectorConstructorTestCase::OneVectorConstructorTestCase
OneVectorConstructorTestCase(Vector v, Angles a)
Definition:
test-angles.cc:52
ns3::TwoVectorsConstructorTestCase::BuildNameString
static std::string BuildNameString(Vector v, Vector o)
Definition:
test-angles.cc:85
ns3::OneVectorConstructorTestCase::m_v
Vector m_v
Definition:
test-angles.cc:40
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
ns3::TestCase::QUICK
Fast test.
Definition:
test.h:857
ns3::OneVectorConstructorTestCase::m_a
Angles m_a
Definition:
test-angles.cc:41
ns3::Angles::phi
double phi
the azimuth angle in radians
Definition:
angles.h:111
ns3::Angles
struct holding the azimuth and inclination angles of spherical coordinates.
Definition:
angles.h:71
ns3::TwoVectorsConstructorTestCase::m_a
Angles m_a
Definition:
test-angles.cc:82
ns3::TwoVectorsConstructorTestCase::m_v
Vector m_v
Definition:
test-angles.cc:80
src
antenna
test
test-angles.cc
Generated on Sat Apr 19 2014 14:06:49 for ns-3 by
1.8.6