A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-spectrum-value-helper-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
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: Tom Henderson <thomas.r.henderson@boeing.com>
18 */
19#include <ns3/log.h>
20#include <ns3/lr-wpan-spectrum-value-helper.h>
21#include <ns3/spectrum-value.h>
22#include <ns3/test.h>
23
24#include <cmath>
25
26using namespace ns3;
27using namespace ns3::lrwpan;
28
29/**
30 * \ingroup lr-wpan-test
31 * \ingroup tests
32 *
33 * \brief LrWpan SpectrumValue Helper TestSuite
34 */
36{
37 public:
40
41 private:
42 void DoRun() override;
43};
44
46 : TestCase("Test the 802.15.4 SpectrumValue helper class")
47{
48}
49
51{
52}
53
54void
56{
59 double pwrWatts;
60 for (uint32_t chan = 11; chan <= 26; chan++)
61 {
62 // 50dBm = 100 W, -50dBm = 0.01 mW
63 for (double pwrdBm = -50; pwrdBm < 50; pwrdBm += 10)
64 {
65 value = helper.CreateTxPowerSpectralDensity(pwrdBm, chan);
66 pwrWatts = pow(10.0, pwrdBm / 10.0) / 1000;
67 // Test that average power calculation is within +/- 25% of expected
68 NS_TEST_ASSERT_MSG_EQ_TOL(helper.TotalAvgPower(value, chan),
69 pwrWatts,
70 pwrWatts / 4.0,
71 "Not equal for channel " << chan << " pwrdBm " << pwrdBm);
72 }
73 }
74}
75
76/**
77 * \ingroup lr-wpan-test
78 * \ingroup tests
79 *
80 * \brief LrWpan SpectrumValue Helper TestSuite
81 */
83{
84 public:
86};
87
89 : TestSuite("lr-wpan-spectrum-value-helper", Type::UNIT)
90{
91 AddTestCase(new LrWpanSpectrumValueHelperTestCase, TestCase::Duration::QUICK);
92}
93
95 g_lrWpanSpectrumValueHelperTestSuite; //!< Static variable for test initialization
LrWpan SpectrumValue Helper TestSuite.
void DoRun() override
Implementation to actually run this TestCase.
LrWpan SpectrumValue Helper TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
This class defines all functions to create spectrum model for LrWpan.
static double TotalAvgPower(Ptr< const SpectrumValue > psd, uint32_t channel)
total average power of the signal is the integral of the PSD using the limits of the given channel
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:338
static LrWpanSpectrumValueHelperTestSuite g_lrWpanSpectrumValueHelperTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.