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