A Discrete-Event Network Simulator
API
test-angles.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/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(Vector v);
51 
52  private:
53  void DoRun() override;
54 
55  Vector m_v;
57 };
58 
59 std::string
61 {
62  std::ostringstream oss;
63  oss << " v = " << v;
64  return oss.str();
65 }
66 
68  : TestCase(BuildNameString(v)),
69  m_v(v),
70  m_a(a)
71 {
72 }
73 
74 void
76 {
77  Angles a(m_v);
78  NS_TEST_EXPECT_MSG_EQ_TOL(a.GetAzimuth(), m_a.GetAzimuth(), 1e-10, "incorrect phi");
79  NS_TEST_EXPECT_MSG_EQ_TOL(a.GetInclination(), m_a.GetInclination(), 1e-10, "incorrect theta");
80 }
81 
88 {
89  public:
96  static std::string BuildNameString(Vector v, Vector o);
103  TwoVectorsConstructorTestCase(Vector v, Vector o, Angles a);
104 
105  private:
106  void DoRun() override;
107 
108  Vector m_v;
109  Vector m_o;
111 };
112 
113 std::string
115 {
116  std::ostringstream oss;
117  oss << " v = " << v << ", o = " << o;
118  return oss.str();
119 }
120 
122  : TestCase(BuildNameString(v, o)),
123  m_v(v),
124  m_o(o),
125  m_a(a)
126 {
127 }
128 
129 void
131 {
132  Angles a(m_v, m_o);
133  NS_TEST_EXPECT_MSG_EQ_TOL(a.GetAzimuth(), m_a.GetAzimuth(), 1e-10, "incorrect phi");
134  NS_TEST_EXPECT_MSG_EQ_TOL(a.GetInclination(), m_a.GetInclination(), 1e-10, "incorrect theta");
135 }
136 
143 {
144  public:
145  AnglesTestSuite();
146 };
147 
149  : TestSuite("angles", UNIT)
150 {
151  AddTestCase(new OneVectorConstructorTestCase(Vector(1, 0, 0), Angles(0, M_PI_2)),
152  TestCase::QUICK);
153  AddTestCase(new OneVectorConstructorTestCase(Vector(-1, 0, 0), Angles(M_PI, M_PI_2)),
154  TestCase::QUICK);
155  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 1, 0), Angles(M_PI_2, M_PI_2)),
156  TestCase::QUICK);
157  AddTestCase(new OneVectorConstructorTestCase(Vector(0, -1, 0), Angles(-M_PI_2, M_PI_2)),
158  TestCase::QUICK);
159  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 0, 1), Angles(0, 0)), TestCase::QUICK);
160  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 0, -1), Angles(0, M_PI)),
161  TestCase::QUICK);
162 
163  AddTestCase(new OneVectorConstructorTestCase(Vector(2, 0, 0), Angles(0, M_PI_2)),
164  TestCase::QUICK);
165  AddTestCase(new OneVectorConstructorTestCase(Vector(-2, 0, 0), Angles(M_PI, M_PI_2)),
166  TestCase::QUICK);
167  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 2, 0), Angles(M_PI_2, M_PI_2)),
168  TestCase::QUICK);
169  AddTestCase(new OneVectorConstructorTestCase(Vector(0, -2, 0), Angles(-M_PI_2, M_PI_2)),
170  TestCase::QUICK);
171  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 0, 2), Angles(0, 0)), TestCase::QUICK);
172  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 0, -2), Angles(0, M_PI)),
173  TestCase::QUICK);
174 
175  AddTestCase(new OneVectorConstructorTestCase(Vector(1, 0, 1), Angles(0, M_PI_4)),
176  TestCase::QUICK);
177  AddTestCase(new OneVectorConstructorTestCase(Vector(1, 0, -1), Angles(0, 3 * M_PI_4)),
178  TestCase::QUICK);
179  AddTestCase(new OneVectorConstructorTestCase(Vector(1, 1, 0), Angles(M_PI_4, M_PI_2)),
180  TestCase::QUICK);
181  AddTestCase(new OneVectorConstructorTestCase(Vector(1, -1, 0), Angles(-M_PI_4, M_PI_2)),
182  TestCase::QUICK);
183  AddTestCase(new OneVectorConstructorTestCase(Vector(-1, 0, 1), Angles(M_PI, M_PI_4)),
184  TestCase::QUICK);
185  AddTestCase(new OneVectorConstructorTestCase(Vector(-1, 0, -1), Angles(M_PI, 3 * M_PI_4)),
186  TestCase::QUICK);
187  AddTestCase(new OneVectorConstructorTestCase(Vector(-1, 1, 0), Angles(3 * M_PI_4, M_PI_2)),
188  TestCase::QUICK);
189  AddTestCase(new OneVectorConstructorTestCase(Vector(-1, -1, 0), Angles(-3 * M_PI_4, M_PI_2)),
190  TestCase::QUICK);
191  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 1, 1), Angles(M_PI_2, M_PI_4)),
192  TestCase::QUICK);
193  AddTestCase(new OneVectorConstructorTestCase(Vector(0, 1, -1), Angles(M_PI_2, 3 * M_PI_4)),
194  TestCase::QUICK);
195  AddTestCase(new OneVectorConstructorTestCase(Vector(0, -1, 1), Angles(-M_PI_2, M_PI_4)),
196  TestCase::QUICK);
197  AddTestCase(new OneVectorConstructorTestCase(Vector(0, -1, -1), Angles(-M_PI_2, 3 * M_PI_4)),
198  TestCase::QUICK);
199 
200  AddTestCase(
201  new OneVectorConstructorTestCase(Vector(1, 1, std::sqrt(2)), Angles(M_PI_4, M_PI_4)),
202  TestCase::QUICK);
203  AddTestCase(
204  new OneVectorConstructorTestCase(Vector(1, 1, -std::sqrt(2)), Angles(M_PI_4, 3 * M_PI_4)),
205  TestCase::QUICK);
206  AddTestCase(
207  new OneVectorConstructorTestCase(Vector(1, -1, std::sqrt(2)), Angles(-M_PI_4, M_PI_4)),
208  TestCase::QUICK);
209  AddTestCase(
210  new OneVectorConstructorTestCase(Vector(-1, 1, std::sqrt(2)), Angles(3 * M_PI_4, M_PI_4)),
211  TestCase::QUICK);
212 
213  AddTestCase(
214  new TwoVectorsConstructorTestCase(Vector(1, 0, 0), Vector(0, 0, 0), Angles(0, M_PI_2)),
215  TestCase::QUICK);
216  AddTestCase(
217  new TwoVectorsConstructorTestCase(Vector(-1, 0, 0), Vector(0, 0, 0), Angles(M_PI, M_PI_2)),
218  TestCase::QUICK);
219  AddTestCase(
220  new TwoVectorsConstructorTestCase(Vector(0, 1, 0), Vector(0, 0, 0), Angles(M_PI_2, M_PI_2)),
221  TestCase::QUICK);
222  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, -1, 0),
223  Vector(0, 0, 0),
224  Angles(-M_PI_2, M_PI_2)),
225  TestCase::QUICK);
226  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, 0, 1), Vector(0, 0, 0), Angles(0, 0)),
227  TestCase::QUICK);
228  AddTestCase(
229  new TwoVectorsConstructorTestCase(Vector(0, 0, -1), Vector(0, 0, 0), Angles(0, M_PI)),
230  TestCase::QUICK);
231 
232  AddTestCase(
233  new TwoVectorsConstructorTestCase(Vector(2, 0, 0), Vector(0, 0, 0), Angles(0, M_PI_2)),
234  TestCase::QUICK);
235  AddTestCase(
236  new TwoVectorsConstructorTestCase(Vector(-2, 0, 0), Vector(0, 0, 0), Angles(M_PI, M_PI_2)),
237  TestCase::QUICK);
238  AddTestCase(
239  new TwoVectorsConstructorTestCase(Vector(0, 2, 0), Vector(0, 0, 0), Angles(M_PI_2, M_PI_2)),
240  TestCase::QUICK);
241  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, -2, 0),
242  Vector(0, 0, 0),
243  Angles(-M_PI_2, M_PI_2)),
244  TestCase::QUICK);
245  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, 0, 2), Vector(0, 0, 0), Angles(0, 0)),
246  TestCase::QUICK);
247  AddTestCase(
248  new TwoVectorsConstructorTestCase(Vector(0, 0, -2), Vector(0, 0, 0), Angles(0, M_PI)),
249  TestCase::QUICK);
250 
251  AddTestCase(
252  new TwoVectorsConstructorTestCase(Vector(1, 0, 1), Vector(0, 0, 0), Angles(0, M_PI_4)),
253  TestCase::QUICK);
254  AddTestCase(
255  new TwoVectorsConstructorTestCase(Vector(1, 0, -1), Vector(0, 0, 0), Angles(0, 3 * M_PI_4)),
256  TestCase::QUICK);
257  AddTestCase(
258  new TwoVectorsConstructorTestCase(Vector(1, 1, 0), Vector(0, 0, 0), Angles(M_PI_4, M_PI_2)),
259  TestCase::QUICK);
260  AddTestCase(new TwoVectorsConstructorTestCase(Vector(1, -1, 0),
261  Vector(0, 0, 0),
262  Angles(-M_PI_4, M_PI_2)),
263  TestCase::QUICK);
264  AddTestCase(
265  new TwoVectorsConstructorTestCase(Vector(-1, 0, 1), Vector(0, 0, 0), Angles(M_PI, M_PI_4)),
266  TestCase::QUICK);
267  AddTestCase(new TwoVectorsConstructorTestCase(Vector(-1, 0, -1),
268  Vector(0, 0, 0),
269  Angles(M_PI, 3 * M_PI_4)),
270  TestCase::QUICK);
271  AddTestCase(new TwoVectorsConstructorTestCase(Vector(-1, 1, 0),
272  Vector(0, 0, 0),
273  Angles(3 * M_PI_4, M_PI_2)),
274  TestCase::QUICK);
275  AddTestCase(new TwoVectorsConstructorTestCase(Vector(-1, -1, 0),
276  Vector(0, 0, 0),
277  Angles(-3 * M_PI_4, M_PI_2)),
278  TestCase::QUICK);
279  AddTestCase(
280  new TwoVectorsConstructorTestCase(Vector(0, 1, 1), Vector(0, 0, 0), Angles(M_PI_2, M_PI_4)),
281  TestCase::QUICK);
282  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, 1, -1),
283  Vector(0, 0, 0),
284  Angles(M_PI_2, 3 * M_PI_4)),
285  TestCase::QUICK);
286  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, -1, 1),
287  Vector(0, 0, 0),
288  Angles(-M_PI_2, M_PI_4)),
289  TestCase::QUICK);
290  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, -1, -1),
291  Vector(0, 0, 0),
292  Angles(-M_PI_2, 3 * M_PI_4)),
293  TestCase::QUICK);
294 
295  AddTestCase(new TwoVectorsConstructorTestCase(Vector(1, 1, std::sqrt(2)),
296  Vector(0, 0, 0),
297  Angles(M_PI_4, M_PI_4)),
298  TestCase::QUICK);
299  AddTestCase(new TwoVectorsConstructorTestCase(Vector(1, 1, -std::sqrt(2)),
300  Vector(0, 0, 0),
301  Angles(M_PI_4, 3 * M_PI_4)),
302  TestCase::QUICK);
303  AddTestCase(new TwoVectorsConstructorTestCase(Vector(1, -1, std::sqrt(2)),
304  Vector(0, 0, 0),
305  Angles(-M_PI_4, M_PI_4)),
306  TestCase::QUICK);
307  AddTestCase(new TwoVectorsConstructorTestCase(Vector(-1, 1, std::sqrt(2)),
308  Vector(0, 0, 0),
309  Angles(3 * M_PI_4, M_PI_4)),
310  TestCase::QUICK);
311 
312  AddTestCase(
313  new TwoVectorsConstructorTestCase(Vector(3, 2, 2), Vector(2, 2, 2), Angles(0, M_PI_2)),
314  TestCase::QUICK);
315  AddTestCase(
316  new TwoVectorsConstructorTestCase(Vector(1, 2, 2), Vector(2, 2, 2), Angles(M_PI, M_PI_2)),
317  TestCase::QUICK);
318  AddTestCase(
319  new TwoVectorsConstructorTestCase(Vector(2, 3, 2), Vector(2, 2, 2), Angles(M_PI_2, M_PI_2)),
320  TestCase::QUICK);
321  AddTestCase(new TwoVectorsConstructorTestCase(Vector(-1, 2, 2),
322  Vector(-1, 3, 2),
323  Angles(-M_PI_2, M_PI_2)),
324  TestCase::QUICK);
325  AddTestCase(new TwoVectorsConstructorTestCase(Vector(4, -2, 7), Vector(4, -2, 6), Angles(0, 0)),
326  TestCase::QUICK);
327  AddTestCase(
328  new TwoVectorsConstructorTestCase(Vector(0, -5, -1), Vector(0, -5, 0), Angles(0, M_PI)),
329  TestCase::QUICK);
330 
331  AddTestCase(
332  new TwoVectorsConstructorTestCase(Vector(-2, 2, -1), Vector(-4, 2, -1), Angles(0, M_PI_2)),
333  TestCase::QUICK);
334  AddTestCase(
335  new TwoVectorsConstructorTestCase(Vector(2, 2, 0), Vector(4, 2, 0), Angles(M_PI, M_PI_2)),
336  TestCase::QUICK);
337 
338  AddTestCase(
339  new TwoVectorsConstructorTestCase(Vector(-1, 4, 4), Vector(-2, 4, 3), Angles(0, M_PI_4)),
340  TestCase::QUICK);
341  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0, -2, -6),
342  Vector(-1, -2, -5),
343  Angles(0, 3 * M_PI_4)),
344  TestCase::QUICK);
345  AddTestCase(new TwoVectorsConstructorTestCase(Vector(77, 3, 43),
346  Vector(78, 2, 43),
347  Angles(3 * M_PI_4, M_PI_2)),
348  TestCase::QUICK);
349 
350  AddTestCase(new TwoVectorsConstructorTestCase(Vector(24, -2, -6 - std::sqrt(2)),
351  Vector(23, -3, -6),
352  Angles(M_PI_4, 3 * M_PI_4)),
353  TestCase::QUICK);
354  AddTestCase(new TwoVectorsConstructorTestCase(Vector(0.5, 11.45, std::sqrt(2) - 1),
355  Vector(-0.5, 12.45, -1),
356  Angles(-M_PI_4, M_PI_4)),
357  TestCase::QUICK);
358 }
359 
Angles TestSuite.
Definition: test-angles.cc:143
Angles Test using one vector for initialization.
Definition: test-angles.cc:37
void DoRun() override
Implementation to actually run this TestCase.
Definition: test-angles.cc:75
OneVectorConstructorTestCase(Vector v, Angles a)
Constructor.
Definition: test-angles.cc:67
Angles m_a
expected angle
Definition: test-angles.cc:56
static std::string BuildNameString(Vector v)
Build the test name.
Definition: test-angles.cc:60
Angles Test using two vectors for initialization.
Definition: test-angles.cc:88
TwoVectorsConstructorTestCase(Vector v, Vector o, Angles a)
Constructor.
Definition: test-angles.cc:121
void DoRun() override
Implementation to actually run this TestCase.
Definition: test-angles.cc:130
Angles m_a
expected angle
Definition: test-angles.cc:110
static std::string BuildNameString(Vector v, Vector o)
Build the test name.
Definition: test-angles.cc:114
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:216
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:210
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:305
A suite of tests to run.
Definition: test.h:1256
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
#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 AnglesTestSuite g_staticAnglesTestSuiteInstance
Static variable for test initialization.
Definition: test-angles.cc:361