diff options
Diffstat (limited to 'tests/test-statistics.cpp')
-rw-r--r-- | tests/test-statistics.cpp | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp index 9ed7d06..fbc8cfb 100644 --- a/tests/test-statistics.cpp +++ b/tests/test-statistics.cpp @@ -6,23 +6,88 @@ #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> +#include <filesystem> #include <sstream> #include <string> #include "statistics.h" +#include "config.h" + using namespace std::string_literals; +namespace fs = std::filesystem; class StatisticsFixture { public: StatisticsFixture(){} ~StatisticsFixture(){} - void setup(){} - void teardown(){} + void setup() + { + std::error_code ec; + fs::remove("stats.db", ec); + } + void teardown() + { + std::error_code ec; + fs::remove("stats.db", ec); + } }; BOOST_FIXTURE_TEST_CASE(statistics, StatisticsFixture) { + { + Statistics stats; + + BOOST_CHECK_EQUAL(stats.getValues(), ""); + + stats.count(10, 1000, false, true, true); + + auto v{stats.getValues()}; + BOOST_CHECK_GT(v.size(), 0); + + auto pos{v.find(",")}; + BOOST_CHECK(pos != std::string::npos); + BOOST_CHECK_GT(pos, 0); + + std::string v2{v.substr(pos)}; + + BOOST_CHECK_EQUAL(v2, ",1,0,10,1000,1,0,10,1000,1,0,10,1000\n"); + + stats.save(); + + BOOST_CHECK_EQUAL(v2, ",1,0,10,1000,1,0,10,1000,1,0,10,1000\n"); + } + + { + Statistics stats("stats.db"); + auto v{stats.getValues()}; + BOOST_CHECK_GT(v.size(), 0); + + auto pos{v.find(",")}; + BOOST_CHECK(pos != std::string::npos); + BOOST_CHECK_GT(pos, 0); + + std::string v2{v.substr(pos)}; + + BOOST_CHECK_EQUAL(v2, ",1,0,10,1000,1,0,10,1000,1,0,10,1000\n"); + + stats.count(10, 1000, false, true, true); + BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",2,0,20,2000,2,0,20,2000,2,0,20,2000\n"); + stats.count(10, 1000, true, true, true); + BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",3,1,30,3000,3,1,30,3000,3,1,30,3000\n"); + stats.count(10, 1000, false, false, false); + BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",4,1,40,4000,3,1,30,3000,3,1,30,3000\n"); + stats.count(10, 1000, false, true, false); + BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",5,1,50,5000,4,1,40,4000,3,1,30,3000\n"); + stats.count(10, 1000, false, false, true); + BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",6,1,60,6000,4,1,40,4000,4,1,40,4000\n"); + } +} + +BOOST_FIXTURE_TEST_CASE(statistics_non_existing, StatisticsFixture) +{ + Statistics stats("nonexistingpath/stats.db"); + BOOST_CHECK_EQUAL(stats.getValues(), ""); } |