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 
29 using namespace ns3;
30 
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 
46 {
47  std::ostringstream oss;
48  oss << "angle = " << a << " degrees";
49  return oss.str ();
50 }
51 
52 
54  : TestCase (BuildNameString (a)),
55  m_a (a),
56  m_b (b)
57 {
58 }
59 
60 void
62 {
63 
64  NS_TEST_EXPECT_MSG_EQ_TOL (DegreesToRadians (m_a), m_b, 1e-10, "wrong conversion");
65 }
66 
67 
68 
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 
84 {
85  std::ostringstream oss;
86  oss << "angle = " << a << " degrees";
87  return oss.str ();
88 }
89 
90 
92  : TestCase (BuildNameString (a)),
93  m_a (a),
94  m_b (b)
95 {
96 }
97 
98 void
100 {
101 
102  NS_TEST_EXPECT_MSG_EQ_TOL (RadiansToDegrees (m_a), m_b, 1e-10, "wrong conversion");
103 }
104 
105 
106 
108 {
109 public:
111 };
112 
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 
DegreesToRadiansTestCase(double a, double b)
static DegreesRadiansTestSuite staticDegreesRadiansTestSuiteInstance
A suite of tests to run.
Definition: test.h:1342
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:31
encapsulates test code
Definition: test.h:1155
RadiansToDegreesTestCase(double a, double b)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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:565
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static std::string BuildNameString(double a)
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:37
static std::string BuildNameString(double a)
virtual void DoRun(void)
Implementation to actually run this TestCase.