A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
histogram-test-suite.cc
Go to the documentation of this file.
1
//
2
// Copyright (c) 2009 INESC Porto
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: Pedro Fortuna <pedro.fortuna@inescporto.pt> <pedro.fortuna@gmail.com>
18
//
19
20
#include "ns3/histogram.h"
21
#include "ns3/test.h"
22
23
using namespace
ns3
;
24
30
class
HistogramTestCase
:
public
ns3::TestCase
31
{
32
private
:
33
public
:
34
HistogramTestCase
();
35
void
DoRun()
override
;
36
};
37
38
HistogramTestCase::HistogramTestCase
()
39
:
ns3
::
TestCase
(
"Histogram"
)
40
{
41
}
42
43
void
44
HistogramTestCase::DoRun
()
45
{
46
Histogram
h0(3.5);
47
// Testing floating-point bin widths
48
{
49
for
(
int
i = 1; i <= 10; i++)
50
{
51
h0.
AddValue
(3.4);
52
}
53
54
for
(
int
i = 1; i <= 5; i++)
55
{
56
h0.
AddValue
(3.6);
57
}
58
59
NS_TEST_EXPECT_MSG_EQ_TOL
(h0.
GetBinWidth
(0), 3.5, 1e-6,
""
);
60
NS_TEST_EXPECT_MSG_EQ
(h0.
GetNBins
(), 2,
""
);
61
NS_TEST_EXPECT_MSG_EQ_TOL
(h0.
GetBinStart
(1), 3.5, 1e-6,
""
);
62
NS_TEST_EXPECT_MSG_EQ
(h0.
GetBinCount
(0), 10,
""
);
63
NS_TEST_EXPECT_MSG_EQ
(h0.
GetBinCount
(1), 5,
""
);
64
}
65
66
{
67
// Testing bin expansion
68
h0.
AddValue
(74.3);
69
NS_TEST_EXPECT_MSG_EQ
(h0.
GetNBins
(), 22,
""
);
70
NS_TEST_EXPECT_MSG_EQ
(h0.
GetBinCount
(21), 1,
""
);
71
}
72
}
73
79
class
HistogramTestSuite
:
public
TestSuite
80
{
81
public
:
82
HistogramTestSuite
();
83
};
84
85
HistogramTestSuite::HistogramTestSuite
()
86
:
TestSuite
(
"histogram"
, UNIT)
87
{
88
AddTestCase
(
new
HistogramTestCase
, TestCase::QUICK);
89
}
90
91
static
HistogramTestSuite
g_HistogramTestSuite
;
HistogramTestCase
Histogram Test.
Definition:
histogram-test-suite.cc:31
HistogramTestCase::HistogramTestCase
HistogramTestCase()
Definition:
histogram-test-suite.cc:38
HistogramTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
histogram-test-suite.cc:44
HistogramTestSuite
Histogram TestSuite.
Definition:
histogram-test-suite.cc:80
HistogramTestSuite::HistogramTestSuite
HistogramTestSuite()
Definition:
histogram-test-suite.cc:85
ns3::Histogram
Class used to store data and make an histogram of the data frequency.
Definition:
histogram.h:46
ns3::Histogram::GetBinWidth
double GetBinWidth(uint32_t index) const
Returns the bin width.
Definition:
histogram.cc:61
ns3::Histogram::GetBinCount
uint32_t GetBinCount(uint32_t index) const
Get the number of data added to the bin.
Definition:
histogram.cc:74
ns3::Histogram::GetNBins
uint32_t GetNBins() const
Returns the number of bins in the histogram.
Definition:
histogram.cc:43
ns3::Histogram::AddValue
void AddValue(double value)
Add a value to the histogram.
Definition:
histogram.cc:81
ns3::Histogram::GetBinStart
double GetBinStart(uint32_t index) const
Returns the bin start, i.e., index*binWidth.
Definition:
histogram.cc:49
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
NS_TEST_EXPECT_MSG_EQ
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition:
test.h:251
NS_TEST_EXPECT_MSG_EQ_TOL
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition:
test.h:510
g_HistogramTestSuite
static HistogramTestSuite g_HistogramTestSuite
Static variable for test initialization.
Definition:
histogram-test-suite.cc:91
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
stats
test
histogram-test-suite.cc
Generated on Sun Mar 3 2024 17:11:08 for ns-3 by
1.9.1