]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testStatHist.cc
2 * Copyright (C) 1996-2023 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"
12 #include "unitTestMain.h"
14 CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist
);
17 ZERO
, ONE
, TWO
, THREE
, FOUR
, FIVE
20 class InspectingStatHist
: public StatHist
23 bool operator==(const InspectingStatHist
&);
24 bins_type
counter(double v
) {
25 return bins
[findBin(v
)];
30 InspectingStatHist::operator ==(const InspectingStatHist
& src
)
32 assert(bins
!= nullptr && src
.bins
!= nullptr); // TODO: remove after initializing bins at construction time
33 if (capacity_
!= src
.capacity_
||
40 return (memcmp(bins
,src
.bins
,capacity_
*sizeof(*bins
))==0);
44 testStatHist::testStatHistBaseEquality()
46 InspectingStatHist raw
, test
;
49 CPPUNIT_ASSERT(raw
==test
);
51 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw
==test
));
55 testStatHist::testStatHistBaseAssignment()
57 InspectingStatHist raw
, test
;
61 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw
==test
));
63 CPPUNIT_ASSERT(raw
==test
);
67 testStatHist::testStatHistLog()
69 const double min
=0.0, max
=10000.0;
70 const int capacity
=10;
71 InspectingStatHist raw
, test
;
72 raw
.logInit(capacity
,min
,max
);
74 CPPUNIT_ASSERT(test
.counter(min
)==0);
76 CPPUNIT_ASSERT(test
.counter(min
)==1);
77 CPPUNIT_ASSERT(test
.counter(max
)==0);
79 CPPUNIT_ASSERT(test
.counter(max
)==1);
82 //CPPUNIT_ASSERT(test.val(capacity-1)==1); // XXX: val() returns a density
86 testStatHist::testStatHistSum()
88 InspectingStatHist s1
, s2
;
89 s1
.logInit(30,1.0,100.0);
90 s2
.logInit(30,1.0,100.0);
93 InspectingStatHist ts1
, ts2
;
98 CPPUNIT_ASSERT(ts1
== ts2
);
99 InspectingStatHist ts3
;
100 ts3
.logInit(30,1.0,100.0);
103 CPPUNIT_ASSERT(ts3
== ts1
);