testStatHist.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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
16typedef enum {
19
21{
22public:
23 bool operator==(const InspectingStatHist &);
24 bins_type counter(double v) {
25 return bins[findBin(v)];
26 }
27};
28
29bool
31{
32 assert(bins != nullptr && src.bins != nullptr); // 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
43void
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
54void
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
66void
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); // XXX: val() returns a density
83}
84
85void
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
#define assert(EX)
Definition: assert.h:19
@ s1
Definition: cf_gen.cc:55
bool operator==(const InspectingStatHist &)
Definition: testStatHist.cc:30
bins_type counter(double v)
Definition: testStatHist.cc:24
uint64_t bins_type
Definition: StatHist.h:44
hbase_f * val_in
Definition: StatHist.h:112
double max_
value of the maximum counter in the histogram
Definition: StatHist.h:108
double scale_
scaling factor when looking for a bin
Definition: StatHist.h:111
void logInit(unsigned int capacity, double min, double max)
Definition: StatHist.cc:221
unsigned int capacity_
Definition: StatHist.h:102
unsigned int findBin(double v)
Definition: StatHist.cc:64
bins_type * bins
the histogram counters
Definition: StatHist.h:101
void enumInit(unsigned int last_enum)
Definition: StatHist.cc:235
void count(double val)
Definition: StatHist.cc:55
double min_
minimum value to be stored, corresponding to the first bin
Definition: StatHist.h:105
hbase_f * val_out
Definition: StatHist.h:113
void testStatHistLog()
Definition: testStatHist.cc:67
void testStatHistBaseAssignment()
Definition: testStatHist.cc:55
void testStatHistBaseEquality()
Definition: testStatHist.cc:44
void testStatHistSum()
Definition: testStatHist.cc:86
A const & max(A const &lhs, A const &rhs)
A const & min(A const &lhs, A const &rhs)
CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist)
number
Definition: testStatHist.cc:16
@ TWO
Definition: testStatHist.cc:17
@ THREE
Definition: testStatHist.cc:17
@ FOUR
Definition: testStatHist.cc:17
@ FIVE
Definition: testStatHist.cc:17
@ ONE
Definition: testStatHist.cc:17
@ ZERO
Definition: testStatHist.cc:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors