From faa5eb15b85a694c1baff51919de16be888cfed9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 7 Jul 2019 14:55:46 +0200 Subject: [PATCH] Move colony and list test helpers to new header --- tests/colony_list_test_helpers.h | 47 ++++++++++++++++++++++++++++++++ tests/colony_test.cpp | 44 +----------------------------- tests/list_test.cpp | 46 ++----------------------------- 3 files changed, 50 insertions(+), 87 deletions(-) create mode 100644 tests/colony_list_test_helpers.h diff --git a/tests/colony_list_test_helpers.h b/tests/colony_list_test_helpers.h new file mode 100644 index 0000000000000..47644b9a63049 --- /dev/null +++ b/tests/colony_list_test_helpers.h @@ -0,0 +1,47 @@ +#pragma once +#ifndef COLONY_LIST_TEST_HELPERS_H +#define COLONY_LIST_TEST_HELPERS_H + +// Fast xorshift+128 random number generator function +// original: https://codingforspeed.com/using-faster-psudo-random-generator-xorshift/ +static unsigned int xor_rand() +{ + static unsigned int x = 123456789; + static unsigned int y = 362436069; + static unsigned int z = 521288629; + static unsigned int w = 88675123; + + const unsigned int t = x ^ ( x << 11 ); + + // Rotate the static values (w rotation in return statement): + x = y; + y = z; + z = w; + + return w = w ^ ( w >> 19 ) ^ ( t ^ ( t >> 8 ) ); +} + +struct small_struct { + double *empty_field_1; + double unused_number; + unsigned int empty_field2; + double *empty_field_3; + int number; + unsigned int empty_field4; + + small_struct( const int num ) noexcept: number( num ) {}; +}; + +struct perfect_forwarding_test { + const bool success; + + perfect_forwarding_test( int && /*perfect1*/, int &perfect2 ) : success( true ) { + perfect2 = 1; + } + + template + perfect_forwarding_test( T && /*imperfect1*/, U && /*imperfect2*/ ) : success( false ) + {} +}; + +#endif // COLONY_LIST_TEST_HELPERS_H diff --git a/tests/colony_test.cpp b/tests/colony_test.cpp index af1f5f87899d1..30a96008bfba5 100644 --- a/tests/colony_test.cpp +++ b/tests/colony_test.cpp @@ -6,25 +6,7 @@ #include "catch/catch.hpp" #include "colony.h" - -// Fast xorshift+128 random number generator function -// original: https://codingforspeed.com/using-faster-psudo-random-generator-xorshift/ -static unsigned int xor_rand() -{ - static unsigned int x = 123456789; - static unsigned int y = 362436069; - static unsigned int z = 521288629; - static unsigned int w = 88675123; - - const unsigned int t = x ^ ( x << 11 ); - - // Rotate the static values (w rotation in return statement): - x = y; - y = z; - z = w; - - return w = w ^ ( w >> 19 ) ^ ( t ^ ( t >> 8 ) ); -} +#include "colony_list_test_helpers.h" TEST_CASE( "colony basics", "[colony]" ) { @@ -888,18 +870,6 @@ TEST_CASE( "colony insertion methods", "[colony]" ) CHECK( sum == 12060 ); } -struct perfect_forwarding_test { - const bool success; - - perfect_forwarding_test( int && /*perfect1*/, int &perfect2 ) : success( true ) { - perfect2 = 1; - } - - template - perfect_forwarding_test( T && /*imperfect1*/, U && /*imperfect2*/ ) : success( false ) - {} -}; - TEST_CASE( "colony perfect forwarding", "[colony]" ) { cata::colony test_colony; @@ -913,18 +883,6 @@ TEST_CASE( "colony perfect forwarding", "[colony]" ) CHECK( lvalueref == 1 ); } -struct small_struct { - double *empty_field_1; - double unused_number; - unsigned int empty_field2; - double *empty_field_3; - int number; - unsigned int empty_field4; - - small_struct( const int num ) noexcept: - number( num ) {}; -}; - TEST_CASE( "colony emplace", "[colony]" ) { cata::colony test_colony; diff --git a/tests/list_test.cpp b/tests/list_test.cpp index c64c2172377ab..4890ddda09579 100644 --- a/tests/list_test.cpp +++ b/tests/list_test.cpp @@ -6,49 +6,9 @@ #include // range-insert testing #include "catch/catch.hpp" +#include "colony_list_test_helpers.h" #include "list.h" -// Fast xorshift+128 random number generator function -// original: https://codingforspeed.com/using-faster-psudo-random-generator-xorshift/ -static unsigned int xor_rand() -{ - static unsigned int x = 123456789; - static unsigned int y = 362436069; - static unsigned int z = 521288629; - static unsigned int w = 88675123; - - const unsigned int t = x ^ ( x << 11 ); - - // Rotate the static values (w rotation in return statement): - x = y; - y = z; - z = w; - - return w = w ^ ( w >> 19 ) ^ ( t ^ ( t >> 8 ) ); -} - -struct small_struct { - double *empty_field_1; - double unused_number; - unsigned int empty_field2; - double *empty_field_3; - int number; - unsigned int empty_field4; - - small_struct( const int num ) noexcept: number( num ) {}; -}; - -struct perfect_forwarding_test { - const bool success; - - perfect_forwarding_test( int && /*perfect1*/, int &perfect2 ) : success( true ) { - perfect2 = 1; - } - - template - perfect_forwarding_test( T && /*imperfect1*/, U && /*imperfect2*/ ) : success( false ) - {} -}; TEST_CASE( "list basics", "[list]" ) { @@ -293,7 +253,7 @@ TEST_CASE( "list basics", "[list]" ) } } -TEST_CASE( "list insert and erase" ) +TEST_CASE( "list insert and erase", "[list]" ) { cata::list test_list; @@ -656,8 +616,6 @@ TEST_CASE( "list sort and reverse", "[list]" ) CHECK( passed ); } } - - } TEST_CASE( "list unique", "[list]" )