2 #include <gtest/gtest.h>
3 #include <OpenMesh/Core/Utils/RandomNumberGenerator.hh>
7 class RandomNumberGenerator :
public testing::Test {
12 virtual void SetUp() {
18 virtual void TearDown() {
33 TEST_F(RandomNumberGenerator, RandomNumberGeneratorMaxTestHighres) {
38 unsigned int lowerZero = 0;
39 unsigned int above1 = 0;
43 for (
unsigned int i = 0 ; i < 100000000 ; ++i) {
44 double randomNumber = rng.getRand();
45 if ( randomNumber < 0.0 )
48 if ( randomNumber > 1.0 )
51 average += randomNumber;
54 average /= 100000000.0;
56 EXPECT_EQ(0u, lowerZero ) <<
"Below zero!";
57 EXPECT_EQ(0u, above1 ) <<
"Above zero!";
59 EXPECT_TRUE( (average - 0.5) < 0.01 ) <<
"Expected value not 0.5";
62 TEST_F(RandomNumberGenerator, RandomNumberGeneratorMaxTestLowres) {
66 unsigned int lowerZero = 0;
67 unsigned int above1 = 0;
71 for (
unsigned int i = 0 ; i < 10000000 ; ++i) {
73 double randomNumber = rng.getRand();
74 if ( randomNumber < 0.0 )
77 if ( randomNumber > 1.0 ) {
81 average += randomNumber;
84 average /= 10000000.0;
86 EXPECT_EQ(0u, lowerZero ) <<
"Below zero!";
87 EXPECT_EQ(0u, above1 ) <<
"Above zero!";
89 EXPECT_TRUE( (average - 0.5) < 0.01 ) <<
"Expected value not 0.5";