330 lines
9.2 KiB
C
330 lines
9.2 KiB
C
#include "VoxelSpace.h"
|
|
#include "lib/djstdlib/core.h"
|
|
|
|
typedef struct MismatchData MismatchData;
|
|
struct MismatchData {
|
|
int i;
|
|
uint64 actual;
|
|
uint64 expected;
|
|
};
|
|
DefineList(MismatchData, MismatchData);
|
|
|
|
void test() {
|
|
{
|
|
VoxelSpace space = {};
|
|
space.space=23ull;
|
|
space.dim_x=3;
|
|
space.dim_y=3;
|
|
space.dim_z=3;
|
|
|
|
Assert(filledAt(&space, 0, 0, 1) == true);
|
|
Assert(filledAt(&space, 1, 0, 0) == false);
|
|
Assert(filledAt(&space, 2, 1, 2) == false);
|
|
Assert(filledAt(&space, 1, 2, 1) == false);
|
|
Assert(filledAt(&space, 0, 0, 0) == true);
|
|
Assert(filledAt(&space, 2, 2, 1) == false);
|
|
|
|
space.space = 30ull;
|
|
Assert(filledAt(&space, 0, 0, 1) == true);
|
|
Assert(filledAt(&space, 1, 0, 0) == false);
|
|
Assert(filledAt(&space, 2, 1, 2) == false);
|
|
Assert(filledAt(&space, 1, 2, 1) == false);
|
|
Assert(filledAt(&space, 0, 0, 0) == false);
|
|
Assert(filledAt(&space, 2, 2, 1) == false);
|
|
|
|
space.space = 15ull;
|
|
Assert(filledAt(&space, 0, 0, 1) == true);
|
|
Assert(filledAt(&space, 1, 0, 0) == false);
|
|
Assert(filledAt(&space, 2, 1, 2) == false);
|
|
Assert(filledAt(&space, 1, 2, 1) == false);
|
|
Assert(filledAt(&space, 0, 0, 0) == true);
|
|
Assert(filledAt(&space, 2, 2, 1) == false);
|
|
|
|
space.space = 23ull;
|
|
Assert(filledAt(&space, 0, 0, 1) == true);
|
|
Assert(filledAt(&space, 1, 0, 0) == false);
|
|
Assert(filledAt(&space, 2, 1, 2) == false);
|
|
Assert(filledAt(&space, 1, 2, 1) == false);
|
|
Assert(filledAt(&space, 0, 0, 0) == true);
|
|
Assert(filledAt(&space, 2, 2, 1) == false);
|
|
};
|
|
|
|
{
|
|
VoxelSpace space1 = {};
|
|
space1.space=172ull;
|
|
space1.dim_x=3;
|
|
space1.dim_y=3;
|
|
space1.dim_z=3;
|
|
|
|
Assert(newIndexRotX(&space1, 0, 0, 0) == 6);
|
|
Assert(newIndexRotX(&space1, 1, 0, 1) == 12);
|
|
|
|
Assert(newIndexRotY(&space1, 0, 1, 0) == 5);
|
|
Assert(newIndexRotY(&space1, 1, 2, 0) == 7);
|
|
|
|
Assert(newIndexRotZ(&space1, 1, 0, 2) == 23);
|
|
Assert(newIndexRotZ(&space1, 0, 0, 0) == 18);
|
|
}
|
|
|
|
{
|
|
Arena *arena = arenaAlloc(Megabytes(64));
|
|
VoxelSpace space1 = {};
|
|
space1.space=30ull;
|
|
space1.dim_x=3;
|
|
space1.dim_y=3;
|
|
space1.dim_z=3;
|
|
|
|
VoxelSpaceList rotations = getUniqueRotations(arena, &space1);
|
|
VoxelSpace expected_rots[] = {
|
|
{ 30ull, 1, 2, 3 },
|
|
{ 45ull, 1, 3, 2 },
|
|
{ 30ull, 3, 2, 1 },
|
|
{ 30ull, 3, 1, 2 },
|
|
{ 45ull, 3, 2, 1 },
|
|
{ 45ull, 3, 1, 2 },
|
|
{ 51ull, 1, 2, 3 },
|
|
{ 30ull, 1, 3, 2 },
|
|
{ 30ull, 2, 3, 1 },
|
|
{ 30ull, 2, 1, 3 },
|
|
{ 51ull, 2, 3, 1 },
|
|
{ 51ull, 2, 1, 3 },
|
|
};
|
|
|
|
Assert(ArrayCount(expected_rots) == rotations.length);
|
|
|
|
for (int i = 0; i < rotations.length; i++) {
|
|
if (i <= ArrayCount(expected_rots)) {
|
|
Assert(isMatch(&expected_rots[i], &rotations.data[i]) == true);
|
|
}
|
|
}
|
|
|
|
arenaFree(arena);
|
|
}
|
|
|
|
{
|
|
Arena *arena = arenaAlloc(Megabytes(64));
|
|
|
|
VoxelSpace space1 = {};
|
|
space1.space=30ul;
|
|
space1.dim_x=3;
|
|
space1.dim_y=3;
|
|
space1.dim_z=3;
|
|
|
|
int prism_dims[] = { 3, 3, 3 };
|
|
VoxelSpaceReprList perms = getAllPermutationsInPrism(arena, &space1, prism_dims);
|
|
uint64 expected_perms[] = {
|
|
30ull,
|
|
240ull,
|
|
15360ull,
|
|
122880ull,
|
|
7864320ull,
|
|
62914560ull,
|
|
153ull,
|
|
306ull,
|
|
78336ull,
|
|
156672ull,
|
|
40108032ull,
|
|
80216064ull,
|
|
266760ull,
|
|
533520ull,
|
|
1067040ull,
|
|
2134080ull,
|
|
4268160ull,
|
|
8536320ull,
|
|
263682ull,
|
|
527364ull,
|
|
2109456ull,
|
|
4218912ull,
|
|
16875648ull,
|
|
33751296ull,
|
|
2101761ull,
|
|
4203522ull,
|
|
8407044ull,
|
|
16814088ull,
|
|
33628176ull,
|
|
67256352ull,
|
|
525825ull,
|
|
1051650ull,
|
|
4206600ull,
|
|
8413200ull,
|
|
33652800ull,
|
|
67305600ull,
|
|
51ull,
|
|
408ull,
|
|
26112ull,
|
|
208896ull,
|
|
13369344ull,
|
|
106954752ull,
|
|
90ull,
|
|
180ull,
|
|
46080ull,
|
|
92160ull,
|
|
23592960ull,
|
|
47185920ull,
|
|
4680ull,
|
|
9360ull,
|
|
18720ull,
|
|
2396160ull,
|
|
4792320ull,
|
|
9584640ull,
|
|
1542ull,
|
|
12336ull,
|
|
98688ull,
|
|
789504ull,
|
|
6316032ull,
|
|
50528256ull,
|
|
36873ull,
|
|
73746ull,
|
|
147492ull,
|
|
18878976ull,
|
|
37757952ull,
|
|
75515904ull,
|
|
3075ull,
|
|
24600ull,
|
|
196800ull,
|
|
1574400ull,
|
|
12595200ull,
|
|
100761600ull,
|
|
};
|
|
|
|
Assert(ArrayCount(expected_perms) == perms.length);
|
|
|
|
for (int i = 0; i < perms.length; i++) {
|
|
if (i <= ArrayCount(expected_perms)) {
|
|
Assert(expected_perms[i] == perms.data[i]);
|
|
}
|
|
}
|
|
|
|
arenaFree(arena);
|
|
}
|
|
|
|
{
|
|
VoxelSpace space1 = {};
|
|
space1.space=30ull;
|
|
space1.dim_x=3;
|
|
space1.dim_y=3;
|
|
space1.dim_z=3;
|
|
|
|
VoxelSpace space2 = {};
|
|
space2.space=30ull;
|
|
space2.dim_x=3;
|
|
space2.dim_y=3;
|
|
space2.dim_z=3;
|
|
|
|
VoxelSpace space3 = {};
|
|
space3.space=30ull;
|
|
space3.dim_x=3;
|
|
space3.dim_y=3;
|
|
space3.dim_z=3;
|
|
|
|
rotate90X(&space1);
|
|
rotate90Y(&space2);
|
|
rotate90Z(&space3);
|
|
Assert(space1.space == 153ull);
|
|
Assert(space2.space == 1067040ull);
|
|
Assert(space3.space == 1574400ull);
|
|
}
|
|
|
|
{
|
|
Arena *arena = arenaAlloc(Megabytes(64));
|
|
|
|
int dims[] = {3, 3, 3};
|
|
|
|
VoxelSpace space1 = {};
|
|
space1.space=30ull;
|
|
space1.dim_x=3;
|
|
space1.dim_y=3;
|
|
space1.dim_z=3;
|
|
|
|
cullEmptySpace(&space1);
|
|
uint64 expected_results1[] = {
|
|
30ull,
|
|
240ull,
|
|
15360ull,
|
|
122880ull,
|
|
7864320ull,
|
|
62914560ull,
|
|
};
|
|
|
|
VoxelSpace space2 = {};
|
|
space2.space=23ul;
|
|
space2.dim_x=3;
|
|
space2.dim_y=3;
|
|
space2.dim_z=3;
|
|
|
|
cullEmptySpace(&space2);
|
|
uint64_t expected_results2[] = {
|
|
23ull,
|
|
184ull,
|
|
11776ull,
|
|
94208ull,
|
|
6029312ull,
|
|
48234496ull,
|
|
};
|
|
|
|
VoxelSpace space3 = {};
|
|
space3.space=15ull;
|
|
space3.dim_x=3;
|
|
space3.dim_y=3;
|
|
space3.dim_z=3;
|
|
|
|
cullEmptySpace(&space3);
|
|
uint64 expected_results3[] = {
|
|
15ull,
|
|
120ull,
|
|
7680ull,
|
|
61440ull,
|
|
3932160ull,
|
|
31457280ull,
|
|
};
|
|
|
|
VoxelSpaceReprList positions1 = getAllPositionsInPrism(arena, &space1, dims);
|
|
VoxelSpaceReprList positions2 = getAllPositionsInPrism(arena, &space2, dims);
|
|
VoxelSpaceReprList positions3 = getAllPositionsInPrism(arena, &space3, dims);
|
|
|
|
MismatchDataList mismatches1 = PushList(arena, MismatchDataList, 6);
|
|
MismatchDataList mismatches2 = PushList(arena, MismatchDataList, 6);
|
|
MismatchDataList mismatches3 = PushList(arena, MismatchDataList, 6);
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
if (positions1.data[i] != expected_results1[i]) {
|
|
MismatchData data = { i, positions1.data[i], expected_results1[i] };
|
|
AppendList(&mismatches1, data);
|
|
}
|
|
if (positions2.data[i] != expected_results2[i]) {
|
|
MismatchData data = { i, positions2.data[i], expected_results2[i] };
|
|
AppendList(&mismatches2, data);
|
|
}
|
|
if (positions3.data[i] != expected_results3[i]) {
|
|
MismatchData data = { i, positions3.data[i], expected_results3[i] };
|
|
AppendList(&mismatches3, data);
|
|
}
|
|
}
|
|
Assert(mismatches1.length == 0);
|
|
if (mismatches1.length > 0) {
|
|
print("Index - Actual - Expected\n");
|
|
for (EachIn(mismatches1, i)) {
|
|
print("%zu - %zu - %zu\n", mismatches1.data[i].i, mismatches1.data[i].actual, mismatches1.data[i].expected);
|
|
}
|
|
}
|
|
Assert(mismatches2.length == 0);
|
|
if (mismatches2.length > 0) {
|
|
print("Index - Actual - Expected\n");
|
|
for (EachIn(mismatches2, i)) {
|
|
print("%zu - %zu - %zu\n", mismatches2.data[i].i, mismatches2.data[i].actual, mismatches2.data[i].expected);
|
|
}
|
|
}
|
|
Assert(mismatches3.length == 0);
|
|
if (mismatches3.length > 0) {
|
|
print("Index - Actual - Expected\n");
|
|
for (EachIn(mismatches3, i)) {
|
|
print("%zu - %zu - %zu\n", mismatches3.data[i].i, mismatches3.data[i].actual, mismatches3.data[i].expected);
|
|
}
|
|
}
|
|
|
|
arenaFree(arena);
|
|
}
|
|
}
|
|
|
|
|