]>
Commit | Line | Data |
---|---|---|
4e0938ef AJ |
1 | /* |
2 | * Copyright (C) 1996-2014 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 | ||
f7f3304a | 9 | #include "squid.h" |
4541d989 | 10 | #include "StatHist.h" |
602d9612 | 11 | #include "testStatHist.h" |
4541d989 FC |
12 | |
13 | CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist); | |
14 | ||
15 | typedef enum { | |
16 | ZERO, ONE, TWO, THREE, FOUR, FIVE | |
17 | } number ; | |
18 | ||
19 | class InspectingStatHist : public StatHist | |
20 | { | |
21 | public: | |
22 | bool operator==(const InspectingStatHist &); | |
9dca980d AJ |
23 | bins_type counter(double v) { |
24 | return bins[findBin(v)]; | |
4541d989 FC |
25 | } |
26 | }; | |
27 | ||
28 | bool | |
29 | InspectingStatHist::operator ==(const InspectingStatHist & src) | |
30 | { | |
31 | assert(bins != NULL && src.bins != NULL); // TODO: remove after initializing bins at construction time | |
32 | if (capacity_ != src.capacity_ || | |
00b7155c A |
33 | min_!=src.min_ || |
34 | max_!=src.max_ || | |
35 | scale_!=src.scale_ || | |
36 | val_in!=src.val_in || | |
37 | val_out!=src.val_out) | |
4541d989 FC |
38 | return false; |
39 | return (memcmp(bins,src.bins,capacity_*sizeof(*bins))==0); | |
40 | } | |
41 | ||
4541d989 FC |
42 | void |
43 | testStatHist::testStatHistBaseEquality() | |
44 | { | |
45 | InspectingStatHist raw, test; | |
46 | raw.enumInit(FIVE); | |
47 | test.enumInit(FIVE); | |
48 | CPPUNIT_ASSERT(raw==test); | |
49 | test.count(ZERO); | |
50 | CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test)); | |
51 | } | |
52 | ||
53 | void | |
54 | testStatHist::testStatHistBaseAssignment() | |
55 | { | |
56 | InspectingStatHist raw, test; | |
57 | raw.enumInit(FIVE); | |
58 | test.enumInit(FIVE); | |
59 | test.count(ZERO); | |
60 | CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test)); | |
61 | test=raw; | |
62 | CPPUNIT_ASSERT(raw==test); | |
63 | } | |
64 | ||
4541d989 FC |
65 | void |
66 | testStatHist::testStatHistLog() | |
67 | { | |
68 | const double min=0.0, max=10000.0; | |
69 | const int capacity=10; | |
70 | InspectingStatHist raw, test; | |
71 | raw.logInit(capacity,min,max); | |
72 | test=raw; | |
73 | CPPUNIT_ASSERT(test.counter(min)==0); | |
74 | test.count(min); | |
75 | CPPUNIT_ASSERT(test.counter(min)==1); | |
76 | CPPUNIT_ASSERT(test.counter(max)==0); | |
77 | test.count(max); | |
78 | CPPUNIT_ASSERT(test.counter(max)==1); | |
79 | test=raw; | |
80 | test.count(max); | |
81 | //CPPUNIT_ASSERT(test.val(capacity-1)==1); //FIXME: val() returns a density | |
82 | } | |
ff1eb053 FC |
83 | |
84 | void | |
85 | testStatHist::testStatHistSum() | |
86 | { | |
87 | InspectingStatHist s1, s2; | |
88 | s1.logInit(30,1.0,100.0); | |
89 | s2.logInit(30,1.0,100.0); | |
90 | s1.count(3); | |
91 | s2.count(30); | |
92 | InspectingStatHist ts1, ts2; | |
93 | ts1=s1; | |
94 | ts1+=s2; | |
95 | ts2=s2; | |
96 | ts2+=s1; | |
97 | CPPUNIT_ASSERT(ts1 == ts2); | |
98 | InspectingStatHist ts3; | |
99 | ts3.logInit(30,1.0,100.0); | |
100 | ts3.count(3); | |
101 | ts3.count(30); | |
102 | CPPUNIT_ASSERT(ts3 == ts1); | |
103 | ||
104 | } | |
f53969cc | 105 |