-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_random.cpp
More file actions
53 lines (41 loc) · 1.2 KB
/
Copy pathtest_random.cpp
File metadata and controls
53 lines (41 loc) · 1.2 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "utils.h"
#include <catch2/catch.hpp>
#include "faasm/random.h"
using namespace faasm;
namespace tests {
TEST_CASE("Test random integer", "[random]")
{
// Slightly sketch to be testing a random number like this but probably a
// necessary evil.
int topEnd = 1000;
int a = randomInteger(10, topEnd);
int b = randomInteger(30, topEnd);
int c = randomInteger(100, topEnd);
REQUIRE(a >= 10);
REQUIRE(a <= topEnd);
REQUIRE(b >= 30);
REQUIRE(b <= topEnd);
REQUIRE(c >= 100);
REQUIRE(c <= topEnd);
bool allUnequal = (a != b) & (b != c);
REQUIRE(allUnequal);
}
TEST_CASE("Test array shuffling", "[random]")
{
std::vector<int> arrayIn = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<int> arrayInCopy = arrayIn;
shuffleArray(arrayIn.data(), arrayIn.size());
REQUIRE(arrayIn != arrayInCopy);
}
TEST_CASE("Test random int range", "[random]")
{
int* actual = randomIntRange(20);
// Check all integers are present
std::vector<int> actualVec(actual, actual + 20);
for (int i = 0; i < 20; i++) {
bool isPresent =
std::find(actualVec.begin(), actualVec.end(), i) != actualVec.end();
REQUIRE(isPresent);
}
}
}