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 #define private public //to make private method testable
22 
23 #include <ns3/test.h>
24 #include <ns3/log.h>
25 #include <ns3/tv-spectrum-transmitter-helper.h>
26 
45 NS_LOG_COMPONENT_DEFINE ("TvHelperDistributionTest");
46 
47 using namespace ns3;
48 
49 
51 {
52 public:
53  TvHelperDistributionTestCase (uint32_t maxNumTransmitters);
54  virtual ~TvHelperDistributionTestCase ();
55 
56 private:
57  virtual void DoRun (void);
58  static std::string Name (uint32_t maxNumTransmitters);
60 };
61 
62 std::string
63 TvHelperDistributionTestCase::Name (uint32_t maxNumTransmitters)
64 {
65  std::ostringstream oss;
66  oss << "Max Number of Transmitters = " << maxNumTransmitters;
67  return oss.str();
68 }
69 
71  : TestCase (Name (maxNumTransmitters)),
72  m_maxNumTransmitters (maxNumTransmitters)
73 {
74 }
75 
77 {
78 }
79 
80 void
82 {
84  TvSpectrumTransmitterHelper tvTransHelper;
85  uint32_t rand;
86  uint32_t maxLow = 0;
87  uint32_t minMid = m_maxNumTransmitters;
88  uint32_t maxMid = 0;
89  uint32_t minHigh = m_maxNumTransmitters;
90  for (int i = 0; i < 30; i ++)
91  {
92  rand = tvTransHelper.GetRandomNumTransmitters (TvSpectrumTransmitterHelper::DENSITY_LOW, m_maxNumTransmitters);
93  NS_TEST_ASSERT_MSG_GT (rand, 0, "lower bound exceeded");
94  if (rand > maxLow)
95  {
96  maxLow = rand;
97  }
98  }
99  for (int i = 0; i < 30; i ++)
100  {
101  rand = tvTransHelper.GetRandomNumTransmitters (TvSpectrumTransmitterHelper::DENSITY_MEDIUM, m_maxNumTransmitters);
102  if (rand < minMid)
103  {
104  minMid = rand;
105  }
106  if (rand > maxMid)
107  {
108  maxMid = rand;
109  }
110  }
111  for (int i = 0; i < 30; i ++)
112  {
113  rand = tvTransHelper.GetRandomNumTransmitters (TvSpectrumTransmitterHelper::DENSITY_HIGH, m_maxNumTransmitters);
114  NS_TEST_ASSERT_MSG_LT (rand, m_maxNumTransmitters + 1, "upper bound exceeded");
115  if (rand < minHigh)
116  {
117  minHigh = rand;
118  }
119  }
120  NS_TEST_ASSERT_MSG_LT (maxLow, minMid, "low density overlaps with medium density");
121  NS_TEST_ASSERT_MSG_LT (maxMid, minHigh, "medium density overlaps with high density");
122 }
123 
124 
126 {
127 public:
129 };
130 
132  : TestSuite ("tv-helper-distribution", UNIT)
133 {
134  NS_LOG_INFO ("creating TvHelperDistributionTestSuite");
135  for (uint32_t maxNumTransmitters = 3; maxNumTransmitters <= 203; maxNumTransmitters+= 10)
136  {
137  AddTestCase (new TvHelperDistributionTestCase (maxNumTransmitters),
138  TestCase::QUICK);
139  }
140 }
141 
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
A suite of tests to run.
Definition: test.h:1276
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
encapsulates test code
Definition: test.h:1108
TvHelperDistributionTestCase(uint32_t maxNumTransmitters)
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:97
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:190
static std::string Name(uint32_t maxNumTransmitters)
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
static TvHelperDistributionTestSuite g_TvHelperDistributionTestSuite
#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:960
#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:778