]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/testStatHist.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / tests / testStatHist.cc
CommitLineData
4e0938ef 1/*
5b74111a 2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
4e0938ef
AJ
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
f7f3304a 9#include "squid.h"
4541d989 10#include "StatHist.h"
602d9612 11#include "testStatHist.h"
7f861c77
AJ
12#include "unitTestMain.h"
13
4541d989
FC
14CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist);
15
16typedef enum {
17 ZERO, ONE, TWO, THREE, FOUR, FIVE
18} number ;
19
20class InspectingStatHist : public StatHist
21{
22public:
23 bool operator==(const InspectingStatHist &);
9dca980d
AJ
24 bins_type counter(double v) {
25 return bins[findBin(v)];
4541d989
FC
26 }
27};
28
29bool
30InspectingStatHist::operator ==(const InspectingStatHist & src)
31{
32 assert(bins != NULL && src.bins != NULL); // TODO: remove after initializing bins at construction time
33 if (capacity_ != src.capacity_ ||
00b7155c
A
34 min_!=src.min_ ||
35 max_!=src.max_ ||
36 scale_!=src.scale_ ||
37 val_in!=src.val_in ||
38 val_out!=src.val_out)
4541d989
FC
39 return false;
40 return (memcmp(bins,src.bins,capacity_*sizeof(*bins))==0);
41}
42
4541d989
FC
43void
44testStatHist::testStatHistBaseEquality()
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
55testStatHist::testStatHistBaseAssignment()
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
4541d989
FC
66void
67testStatHist::testStatHistLog()
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}
ff1eb053
FC
84
85void
86testStatHist::testStatHistSum()
87{
88 InspectingStatHist s1, s2;
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);
99 InspectingStatHist ts3;
100 ts3.logInit(30,1.0,100.0);
101 ts3.count(3);
102 ts3.count(30);
103 CPPUNIT_ASSERT(ts3 == ts1);
104
105}
f53969cc 106