A Discrete-Event Network Simulator
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
12using namespace ns3;
13
14/**
15 * @ingroup stats-tests
16 *
17 * @brief Histogram Test
18 */
20{
21 private:
22 public:
24 void DoRun() override;
25};
26
31
32void
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, "");
50 NS_TEST_EXPECT_MSG_EQ_TOL(h0.GetBinStart(1), 3.5, 1e-6, "");
53 }
54
55 {
56 // Testing bin expansion
57 h0.AddValue(74.3);
58 NS_TEST_EXPECT_MSG_EQ(h0.GetNBins(), 22, "");
60 }
61}
62
63/**
64 * @ingroup stats-tests
65 *
66 * @brief Histogram TestSuite
67 */
69{
70 public:
72};
73
75 : TestSuite("histogram", Type::UNIT)
76{
77 AddTestCase(new HistogramTestCase, TestCase::Duration::QUICK);
78}
79
80static HistogramTestSuite g_HistogramTestSuite; //!< Static variable for test initialization
void DoRun() override
Implementation to actually run this TestCase.
Histogram TestSuite.
Class used to store data and make an histogram of the data frequency.
Definition histogram.h:35
double GetBinWidth(uint32_t index) const
Returns the bin width.
Definition histogram.cc:50
uint32_t GetBinCount(uint32_t index) const
Get the number of data added to the bin.
Definition histogram.cc:63
uint32_t GetNBins() const
Returns the number of bins in the histogram.
Definition histogram.cc:32
void AddValue(double value)
Add a value to the histogram.
Definition histogram.cc:70
double GetBinStart(uint32_t index) const
Returns the bin start, i.e., index*binWidth.
Definition histogram.cc:38
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
#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
#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
static HistogramTestSuite g_HistogramTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.