about summary refs log tree commit diff stats
path: root/Test/RandomTests.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2018-11-05 10:06:37 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2018-11-05 10:06:37 -0800
commit669717268201197412c69df36e65883b0af6fac8 (patch)
tree6345c3acd1ca42bbd31c3702e649a09512e5aed6 /Test/RandomTests.cpp
parenta828620c6447e8c51f6e9d1767eabe0fc5ade0a0 (diff)
downloadwitness-tutorializer-669717268201197412c69df36e65883b0af6fac8.tar.gz
witness-tutorializer-669717268201197412c69df36e65883b0af6fac8.tar.bz2
witness-tutorializer-669717268201197412c69df36e65883b0af6fac8.zip
Tests work now, + other cleanup
Diffstat (limited to 'Test/RandomTests.cpp')
-rw-r--r--Test/RandomTests.cpp36
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
4TEST(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
15TEST(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
25TEST(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