/*---------------------------------------------------------------------------- * * Copyright (C) 2021 Antonio Augusto Alves Junior * * This file is part of RandomIterator. * * RandomIterator is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * RandomIterator is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with RandomIterator. If not, see <http://www.gnu.org/licenses/>. * *---------------------------------------------------------------------------*/ /* * testing.cpp * * Created on: 25/02/2021 * Author: Antonio Augusto Alves Junior */ #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #define CATCH_CONFIG_ENABLE_BENCHMARKING #include <catch.hpp> #include <cstdio> #include <cstdint> //hydra #include <random_iterator/Stream.hpp> #include <random> //set a global seed static const uint64_t default_seed= 0x548c9decbce65295 ; #define NSTREAMS 1024 #define NCHECKS 1024 TEST_CASE("Streams correctness") { SECTION( "[ random_iterator::squares3_128 ] Random test different streams produces different sequences." ) { INFO("Checking streams"); std::random_device rd{}; std::mt19937 stream_index(rd()); std::mt19937_64 number_index(rd()); random_iterator::squares3_128 RNG(default_seed); std::uniform_int_distribution<uint64_t> dist(RNG.min(), RNG.max()); for(size_t i=0; i<NSTREAMS; ++i ) //loop stream { uint32_t index_stream_a = stream_index(); uint32_t index_stream_b = stream_index(); auto stream_A = random_iterator::make_stream( dist, RNG , index_stream_a ); auto stream_B = random_iterator::make_stream( dist, RNG , index_stream_b ); INFO("Streams A: " << index_stream_a << " B: " << index_stream_b); for(size_t j=0; j<NCHECKS; ++j ) //loop sequence { uint64_t index = number_index(); INFO("Index: " << j ); CHECK( stream_A[j] != stream_B[j]); } } }//SECTION( "[ random_iterator::squares3_128 ] Random test different streams produces different sequences." ) SECTION( "[ random_iterator::squares4_128 ] Random test different streams produces different sequences." ) { INFO("Checking streams"); std::random_device rd{}; std::mt19937 stream_index(rd()); std::mt19937_64 number_index(rd()); random_iterator::squares4_128 RNG(default_seed); std::uniform_int_distribution<uint64_t> dist(RNG.min(), RNG.max()); for(size_t i=0; i<NSTREAMS; ++i ) //loop stream { uint32_t index_stream_a = stream_index(); uint32_t index_stream_b = stream_index(); auto stream_A = random_iterator::make_stream( dist, RNG , index_stream_a ); auto stream_B = random_iterator::make_stream( dist, RNG , index_stream_b ); INFO("Streams A: " << index_stream_a << " B: " << index_stream_b); for(size_t j=0; j<NCHECKS; ++j ) //loop sequence { uint64_t index = number_index(); INFO("Index: " << j ); CHECK( stream_A[j] != stream_B[j]); } } }//SECTION( "[ random_iterator::squares4_128 ] Random test different streams produces different sequences." ) SECTION( "[ random_iterator::philox ] Random test different streams produces different sequences." ) { INFO("Checking streams"); std::random_device rd{}; std::mt19937 stream_index(rd()); std::mt19937_64 number_index(rd()); random_iterator::philox RNG(default_seed); std::uniform_int_distribution<uint64_t> dist(RNG.min(), RNG.max()); for(size_t i=0; i<NSTREAMS; ++i ) //loop stream { uint32_t index_stream_a = stream_index(); uint32_t index_stream_b = stream_index(); auto stream_A = random_iterator::make_stream( dist, RNG , index_stream_a ); auto stream_B = random_iterator::make_stream( dist, RNG , index_stream_b ); INFO("Streams A: " << index_stream_a << " B: " << index_stream_b); for(size_t j=0; j<NCHECKS; ++j ) //loop sequence { uint64_t index = number_index(); INFO("Index: " << j ); CHECK( stream_A[j] != stream_B[j]); } } }//SECTION( "[ random_iterator::philox ] Random test different streams produces different sequences." ) SECTION( "[ random_iterator::threefry ] Random test different streams produces different sequences." ) { INFO("Checking streams"); std::random_device rd{}; std::mt19937 stream_index(rd()); std::mt19937_64 number_index(rd()); random_iterator::threefry RNG(default_seed); std::uniform_int_distribution<uint64_t> dist(RNG.min(), RNG.max()); for(size_t i=0; i<NSTREAMS; ++i ) //loop stream { uint32_t index_stream_a = stream_index(); uint32_t index_stream_b = stream_index(); auto stream_A = random_iterator::make_stream( dist, RNG , index_stream_a ); auto stream_B = random_iterator::make_stream( dist, RNG , index_stream_b ); INFO("Streams A: " << index_stream_a << " B: " << index_stream_b); for(size_t j=0; j<NCHECKS; ++j ) //loop sequence { uint64_t index = number_index(); INFO("Index: " << j ); CHECK( stream_A[j] != stream_B[j]); } } }//SECTION( "[ random_iterator::threefry ] Random test different streams produces different sequences." ) SECTION( "[ random_iterator::ars ] Random test different streams produces different sequences." ) { INFO("Checking streams"); std::random_device rd{}; std::mt19937 stream_index(rd()); std::mt19937_64 number_index(rd()); random_iterator::ars RNG(default_seed); std::uniform_int_distribution<uint64_t> dist(RNG.min(), RNG.max()); for(size_t i=0; i<NSTREAMS; ++i ) //loop stream { uint32_t index_stream_a = stream_index(); uint32_t index_stream_b = stream_index(); auto stream_A = random_iterator::make_stream( dist, RNG , index_stream_a ); auto stream_B = random_iterator::make_stream( dist, RNG , index_stream_b ); INFO("Streams A: " << index_stream_a << " B: " << index_stream_b); for(size_t j=0; j<NCHECKS; ++j ) //loop sequence { uint64_t index = number_index(); INFO("Index: " << j ); CHECK( stream_A[j] != stream_B[j]); } } }//SECTION( "[ random_iterator::ars ] Random test different streams produces different sequences." ) }//TEST_CASE("Streams correctness")