A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
histogram-test-suite.cc
Go to the documentation of this file.
1
//
2
// Copyright (c) 2009 INESC Porto
3
//
4
// SPDX-License-Identifier: GPL-2.0-only
5
//
6
// Author: Pedro Fortuna <pedro.fortuna@inescporto.pt> <pedro.fortuna@gmail.com>
7
//
8
9
#include "ns3/histogram.h"
10
#include "ns3/test.h"
11
12
using namespace
ns3
;
13
14
/**
15
* \ingroup stats-tests
16
*
17
* \brief Histogram Test
18
*/
19
class
HistogramTestCase
:
public
ns3::TestCase
20
{
21
private
:
22
public
:
23
HistogramTestCase
();
24
void
DoRun
()
override
;
25
};
26
27
HistogramTestCase::HistogramTestCase
()
28
:
ns3
::
TestCase
(
"Histogram"
)
29
{
30
}
31
32
void
33
HistogramTestCase::DoRun
()
34
{
35
Histogram
h0(3.5);
36
// Testing floating-point bin widths
37
{
38
for
(
int
i = 1; i <= 10; i++)
39
{
40
h0.
AddValue
(3.4);
41
}
42
43
for
(
int
i = 1; i <= 5; i++)
44
{
45
h0.
AddValue
(3.6);
46
}
47
48
NS_TEST_EXPECT_MSG_EQ_TOL
(h0.
GetBinWidth
(0), 3.5, 1e-6,
""
);
49
NS_TEST_EXPECT_MSG_EQ
(h0.
GetNBins
(), 2,
""
);
50
NS_TEST_EXPECT_MSG_EQ_TOL
(h0.
GetBinStart
(1), 3.5, 1e-6,
""
);
51
NS_TEST_EXPECT_MSG_EQ
(h0.
GetBinCount
(0), 10,
""
);
52
NS_TEST_EXPECT_MSG_EQ
(h0.
GetBinCount
(1), 5,
""
);
53
}
54
55
{
56
// Testing bin expansion
57
h0.
AddValue
(74.3);
58
NS_TEST_EXPECT_MSG_EQ
(h0.
GetNBins
(), 22,
""
);
59
NS_TEST_EXPECT_MSG_EQ
(h0.
GetBinCount
(21), 1,
""
);
60
}
61
}
62
63
/**
64
* \ingroup stats-tests
65
*
66
* \brief Histogram TestSuite
67
*/
68
class
HistogramTestSuite
:
public
TestSuite
69
{
70
public
:
71
HistogramTestSuite
();
72
};
73
74
HistogramTestSuite::HistogramTestSuite
()
75
:
TestSuite
(
"histogram"
,
Type
::UNIT)
76
{
77
AddTestCase
(
new
HistogramTestCase
, TestCase::Duration::QUICK);
78
}
79
80
static
HistogramTestSuite
g_HistogramTestSuite
;
//!< Static variable for test initialization
HistogramTestCase
Histogram Test.
Definition
histogram-test-suite.cc:20
HistogramTestCase::HistogramTestCase
HistogramTestCase()
Definition
histogram-test-suite.cc:27
HistogramTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
histogram-test-suite.cc:33
HistogramTestSuite
Histogram TestSuite.
Definition
histogram-test-suite.cc:69
HistogramTestSuite::HistogramTestSuite
HistogramTestSuite()
Definition
histogram-test-suite.cc:74
ns3::Histogram
Class used to store data and make an histogram of the data frequency.
Definition
histogram.h:35
ns3::Histogram::GetBinWidth
double GetBinWidth(uint32_t index) const
Returns the bin width.
Definition
histogram.cc:50
ns3::Histogram::GetBinCount
uint32_t GetBinCount(uint32_t index) const
Get the number of data added to the bin.
Definition
histogram.cc:63
ns3::Histogram::GetNBins
uint32_t GetNBins() const
Returns the number of bins in the histogram.
Definition
histogram.cc:32
ns3::Histogram::AddValue
void AddValue(double value)
Add a value to the histogram.
Definition
histogram.cc:70
ns3::Histogram::GetBinStart
double GetBinStart(uint32_t index) const
Returns the bin start, i.e., index*binWidth.
Definition
histogram.cc:38
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
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:241
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:500
g_HistogramTestSuite
static HistogramTestSuite g_HistogramTestSuite
Static variable for test initialization.
Definition
histogram-test-suite.cc:80
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
stats
test
histogram-test-suite.cc
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0