testStatHist.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "StatHist.h"
11 #include "testStatHist.h"
12 #include "unitTestMain.h"
13 
15 
16 typedef enum {
18 } number ;
19 
21 {
22 public:
23  bool operator==(const InspectingStatHist &);
24  bins_type counter(double v) {
25  return bins[findBin(v)];
26  }
27 };
28 
29 bool
31 {
32  assert(bins != NULL && src.bins != NULL); // TODO: remove after initializing bins at construction time
33  if (capacity_ != src.capacity_ ||
34  min_!=src.min_ ||
35  max_!=src.max_ ||
36  scale_!=src.scale_ ||
37  val_in!=src.val_in ||
38  val_out!=src.val_out)
39  return false;
40  return (memcmp(bins,src.bins,capacity_*sizeof(*bins))==0);
41 }
42 
43 void
45 {
46  InspectingStatHist raw, test;
47  raw.enumInit(FIVE);
48  test.enumInit(FIVE);
49  CPPUNIT_ASSERT(raw==test);
50  test.count(ZERO);
51  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test));
52 }
53 
54 void
56 {
57  InspectingStatHist raw, test;
58  raw.enumInit(FIVE);
59  test.enumInit(FIVE);
60  test.count(ZERO);
61  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test));
62  test=raw;
63  CPPUNIT_ASSERT(raw==test);
64 }
65 
66 void
68 {
69  const double min=0.0, max=10000.0;
70  const int capacity=10;
71  InspectingStatHist raw, test;
72  raw.logInit(capacity,min,max);
73  test=raw;
74  CPPUNIT_ASSERT(test.counter(min)==0);
75  test.count(min);
76  CPPUNIT_ASSERT(test.counter(min)==1);
77  CPPUNIT_ASSERT(test.counter(max)==0);
78  test.count(max);
79  CPPUNIT_ASSERT(test.counter(max)==1);
80  test=raw;
81  test.count(max);
82  //CPPUNIT_ASSERT(test.val(capacity-1)==1); //FIXME: val() returns a density
83 }
84 
85 void
87 {
89  s1.logInit(30,1.0,100.0);
90  s2.logInit(30,1.0,100.0);
91  s1.count(3);
92  s2.count(30);
93  InspectingStatHist ts1, ts2;
94  ts1=s1;
95  ts1+=s2;
96  ts2=s2;
97  ts2+=s1;
98  CPPUNIT_ASSERT(ts1 == ts2);
100  ts3.logInit(30,1.0,100.0);
101  ts3.count(3);
102  ts3.count(30);
103  CPPUNIT_ASSERT(ts3 == ts1);
104 
105 }
106 
void count(double val)
Definition: StatHist.cc:57
#define assert(EX)
Definition: assert.h:17
bins_type counter(double v)
Definition: testStatHist.cc:24
unsigned int capacity_
Definition: StatHist.h:106
Definition: cf_gen.cc:55
A const & max(A const &lhs, A const &rhs)
void logInit(unsigned int capacity, double min, double max)
Definition: StatHist.cc:223
hbase_f * val_in
Definition: StatHist.h:116
bins_type * bins
the histogram counters
Definition: StatHist.h:105
void testStatHistLog()
Definition: testStatHist.cc:67
uint64_t bins_type
Definition: StatHist.h:39
double scale_
scaling factor when looking for a bin
Definition: StatHist.h:115
void testStatHistBaseAssignment()
Definition: testStatHist.cc:55
unsigned int findBin(double v)
Definition: StatHist.cc:66
double max_
value of the maximum counter in the histogram
Definition: StatHist.h:112
CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist)
number
Definition: testStatHist.cc:16
bool operator==(const InspectingStatHist &)
Definition: testStatHist.cc:30
void testStatHistBaseEquality()
Definition: testStatHist.cc:44
hbase_f * val_out
Definition: StatHist.h:117
double min_
minimum value to be stored, corresponding to the first bin
Definition: StatHist.h:109
#define NULL
Definition: types.h:166
A const & min(A const &lhs, A const &rhs)
void testStatHistSum()
Definition: testStatHist.cc:86
void enumInit(unsigned int last_enum)
Definition: StatHist.cc:237

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors