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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include <ns3/antenna-model.h>
10#include <ns3/log.h>
11#include <ns3/test.h>
12
13#include <cmath>
14#include <iostream>
15#include <sstream>
16#include <string>
17
18using namespace ns3;
19
20/**
21 * @ingroup tests
22 *
23 * @brief Test degree to radians conversion
24 */
26{
27 public:
28 /**
29 * Build the test name
30 * @param a test param
31 * @return the test name
32 */
33 static std::string BuildNameString(double a);
34 /**
35 * Constructor
36 * @param a angle in degrees
37 * @param b expected angle in radians
38 */
39 DegreesToRadiansTestCase(double a, double b);
40
41 private:
42 void DoRun() override;
43
44 double m_a; //!< angle in degrees
45 double m_b; //!< expected angle in radians
46};
47
48std::string
50{
51 std::ostringstream oss;
52 oss << "angle = " << a << " degrees";
53 return oss.str();
54}
55
57 : TestCase(BuildNameString(a)),
58 m_a(a),
59 m_b(b)
60{
61}
62
63void
68
69/**
70 * @ingroup tests
71 *
72 * @brief Test radians to degree conversion
73 */
75{
76 public:
77 /**
78 * Build the test name
79 * @param a test param
80 * @return the test name
81 */
82 static std::string BuildNameString(double a);
83 /**
84 * Constructor
85 * @param a angle in radians
86 * @param b expected angle in degrees
87 */
88 RadiansToDegreesTestCase(double a, double b);
89
90 private:
91 void DoRun() override;
92
93 double m_a; //!< angle in radians
94 double m_b; //!< expected angle in degrees
95};
96
97std::string
99{
100 std::ostringstream oss;
101 oss << "angle = " << a << " degrees";
102 return oss.str();
103}
104
106 : TestCase(BuildNameString(a)),
107 m_a(a),
108 m_b(b)
109{
110}
111
112void
117
118/**
119 * @ingroup tests
120 *
121 * @brief TestSuite: degree to radians (and vice-versa) conversions
122 */
124{
125 public:
127};
128
130 : TestSuite("degrees-radians", Type::UNIT)
131{
132 AddTestCase(new DegreesToRadiansTestCase(0, 0), TestCase::Duration::QUICK);
133 AddTestCase(new DegreesToRadiansTestCase(90, M_PI_2), TestCase::Duration::QUICK);
134 AddTestCase(new DegreesToRadiansTestCase(180, M_PI), TestCase::Duration::QUICK);
135 AddTestCase(new DegreesToRadiansTestCase(270, M_PI + M_PI_2), TestCase::Duration::QUICK);
136 AddTestCase(new DegreesToRadiansTestCase(360, M_PI + M_PI), TestCase::Duration::QUICK);
137 AddTestCase(new DegreesToRadiansTestCase(-90, -M_PI_2), TestCase::Duration::QUICK);
138 AddTestCase(new DegreesToRadiansTestCase(810, 4.5 * M_PI), TestCase::Duration::QUICK);
139
140 AddTestCase(new RadiansToDegreesTestCase(0, 0), TestCase::Duration::QUICK);
141 AddTestCase(new RadiansToDegreesTestCase(M_PI_2, 90), TestCase::Duration::QUICK);
142 AddTestCase(new RadiansToDegreesTestCase(M_PI, 180), TestCase::Duration::QUICK);
143 AddTestCase(new RadiansToDegreesTestCase(M_PI + M_PI_2, 270), TestCase::Duration::QUICK);
144 AddTestCase(new RadiansToDegreesTestCase(M_PI + M_PI, 360), TestCase::Duration::QUICK);
145 AddTestCase(new RadiansToDegreesTestCase(-M_PI_2, -90), TestCase::Duration::QUICK);
146 AddTestCase(new RadiansToDegreesTestCase(4.5 * M_PI, 810), TestCase::Duration::QUICK);
147}
148
149/// 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:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
#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:500
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition angles.cc:28
double RadiansToDegrees(double radians)
converts radians to degrees
Definition angles.cc:34
static DegreesRadiansTestSuite g_staticDegreesRadiansTestSuiteInstance
Static variable for test initialization.