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-degrees-radians.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
DegreesToRadiansTestCase
:
public
TestCase
32
{
33
public
:
34
static
std::string
BuildNameString
(
double
a);
35
DegreesToRadiansTestCase
(
double
a,
double
b);
36
37
38
private
:
39
virtual
void
DoRun
(
void
);
40
41
double
m_a
;
42
double
m_b
;
43
};
44
45
std::string
DegreesToRadiansTestCase::BuildNameString
(
double
a)
46
{
47
std::ostringstream oss;
48
oss <<
"angle = "
<< a <<
" degrees"
;
49
return
oss.str ();
50
}
51
52
53
DegreesToRadiansTestCase::DegreesToRadiansTestCase
(
double
a,
double
b)
54
:
TestCase
(BuildNameString (a)),
55
m_a (a),
56
m_b (b)
57
{
58
}
59
60
void
61
DegreesToRadiansTestCase::DoRun
()
62
{
63
64
NS_TEST_EXPECT_MSG_EQ_TOL
(
DegreesToRadians
(
m_a
),
m_b
, 1e-10,
"wrong conversion"
);
65
}
66
67
68
69
class
RadiansToDegreesTestCase
:
public
TestCase
70
{
71
public
:
72
static
std::string
BuildNameString
(
double
a);
73
RadiansToDegreesTestCase
(
double
a,
double
b);
74
75
76
private
:
77
virtual
void
DoRun
(
void
);
78
79
double
m_a
;
80
double
m_b
;
81
};
82
83
std::string
RadiansToDegreesTestCase::BuildNameString
(
double
a)
84
{
85
std::ostringstream oss;
86
oss <<
"angle = "
<< a <<
" degrees"
;
87
return
oss.str ();
88
}
89
90
91
RadiansToDegreesTestCase::RadiansToDegreesTestCase
(
double
a,
double
b)
92
:
TestCase
(BuildNameString (a)),
93
m_a (a),
94
m_b (b)
95
{
96
}
97
98
void
99
RadiansToDegreesTestCase::DoRun
()
100
{
101
102
NS_TEST_EXPECT_MSG_EQ_TOL
(
RadiansToDegrees
(
m_a
),
m_b
, 1e-10,
"wrong conversion"
);
103
}
104
105
106
107
class
DegreesRadiansTestSuite
:
public
TestSuite
108
{
109
public
:
110
DegreesRadiansTestSuite
();
111
};
112
113
DegreesRadiansTestSuite::DegreesRadiansTestSuite
()
114
:
TestSuite
(
"degrees-radians"
, UNIT)
115
{
116
AddTestCase
(
new
DegreesToRadiansTestCase
(0, 0),
TestCase::QUICK
);
117
AddTestCase
(
new
DegreesToRadiansTestCase
(90, M_PI_2),
TestCase::QUICK
);
118
AddTestCase
(
new
DegreesToRadiansTestCase
(180, M_PI),
TestCase::QUICK
);
119
AddTestCase
(
new
DegreesToRadiansTestCase
(270, M_PI + M_PI_2),
TestCase::QUICK
);
120
AddTestCase
(
new
DegreesToRadiansTestCase
(360, M_PI + M_PI),
TestCase::QUICK
);
121
AddTestCase
(
new
DegreesToRadiansTestCase
(-90, -M_PI_2),
TestCase::QUICK
);
122
AddTestCase
(
new
DegreesToRadiansTestCase
(810, 4.5*M_PI),
TestCase::QUICK
);
123
124
AddTestCase
(
new
RadiansToDegreesTestCase
(0, 0),
TestCase::QUICK
);
125
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI_2, 90),
TestCase::QUICK
);
126
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI, 180),
TestCase::QUICK
);
127
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI + M_PI_2, 270),
TestCase::QUICK
);
128
AddTestCase
(
new
RadiansToDegreesTestCase
(M_PI + M_PI, 360),
TestCase::QUICK
);
129
AddTestCase
(
new
RadiansToDegreesTestCase
(-M_PI_2, -90),
TestCase::QUICK
);
130
AddTestCase
(
new
RadiansToDegreesTestCase
(4.5*M_PI, 810),
TestCase::QUICK
);
131
132
};
133
134
static
DegreesRadiansTestSuite
staticDegreesRadiansTestSuiteInstance
;
135
136
137
138
139
}
// namespace ns3
ns3::DegreesRadiansTestSuite
Definition:
test-degrees-radians.cc:107
ns3::RadiansToDegreesTestCase::RadiansToDegreesTestCase
RadiansToDegreesTestCase(double a, double b)
Definition:
test-degrees-radians.cc:91
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
ns3::DegreesToRadians
double DegreesToRadians(double degrees)
converts degrees to radians
Definition:
angles.cc:32
ns3::RadiansToDegreesTestCase::m_b
double m_b
Definition:
test-degrees-radians.cc:80
ns3::RadiansToDegreesTestCase
Definition:
test-degrees-radians.cc:69
ns3::DegreesToRadiansTestCase::BuildNameString
static std::string BuildNameString(double a)
Definition:
test-degrees-radians.cc:45
ns3::TestCase
encapsulates test code
Definition:
test.h:849
ns3::DegreesToRadiansTestCase::m_a
double m_a
Definition:
test-degrees-radians.cc:41
ns3::DegreesRadiansTestSuite::DegreesRadiansTestSuite
DegreesRadiansTestSuite()
Definition:
test-degrees-radians.cc:113
ns3::DegreesToRadiansTestCase
Definition:
test-degrees-radians.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::staticDegreesRadiansTestSuiteInstance
static DegreesRadiansTestSuite staticDegreesRadiansTestSuiteInstance
Definition:
test-degrees-radians.cc:132
ns3::DegreesToRadiansTestCase::DegreesToRadiansTestCase
DegreesToRadiansTestCase(double a, double b)
Definition:
test-degrees-radians.cc:53
ns3::DegreesToRadiansTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
test-degrees-radians.cc:61
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
ns3::RadiansToDegreesTestCase::m_a
double m_a
Definition:
test-degrees-radians.cc:79
ns3::RadiansToDegrees
double RadiansToDegrees(double radians)
converts radians to degrees
Definition:
angles.cc:38
ns3::TestCase::QUICK
Fast test.
Definition:
test.h:857
ns3::RadiansToDegreesTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
test-degrees-radians.cc:99
ns3::RadiansToDegreesTestCase::BuildNameString
static std::string BuildNameString(double a)
Definition:
test-degrees-radians.cc:83
ns3::DegreesToRadiansTestCase::m_b
double m_b
Definition:
test-degrees-radians.cc:42
src
antenna
test
test-degrees-radians.cc
Generated on Sat Apr 19 2014 14:06:49 for ns-3 by
1.8.6