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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
7 */
8
9#include <ns3/log.h>
10#include <ns3/test.h>
11#include <ns3/tv-spectrum-transmitter-helper.h>
12
13NS_LOG_COMPONENT_DEFINE("TvHelperDistributionTest");
14
15using namespace ns3;
16
17/**
18 * \ingroup spectrum-tests
19 *
20 * This test verifies the accuracy of the private GetRandomNumTransmitters()
21 * method in the TvSpectrumTransmitterHelper class. The method generates a
22 * random number corresponding to the number of TV transmitters to create based
23 * on the given location density (low, medium, or high) and maximum possible
24 * number of TV channels. Low density will generate a transmitter for between
25 * one (a single transmitter) and one third of the number of possible channels,
26 * medium density will generate a transmitter for between one third and two
27 * thirds, and high density will generate a transmitter for between two thirds
28 * and all of the possible channels. In this test, it is verified that the
29 * lower (1) and upper (max number of possible channels input) bounds are not
30 * exceeded and that the number of transmitters to be generated does not overlap
31 * between adjacent densities. For example, given 60 possible channels, for low
32 * density between 1 and 20 transmitters can be created, for medium density
33 * between 21 and 40 transmitters can be created, and for high density between
34 * 41 and 60 transmitters can be created (all inclusive). This is tested with
35 * various cases.
36 */
38{
39 public:
40 /**
41 * Constructor
42 *
43 * \param maxNumTransmitters maximum number of transmitters.
44 */
45 TvHelperDistributionTestCase(uint32_t maxNumTransmitters);
47
48 private:
49 void DoRun() override;
50 /**
51 * Build the test name
52 * \param maxNumTransmitters maximum number of transmitters.
53 * \return The test name
54 */
55 static std::string Name(uint32_t maxNumTransmitters);
56 uint32_t m_maxNumTransmitters; //!< Maximum number of transmitters.
57};
58
59std::string
61{
62 std::ostringstream oss;
63 oss << "Max Number of Transmitters = " << maxNumTransmitters;
64 return oss.str();
65}
66
68 : TestCase(Name(maxNumTransmitters)),
69 m_maxNumTransmitters(maxNumTransmitters)
70{
71}
72
76
77void
79{
81 TvSpectrumTransmitterHelper tvTransHelper;
82 uint32_t rand;
83 uint32_t maxLow = 0;
85 uint32_t maxMid = 0;
87 for (int i = 0; i < 30; i++)
88 {
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 {
101 if (rand < minMid)
102 {
103 minMid = rand;
104 }
105 if (rand > maxMid)
106 {
107 maxMid = rand;
108 }
109 }
110 for (int i = 0; i < 30; i++)
111 {
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/**
125 * \ingroup spectrum-tests
126 *
127 * Test suite for the TvSpectrumTransmitterHelper class
128 */
130{
131 public:
133};
134
136 : TestSuite("tv-helper-distribution", Type::UNIT)
137{
138 NS_LOG_INFO("creating TvHelperDistributionTestSuite");
139 for (uint32_t maxNumTransmitters = 3; maxNumTransmitters <= 203; maxNumTransmitters += 10)
140 {
141 AddTestCase(new TvHelperDistributionTestCase(maxNumTransmitters),
142 TestCase::Duration::QUICK);
143 }
144}
145
146/// 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:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
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:191
#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:264
#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:699
#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:864
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:155
static TvHelperDistributionTestSuite g_TvHelperDistributionTestSuite
Static variable for test initialization.