From 8991e7aed0086635637682d2660fbd75f17ed901 Mon Sep 17 00:00:00 2001 From: khizmax Date: Thu, 9 Apr 2015 20:47:04 +0300 Subject: [PATCH] Issue #23: Added std::random_device to TestCase class --- tests/cppunit/cppunit_mini.h | 14 +++++++++++++- tests/cppunit/test_main.cpp | 28 ++++++++++++++++------------ tests/unit/map2/map_delodd.cpp | 4 ++-- tests/unit/map2/map_delodd.h | 1 - 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/tests/cppunit/cppunit_mini.h b/tests/cppunit/cppunit_mini.h index e0a8507b..9e88bae9 100644 --- a/tests/cppunit/cppunit_mini.h +++ b/tests/cppunit/cppunit_mini.h @@ -30,6 +30,8 @@ #include #include #include +#include + #include #include @@ -191,7 +193,13 @@ namespace CppUnitMini static void print_gc_state(); - static std::vector const & getTestStrings(); + static std::vector const& getTestStrings(); + + template + void shuffle( RandomIt first, RandomIt last ) + { + std::shuffle( first, last, m_RandomGen ); + } protected: static std::vector m_arrStrings ; // array of test strings @@ -202,6 +210,10 @@ namespace CppUnitMini static std::string m_strTestDataDir; static bool m_bExactMatch; + // random shuffle support + static std::random_device m_RandomDevice; + static std::mt19937 m_RandomGen; + protected: static int m_numErrors; static int m_numTests; diff --git a/tests/cppunit/test_main.cpp b/tests/cppunit/test_main.cpp index 529defc7..c99fe5a3 100644 --- a/tests/cppunit/test_main.cpp +++ b/tests/cppunit/test_main.cpp @@ -75,18 +75,22 @@ std::ostream& operator << (std::ostream& s, const cds::gc::hp::GarbageCollector: namespace CppUnitMini { - int TestCase::m_numErrors = 0; - int TestCase::m_numTests = 0; - std::vector TestCase::m_arrStrings; - bool TestCase::m_bPrintGCState = false; - std::string TestCase::m_strTestDataDir("."); - Config TestCase::m_Cfg; - bool TestCase::m_bExactMatch = false; - - TestCase * TestCase::m_pCurTestCase = nullptr; - - TestCase *TestCase::m_root = 0; - Reporter *TestCase::m_reporter = 0; + int TestCase::m_numErrors = 0; + int TestCase::m_numTests = 0; + std::vector TestCase::m_arrStrings; + bool TestCase::m_bPrintGCState = false; + std::string TestCase::m_strTestDataDir("."); + Config TestCase::m_Cfg; + bool TestCase::m_bExactMatch = false; + + // random shuffle support + /*static*/ std::random_device TestCase::m_RandomDevice; + /*static*/ std::mt19937 TestCase::m_RandomGen( TestCase::m_RandomDevice() ); + + TestCase * TestCase::m_pCurTestCase = nullptr; + + TestCase *TestCase::m_root = 0; + Reporter *TestCase::m_reporter = 0; void TestCase::registerTestCase(TestCase *in_testCase) { in_testCase->m_next = m_root; diff --git a/tests/unit/map2/map_delodd.cpp b/tests/unit/map2/map_delodd.cpp index 8ddb4e98..7c65caf2 100644 --- a/tests/unit/map2/map_delodd.cpp +++ b/tests/unit/map2/map_delodd.cpp @@ -33,8 +33,8 @@ namespace map2 { m_arrInsert[i] = i; m_arrRemove[i] = i; } - std::random_shuffle( m_arrInsert.begin(), m_arrInsert.end() ); - std::random_shuffle( m_arrRemove.begin(), m_arrRemove.end() ); + shuffle( m_arrInsert.begin(), m_arrInsert.end() ); + shuffle( m_arrRemove.begin(), m_arrRemove.end() ); } void Map_DelOdd::myRun(const char *in_name, bool invert /*= false*/) diff --git a/tests/unit/map2/map_delodd.h b/tests/unit/map2/map_delodd.h index 56e2afc1..4cda89e1 100644 --- a/tests/unit/map2/map_delodd.h +++ b/tests/unit/map2/map_delodd.h @@ -2,7 +2,6 @@ #include "cppunit/thread.h" #include "map2/map_type.h" -#include // random_shuffle #include namespace map2 { -- 2.34.1