aboutsummaryrefslogtreecommitdiff
path: root/src/test.cpp
diff options
context:
space:
mode:
authorgregorycu <gregory.currie@gmail.com>2015-01-22 00:25:06 +1100
committerShadowNinja <shadowninja@minetest.net>2015-03-07 20:04:01 -0500
commit267c9f4cb4616afcf07a2a33aaca43a903ac895a (patch)
treebbef409747af8e8a313b3c87813067b22a4adb1d /src/test.cpp
parentd75a0a73941259ea3ebac297803838094c7d458f (diff)
downloadminetest-267c9f4cb4616afcf07a2a33aaca43a903ac895a.tar.xz
Optimize Profiler::avg()
Diffstat (limited to 'src/test.cpp')
-rw-r--r--src/test.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test.cpp b/src/test.cpp
index 7b82a2c31..8c9f26c52 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -43,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/serialize.h"
#include "noise.h" // PseudoRandom used for random data for compression
#include "network/networkprotocol.h" // LATEST_PROTOCOL_VERSION
+#include "profiler.h"
#include <algorithm>
/*
@@ -2118,6 +2119,40 @@ struct TestConnection: public TestBase
}
};
+struct TestProfiler : public TestBase
+{
+ void Run()
+ {
+ Profiler p;
+
+ p.avg("Test1", 1.f);
+ UASSERT(p.getValue("Test1") == 1.f);
+
+ p.avg("Test1", 2.f);
+ UASSERT(p.getValue("Test1") == 1.5f);
+
+ p.avg("Test1", 3.f);
+ UASSERT(p.getValue("Test1") == 2.f);
+
+ p.avg("Test1", 486.f);
+ UASSERT(p.getValue("Test1") == 123.f);
+
+ p.avg("Test1", 8);
+ UASSERT(p.getValue("Test1") == 100.f);
+
+ p.avg("Test1", 700);
+ UASSERT(p.getValue("Test1") == 200.f);
+
+ p.avg("Test1", 10000);
+ UASSERT(p.getValue("Test1") == 1600.f);
+
+ p.avg("Test2", 123.56);
+ p.avg("Test2", 123.58);
+
+ UASSERT(p.getValue("Test2") == 123.57f);
+ }
+};
+
#define TEST(X) do {\
X x;\
infostream<<"Running " #X <<std::endl;\
@@ -2155,6 +2190,7 @@ void run_tests()
TEST(TestCompress);
TEST(TestSerialization);
TEST(TestNodedefSerialization);
+ TEST(TestProfiler);
TESTPARAMS(TestMapNode, ndef);
TESTPARAMS(TestVoxelManipulator, ndef);
TESTPARAMS(TestVoxelAlgorithms, ndef);