A Discrete-Event Network Simulator
API
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 
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
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 
74 void
76 {
77  NS_TEST_EXPECT_MSG_EQ_TOL(DegreesToRadians(m_a), m_b, 1e-10, "wrong conversion");
78 }
79 
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
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 
123 void
125 {
126  NS_TEST_EXPECT_MSG_EQ_TOL(RadiansToDegrees(m_a), m_b, 1e-10, "wrong conversion");
127 }
128 
135 {
136  public:
138 };
139 
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 
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:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
#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.
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.