src/flow-monitor/test/histogram-test-suite.cc
author Tom Henderson <tomh@tomh.org>
Mon, 28 Sep 2015 20:27:25 -0700
changeset 11676 05ea1489e509
parent 10553 8c347165bb56
permissions -rw-r--r--
bug 2184: Integer overflow in MacLow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     2
//
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     3
// Copyright (c) 2009 INESC Porto
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     4
//
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     7
// published by the Free Software Foundation;
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     8
//
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    12
// GNU General Public License for more details.
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    13
//
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    17
//
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    18
// Author: Pedro Fortuna  <pedro.fortuna@inescporto.pt> <pedro.fortuna@gmail.com>
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    19
//
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    20
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    21
#include "ns3/histogram.h"
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    22
#include "ns3/test.h"
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    23
10553
8c347165bb56 Move tests outside ns3 namespace
Vedran Miletić <rivanvx@gmail.com>
parents: 9266
diff changeset
    24
using namespace ns3;
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    25
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    26
class HistogramTestCase : public ns3::TestCase {
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    27
private:
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    28
public:
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    29
  HistogramTestCase ();
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    30
  virtual void DoRun (void);
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    31
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    32
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    33
};
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    34
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    35
HistogramTestCase::HistogramTestCase ()
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    36
  : ns3::TestCase ("Histogram")
7175
8fffa1497fba flow-monitor coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6952
diff changeset
    37
{
8fffa1497fba flow-monitor coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6952
diff changeset
    38
}
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    39
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    40
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    41
void
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    42
HistogramTestCase::DoRun (void)
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    43
{
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7175
diff changeset
    44
  Histogram h0 (3.5);
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    45
  // Testing floating-point bin widths
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    46
  {
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    47
    for (int i=1; i <= 10; i++)
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    48
      { 
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    49
        h0.AddValue (3.4);
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    50
      }
7175
8fffa1497fba flow-monitor coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6952
diff changeset
    51
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    52
    for (int i=1; i <= 5; i++)
7175
8fffa1497fba flow-monitor coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6952
diff changeset
    53
      {
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    54
        h0.AddValue (3.6);
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    55
      }
7175
8fffa1497fba flow-monitor coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6952
diff changeset
    56
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    57
    NS_TEST_EXPECT_MSG_EQ_TOL (h0.GetBinWidth (0),  3.5, 1e-6, "");
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    58
    NS_TEST_EXPECT_MSG_EQ (h0.GetNBins (),  2, "");
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    59
    NS_TEST_EXPECT_MSG_EQ_TOL (h0.GetBinStart (1),  3.5, 1e-6, "");
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    60
    NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (0),  10, "");
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    61
    NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (1),  5, "");
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    62
  }
7175
8fffa1497fba flow-monitor coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6952
diff changeset
    63
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    64
  {
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    65
    // Testing bin expansion
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    66
    h0.AddValue (74.3);
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    67
    NS_TEST_EXPECT_MSG_EQ (h0.GetNBins (), 22, "");
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    68
    NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (21), 1, "");
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    69
  }
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    70
}
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    71
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    72
static class HistogramTestSuite : public TestSuite
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    73
{
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    74
public:
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    75
  HistogramTestSuite ()
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    76
    : TestSuite ("histogram", UNIT) 
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    77
  {
9266
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 7256
diff changeset
    78
    AddTestCase (new HistogramTestCase (), TestCase::QUICK);
6952
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    79
  }
91a77c7f3bb2 Move tests from some modules to their test libraries
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    80
} g_HistogramTestSuite;