]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/tests/testStatHist.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / tests / testStatHist.cc
index 8e037686610a0d802ddd7aa4c3354a425999d7fb..4057beec694bfbd9a8f6ee65987b8015fd941862 100644 (file)
@@ -1,7 +1,15 @@
-#define SQUID_UNIT_TEST 1
+/*
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #include "squid.h"
-#include "testStatHist.h"
 #include "StatHist.h"
+#include "testStatHist.h"
+#include "unitTestMain.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist);
 
@@ -13,15 +21,15 @@ class InspectingStatHist : public StatHist
 {
 public:
     bool operator==(const InspectingStatHist &);
-    bins_type counter(double val) {
-        return bins[findBin(val)];
+    bins_type counter(double v) {
+        return bins[findBin(v)];
     }
 };
 
 bool
 InspectingStatHist::operator ==(const InspectingStatHist & src)
 {
-    assert(bins != NULL && src.bins != NULL); // TODO: remove after initializing bins at construction time
+    assert(bins != nullptr && src.bins != nullptr); // TODO: remove after initializing bins at construction time
     if (capacity_ != src.capacity_ ||
             min_!=src.min_ ||
             max_!=src.max_ ||
@@ -32,8 +40,6 @@ InspectingStatHist::operator ==(const InspectingStatHist & src)
     return (memcmp(bins,src.bins,capacity_*sizeof(*bins))==0);
 }
 
-
-
 void
 testStatHist::testStatHistBaseEquality()
 {
@@ -57,7 +63,6 @@ testStatHist::testStatHistBaseAssignment()
     CPPUNIT_ASSERT(raw==test);
 }
 
-
 void
 testStatHist::testStatHistLog()
 {
@@ -74,5 +79,28 @@ testStatHist::testStatHistLog()
     CPPUNIT_ASSERT(test.counter(max)==1);
     test=raw;
     test.count(max);
-    //CPPUNIT_ASSERT(test.val(capacity-1)==1); //FIXME: val() returns a density
+    //CPPUNIT_ASSERT(test.val(capacity-1)==1); // XXX: val() returns a density
 }
+
+void
+testStatHist::testStatHistSum()
+{
+    InspectingStatHist s1, s2;
+    s1.logInit(30,1.0,100.0);
+    s2.logInit(30,1.0,100.0);
+    s1.count(3);
+    s2.count(30);
+    InspectingStatHist ts1, ts2;
+    ts1=s1;
+    ts1+=s2;
+    ts2=s2;
+    ts2+=s1;
+    CPPUNIT_ASSERT(ts1 == ts2);
+    InspectingStatHist ts3;
+    ts3.logInit(30,1.0,100.0);
+    ts3.count(3);
+    ts3.count(30);
+    CPPUNIT_ASSERT(ts3 == ts1);
+
+}
+