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 
43 NS_LOG_COMPONENT_DEFINE ("TvHelperDistributionTest");
44 
45 using namespace ns3;
46 
47 
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);
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 
69  : TestCase (Name (maxNumTransmitters)),
70  m_maxNumTransmitters (maxNumTransmitters)
71 {
72 }
73 
75 {
76 }
77 
78 void
80 {
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 
124 {
125 public:
127 };
128 
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 
virtual void DoRun(void)
Implementation to actually run this TestCase.
TvHelperDistributionTestCase(uint32_t maxNumTransmitters)
static std::string Name(uint32_t maxNumTransmitters)
encapsulates test code
Definition: test.h:1154
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:1344
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:809
#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
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