diff options
author | Morgan Deters <mdeters@gmail.com> | 2010-09-02 07:31:04 +0000 |
---|---|---|
committer | Morgan Deters <mdeters@gmail.com> | 2010-09-02 07:31:04 +0000 |
commit | 79015a017495691ddfe2a4479de8fb7d558e4228 (patch) | |
tree | bd985ccb0c453c26100f6420807072ed7d81d530 /test/unit | |
parent | 81d178c1ca853754aaa614d0400e45a8900092b9 (diff) |
* add TimerStat statistic type
* add Stats black-box unit test
* new make target: "make units" now runs unit tests only
* revised make target: "make regress" now runs regressions only
* configure.ac: pull in librt for clock_gettime()
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/Makefile.am | 15 | ||||
-rw-r--r-- | test/unit/util/stats_black.h | 103 |
2 files changed, 111 insertions, 7 deletions
diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index eb920e6c5..1272be069 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -35,7 +35,8 @@ UNIT_TESTS = \ util/integer_black \ util/integer_white \ util/rational_black \ - util/rational_white + util/rational_white \ + util/stats_black export VERBOSE = 1 @@ -52,7 +53,7 @@ AM_CPPFLAGS = \ "-I@top_srcdir@/src" "-I@top_builddir@/src" \ "-I@top_srcdir@/src/prop/minisat" \ -D __STDC_LIMIT_MACROS \ - -D __STDC_FORMAT_MACROS \ + -D __STDC_FORMAT_MACROS \ $(ANTLR_INCLUDES) $(TEST_CPPFLAGS) AM_CXXFLAGS = -Wall -Wno-unknown-pragmas -Wno-parentheses $(TEST_CXXFLAGS) AM_LDFLAGS = $(TEST_LDFLAGS) @@ -158,12 +159,12 @@ libdummy_la_LIBADD = @abs_top_builddir@/src/libcvc4.la endif # synonyms for "check" -.PHONY: regress test -regress test: check +.PHONY: units test +units test: check -# in unit test dir, regressN are also synonyms for check -.PHONY: regress0 regress1 regress2 regress3 -regress0 regress1 regress2 regress3: check +# no-ops here +.PHONY: regress regress0 regress1 regress2 regress3 +regress regress0 regress1 regress2 regress3: if HAVE_CXXTESTGEN # all is fine with the world diff --git a/test/unit/util/stats_black.h b/test/unit/util/stats_black.h new file mode 100644 index 000000000..032efc37a --- /dev/null +++ b/test/unit/util/stats_black.h @@ -0,0 +1,103 @@ +/********************* */ +/*! \file stats_black.h + ** \verbatim + ** Original author: mdeters + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 prototype. + ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys) + ** Courant Institute of Mathematical Sciences + ** New York University + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Black box testing of CVC4::Stat and associated classes + ** + ** Black box testing of CVC4::Stat and associated classes. + **/ + +#include <cxxtest/TestSuite.h> +#include <sstream> +#include <string> +#include <ctime> + +#include "util/stats.h" + +using namespace CVC4; +using namespace std; + +class StatsBlack : public CxxTest::TestSuite { +public: + + void testStats() { + + // StatisticsRegistry + //static void flushStatistics(std::ostream& out); + + //static inline void registerStat(Stat* s) throw (AssertionException); + //static inline void unregisterStat(Stat* s) throw (AssertionException); + + string empty, bar = "bar", baz = "baz"; + ReferenceStat<string> refStr("stat #1", empty); + ReferenceStat<string> refStr2("refStr2", bar); + // setData + // getData + + // flushInformation + // flushStat + + BackedStat<string> backedStr("backed", baz); + // setData + // getData + // operator= + + IntStat sInt("my int", 10); + TimerStat sTimer("a timer ! for measuring time"); + + TS_ASSERT_EQUALS(refStr.getName(), "stat #1"); + TS_ASSERT_EQUALS(refStr2.getName(), "refStr2"); + TS_ASSERT_EQUALS(backedStr.getName(), "backed"); + TS_ASSERT_EQUALS(sInt.getName(), "my int"); + TS_ASSERT_EQUALS(sTimer.getName(), "a timer ! for measuring time"); + + TS_ASSERT_EQUALS(refStr.getData(), empty); + TS_ASSERT_EQUALS(refStr2.getData(), bar); + empty = "a different string"; + bar += " and with an addition"; + TS_ASSERT_EQUALS(refStr.getData(), empty); + TS_ASSERT_EQUALS(refStr2.getData(), bar); + + TS_ASSERT_EQUALS(backedStr.getData(), "baz"); + baz = "something else"; + TS_ASSERT_EQUALS(backedStr.getData(), "baz"); + + TS_ASSERT_EQUALS(sInt.getData(), 10); + sInt.setData(100); + TS_ASSERT_EQUALS(sInt.getData(), 100); + + TS_ASSERT_EQUALS(sTimer.getData(), timespec()); + + stringstream sstr; + + refStr.flushInformation(sstr); + TS_ASSERT_EQUALS(sstr.str(), empty); + sstr.str(""); + refStr2.flushInformation(sstr); + TS_ASSERT_EQUALS(sstr.str(), bar); + sstr.str(""); + backedStr.flushInformation(sstr); + TS_ASSERT_EQUALS(sstr.str(), "baz"); + sstr.str(""); + sInt.flushInformation(sstr); + TS_ASSERT_EQUALS(sstr.str(), "100"); + sstr.str(""); + sTimer.flushInformation(sstr); + TS_ASSERT_EQUALS(sstr.str(), "0.00000000"); + + sTimer.start(); + TS_ASSERT_EQUALS(timespec(), sTimer.getData()); + sTimer.stop(); + TS_ASSERT_LESS_THAN(timespec(), sTimer.getData()); + } + +}; |