A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
test-degrees-radians.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
36
class
DegreesToRadiansTestCase
:
public
TestCase
37
{
38
public
:
44
static
std::string
BuildNameString
(
double
a);
50
DegreesToRadiansTestCase
(
double
a,
double
b);
51
52
private
:
53
void
DoRun
()
override
;
54
55
double
m_a
;
56
double
m_b
;
57
};
58
59
std::string
60
DegreesToRadiansTestCase::BuildNameString
(
double
a)
61
{
62
std::ostringstream oss;
63
oss <<
"angle = "
<< a <<
" degrees"
;
64
return
oss.str();
65
}
66
67
DegreesToRadiansTestCase::DegreesToRadiansTestCase
(
double
a,
double
b)
68
:
TestCase
(BuildNameString(a)),
69
m_a(a),
70
m_b(b)
71
{
72
}
73
74
void
75
DegreesToRadiansTestCase::DoRun
()
76
{
77
NS_TEST_EXPECT_MSG_EQ_TOL
(
DegreesToRadians
(
m_a
),
m_b
, 1e-10,
"wrong conversion"
);
78
}
79
85
class
RadiansToDegreesTestCase
:
public
TestCase
86
{
87
public
:
93
static
std::string
BuildNameString
(
double
a);
99
RadiansToDegreesTestCase
(
double
a,
double
b);
100
101
private
:
102
void
DoRun
()
override
;
103
104
double
m_a
;
105
double
m_b
;
106
};
107
108
std::string
109
RadiansToDegreesTestCase::BuildNameString
(
double
a)
110
{
111
std::ostringstream oss;
112
oss <<
"angle = "
<< a <<
" degrees"
;
113
return
oss.str();
114
}
115
116
RadiansToDegreesTestCase::RadiansToDegreesTestCase
(
double
a,
double
b)
117
:
TestCase
(BuildNameString(a)),
118
m_a(a),
119
m_b(b)
120
{
121
}
122
123
void
124
RadiansToDegreesTestCase::DoRun
()
125
{
126
NS_TEST_EXPECT_MSG_EQ_TOL
(
RadiansToDegrees
(
m_a
),
m_b
, 1e-10,
"wrong conversion"
);
127
}
128
134
class
DegreesRadiansTestSuite
:
public
TestSuite
135
{
136
public
:
137
DegreesRadiansTestSuite
();
138
};
139
140
DegreesRadiansTestSuite::DegreesRadiansTestSuite
()
141
:
TestSuite
(
"degrees-radians"
, UNIT)
142
{
143
AddTestCase
(
new
DegreesToRadiansTestCase
(0, 0),
TestCase::QUICK
);
144
AddTestCase
(
new
DegreesToRadiansTestCase
(90, M_PI_2),
TestCase::QUICK
);
145
AddTestCase
(
new
DegreesToRadiansTestCase
(180, M_PI),
TestCase::QUICK
);
146
AddTestCase
(
new
DegreesToRadiansTestCase
(270, M_PI + M_PI_2),
TestCase::QUICK
);
147
AddTestCase
(
new
DegreesToRadiansTestCase
(360, M_PI + M_PI),
TestCase::QUICK
);
148
AddTestCase
(
new
DegreesToRadiansTestCase
(-90, -M_PI_2),
TestCase::QUICK
);
149
AddTestCase
(
new
DegreesToRadiansTestCase
(810, 4.5 * M_PI),
TestCase::QUICK
);
150
151
AddTestCase
(
new
RadiansToDegreesTestCase
(0, 0),
TestCase::QUICK
);
152
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI_2, 90),
TestCase::QUICK
);
153
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI, 180),
TestCase::QUICK
);
154
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI + M_PI_2, 270),
TestCase::QUICK
);
155
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI + M_PI, 360),
TestCase::QUICK
);
156
AddTestCase
(
new
RadiansToDegreesTestCase
(-M_PI_2, -90),
TestCase::QUICK
);
157
AddTestCase
(
new
RadiansToDegreesTestCase
(4.5 * M_PI, 810),
TestCase::QUICK
);
158
};
159
161
static
DegreesRadiansTestSuite
g_staticDegreesRadiansTestSuiteInstance
;
DegreesRadiansTestSuite
TestSuite: degree to radians (and vice-versa) conversions.
Definition:
test-degrees-radians.cc:135
DegreesRadiansTestSuite::DegreesRadiansTestSuite
DegreesRadiansTestSuite()
Definition:
test-degrees-radians.cc:140
DegreesToRadiansTestCase
Test degree to radians conversion.
Definition:
test-degrees-radians.cc:37
DegreesToRadiansTestCase::m_b
double m_b
expected angle in radians
Definition:
test-degrees-radians.cc:56
DegreesToRadiansTestCase::m_a
double m_a
angle in degrees
Definition:
test-degrees-radians.cc:55
DegreesToRadiansTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
test-degrees-radians.cc:75
DegreesToRadiansTestCase::DegreesToRadiansTestCase
DegreesToRadiansTestCase(double a, double b)
Constructor.
Definition:
test-degrees-radians.cc:67
DegreesToRadiansTestCase::BuildNameString
static std::string BuildNameString(double a)
Build the test name.
Definition:
test-degrees-radians.cc:60
RadiansToDegreesTestCase
Test radians to degree conversion.
Definition:
test-degrees-radians.cc:86
RadiansToDegreesTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
test-degrees-radians.cc:124
RadiansToDegreesTestCase::m_a
double m_a
angle in radians
Definition:
test-degrees-radians.cc:104
RadiansToDegreesTestCase::BuildNameString
static std::string BuildNameString(double a)
Build the test name.
Definition:
test-degrees-radians.cc:109
RadiansToDegreesTestCase::RadiansToDegreesTestCase
RadiansToDegreesTestCase(double a, double b)
Constructor.
Definition:
test-degrees-radians.cc:116
RadiansToDegreesTestCase::m_b
double m_b
expected angle in degrees
Definition:
test-degrees-radians.cc:105
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::QUICK
@ QUICK
Fast test.
Definition:
test.h:1065
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
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:510
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DegreesToRadians
double DegreesToRadians(double degrees)
converts degrees to radians
Definition:
angles.cc:39
ns3::RadiansToDegrees
double RadiansToDegrees(double radians)
converts radians to degrees
Definition:
angles.cc:45
g_staticDegreesRadiansTestSuiteInstance
static DegreesRadiansTestSuite g_staticDegreesRadiansTestSuiteInstance
Static variable for test initialization.
Definition:
test-degrees-radians.cc:161
src
antenna
test
test-degrees-radians.cc
Generated on Wed Sep 27 2023 18:43:56 for ns-3 by
1.9.6