A Discrete-Event Network Simulator
API
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 
24 NS_LOG_COMPONENT_DEFINE("TvHelperDistributionTest");
25 
26 using namespace ns3;
27 
49 {
50  public:
56  TvHelperDistributionTestCase(uint32_t maxNumTransmitters);
57  ~TvHelperDistributionTestCase() override;
58 
59  private:
60  void DoRun() override;
66  static std::string Name(uint32_t maxNumTransmitters);
68 };
69 
70 std::string
71 TvHelperDistributionTestCase::Name(uint32_t maxNumTransmitters)
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 
88 void
90 {
92  TvSpectrumTransmitterHelper tvTransHelper;
93  uint32_t rand;
94  uint32_t maxLow = 0;
95  uint32_t minMid = m_maxNumTransmitters;
96  uint32_t maxMid = 0;
97  uint32_t minHigh = m_maxNumTransmitters;
98  for (int i = 0; i < 30; i++)
99  {
100  rand = tvTransHelper.GetRandomNumTransmitters(TvSpectrumTransmitterHelper::DENSITY_LOW,
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  {
110  rand = tvTransHelper.GetRandomNumTransmitters(TvSpectrumTransmitterHelper::DENSITY_MEDIUM,
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  {
123  rand = tvTransHelper.GetRandomNumTransmitters(TvSpectrumTransmitterHelper::DENSITY_HIGH,
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 
141 {
142  public:
144 };
145 
147  : TestSuite("tv-helper-distribution", UNIT)
148 {
149  NS_LOG_INFO("creating TvHelperDistributionTestSuite");
150  for (uint32_t maxNumTransmitters = 3; maxNumTransmitters <= 203; maxNumTransmitters += 10)
151  {
152  AddTestCase(new TvHelperDistributionTestCase(maxNumTransmitters), TestCase::QUICK);
153  }
154 }
155 
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:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
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:709
#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:874
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.