A Discrete-Event Network Simulator
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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
18 */
19
20#include <ns3/log.h>
21#include <ns3/test.h>
22#include <ns3/tv-spectrum-transmitter-helper.h>
23
24NS_LOG_COMPONENT_DEFINE("TvHelperDistributionTest");
25
26using namespace ns3;
27
28/**
29 * \ingroup spectrum-tests
30 *
31 * This test verifies the accuracy of the private GetRandomNumTransmitters()
32 * method in the TvSpectrumTransmitterHelper class. The method generates a
33 * random number corresponding to the number of TV transmitters to create based
34 * on the given location density (low, medium, or high) and maximum possible
35 * number of TV channels. Low density will generate a transmitter for between
36 * one (a single transmitter) and one third of the number of possible channels,
37 * medium density will generate a transmitter for between one third and two
38 * thirds, and high density will generate a transmitter for between two thirds
39 * and all of the possible channels. In this test, it is verified that the
40 * lower (1) and upper (max number of possible channels input) bounds are not
41 * exceeded and that the number of transmitters to be generated does not overlap
42 * between adjacent densities. For example, given 60 possible channels, for low
43 * density between 1 and 20 transmitters can be created, for medium density
44 * between 21 and 40 transmitters can be created, and for high density between
45 * 41 and 60 transmitters can be created (all inclusive). This is tested with
46 * various cases.
47 */
49{
50 public:
51 /**
52 * Constructor
53 *
54 * \param maxNumTransmitters maximum number of transmitters.
55 */
56 TvHelperDistributionTestCase(uint32_t maxNumTransmitters);
58
59 private:
60 void DoRun() override;
61 /**
62 * Build the test name
63 * \param maxNumTransmitters maximum number of transmitters.
64 * \return The test name
65 */
66 static std::string Name(uint32_t maxNumTransmitters);
67 uint32_t m_maxNumTransmitters; //!< Maximum number of transmitters.
68};
69
70std::string
72{
73 std::ostringstream oss;
74 oss << "Max Number of Transmitters = " << maxNumTransmitters;
75 return oss.str();
76}
77
79 : TestCase(Name(maxNumTransmitters)),
80 m_maxNumTransmitters(maxNumTransmitters)
81{
82}
83
85{
86}
87
88void
90{
92 TvSpectrumTransmitterHelper tvTransHelper;
93 uint32_t rand;
94 uint32_t maxLow = 0;
96 uint32_t maxMid = 0;
98 for (int i = 0; i < 30; i++)
99 {
102 NS_TEST_ASSERT_MSG_GT(rand, 0, "lower bound exceeded");
103 if (rand > maxLow)
104 {
105 maxLow = rand;
106 }
107 }
108 for (int i = 0; i < 30; i++)
109 {
112 if (rand < minMid)
113 {
114 minMid = rand;
115 }
116 if (rand > maxMid)
117 {
118 maxMid = rand;
119 }
120 }
121 for (int i = 0; i < 30; i++)
122 {
125 NS_TEST_ASSERT_MSG_LT(rand, m_maxNumTransmitters + 1, "upper bound exceeded");
126 if (rand < minHigh)
127 {
128 minHigh = rand;
129 }
130 }
131 NS_TEST_ASSERT_MSG_LT(maxLow, minMid, "low density overlaps with medium density");
132 NS_TEST_ASSERT_MSG_LT(maxMid, minHigh, "medium density overlaps with high density");
133}
134
135/**
136 * \ingroup spectrum-tests
137 *
138 * Test suite for the TvSpectrumTransmitterHelper class
139 */
141{
142 public:
144};
145
147 : TestSuite("tv-helper-distribution", Type::UNIT)
148{
149 NS_LOG_INFO("creating TvHelperDistributionTestSuite");
150 for (uint32_t maxNumTransmitters = 3; maxNumTransmitters <= 203; maxNumTransmitters += 10)
151 {
152 AddTestCase(new TvHelperDistributionTestCase(maxNumTransmitters),
153 TestCase::Duration::QUICK);
154 }
155}
156
157/// Static variable for test initialization
This test verifies the accuracy of the private GetRandomNumTransmitters() method in the TvSpectrumTra...
void DoRun() override
Implementation to actually run this TestCase.
TvHelperDistributionTestCase(uint32_t maxNumTransmitters)
Constructor.
static std::string Name(uint32_t maxNumTransmitters)
Build the test name.
uint32_t m_maxNumTransmitters
Maximum number of transmitters.
Test suite for the TvSpectrumTransmitterHelper class.
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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:710
#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:875
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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
static TvHelperDistributionTestSuite g_TvHelperDistributionTestSuite
Static variable for test initialization.