forked from rozukke/mcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_tests.cpp
More file actions
130 lines (104 loc) · 3.01 KB
/
local_tests.cpp
File metadata and controls
130 lines (104 loc) · 3.01 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "../include/mcpp/block.h"
#include "../include/mcpp/coordinate.h"
#include "doctest.h"
#include <random>
// NOLINTBEGIN
using namespace mcpp;
/*
* Used to test code that is not connection dependent such as the implementation
* of Coordinate and various other utility functions as well as Block
* functionality.
*/
TEST_CASE("Test Coordinate class") {
SUBCASE("Test init") {
Coordinate test_coord;
CHECK_EQ(test_coord.x, 0);
CHECK_EQ(test_coord.y, 0);
CHECK_EQ(test_coord.z, 0);
}
SUBCASE("Test hash no collision") {
const int seed = 12345;
std::set<size_t> hashes;
std::mt19937 gen(seed);
std::uniform_int_distribution<int> dis(-3e7, 3e7);
std::uniform_int_distribution<int> dis2(-64, 256);
Coordinate hashing;
for (int i = 0; i < 100; i++) {
Coordinate testCoord(dis(gen), dis2(gen), dis(gen));
size_t hash = hashing(testCoord);
hashes.insert(hash);
}
CHECK_EQ(hashes.size(), 100);
}
SUBCASE("Test double init") {
Coordinate test_coord(1.5, 2.5, 3.5);
Coordinate test_coord_float(1.5F, 2.5F, 3.5F);
Coordinate test_coord_rhs(1, 2, 3);
CHECK_EQ(test_coord, test_coord_rhs);
CHECK_EQ(test_coord, test_coord_float);
}
SUBCASE("Test equals") {
Coordinate testCoord(3, 2, 1);
Coordinate testCoordRHS(3, 2, 1);
CHECK_EQ(testCoord, testCoordRHS);
}
SUBCASE("Test not equals") {
Coordinate testCoord(3, 2, 1);
Coordinate testCoordRHS(2, 2, 1);
CHECK(testCoord != testCoordRHS);
CHECK_NE(testCoord, testCoordRHS);
}
SUBCASE("Test add") {
Coordinate testCoord(3, 2, 1);
Coordinate testCoordRHS(1, 2, 3);
Coordinate result(4, 4, 4);
CHECK_EQ((testCoord + testCoordRHS), result);
}
SUBCASE("Test subtract") {
Coordinate testCoord(1, 2, 3);
Coordinate testCoordRHS(0, 2, 4);
Coordinate result(1, 0, -1);
CHECK_EQ((testCoord - testCoordRHS), result);
}
SUBCASE("Test print") {
Coordinate testCoord(1, 2, 3);
std::stringstream ss;
ss << testCoord;
CHECK_EQ(ss.str(), "(1,2,3)");
}
}
TEST_CASE("Test block class") {
SUBCASE("Default ctor") {
BlockType def;
CHECK_EQ(def.id, 0);
CHECK_EQ(def.mod, 0);
}
SUBCASE("Test equality") {
BlockType testBlock(10, 2);
BlockType testBlockRHS(10, 2);
CHECK_EQ(testBlock, testBlockRHS);
}
SUBCASE("Test non equality") {
BlockType testBlock(10);
BlockType testBlockRHS(11);
CHECK(testBlock != testBlockRHS);
CHECK_NE(testBlock, testBlockRHS);
BlockType testBlockWithMod(10, 2);
BlockType testBlockWithModRHS(10, 3);
CHECK(testBlockWithMod != testBlockWithModRHS);
CHECK_NE(testBlockWithMod, testBlockWithModRHS);
}
SUBCASE("Test withMod") {
BlockType testBlock(10);
BlockType testBlockRHS(10, 2);
CHECK_EQ(testBlock.with_mod(2), testBlockRHS);
}
SUBCASE("Test print") {
BlockType testBlock(2, 3);
std::stringstream ss;
ss << testBlock;
CHECK_EQ(ss.str(), "[2, 3]");
}
}
// NOLINTEND