]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testStatHist.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
11 #include "testStatHist.h"
13 CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist
);
16 ZERO
, ONE
, TWO
, THREE
, FOUR
, FIVE
19 class InspectingStatHist
: public StatHist
22 bool operator==(const InspectingStatHist
&);
23 bins_type
counter(double v
) {
24 return bins
[findBin(v
)];
29 InspectingStatHist::operator ==(const InspectingStatHist
& src
)
31 assert(bins
!= NULL
&& src
.bins
!= NULL
); // TODO: remove after initializing bins at construction time
32 if (capacity_
!= src
.capacity_
||
39 return (memcmp(bins
,src
.bins
,capacity_
*sizeof(*bins
))==0);
43 testStatHist::testStatHistBaseEquality()
45 InspectingStatHist raw
, test
;
48 CPPUNIT_ASSERT(raw
==test
);
50 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw
==test
));
54 testStatHist::testStatHistBaseAssignment()
56 InspectingStatHist raw
, test
;
60 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw
==test
));
62 CPPUNIT_ASSERT(raw
==test
);
66 testStatHist::testStatHistLog()
68 const double min
=0.0, max
=10000.0;
69 const int capacity
=10;
70 InspectingStatHist raw
, test
;
71 raw
.logInit(capacity
,min
,max
);
73 CPPUNIT_ASSERT(test
.counter(min
)==0);
75 CPPUNIT_ASSERT(test
.counter(min
)==1);
76 CPPUNIT_ASSERT(test
.counter(max
)==0);
78 CPPUNIT_ASSERT(test
.counter(max
)==1);
81 //CPPUNIT_ASSERT(test.val(capacity-1)==1); //FIXME: val() returns a density
85 testStatHist::testStatHistSum()
87 InspectingStatHist s1
, s2
;
88 s1
.logInit(30,1.0,100.0);
89 s2
.logInit(30,1.0,100.0);
92 InspectingStatHist ts1
, ts2
;
97 CPPUNIT_ASSERT(ts1
== ts2
);
98 InspectingStatHist ts3
;
99 ts3
.logInit(30,1.0,100.0);
102 CPPUNIT_ASSERT(ts3
== ts1
);