A Discrete-Event Network Simulator
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 
25 NS_LOG_COMPONENT_DEFINE ("TvHelperDistributionTest");
26 
27 using namespace ns3;
28 
50 {
51 public:
57  TvHelperDistributionTestCase (uint32_t maxNumTransmitters);
58  virtual ~TvHelperDistributionTestCase ();
59 
60 private:
61  virtual void DoRun (void);
67  static std::string Name (uint32_t maxNumTransmitters);
69 };
70 
71 std::string
72 TvHelperDistributionTestCase::Name (uint32_t maxNumTransmitters)
73 {
74  std::ostringstream oss;
75  oss << "Max Number of Transmitters = " << maxNumTransmitters;
76  return oss.str();
77 }
78 
80  : TestCase (Name (maxNumTransmitters)),
81  m_maxNumTransmitters (maxNumTransmitters)
82 {
83 }
84 
86 {
87 }
88 
89 void
91 {
93  TvSpectrumTransmitterHelper tvTransHelper;
94  uint32_t rand;
95  uint32_t maxLow = 0;
96  uint32_t minMid = m_maxNumTransmitters;
97  uint32_t maxMid = 0;
98  uint32_t minHigh = m_maxNumTransmitters;
99  for (int i = 0; i < 30; i ++)
100  {
101  rand = tvTransHelper.GetRandomNumTransmitters (TvSpectrumTransmitterHelper::DENSITY_LOW, m_maxNumTransmitters);
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, m_maxNumTransmitters);
111  if (rand < minMid)
112  {
113  minMid = rand;
114  }
115  if (rand > maxMid)
116  {
117  maxMid = rand;
118  }
119  }
120  for (int i = 0; i < 30; i ++)
121  {
122  rand = tvTransHelper.GetRandomNumTransmitters (TvSpectrumTransmitterHelper::DENSITY_HIGH, m_maxNumTransmitters);
123  NS_TEST_ASSERT_MSG_LT (rand, m_maxNumTransmitters + 1, "upper bound exceeded");
124  if (rand < minHigh)
125  {
126  minHigh = rand;
127  }
128  }
129  NS_TEST_ASSERT_MSG_LT (maxLow, minMid, "low density overlaps with medium density");
130  NS_TEST_ASSERT_MSG_LT (maxMid, minHigh, "medium density overlaps with high density");
131 }
132 
133 
140 {
141 public:
143 };
144 
146  : TestSuite ("tv-helper-distribution", UNIT)
147 {
148  NS_LOG_INFO ("creating TvHelperDistributionTestSuite");
149  for (uint32_t maxNumTransmitters = 3; maxNumTransmitters <= 203; maxNumTransmitters+= 10)
150  {
151  AddTestCase (new TvHelperDistributionTestCase (maxNumTransmitters),
152  TestCase::QUICK);
153  }
154 }
155 
This test verifies the accuracy of the private GetRandomNumTransmitters() method in the TvSpectrumT...
virtual void DoRun(void)
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:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
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:205
#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:281
#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:675
#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:825
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.