A Discrete-Event Network Simulator
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
29using namespace ns3;
30
31/**
32 * \ingroup tests
33 *
34 * \brief Test degree to radians conversion
35 */
37{
38 public:
39 /**
40 * Build the test name
41 * \param a test param
42 * \return the test name
43 */
44 static std::string BuildNameString(double a);
45 /**
46 * Constructor
47 * \param a angle in degrees
48 * \param b expected angle in radians
49 */
50 DegreesToRadiansTestCase(double a, double b);
51
52 private:
53 void DoRun() override;
54
55 double m_a; //!< angle in degrees
56 double m_b; //!< expected angle in radians
57};
58
59std::string
61{
62 std::ostringstream oss;
63 oss << "angle = " << a << " degrees";
64 return oss.str();
65}
66
68 : TestCase(BuildNameString(a)),
69 m_a(a),
70 m_b(b)
71{
72}
73
74void
76{
77 NS_TEST_EXPECT_MSG_EQ_TOL(DegreesToRadians(m_a), m_b, 1e-10, "wrong conversion");
78}
79
80/**
81 * \ingroup tests
82 *
83 * \brief Test radians to degree conversion
84 */
86{
87 public:
88 /**
89 * Build the test name
90 * \param a test param
91 * \return the test name
92 */
93 static std::string BuildNameString(double a);
94 /**
95 * Constructor
96 * \param a angle in radians
97 * \param b expected angle in degrees
98 */
99 RadiansToDegreesTestCase(double a, double b);
100
101 private:
102 void DoRun() override;
103
104 double m_a; //!< angle in radians
105 double m_b; //!< expected angle in degrees
106};
107
108std::string
110{
111 std::ostringstream oss;
112 oss << "angle = " << a << " degrees";
113 return oss.str();
114}
115
117 : TestCase(BuildNameString(a)),
118 m_a(a),
119 m_b(b)
120{
121}
122
123void
125{
126 NS_TEST_EXPECT_MSG_EQ_TOL(RadiansToDegrees(m_a), m_b, 1e-10, "wrong conversion");
127}
128
129/**
130 * \ingroup tests
131 *
132 * \brief TestSuite: degree to radians (and vice-versa) conversions
133 */
135{
136 public:
138};
139
141 : TestSuite("degrees-radians", Type::UNIT)
142{
143 AddTestCase(new DegreesToRadiansTestCase(0, 0), TestCase::Duration::QUICK);
144 AddTestCase(new DegreesToRadiansTestCase(90, M_PI_2), TestCase::Duration::QUICK);
145 AddTestCase(new DegreesToRadiansTestCase(180, M_PI), TestCase::Duration::QUICK);
146 AddTestCase(new DegreesToRadiansTestCase(270, M_PI + M_PI_2), TestCase::Duration::QUICK);
147 AddTestCase(new DegreesToRadiansTestCase(360, M_PI + M_PI), TestCase::Duration::QUICK);
148 AddTestCase(new DegreesToRadiansTestCase(-90, -M_PI_2), TestCase::Duration::QUICK);
149 AddTestCase(new DegreesToRadiansTestCase(810, 4.5 * M_PI), TestCase::Duration::QUICK);
150
151 AddTestCase(new RadiansToDegreesTestCase(0, 0), TestCase::Duration::QUICK);
152 AddTestCase(new RadiansToDegreesTestCase(M_PI_2, 90), TestCase::Duration::QUICK);
153 AddTestCase(new RadiansToDegreesTestCase(M_PI, 180), TestCase::Duration::QUICK);
154 AddTestCase(new RadiansToDegreesTestCase(M_PI + M_PI_2, 270), TestCase::Duration::QUICK);
155 AddTestCase(new RadiansToDegreesTestCase(M_PI + M_PI, 360), TestCase::Duration::QUICK);
156 AddTestCase(new RadiansToDegreesTestCase(-M_PI_2, -90), TestCase::Duration::QUICK);
157 AddTestCase(new RadiansToDegreesTestCase(4.5 * M_PI, 810), TestCase::Duration::QUICK);
158}
159
160/// Static variable for test initialization
TestSuite: degree to radians (and vice-versa) conversions.
Test degree to radians conversion.
double m_b
expected angle in radians
double m_a
angle in degrees
void DoRun() override
Implementation to actually run this TestCase.
DegreesToRadiansTestCase(double a, double b)
Constructor.
static std::string BuildNameString(double a)
Build the test name.
Test radians to degree conversion.
void DoRun() override
Implementation to actually run this TestCase.
double m_a
angle in radians
static std::string BuildNameString(double a)
Build the test name.
RadiansToDegreesTestCase(double a, double b)
Constructor.
double m_b
expected angle in degrees
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
#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:511
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:45
static DegreesRadiansTestSuite g_staticDegreesRadiansTestSuiteInstance
Static variable for test initialization.