]>
Commit | Line | Data |
---|---|---|
4541d989 | 1 | #define SQUID_UNIT_TEST 1 |
f7f3304a | 2 | #include "squid.h" |
4541d989 FC |
3 | #include "testStatHist.h" |
4 | #include "StatHist.h" | |
5 | ||
6 | CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist); | |
7 | ||
8 | typedef enum { | |
9 | ZERO, ONE, TWO, THREE, FOUR, FIVE | |
10 | } number ; | |
11 | ||
12 | class InspectingStatHist : public StatHist | |
13 | { | |
14 | public: | |
15 | bool operator==(const InspectingStatHist &); | |
16 | bins_type counter(double val) { | |
17 | return bins[findBin(val)]; | |
18 | } | |
19 | }; | |
20 | ||
21 | bool | |
22 | InspectingStatHist::operator ==(const InspectingStatHist & src) | |
23 | { | |
24 | assert(bins != NULL && src.bins != NULL); // TODO: remove after initializing bins at construction time | |
25 | if (capacity_ != src.capacity_ || | |
00b7155c A |
26 | min_!=src.min_ || |
27 | max_!=src.max_ || | |
28 | scale_!=src.scale_ || | |
29 | val_in!=src.val_in || | |
30 | val_out!=src.val_out) | |
4541d989 FC |
31 | return false; |
32 | return (memcmp(bins,src.bins,capacity_*sizeof(*bins))==0); | |
33 | } | |
34 | ||
4541d989 FC |
35 | void |
36 | testStatHist::testStatHistBaseEquality() | |
37 | { | |
38 | InspectingStatHist raw, test; | |
39 | raw.enumInit(FIVE); | |
40 | test.enumInit(FIVE); | |
41 | CPPUNIT_ASSERT(raw==test); | |
42 | test.count(ZERO); | |
43 | CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test)); | |
44 | } | |
45 | ||
46 | void | |
47 | testStatHist::testStatHistBaseAssignment() | |
48 | { | |
49 | InspectingStatHist raw, test; | |
50 | raw.enumInit(FIVE); | |
51 | test.enumInit(FIVE); | |
52 | test.count(ZERO); | |
53 | CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test)); | |
54 | test=raw; | |
55 | CPPUNIT_ASSERT(raw==test); | |
56 | } | |
57 | ||
4541d989 FC |
58 | void |
59 | testStatHist::testStatHistLog() | |
60 | { | |
61 | const double min=0.0, max=10000.0; | |
62 | const int capacity=10; | |
63 | InspectingStatHist raw, test; | |
64 | raw.logInit(capacity,min,max); | |
65 | test=raw; | |
66 | CPPUNIT_ASSERT(test.counter(min)==0); | |
67 | test.count(min); | |
68 | CPPUNIT_ASSERT(test.counter(min)==1); | |
69 | CPPUNIT_ASSERT(test.counter(max)==0); | |
70 | test.count(max); | |
71 | CPPUNIT_ASSERT(test.counter(max)==1); | |
72 | test=raw; | |
73 | test.count(max); | |
74 | //CPPUNIT_ASSERT(test.val(capacity-1)==1); //FIXME: val() returns a density | |
75 | } |