OEMCrypto v16.1 -- update ODK
This CL updates the ODK library to address review comments.
This commit is contained in:
@@ -4,10 +4,13 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -30,6 +33,43 @@ constexpr unsigned int kSeeds[] = {0, 1337, 1565904109, 776964657};
|
||||
class CdmRandomGeneratorTest : public testing::TestWithParam<unsigned int> {};
|
||||
} // namespace
|
||||
|
||||
// Checks that the class CdmRandomGenerator meets the requirements of
|
||||
// UniformRandomBitGenerator.
|
||||
// ref: https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator
|
||||
TEST(CdmRandomGeneratorTest, UniformRandomBitGeneratorRequirements) {
|
||||
// Let G represent class CdmRandomGenerator, and g represent an instance
|
||||
// of CdmRandomGenerator.
|
||||
// 1) G::result_type is an unsigned integer (unspecified precision).
|
||||
EXPECT_TRUE(std::is_integral<CdmRandomGenerator::result_type>::value);
|
||||
EXPECT_TRUE(std::is_unsigned<CdmRandomGenerator::result_type>::value);
|
||||
// 2&3 a) G::min() and G::max() have the result type of G::result_type.
|
||||
EXPECT_TRUE((std::is_same<CdmRandomGenerator::result_type,
|
||||
decltype(CdmRandomGenerator::min())>::value));
|
||||
EXPECT_TRUE((std::is_same<CdmRandomGenerator::result_type,
|
||||
decltype(CdmRandomGenerator::max())>::value));
|
||||
// 2&3 b) G::min() is strictly less than G::max().
|
||||
EXPECT_LT(CdmRandomGenerator::min(), CdmRandomGenerator::max());
|
||||
// 4 a) g() have the result type of G::result_type.
|
||||
CdmRandomGenerator g;
|
||||
EXPECT_TRUE(
|
||||
(std::is_same<CdmRandomGenerator::result_type, decltype(g())>::value));
|
||||
// 4 b) g() is within [G::min() G::max()]
|
||||
std::vector<CdmRandomGenerator::result_type> values;
|
||||
for (size_t i = 0; i < kRandomTrialCount; ++i) {
|
||||
CdmRandomGenerator::result_type x = g();
|
||||
EXPECT_LE(CdmRandomGenerator::min(), x);
|
||||
EXPECT_GE(CdmRandomGenerator::max(), x);
|
||||
values.push_back(x);
|
||||
}
|
||||
|
||||
// Verify compilation.
|
||||
|
||||
// std::shuffle(RandomIt first, RandomIt last, URBG&& g) requires the
|
||||
// class URBG to meet "UniformRandomBitGenerator" requirements. This
|
||||
// will fail to compile if the requirements are not met.
|
||||
std::shuffle(values.begin(), values.end(), CdmRandomGenerator());
|
||||
}
|
||||
|
||||
TEST_P(CdmRandomGeneratorTest, AllMethods) {
|
||||
const unsigned int seed = GetParam();
|
||||
CdmRandomGenerator rng;
|
||||
|
||||
Reference in New Issue
Block a user