A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
tv-helper-distribution-test.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2014 University of Washington
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: Benjamin Cizdziel <ben.cizdziel@gmail.com>
19
*/
20
21
#include <ns3/test.h>
22
#include <ns3/log.h>
23
#include <ns3/tv-spectrum-transmitter-helper.h>
24
43
NS_LOG_COMPONENT_DEFINE
(
"TvHelperDistributionTest"
);
44
45
using namespace
ns3
;
46
47
48
class
TvHelperDistributionTestCase
:
public
TestCase
49
{
50
public
:
51
TvHelperDistributionTestCase
(uint32_t maxNumTransmitters);
52
virtual
~
TvHelperDistributionTestCase
();
53
54
private
:
55
virtual
void
DoRun (
void
);
56
static
std::string
Name
(uint32_t maxNumTransmitters);
57
uint32_t
m_maxNumTransmitters
;
58
};
59
60
std::string
61
TvHelperDistributionTestCase::Name
(uint32_t maxNumTransmitters)
62
{
63
std::ostringstream oss;
64
oss <<
"Max Number of Transmitters = "
<< maxNumTransmitters;
65
return
oss.str();
66
}
67
68
TvHelperDistributionTestCase::TvHelperDistributionTestCase
(uint32_t maxNumTransmitters)
69
:
TestCase
(
Name
(maxNumTransmitters)),
70
m_maxNumTransmitters (maxNumTransmitters)
71
{
72
}
73
74
TvHelperDistributionTestCase::~TvHelperDistributionTestCase
()
75
{
76
}
77
78
void
79
TvHelperDistributionTestCase::DoRun
(
void
)
80
{
81
NS_LOG_FUNCTION
(
m_maxNumTransmitters
);
82
TvSpectrumTransmitterHelper
tvTransHelper;
83
uint32_t rand;
84
uint32_t maxLow = 0;
85
uint32_t minMid =
m_maxNumTransmitters
;
86
uint32_t maxMid = 0;
87
uint32_t minHigh =
m_maxNumTransmitters
;
88
for
(
int
i = 0; i < 30; i ++)
89
{
90
rand = tvTransHelper.
GetRandomNumTransmitters
(TvSpectrumTransmitterHelper::DENSITY_LOW,
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,
m_maxNumTransmitters
);
100
if
(rand < minMid)
101
{
102
minMid = rand;
103
}
104
if
(rand > maxMid)
105
{
106
maxMid = rand;
107
}
108
}
109
for
(
int
i = 0; i < 30; i ++)
110
{
111
rand = tvTransHelper.
GetRandomNumTransmitters
(TvSpectrumTransmitterHelper::DENSITY_HIGH,
m_maxNumTransmitters
);
112
NS_TEST_ASSERT_MSG_LT
(rand,
m_maxNumTransmitters
+ 1,
"upper bound exceeded"
);
113
if
(rand < minHigh)
114
{
115
minHigh = rand;
116
}
117
}
118
NS_TEST_ASSERT_MSG_LT
(maxLow, minMid,
"low density overlaps with medium density"
);
119
NS_TEST_ASSERT_MSG_LT
(maxMid, minHigh,
"medium density overlaps with high density"
);
120
}
121
122
123
class
TvHelperDistributionTestSuite
:
public
TestSuite
124
{
125
public
:
126
TvHelperDistributionTestSuite
();
127
};
128
129
TvHelperDistributionTestSuite::TvHelperDistributionTestSuite
()
130
:
TestSuite
(
"tv-helper-distribution"
, UNIT)
131
{
132
NS_LOG_INFO
(
"creating TvHelperDistributionTestSuite"
);
133
for
(uint32_t maxNumTransmitters = 3; maxNumTransmitters <= 203; maxNumTransmitters+= 10)
134
{
135
AddTestCase
(
new
TvHelperDistributionTestCase
(maxNumTransmitters),
136
TestCase::QUICK);
137
}
138
}
139
140
static
TvHelperDistributionTestSuite
g_TvHelperDistributionTestSuite
;
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TvHelperDistributionTestCase
Definition:
tv-helper-distribution-test.cc:49
ns3::TvSpectrumTransmitterHelper
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
Definition:
tv-spectrum-transmitter-helper.h:68
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:281
TvHelperDistributionTestCase::TvHelperDistributionTestCase
TvHelperDistributionTestCase(uint32_t maxNumTransmitters)
Definition:
tv-helper-distribution-test.cc:68
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:809
TvHelperDistributionTestCase::Name
static std::string Name(uint32_t maxNumTransmitters)
Definition:
tv-helper-distribution-test.cc:61
TvHelperDistributionTestSuite::TvHelperDistributionTestSuite
TvHelperDistributionTestSuite()
Definition:
tv-helper-distribution-test.cc:129
TvHelperDistributionTestCase::m_maxNumTransmitters
uint32_t m_maxNumTransmitters
Definition:
tv-helper-distribution-test.cc:57
g_TvHelperDistributionTestSuite
static TvHelperDistributionTestSuite g_TvHelperDistributionTestSuite
Definition:
tv-helper-distribution-test.cc:140
TvHelperDistributionTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
tv-helper-distribution-test.cc:79
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
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:995
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:244
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:440
TvHelperDistributionTestCase::~TvHelperDistributionTestCase
virtual ~TvHelperDistributionTestCase()
Definition:
tv-helper-distribution-test.cc:74
TvHelperDistributionTestSuite
Definition:
tv-helper-distribution-test.cc:124
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:166
src
spectrum
test
tv-helper-distribution-test.cc
Generated on Fri Oct 1 2021 17:03:36 for ns-3 by
1.8.20