-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.cpp
304 lines (259 loc) · 9.96 KB
/
test.cpp
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#include "test.hpp"
#include "Renderer/Renderer.hpp"
#include "Shapes/Cuboid.hpp"
#include "Shapes/Cylinder.hpp"
#include "Shapes/Sphere.hpp"
#include "Shapes/Tetrahedron.hpp"
#include "userInput/config/ConfigFile.hpp"
#include "miscFunctions.hpp"
#include "debugMisc.hpp"
#include <iostream>
#include <string>
#include <vector>
#include <ostream>
#include <random>
void test( )
{
bool l_mReceivedCorrectInput{ false };
char l_mInputChar{ };
std::cout << "\nSelect a test:" << std::endl;
std::cout << "[1] Test ray casting" << std::endl;
std::cout << "[2] Test ray casting NO. 2" << std::endl;
std::cout << "[3] Test cam rotation" << std::endl;
std::cout << "[4] Test file name parser" << std::endl;
std::cout << "[5] Test file saving" << std::endl;
std::cout << "[6] Test image data to 1D array conversion" << std::endl;
std::cout << "[7] Super Test" << std::endl;
do
{
std::cin >> l_mInputChar;
switch ( l_mInputChar )
{
case '1':
{
testRayCasting( );
l_mReceivedCorrectInput = true;
break;
}
case '2':
{
testRayCastingTwo( );
l_mReceivedCorrectInput = true;
break;
}
case '3':
{
testCamRotation( );
l_mReceivedCorrectInput = true;
break;
}
case '4':
{
testFilenameParser( );
l_mReceivedCorrectInput = true;
break;
}
case '5':
{
testFileSave( );
l_mReceivedCorrectInput = true;
break;
}
case '6':
{
testImageDataTo1DArray( );
l_mReceivedCorrectInput = true;
break;
}
case '7':
{
superTest( );
l_mReceivedCorrectInput = true;
break;
}
default:
{
throwDevWarning( "Invalid input!", __LINE__, __FILE__, __FUNCTION__ );
break;
}
}
}
while ( !l_mReceivedCorrectInput );
}
// this test tests if rays are cast correctly
void testRayCasting( )
{
extern ConfigFile g_ConfigFile;
const auto l_xSize = any_cast<const float>( g_ConfigFile.getConfigValue( "areaWidth" ));
Renderer l_renderer( -l_xSize / 2.0F, 0.0F, 90.0F );
l_renderer.testRenderer( );
}
void testRayCastingTwo( )
{
extern ConfigFile g_ConfigFile;
const float l_testedValues[9][2] = {
{ 1.0F, 1.0F },
{ 1.0F, 0.0F },
{ 1.0F, -1.0F },
{ .0F, 1.0F },
{ 0.0F, 0.0F },
{ 0.0F, -1.0F },
{ -1.0F, 1.0F },
{ -1.0F, 0.0F },
{ -1.0F, -1.0F }
};
std::cout << std::endl;
for ( auto l_item : l_testedValues )
{
const float l_x = l_item[0];
const float l_y = l_item[1];
Renderer l_renderer( l_x, l_y, 45.0F );
l_renderer.testRenderer( 100.0F, false );
}
}
void testCamRotation( )
{
const float l_testedValues[9][2] = {
{ 1.0F, 1.0F },
{ 1.0F, 0.0F },
{ 1.0F, -1.0F },
{ 0.0F, 1.0F },
{ 0.0F, 0.0F },
{ 0.0F, -1.0F },
{ -1.0F, 1.0F },
{ -1.0F, 0.0F },
{ -1.0F, -1.0F }
};
std::cout << "\nCamera rotation test results:" << std::endl;
for ( auto l_item : l_testedValues )
{
const float l_x = l_item[0];
const float l_y = l_item[1];
Renderer l_cam( l_x, l_y, 45.0F );
std::cout << "[" << l_x << "; " << l_y << "] \t" << l_cam.m_camRot.getDegrees( ) << std::endl;
}
for ( auto l_item : l_testedValues )
{
const float l_multiplier = 4.0F;
const float l_x = l_item[0] * l_multiplier;
const float l_y = l_item[1] * l_multiplier;
Renderer l_cam( l_x, l_y, 45.0F );
std::cout << "[" << l_x << "; " << l_y << "] \t" << l_cam.m_camRot.getDegrees( ) << std::endl;
}
}
void testFilenameParser( )
{
const auto l_correctFileName{ "correctFilename" };
const auto l_incorrectFileNameWithPath{ "incorrect/filename/with/path" };
const auto l_fileNameWithCorrectButUnnecessaryButCorrectExtension{ "filenameWithUnnecessaryButCorrectExtension.bmp" };
const auto l_filenameWithIncorrectExtension{ "filenameWithIncorrect.Extension" };
const auto l_filenameWithPathAndCorrectExtension{ "filename/with/path/and/correct/extension.bmp" };
const auto l_filenameWithPathAndIncorrectExtension{ "filename/with/path/and/incorrect.extension" };
std::cout << std::endl;
std::cout << "Filename parser test results: " << std::endl;
std::cout << "Correct file name original: " << l_correctFileName << std::endl;
std::cout << "Correct file name parsed: " << parseFileName( l_correctFileName ) << std::endl;
std::cout << std::endl;
std::cout << "Incorrect file name with path original: " << l_incorrectFileNameWithPath << std::endl;
std::cout << "Incorrect file name with path parsed: " << parseFileName( l_incorrectFileNameWithPath ) << std::endl;
std::cout << std::endl;
std::cout << "File name with correct but unnecessary extension original: " << l_fileNameWithCorrectButUnnecessaryButCorrectExtension << std::endl;
std::cout << "File name with correct but unnecessary extension parsed: " << parseFileName( l_fileNameWithCorrectButUnnecessaryButCorrectExtension ) << std::endl;
std::cout << std::endl;
std::cout << "File name with incorrect extension original: " << l_filenameWithIncorrectExtension << std::endl;
std::cout << "File name with incorrect extension parsed: " << parseFileName( l_filenameWithIncorrectExtension ) << std::endl;
std::cout << std::endl;
std::cout << "File name with path and correct extension original: " << l_filenameWithPathAndCorrectExtension << std::endl;
std::cout << "File name with path and correct extension parsed: " << parseFileName( l_filenameWithPathAndCorrectExtension ) << std::endl;
std::cout << std::endl;
std::cout << "File name with path and incorrect extension original: " << l_filenameWithPathAndIncorrectExtension << std::endl;
std::cout << "File name with path and incorrect extension parsed: " << parseFileName( l_filenameWithPathAndIncorrectExtension ) << std::endl;
}
void testFileSave( )
{
}
void testImageDataTo1DArray( )
{
extern ConfigFile g_ConfigFile;
const auto l_resolution = static_cast<unsigned long long>(std::any_cast<unsigned int>( g_ConfigFile.getConfigValue( "resolution" )));
unsigned long long l_i{ 0ULL };
unsigned long long l_j{ 0ULL };
unsigned long long l_k{ 0ULL };
std::vector<std::vector<std::vector<uint8_t>>> l_imageData{ };
std::random_device l_rd;
std::mt19937 l_gen( l_rd( ));
std::uniform_int_distribution<uint8_t> l_dis( 0U, 255U );
std::cout << "resolution: " << std::to_string( l_resolution ) << std::endl;
l_imageData.resize( l_resolution );
for ( auto &l_row : l_imageData )
{
l_row.resize( l_resolution );
/*for ( auto &l_pixels : l_row )
{
l_pixels.resize( 2ULL );
}*/
}
for ( unsigned long long l_a = 0ULL; l_a < l_resolution; ++l_a )
{
for ( unsigned long long l_b = 0ULL; l_b < l_resolution; ++l_b )
{
for ( unsigned long long l_c = 0ULL; l_c < 3ULL; ++l_c )
{
l_imageData[l_a][l_b].push_back( l_dis( l_gen ));
}
}
}
const auto l_imageDataAs1DArray = imageDataTo1DArray( l_imageData );
std::cout << "imageDataAs1DArray: " << sizeof(l_imageDataAs1DArray) / sizeof( uint8_t ) << std::endl;
for ( const auto &l_item0 : l_imageData )
{
for ( const auto &l_item1 : l_item0 )
{
for ( const auto l_item2 : l_item1 )
{
const bool l_equality{ l_item2 == l_imageDataAs1DArray[l_i * l_resolution * 3ULL + l_j * 3ULL + l_k] };
// std::cout << "Test" << std::endl;
std::cout << "Input array: " << std::to_string( static_cast<int>(l_item2))
<< " Output array: " << std::to_string( static_cast<int>(l_imageDataAs1DArray[l_i * l_resolution * 3ULL + l_j * 3ULL + l_k]))
<< " equality: " << (l_equality ? "true" : "false")
<< l_i << " " << l_j << " " << l_k
<< std::endl;
++l_k;
}
++l_j;
l_k = 0ULL;
}
++l_i;
l_j = 0ULL;
}
}
void superTest( )
{
extern ConfigFile g_ConfigFile;
const int l_cube1X = 4;
const int l_cube1Y = 4;
const uint8_t l_colorCube1[3] = { 255U, 0U, 0U };
const int l_cube2X = 4;
const int l_cube2Y = -4;
const uint8_t l_colorCube2[3] = { 0U, 255U, 0U };
const int l_cube3X = -4;
const int l_cube3Y = 4;
const uint8_t l_colorCube3[3] = { 0U, 0U, 255U };
const int l_cube4X = -4;
const int l_cube4Y = -4;
const uint8_t l_colorCube4[3] = { 0U, 0U, 0U };
const int l_sizeX = 1;
const int l_sizeY = 1;
const int l_sizeZ = 1;
const auto l_xSize = any_cast<const float>( g_ConfigFile.getConfigValue( "areaWidth" ));
Renderer l_renderer( 0.0F, 0.0F, 360.0F );
Cuboid l_cuboid1 = Cuboid( l_cube1X, l_cube1Y, l_sizeX, l_sizeY, l_sizeZ, l_colorCube1 );
Cuboid l_cuboid2 = Cuboid( l_cube2X, l_cube2Y, l_sizeX, l_sizeY, l_sizeZ, l_colorCube2 );
Cuboid l_cuboid3 = Cuboid( l_cube3X, l_cube3Y, l_sizeX, l_sizeY, l_sizeZ, l_colorCube3 );
Cuboid l_cuboid4 = Cuboid( l_cube4X, l_cube4Y, l_sizeX, l_sizeY, l_sizeZ, l_colorCube4 );
l_renderer.addShape( l_cuboid1.pack( ));
l_renderer.addShape( l_cuboid2.pack( ));
l_renderer.addShape( l_cuboid3.pack( ));
l_renderer.addShape( l_cuboid4.pack( ));
l_renderer.startRender( );
}