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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tom Henderson <thomas.r.henderson@boeing.com>
7 */
8#include <ns3/log.h>
9#include <ns3/lr-wpan-spectrum-value-helper.h>
10#include <ns3/spectrum-value.h>
11#include <ns3/test.h>
12
13#include <cmath>
14
15using namespace ns3;
16using namespace ns3::lrwpan;
17
18/**
19 * @ingroup lr-wpan-test
20 * @ingroup tests
21 *
22 * @brief LrWpan SpectrumValue Helper TestSuite
23 */
25{
26 public:
29
30 private:
31 void DoRun() override;
32};
33
35 : TestCase("Test the 802.15.4 SpectrumValue helper class")
36{
37}
38
42
43void
45{
48 double pwrWatts;
49 for (uint32_t chan = 11; chan <= 26; chan++)
50 {
51 // 50dBm = 100 W, -50dBm = 0.01 mW
52 for (double pwrdBm = -50; pwrdBm < 50; pwrdBm += 10)
53 {
54 value = helper.CreateTxPowerSpectralDensity(pwrdBm, chan);
55 pwrWatts = pow(10.0, pwrdBm / 10.0) / 1000;
56 // Test that average power calculation is within +/- 25% of expected
57 NS_TEST_ASSERT_MSG_EQ_TOL(helper.TotalAvgPower(value, chan),
58 pwrWatts,
59 pwrWatts / 4.0,
60 "Not equal for channel " << chan << " pwrdBm " << pwrdBm);
61 }
62 }
63}
64
65/**
66 * @ingroup lr-wpan-test
67 * @ingroup tests
68 *
69 * @brief LrWpan SpectrumValue Helper TestSuite
70 */
76
78 : TestSuite("lr-wpan-spectrum-value-helper", Type::UNIT)
79{
80 AddTestCase(new LrWpanSpectrumValueHelperTestCase, TestCase::Duration::QUICK);
81}
82
84 g_lrWpanSpectrumValueHelperTestSuite; //!< Static variable for test initialization
LrWpan SpectrumValue Helper TestSuite.
void DoRun() override
Implementation to actually run this TestCase.
Smart pointer class similar to boost::intrusive_ptr.
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
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:327
static LrWpanSpectrumValueHelperTestSuite g_lrWpanSpectrumValueHelperTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.