A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
lr-wpan
test
lr-wpan-spectrum-value-helper-test.cc
Go to the documentation of this file.
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 The Boeing Company
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: Tom Henderson <thomas.r.henderson@boeing.com>
19
*/
20
#include <ns3/log.h>
21
#include <ns3/test.h>
22
#include <ns3/lr-wpan-spectrum-value-helper.h>
23
#include <ns3/spectrum-value.h>
24
25
#include <cmath>
26
27
using namespace
ns3
;
28
35
class
LrWpanSpectrumValueHelperTestCase
:
public
TestCase
36
{
37
public
:
38
LrWpanSpectrumValueHelperTestCase
();
39
virtual
~
LrWpanSpectrumValueHelperTestCase
();
40
41
private
:
42
virtual
void
DoRun (
void
);
43
};
44
45
LrWpanSpectrumValueHelperTestCase::LrWpanSpectrumValueHelperTestCase
()
46
:
TestCase
(
"Test the 802.15.4 SpectrumValue helper class"
)
47
{
48
}
49
50
LrWpanSpectrumValueHelperTestCase::~LrWpanSpectrumValueHelperTestCase
()
51
{
52
}
53
54
void
55
LrWpanSpectrumValueHelperTestCase::DoRun
(
void
)
56
{
57
LrWpanSpectrumValueHelper
helper;
58
Ptr<SpectrumValue>
value;
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), pwrWatts, pwrWatts / 4.0,
"Not equal for channel "
<< chan <<
" pwrdBm "
<< pwrdBm);
69
}
70
}
71
}
72
79
class
LrWpanSpectrumValueHelperTestSuite
:
public
TestSuite
80
{
81
public
:
82
LrWpanSpectrumValueHelperTestSuite
();
83
};
84
85
LrWpanSpectrumValueHelperTestSuite::LrWpanSpectrumValueHelperTestSuite
()
86
:
TestSuite
(
"lr-wpan-spectrum-value-helper"
, UNIT)
87
{
88
AddTestCase
(
new
LrWpanSpectrumValueHelperTestCase
, TestCase::QUICK);
89
}
90
91
static
LrWpanSpectrumValueHelperTestSuite
g_lrWpanSpectrumValueHelperTestSuite
;
LrWpanSpectrumValueHelperTestSuite::LrWpanSpectrumValueHelperTestSuite
LrWpanSpectrumValueHelperTestSuite()
Definition:
lr-wpan-spectrum-value-helper-test.cc:85
ns3::Ptr< SpectrumValue >
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1342
LrWpanSpectrumValueHelperTestCase
LrWpan SpectrumValue Helper TestSuite.
Definition:
lr-wpan-spectrum-value-helper-test.cc:35
ns3::TestCase
encapsulates test code
Definition:
test.h:1155
g_lrWpanSpectrumValueHelperTestSuite
static LrWpanSpectrumValueHelperTestSuite g_lrWpanSpectrumValueHelperTestSuite
Static variable for test initialization.
Definition:
lr-wpan-spectrum-value-helper-test.cc:91
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::LrWpanSpectrumValueHelper
This class defines all functions to create spectrum model for LrWpan.
Definition:
lr-wpan-spectrum-value-helper.h:34
LrWpanSpectrumValueHelperTestSuite
LrWpan SpectrumValue Helper TestSuite.
Definition:
lr-wpan-spectrum-value-helper-test.cc:79
NS_TEST_ASSERT_MSG_EQ_TOL
#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:380
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LrWpanSpectrumValueHelperTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
lr-wpan-spectrum-value-helper-test.cc:55
LrWpanSpectrumValueHelperTestCase::LrWpanSpectrumValueHelperTestCase
LrWpanSpectrumValueHelperTestCase()
Definition:
lr-wpan-spectrum-value-helper-test.cc:45
ns3::LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
Definition:
lr-wpan-spectrum-value-helper.cc:71
ns3::LrWpanSpectrumValueHelper::TotalAvgPower
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 ...
Definition:
lr-wpan-spectrum-value-helper.cc:127
LrWpanSpectrumValueHelperTestCase::~LrWpanSpectrumValueHelperTestCase
virtual ~LrWpanSpectrumValueHelperTestCase()
Definition:
lr-wpan-spectrum-value-helper-test.cc:50
Generated on Wed Nov 7 2018 10:01:58 for ns-3 by
1.8.14