// Copyright (c) 2011-2015 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include "gtest/gtest.h" #include #include "crypto/crypto.h" #include "common/ShuffleGenerator.h" class ShuffleTest : public ::testing::Test { public: typedef ShuffleGenerator DefaultShuffleGenerator; typedef ShuffleGenerator> CryptoShuffleGenerator; template void checkUniqueness(Gen& gen, size_t count) { std::unordered_set values; for (auto i = 0; i < count; ++i) { auto value = gen(); bool inserted = values.insert(value).second; EXPECT_TRUE(inserted); } } template void consume(Gen& gen, size_t count) { for (auto i = 0; i < count; ++i) { gen(); } } template void checkEngine(size_t N, size_t consumeCount, bool check) { ShuffleT gen(N); check ? checkUniqueness(gen, consumeCount) : consume(gen, consumeCount); } }; namespace { const size_t ITERATIONS = 10000; } TEST_F(ShuffleTest, correctness) { checkEngine(ITERATIONS, ITERATIONS, true); } TEST_F(ShuffleTest, correctness_fractionalSize) { checkEngine(ITERATIONS, ITERATIONS, true); checkEngine(ITERATIONS, ITERATIONS/2, true); checkEngine(ITERATIONS, ITERATIONS/3, true); } TEST_F(ShuffleTest, cryptoGenerator) { checkEngine(ITERATIONS * 3, ITERATIONS, false); }