// Copyright (c) 2012-2014, The CryptoNote developers, The Bytecoin developers
//
// This file is part of Bytecoin.
//
// Bytecoin is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Bytecoin 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Bytecoin. If not, see .
#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);
}