A Discrete-Event Network Simulator
API
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
29using namespace ns3;
30
37{
38public:
44 static std::string BuildNameString (double a);
50 DegreesToRadiansTestCase (double a, double b);
51
52
53private:
54 virtual void DoRun (void);
55
56 double m_a;
57 double m_b;
58};
59
61{
62 std::ostringstream oss;
63 oss << "angle = " << a << " degrees";
64 return oss.str ();
65}
66
67
69 : TestCase (BuildNameString (a)),
70 m_a (a),
71 m_b (b)
72{
73}
74
75void
77{
78
79 NS_TEST_EXPECT_MSG_EQ_TOL (DegreesToRadians (m_a), m_b, 1e-10, "wrong conversion");
80}
81
82
83
90{
91public:
97 static std::string BuildNameString (double a);
103 RadiansToDegreesTestCase (double a, double b);
104
105
106private:
107 virtual void DoRun (void);
108
109 double m_a;
110 double m_b;
111};
112
114{
115 std::ostringstream oss;
116 oss << "angle = " << a << " degrees";
117 return oss.str ();
118}
119
120
122 : TestCase (BuildNameString (a)),
123 m_a (a),
124 m_b (b)
125{
126}
127
128void
130{
131
132 NS_TEST_EXPECT_MSG_EQ_TOL (RadiansToDegrees (m_a), m_b, 1e-10, "wrong conversion");
133}
134
135
136
143{
144public:
146};
147
149 : TestSuite ("degrees-radians", UNIT)
150{
151 AddTestCase (new DegreesToRadiansTestCase (0, 0), TestCase::QUICK);
152 AddTestCase (new DegreesToRadiansTestCase (90, M_PI_2), TestCase::QUICK);
153 AddTestCase (new DegreesToRadiansTestCase (180, M_PI), TestCase::QUICK);
154 AddTestCase (new DegreesToRadiansTestCase (270, M_PI + M_PI_2), TestCase::QUICK);
155 AddTestCase (new DegreesToRadiansTestCase (360, M_PI + M_PI), TestCase::QUICK);
156 AddTestCase (new DegreesToRadiansTestCase (-90, -M_PI_2), TestCase::QUICK);
157 AddTestCase (new DegreesToRadiansTestCase (810, 4.5*M_PI), TestCase::QUICK);
158
159 AddTestCase (new RadiansToDegreesTestCase (0, 0), TestCase::QUICK);
160 AddTestCase (new RadiansToDegreesTestCase (M_PI_2, 90), TestCase::QUICK);
161 AddTestCase (new RadiansToDegreesTestCase (M_PI, 180), TestCase::QUICK);
162 AddTestCase (new RadiansToDegreesTestCase (M_PI + M_PI_2, 270), TestCase::QUICK);
163 AddTestCase (new RadiansToDegreesTestCase (M_PI + M_PI, 360), TestCase::QUICK);
164 AddTestCase (new RadiansToDegreesTestCase (-M_PI_2, -90), TestCase::QUICK);
165 AddTestCase (new RadiansToDegreesTestCase (4.5*M_PI, 810), TestCase::QUICK);
166
167};
168
TestSuite: degree to radians (and viceversa) conversions.
Test degree to radians conversion.
double m_b
expected angle in radians
virtual void DoRun(void)
Implementation to actually run this TestCase.
double m_a
angle in degrees
DegreesToRadiansTestCase(double a, double b)
Constructor.
static std::string BuildNameString(double a)
Build the test name.
Test radians to degree conversion.
virtual void DoRun(void)
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:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
#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:491
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:40
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:47
static DegreesRadiansTestSuite g_staticDegreesRadiansTestSuiteInstance
Static variable for test initialization.