diff options
Diffstat (limited to 'Test/RandomTests.cpp')
-rw-r--r-- | Test/RandomTests.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Test/RandomTests.cpp b/Test/RandomTests.cpp new file mode 100644 index 0000000..a322752 --- /dev/null +++ b/Test/RandomTests.cpp | |||
@@ -0,0 +1,36 @@ | |||
1 | #include "gtest/gtest.h" | ||
2 | #include "Random.h" | ||
3 | |||
4 | TEST(RandomTests, RandomInRange) { | ||
5 | int random1 = Random::RandInt(0, 1 << 30); | ||
6 | int random2 = Random::RandInt(0, 1 << 30); | ||
7 | ASSERT_NE(random1, random2); | ||
8 | if (random1 > random2) std::swap(random1, random2); | ||
9 | int random3 = Random::RandInt(random1, random2); | ||
10 | std::cout << random1 << " " << random2 << " " << random3 << std::endl; | ||
11 | ASSERT_GE(random3, random1); | ||
12 | ASSERT_LE(random3, random2); | ||
13 | } | ||
14 | |||
15 | TEST(RandomTests, SeedWorks) { | ||
16 | Random::SetSeed(0); | ||
17 | ASSERT_EQ(2531011, Random::RandInt(0, 1 << 30)); | ||
18 | ASSERT_EQ(505908858, Random::RandInt(0, 1 << 30)); | ||
19 | ASSERT_EQ(318135124, Random::RandInt(0, 1 << 30)); | ||
20 | ASSERT_EQ(159719620, Random::RandInt(0, 1 << 30)); | ||
21 | Random::SetSeed(0); | ||
22 | ASSERT_EQ(2531011, Random::RandInt(0, 1 << 30)); | ||
23 | } | ||
24 | |||
25 | TEST(RandomTests, SeedChangesInitialValue) { | ||
26 | Random::SetSeed(0); | ||
27 | int random1 = Random::RandInt(0, 1 << 30); | ||
28 | Random::SetSeed(1); | ||
29 | int random2 = Random::RandInt(0, 1 << 30); | ||
30 | ASSERT_NE(random1, random2); | ||
31 | |||
32 | Random::SetSeed(2); | ||
33 | int random3 = Random::RandInt(0, 1 << 30); | ||
34 | ASSERT_NE(random3, random1); | ||
35 | ASSERT_NE(random3, random2); | ||
36 | } \ No newline at end of file | ||