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
tv-helper-distribution-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2014 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
7
*/
8
9
#include <ns3/log.h>
10
#include <ns3/test.h>
11
#include <ns3/tv-spectrum-transmitter-helper.h>
12
13
NS_LOG_COMPONENT_DEFINE
(
"TvHelperDistributionTest"
);
14
15
using namespace
ns3
;
16
17
/**
18
* \ingroup spectrum-tests
19
*
20
* This test verifies the accuracy of the private GetRandomNumTransmitters()
21
* method in the TvSpectrumTransmitterHelper class. The method generates a
22
* random number corresponding to the number of TV transmitters to create based
23
* on the given location density (low, medium, or high) and maximum possible
24
* number of TV channels. Low density will generate a transmitter for between
25
* one (a single transmitter) and one third of the number of possible channels,
26
* medium density will generate a transmitter for between one third and two
27
* thirds, and high density will generate a transmitter for between two thirds
28
* and all of the possible channels. In this test, it is verified that the
29
* lower (1) and upper (max number of possible channels input) bounds are not
30
* exceeded and that the number of transmitters to be generated does not overlap
31
* between adjacent densities. For example, given 60 possible channels, for low
32
* density between 1 and 20 transmitters can be created, for medium density
33
* between 21 and 40 transmitters can be created, and for high density between
34
* 41 and 60 transmitters can be created (all inclusive). This is tested with
35
* various cases.
36
*/
37
class
TvHelperDistributionTestCase
:
public
TestCase
38
{
39
public
:
40
/**
41
* Constructor
42
*
43
* \param maxNumTransmitters maximum number of transmitters.
44
*/
45
TvHelperDistributionTestCase
(
uint32_t
maxNumTransmitters);
46
~TvHelperDistributionTestCase
()
override
;
47
48
private
:
49
void
DoRun
()
override
;
50
/**
51
* Build the test name
52
* \param maxNumTransmitters maximum number of transmitters.
53
* \return The test name
54
*/
55
static
std::string
Name
(
uint32_t
maxNumTransmitters);
56
uint32_t
m_maxNumTransmitters
;
//!< Maximum number of transmitters.
57
};
58
59
std::string
60
TvHelperDistributionTestCase::Name
(
uint32_t
maxNumTransmitters)
61
{
62
std::ostringstream oss;
63
oss <<
"Max Number of Transmitters = "
<< maxNumTransmitters;
64
return
oss.str();
65
}
66
67
TvHelperDistributionTestCase::TvHelperDistributionTestCase
(
uint32_t
maxNumTransmitters)
68
:
TestCase
(
Name
(maxNumTransmitters)),
69
m_maxNumTransmitters(maxNumTransmitters)
70
{
71
}
72
73
TvHelperDistributionTestCase::~TvHelperDistributionTestCase
()
74
{
75
}
76
77
void
78
TvHelperDistributionTestCase::DoRun
()
79
{
80
NS_LOG_FUNCTION
(
m_maxNumTransmitters
);
81
TvSpectrumTransmitterHelper
tvTransHelper;
82
uint32_t
rand;
83
uint32_t
maxLow = 0;
84
uint32_t
minMid =
m_maxNumTransmitters
;
85
uint32_t
maxMid = 0;
86
uint32_t
minHigh =
m_maxNumTransmitters
;
87
for
(
int
i = 0; i < 30; i++)
88
{
89
rand = tvTransHelper.
GetRandomNumTransmitters
(
TvSpectrumTransmitterHelper::DENSITY_LOW
,
90
m_maxNumTransmitters
);
91
NS_TEST_ASSERT_MSG_GT
(rand, 0,
"lower bound exceeded"
);
92
if
(rand > maxLow)
93
{
94
maxLow = rand;
95
}
96
}
97
for
(
int
i = 0; i < 30; i++)
98
{
99
rand = tvTransHelper.
GetRandomNumTransmitters
(
TvSpectrumTransmitterHelper::DENSITY_MEDIUM
,
100
m_maxNumTransmitters
);
101
if
(rand < minMid)
102
{
103
minMid = rand;
104
}
105
if
(rand > maxMid)
106
{
107
maxMid = rand;
108
}
109
}
110
for
(
int
i = 0; i < 30; i++)
111
{
112
rand = tvTransHelper.
GetRandomNumTransmitters
(
TvSpectrumTransmitterHelper::DENSITY_HIGH
,
113
m_maxNumTransmitters
);
114
NS_TEST_ASSERT_MSG_LT
(rand,
m_maxNumTransmitters
+ 1,
"upper bound exceeded"
);
115
if
(rand < minHigh)
116
{
117
minHigh = rand;
118
}
119
}
120
NS_TEST_ASSERT_MSG_LT
(maxLow, minMid,
"low density overlaps with medium density"
);
121
NS_TEST_ASSERT_MSG_LT
(maxMid, minHigh,
"medium density overlaps with high density"
);
122
}
123
124
/**
125
* \ingroup spectrum-tests
126
*
127
* Test suite for the TvSpectrumTransmitterHelper class
128
*/
129
class
TvHelperDistributionTestSuite
:
public
TestSuite
130
{
131
public
:
132
TvHelperDistributionTestSuite
();
133
};
134
135
TvHelperDistributionTestSuite::TvHelperDistributionTestSuite
()
136
:
TestSuite
(
"tv-helper-distribution"
,
Type
::UNIT)
137
{
138
NS_LOG_INFO
(
"creating TvHelperDistributionTestSuite"
);
139
for
(
uint32_t
maxNumTransmitters = 3; maxNumTransmitters <= 203; maxNumTransmitters += 10)
140
{
141
AddTestCase
(
new
TvHelperDistributionTestCase
(maxNumTransmitters),
142
TestCase::Duration::QUICK);
143
}
144
}
145
146
/// Static variable for test initialization
147
static
TvHelperDistributionTestSuite
g_TvHelperDistributionTestSuite
;
TvHelperDistributionTestCase
This test verifies the accuracy of the private GetRandomNumTransmitters() method in the TvSpectrumTra...
Definition
tv-helper-distribution-test.cc:38
TvHelperDistributionTestCase::~TvHelperDistributionTestCase
~TvHelperDistributionTestCase() override
Definition
tv-helper-distribution-test.cc:73
TvHelperDistributionTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
tv-helper-distribution-test.cc:78
TvHelperDistributionTestCase::TvHelperDistributionTestCase
TvHelperDistributionTestCase(uint32_t maxNumTransmitters)
Constructor.
Definition
tv-helper-distribution-test.cc:67
TvHelperDistributionTestCase::Name
static std::string Name(uint32_t maxNumTransmitters)
Build the test name.
Definition
tv-helper-distribution-test.cc:60
TvHelperDistributionTestCase::m_maxNumTransmitters
uint32_t m_maxNumTransmitters
Maximum number of transmitters.
Definition
tv-helper-distribution-test.cc:56
TvHelperDistributionTestSuite
Test suite for the TvSpectrumTransmitterHelper class.
Definition
tv-helper-distribution-test.cc:130
TvHelperDistributionTestSuite::TvHelperDistributionTestSuite
TvHelperDistributionTestSuite()
Definition
tv-helper-distribution-test.cc:135
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TvSpectrumTransmitterHelper
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
Definition
tv-spectrum-transmitter-helper.h:56
ns3::TvSpectrumTransmitterHelper::DENSITY_MEDIUM
@ DENSITY_MEDIUM
Definition
tv-spectrum-transmitter-helper.h:76
ns3::TvSpectrumTransmitterHelper::DENSITY_LOW
@ DENSITY_LOW
Definition
tv-spectrum-transmitter-helper.h:75
ns3::TvSpectrumTransmitterHelper::DENSITY_HIGH
@ DENSITY_HIGH
Definition
tv-spectrum-transmitter-helper.h:77
ns3::TvSpectrumTransmitterHelper::GetRandomNumTransmitters
int GetRandomNumTransmitters(Density density, uint32_t numChannels)
Randomly generates the number of TV transmitters to be created based on given density and number of p...
Definition
tv-spectrum-transmitter-helper.cc:415
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
NS_TEST_ASSERT_MSG_LT
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition
test.h:699
NS_TEST_ASSERT_MSG_GT
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition
test.h:864
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Name
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
Definition
tcp-test.cc:155
g_TvHelperDistributionTestSuite
static TvHelperDistributionTestSuite g_TvHelperDistributionTestSuite
Static variable for test initialization.
Definition
tv-helper-distribution-test.cc:147
src
spectrum
test
tv-helper-distribution-test.cc
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0