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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Nicola Baldo <nbaldo@cttc.es>
7
*/
8
9
#include <ns3/antenna-model.h>
10
#include <ns3/log.h>
11
#include <ns3/test.h>
12
13
#include <cmath>
14
#include <iostream>
15
#include <sstream>
16
#include <string>
17
18
using namespace
ns3
;
19
20
/**
21
* @ingroup tests
22
*
23
* @brief Test degree to radians conversion
24
*/
25
class
DegreesToRadiansTestCase
:
public
TestCase
26
{
27
public
:
28
/**
29
* Build the test name
30
* @param a test param
31
* @return the test name
32
*/
33
static
std::string
BuildNameString
(
double
a);
34
/**
35
* Constructor
36
* @param a angle in degrees
37
* @param b expected angle in radians
38
*/
39
DegreesToRadiansTestCase
(
double
a,
double
b);
40
41
private
:
42
void
DoRun
()
override
;
43
44
double
m_a
;
//!< angle in degrees
45
double
m_b
;
//!< expected angle in radians
46
};
47
48
std::string
49
DegreesToRadiansTestCase::BuildNameString
(
double
a)
50
{
51
std::ostringstream oss;
52
oss <<
"angle = "
<< a <<
" degrees"
;
53
return
oss.str();
54
}
55
56
DegreesToRadiansTestCase::DegreesToRadiansTestCase
(
double
a,
double
b)
57
:
TestCase
(BuildNameString(a)),
58
m_a(a),
59
m_b(b)
60
{
61
}
62
63
void
64
DegreesToRadiansTestCase::DoRun
()
65
{
66
NS_TEST_EXPECT_MSG_EQ_TOL
(
DegreesToRadians
(
m_a
),
m_b
, 1e-10,
"wrong conversion"
);
67
}
68
69
/**
70
* @ingroup tests
71
*
72
* @brief Test radians to degree conversion
73
*/
74
class
RadiansToDegreesTestCase
:
public
TestCase
75
{
76
public
:
77
/**
78
* Build the test name
79
* @param a test param
80
* @return the test name
81
*/
82
static
std::string
BuildNameString
(
double
a);
83
/**
84
* Constructor
85
* @param a angle in radians
86
* @param b expected angle in degrees
87
*/
88
RadiansToDegreesTestCase
(
double
a,
double
b);
89
90
private
:
91
void
DoRun
()
override
;
92
93
double
m_a
;
//!< angle in radians
94
double
m_b
;
//!< expected angle in degrees
95
};
96
97
std::string
98
RadiansToDegreesTestCase::BuildNameString
(
double
a)
99
{
100
std::ostringstream oss;
101
oss <<
"angle = "
<< a <<
" degrees"
;
102
return
oss.str();
103
}
104
105
RadiansToDegreesTestCase::RadiansToDegreesTestCase
(
double
a,
double
b)
106
:
TestCase
(BuildNameString(a)),
107
m_a(a),
108
m_b(b)
109
{
110
}
111
112
void
113
RadiansToDegreesTestCase::DoRun
()
114
{
115
NS_TEST_EXPECT_MSG_EQ_TOL
(
RadiansToDegrees
(
m_a
),
m_b
, 1e-10,
"wrong conversion"
);
116
}
117
118
/**
119
* @ingroup tests
120
*
121
* @brief TestSuite: degree to radians (and vice-versa) conversions
122
*/
123
class
DegreesRadiansTestSuite
:
public
TestSuite
124
{
125
public
:
126
DegreesRadiansTestSuite
();
127
};
128
129
DegreesRadiansTestSuite::DegreesRadiansTestSuite
()
130
:
TestSuite
(
"degrees-radians"
,
Type
::UNIT)
131
{
132
AddTestCase
(
new
DegreesToRadiansTestCase
(0, 0), TestCase::Duration::QUICK);
133
AddTestCase
(
new
DegreesToRadiansTestCase
(90, M_PI_2), TestCase::Duration::QUICK);
134
AddTestCase
(
new
DegreesToRadiansTestCase
(180, M_PI), TestCase::Duration::QUICK);
135
AddTestCase
(
new
DegreesToRadiansTestCase
(270, M_PI + M_PI_2), TestCase::Duration::QUICK);
136
AddTestCase
(
new
DegreesToRadiansTestCase
(360, M_PI + M_PI), TestCase::Duration::QUICK);
137
AddTestCase
(
new
DegreesToRadiansTestCase
(-90, -M_PI_2), TestCase::Duration::QUICK);
138
AddTestCase
(
new
DegreesToRadiansTestCase
(810, 4.5 * M_PI), TestCase::Duration::QUICK);
139
140
AddTestCase
(
new
RadiansToDegreesTestCase
(0, 0), TestCase::Duration::QUICK);
141
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI_2, 90), TestCase::Duration::QUICK);
142
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI, 180), TestCase::Duration::QUICK);
143
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI + M_PI_2, 270), TestCase::Duration::QUICK);
144
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI + M_PI, 360), TestCase::Duration::QUICK);
145
AddTestCase
(
new
RadiansToDegreesTestCase
(-M_PI_2, -90), TestCase::Duration::QUICK);
146
AddTestCase
(
new
RadiansToDegreesTestCase
(4.5 * M_PI, 810), TestCase::Duration::QUICK);
147
}
148
149
/// Static variable for test initialization
150
static
DegreesRadiansTestSuite
g_staticDegreesRadiansTestSuiteInstance
;
DegreesRadiansTestSuite
TestSuite: degree to radians (and vice-versa) conversions.
Definition
test-degrees-radians.cc:124
DegreesRadiansTestSuite::DegreesRadiansTestSuite
DegreesRadiansTestSuite()
Definition
test-degrees-radians.cc:129
DegreesToRadiansTestCase
Test degree to radians conversion.
Definition
test-degrees-radians.cc:26
DegreesToRadiansTestCase::m_b
double m_b
expected angle in radians
Definition
test-degrees-radians.cc:45
DegreesToRadiansTestCase::m_a
double m_a
angle in degrees
Definition
test-degrees-radians.cc:44
DegreesToRadiansTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
test-degrees-radians.cc:64
DegreesToRadiansTestCase::DegreesToRadiansTestCase
DegreesToRadiansTestCase(double a, double b)
Constructor.
Definition
test-degrees-radians.cc:56
DegreesToRadiansTestCase::BuildNameString
static std::string BuildNameString(double a)
Build the test name.
Definition
test-degrees-radians.cc:49
RadiansToDegreesTestCase
Test radians to degree conversion.
Definition
test-degrees-radians.cc:75
RadiansToDegreesTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
test-degrees-radians.cc:113
RadiansToDegreesTestCase::m_a
double m_a
angle in radians
Definition
test-degrees-radians.cc:93
RadiansToDegreesTestCase::BuildNameString
static std::string BuildNameString(double a)
Build the test name.
Definition
test-degrees-radians.cc:98
RadiansToDegreesTestCase::RadiansToDegreesTestCase
RadiansToDegreesTestCase(double a, double b)
Constructor.
Definition
test-degrees-radians.cc:105
RadiansToDegreesTestCase::m_b
double m_b
expected angle in degrees
Definition
test-degrees-radians.cc:94
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
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:500
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:28
ns3::RadiansToDegrees
double RadiansToDegrees(double radians)
converts radians to degrees
Definition
angles.cc:34
g_staticDegreesRadiansTestSuiteInstance
static DegreesRadiansTestSuite g_staticDegreesRadiansTestSuiteInstance
Static variable for test initialization.
Definition
test-degrees-radians.cc:150
src
antenna
test
test-degrees-radians.cc
Generated on Thu Dec 12 2024 18:40:35 for ns-3 by
1.11.0