Skip to content

Commit

Permalink
Move colony and list test helpers to new header
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Jul 7, 2019
1 parent 488a837 commit faa5eb1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 87 deletions.
47 changes: 47 additions & 0 deletions tests/colony_list_test_helpers.h
Original file line number Diff line number Diff line change
@@ -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 <typename T, typename U>
perfect_forwarding_test( T && /*imperfect1*/, U && /*imperfect2*/ ) : success( false )
{}
};

#endif // COLONY_LIST_TEST_HELPERS_H
44 changes: 1 addition & 43 deletions tests/colony_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]" )
{
Expand Down Expand Up @@ -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 <typename T, typename U>
perfect_forwarding_test( T && /*imperfect1*/, U && /*imperfect2*/ ) : success( false )
{}
};

TEST_CASE( "colony perfect forwarding", "[colony]" )
{
cata::colony<perfect_forwarding_test> test_colony;
Expand All @@ -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<small_struct> test_colony;
Expand Down
46 changes: 2 additions & 44 deletions tests/list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,9 @@
#include <vector> // 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 <typename T, typename U>
perfect_forwarding_test( T && /*imperfect1*/, U && /*imperfect2*/ ) : success( false )
{}
};

TEST_CASE( "list basics", "[list]" )
{
Expand Down Expand Up @@ -293,7 +253,7 @@ TEST_CASE( "list basics", "[list]" )
}
}

TEST_CASE( "list insert and erase" )
TEST_CASE( "list insert and erase", "[list]" )
{
cata::list<int> test_list;

Expand Down Expand Up @@ -656,8 +616,6 @@ TEST_CASE( "list sort and reverse", "[list]" )
CHECK( passed );
}
}


}

TEST_CASE( "list unique", "[list]" )
Expand Down

0 comments on commit faa5eb1

Please sign in to comment.