summary refs log tree commit diff stats
path: root/Test/RandomTests.cpp
blob: a322752a7ed110541277ba7a1d30b255e65b73e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "gtest/gtest.h"
#include "Random.h"

TEST(RandomTests, RandomInRange) {
	int random1 = Random::RandInt(0, 1 << 30);
	int random2 = Random::RandInt(0, 1 << 30);
	ASSERT_NE(random1, random2);
	if (random1 > random2) std::swap(random1, random2);
	int random3 = Random::RandInt(random1, random2);
	std::cout << random1 << " " << random2 << " " << random3 << std::endl;
	ASSERT_GE(random3, random1);
	ASSERT_LE(random3, random2);
}

TEST(RandomTests, SeedWorks) {
	Random::SetSeed(0);
	ASSERT_EQ(2531011, Random::RandInt(0, 1 << 30));
	ASSERT_EQ(505908858, Random::RandInt(0, 1 << 30));
	ASSERT_EQ(318135124, Random::RandInt(0, 1 << 30));
	ASSERT_EQ(159719620, Random::RandInt(0, 1 << 30));
	Random::SetSeed(0);
	ASSERT_EQ(2531011, Random::RandInt(0, 1 << 30));
}

TEST(RandomTests, SeedChangesInitialValue) {
	Random::SetSeed(0);
	int random1 = Random::RandInt(0, 1 << 30);
	Random::SetSeed(1);
	int random2 = Random::RandInt(0, 1 << 30);
	ASSERT_NE(random1, random2);

	Random::SetSeed(2);
	int random3 = Random::RandInt(0, 1 << 30);
	ASSERT_NE(random3, random1);
	ASSERT_NE(random3, random2);
}