A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
rectangle-closest-border-test.cc
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*
15
* Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
16
*/
17
18
#include <ns3/rectangle.h>
19
#include <ns3/simulator.h>
20
#include <ns3/test.h>
21
22
using namespace
ns3
;
23
29
class
RectangleClosestBorderTestSuite
:
public
TestSuite
30
{
31
public
:
35
RectangleClosestBorderTestSuite
();
36
};
37
43
class
RectangleClosestBorderTestCase
:
public
TestCase
44
{
45
public
:
53
RectangleClosestBorderTestCase
(
double
x,
double
y,
Rectangle
rectangle,
Rectangle::Side
side);
63
std::string
BuildNameString
(
double
x,
double
y,
Rectangle
rectangle,
Rectangle::Side
side);
67
~RectangleClosestBorderTestCase
()
override
;
68
69
private
:
74
void
DoRun
()
override
;
75
76
double
m_x
{0.0};
77
double
m_y
{0.0};
78
Rectangle
m_rectangle
;
79
84
Rectangle::Side
m_side
{
ns3::Rectangle::TOPSIDE
};
85
};
86
95
RectangleClosestBorderTestSuite::RectangleClosestBorderTestSuite
()
96
:
TestSuite
(
"rectangle-closest-border"
, UNIT)
97
{
98
// Rectangle in the positive x-plane to check the intersection with.
99
Rectangle
rectangle =
Rectangle
(0.0, 10.0, 0.0, 10.0);
100
101
/* 2 3 4
102
* +----------------------------+ (10,10)
103
* | 11 16 12 |
104
* | |
105
* | |
106
* 1 | 15 18 17 | 5
107
* | |
108
* | |
109
* | 10 14 13 |
110
* +----------------------------+
111
* 9 7
112
* (0,0)
113
*
114
*
115
*
116
* 8
117
*/
118
// Left side (1 and 15)
119
AddTestCase
(
new
RectangleClosestBorderTestCase
(-5, 5, rectangle,
Rectangle::LEFTSIDE
),
120
TestCase::QUICK
);
121
AddTestCase
(
new
RectangleClosestBorderTestCase
(2, 5, rectangle,
Rectangle::LEFTSIDE
),
122
TestCase::QUICK
);
123
// Right side (5 and 17)
124
AddTestCase
(
new
RectangleClosestBorderTestCase
(17, 5, rectangle,
Rectangle::RIGHTSIDE
),
125
TestCase::QUICK
);
126
AddTestCase
(
new
RectangleClosestBorderTestCase
(7, 5, rectangle,
Rectangle::RIGHTSIDE
),
127
TestCase::QUICK
);
128
// Bottom side (8 and 14)
129
AddTestCase
(
new
RectangleClosestBorderTestCase
(5, -7, rectangle,
Rectangle::BOTTOMSIDE
),
130
TestCase::QUICK
);
131
AddTestCase
(
new
RectangleClosestBorderTestCase
(5, 1, rectangle,
Rectangle::BOTTOMSIDE
),
132
TestCase::QUICK
);
133
// Top side (3 and 16)
134
AddTestCase
(
new
RectangleClosestBorderTestCase
(5, 15, rectangle,
Rectangle::TOPSIDE
),
135
TestCase::QUICK
);
136
AddTestCase
(
new
RectangleClosestBorderTestCase
(5, 7, rectangle,
Rectangle::TOPSIDE
),
137
TestCase::QUICK
);
138
// Left-Bottom corner (9 and 10)
139
AddTestCase
(
new
RectangleClosestBorderTestCase
(-1, -1, rectangle,
Rectangle::BOTTOMLEFTCORNER
),
140
TestCase::QUICK
);
141
AddTestCase
(
new
RectangleClosestBorderTestCase
(0, 0, rectangle,
Rectangle::BOTTOMLEFTCORNER
),
142
TestCase::QUICK
);
143
// Right-Bottom corner (7 and 13)
144
AddTestCase
(
new
RectangleClosestBorderTestCase
(11, -1, rectangle,
Rectangle::BOTTOMRIGHTCORNER
),
145
TestCase::QUICK
);
146
AddTestCase
(
new
RectangleClosestBorderTestCase
(9, 1, rectangle,
Rectangle::BOTTOMRIGHTCORNER
),
147
TestCase::QUICK
);
148
// Left-Top corner (2 and 11)
149
AddTestCase
(
new
RectangleClosestBorderTestCase
(-1, 11, rectangle,
Rectangle::TOPLEFTCORNER
),
150
TestCase::QUICK
);
151
AddTestCase
(
new
RectangleClosestBorderTestCase
(1, 9, rectangle,
Rectangle::TOPLEFTCORNER
),
152
TestCase::QUICK
);
153
// Right-Top corner (4 and 12)
154
AddTestCase
(
new
RectangleClosestBorderTestCase
(11, 11, rectangle,
Rectangle::TOPRIGHTCORNER
),
155
TestCase::QUICK
);
156
AddTestCase
(
new
RectangleClosestBorderTestCase
(9, 9, rectangle,
Rectangle::TOPRIGHTCORNER
),
157
TestCase::QUICK
);
158
// Central position (18)
159
AddTestCase
(
new
RectangleClosestBorderTestCase
(5, 5, rectangle,
Rectangle::TOPSIDE
),
160
TestCase::QUICK
);
161
}
162
167
static
RectangleClosestBorderTestSuite
rectangleClosestBorderTestSuite
;
168
169
RectangleClosestBorderTestCase::RectangleClosestBorderTestCase
(
double
x,
170
double
y,
171
Rectangle
rectangle,
172
Rectangle::Side
side)
173
:
TestCase
(BuildNameString(x, y, rectangle, side)),
174
m_x(x),
175
m_y(y),
176
m_rectangle(rectangle),
177
m_side(side)
178
{
179
}
180
181
RectangleClosestBorderTestCase::~RectangleClosestBorderTestCase
()
182
{
183
}
184
185
std::string
186
RectangleClosestBorderTestCase::BuildNameString
(
double
x,
187
double
y,
188
Rectangle
rectangle,
189
Rectangle::Side
side)
190
{
191
std::ostringstream oss;
192
oss <<
"Rectangle closest border test : checking"
193
<<
" (x,y) = ("
<< x <<
","
<< y <<
") closest border to the rectangle [("
<< rectangle.
xMin
194
<<
", "
<< rectangle.
yMin
<<
"), ("
<< rectangle.
xMax
<<
", "
<< rectangle.
yMax
195
<<
")]. The expected side = "
<< side;
196
return
oss.str();
197
}
198
199
void
200
RectangleClosestBorderTestCase::DoRun
()
201
{
202
Vector position(
m_x
,
m_y
, 0.0);
203
Rectangle::Side
side =
m_rectangle
.
GetClosestSideOrCorner
(position);
204
205
NS_TEST_ASSERT_MSG_EQ
(side,
m_side
,
"Unexpected result of rectangle side!"
);
206
Simulator::Destroy
();
207
}
RectangleClosestBorderTestCase
TestCase to check the rectangle line intersection.
Definition:
rectangle-closest-border-test.cc:44
RectangleClosestBorderTestCase::BuildNameString
std::string BuildNameString(double x, double y, Rectangle rectangle, Rectangle::Side side)
Builds the test name string based on provided parameter values.
Definition:
rectangle-closest-border-test.cc:186
RectangleClosestBorderTestCase::m_side
Rectangle::Side m_side
Flag to indicate the intersection.
Definition:
rectangle-closest-border-test.cc:84
RectangleClosestBorderTestCase::m_x
double m_x
X coordinate of the point to be tested.
Definition:
rectangle-closest-border-test.cc:76
RectangleClosestBorderTestCase::m_y
double m_y
Y coordinate of the point to be tested.
Definition:
rectangle-closest-border-test.cc:77
RectangleClosestBorderTestCase::RectangleClosestBorderTestCase
RectangleClosestBorderTestCase(double x, double y, Rectangle rectangle, Rectangle::Side side)
Create RectangleClosestBorderTestCase.
Definition:
rectangle-closest-border-test.cc:169
RectangleClosestBorderTestCase::~RectangleClosestBorderTestCase
~RectangleClosestBorderTestCase() override
Destructor.
Definition:
rectangle-closest-border-test.cc:181
RectangleClosestBorderTestCase::DoRun
void DoRun() override
Setup the simulation according to the configuration set by the class constructor, run it,...
Definition:
rectangle-closest-border-test.cc:200
RectangleClosestBorderTestCase::m_rectangle
Rectangle m_rectangle
The rectangle to check the intersection with.
Definition:
rectangle-closest-border-test.cc:78
RectangleClosestBorderTestSuite
Rectangle detection of closest border to a point, inside or outside.
Definition:
rectangle-closest-border-test.cc:30
RectangleClosestBorderTestSuite::RectangleClosestBorderTestSuite
RectangleClosestBorderTestSuite()
Constructor.
Definition:
rectangle-closest-border-test.cc:95
ns3::Rectangle
a 2d rectangle
Definition:
rectangle.h:35
ns3::Rectangle::yMax
double yMax
The y coordinate of the top bound of the rectangle.
Definition:
rectangle.h:118
ns3::Rectangle::GetClosestSideOrCorner
Side GetClosestSideOrCorner(const Vector &position) const
Definition:
rectangle.cc:64
ns3::Rectangle::xMax
double xMax
The x coordinate of the right bound of the rectangle.
Definition:
rectangle.h:116
ns3::Rectangle::Side
Side
enum for naming sides
Definition:
rectangle.h:41
ns3::Rectangle::BOTTOMSIDE
@ BOTTOMSIDE
Definition:
rectangle.h:45
ns3::Rectangle::TOPSIDE
@ TOPSIDE
Definition:
rectangle.h:44
ns3::Rectangle::LEFTSIDE
@ LEFTSIDE
Definition:
rectangle.h:43
ns3::Rectangle::BOTTOMLEFTCORNER
@ BOTTOMLEFTCORNER
Definition:
rectangle.h:49
ns3::Rectangle::BOTTOMRIGHTCORNER
@ BOTTOMRIGHTCORNER
Definition:
rectangle.h:48
ns3::Rectangle::TOPLEFTCORNER
@ TOPLEFTCORNER
Definition:
rectangle.h:47
ns3::Rectangle::RIGHTSIDE
@ RIGHTSIDE
Definition:
rectangle.h:42
ns3::Rectangle::TOPRIGHTCORNER
@ TOPRIGHTCORNER
Definition:
rectangle.h:46
ns3::Rectangle::xMin
double xMin
The x coordinate of the left bound of the rectangle.
Definition:
rectangle.h:115
ns3::Rectangle::yMin
double yMin
The y coordinate of the bottom bound of the rectangle.
Definition:
rectangle.h:117
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::QUICK
@ QUICK
Fast test.
Definition:
test.h:1065
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
rectangleClosestBorderTestSuite
static RectangleClosestBorderTestSuite rectangleClosestBorderTestSuite
Static variable for test initialization.
Definition:
rectangle-closest-border-test.cc:167
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition:
test.h:144
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mobility
test
rectangle-closest-border-test.cc
Generated on Thu Feb 8 2024 09:25:37 for ns-3 by
1.9.6