#include #include #include #include "VoxelSpace.h" TEST(VoxelSpaces, BasicPositions) { auto space = Voxel::Space{ .space=23ul, .dim_x=3, .dim_y=3, .dim_z=3, }; EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 1), true); EXPECT_EQ(Voxel::filledAt(&space, 1, 0, 0), false); EXPECT_EQ(Voxel::filledAt(&space, 2, 1, 2), false); EXPECT_EQ(Voxel::filledAt(&space, 1, 2, 1), false); EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 0), true); EXPECT_EQ(Voxel::filledAt(&space, 2, 2, 1), false); space.space = 30ul; EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 1), true); EXPECT_EQ(Voxel::filledAt(&space, 1, 0, 0), false); EXPECT_EQ(Voxel::filledAt(&space, 2, 1, 2), false); EXPECT_EQ(Voxel::filledAt(&space, 1, 2, 1), false); EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 0), false); EXPECT_EQ(Voxel::filledAt(&space, 2, 2, 1), false); space.space = 15ul; EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 1), true); EXPECT_EQ(Voxel::filledAt(&space, 1, 0, 0), false); EXPECT_EQ(Voxel::filledAt(&space, 2, 1, 2), false); EXPECT_EQ(Voxel::filledAt(&space, 1, 2, 1), false); EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 0), true); EXPECT_EQ(Voxel::filledAt(&space, 2, 2, 1), false); space.space = 23ul; EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 1), true); EXPECT_EQ(Voxel::filledAt(&space, 1, 0, 0), false); EXPECT_EQ(Voxel::filledAt(&space, 2, 1, 2), false); EXPECT_EQ(Voxel::filledAt(&space, 1, 2, 1), false); EXPECT_EQ(Voxel::filledAt(&space, 0, 0, 0), true); EXPECT_EQ(Voxel::filledAt(&space, 2, 2, 1), false); } TEST(VoxelSpaces, RotatedIndices) { auto space1 = Voxel::Space{ .space=172ul, .dim_x=3, .dim_y=3, .dim_z=3, }; EXPECT_EQ(Voxel::newIndexRotX(&space1, 0, 0, 0), 6); EXPECT_EQ(Voxel::newIndexRotX(&space1, 1, 0, 1), 12); EXPECT_EQ(Voxel::newIndexRotY(&space1, 0, 1, 0), 5); EXPECT_EQ(Voxel::newIndexRotY(&space1, 1, 2, 0), 7); EXPECT_EQ(Voxel::newIndexRotZ(&space1, 1, 0, 2), 23); EXPECT_EQ(Voxel::newIndexRotZ(&space1, 0, 0, 0), 18); } TEST(VoxelSpaces, UniqueRotations) { auto space1 = Voxel::Space{ .space=30ul, .dim_x=3, .dim_y=3, .dim_z=3, }; auto rotations = Voxel::getUniqueRotations(&space1); auto expected_rots = std::vector{ { 30ul, 1, 2, 3 }, { 45ul, 1, 3, 2 }, { 30ul, 3, 2, 1 }, { 30ul, 3, 1, 2 }, { 45ul, 3, 2, 1 }, { 45ul, 3, 1, 2 }, { 51ul, 1, 2, 3 }, { 30ul, 1, 3, 2 }, { 30ul, 2, 3, 1 }, { 30ul, 2, 1, 3 }, { 51ul, 2, 3, 1 }, { 51ul, 2, 1, 3 }, }; ASSERT_EQ(expected_rots.size(), rotations.size()); for (int i = 0; i < rotations.size(); i++) { if (i <= expected_rots.size()) { EXPECT_EQ(Voxel::isMatch(&expected_rots.at(i), &rotations.at(i)), true); } } } TEST(VoxelSpaces, AllPermutationsInPrism) { auto space1 = Voxel::Space{ .space=30ul, .dim_x=3, .dim_y=3, .dim_z=3, }; auto prism_dims = std::array{ 3, 3, 3 }; auto perms = Voxel::getAllPermutationsInPrism(&space1, prism_dims.begin()); auto expected_perms = std::vector{ 30ul, 240ul, 15360ul, 122880ul, 7864320ul, 62914560ul, 153ul, 306ul, 78336ul, 156672ul, 40108032ul, 80216064ul, 266760ul, 533520ul, 1067040ul, 2134080ul, 4268160ul, 8536320ul, 263682ul, 527364ul, 2109456ul, 4218912ul, 16875648ul, 33751296ul, 2101761ul, 4203522ul, 8407044ul, 16814088ul, 33628176ul, 67256352ul, 525825ul, 1051650ul, 4206600ul, 8413200ul, 33652800ul, 67305600ul, 51ul, 408ul, 26112ul, 208896ul, 13369344ul, 106954752ul, 90ul, 180ul, 46080ul, 92160ul, 23592960ul, 47185920ul, 4680ul, 9360ul, 18720ul, 2396160ul, 4792320ul, 9584640ul, 1542ul, 12336ul, 98688ul, 789504ul, 6316032ul, 50528256ul, 36873ul, 73746ul, 147492ul, 18878976ul, 37757952ul, 75515904ul, 3075ul, 24600ul, 196800ul, 1574400ul, 12595200ul, 100761600ul, }; ASSERT_EQ(expected_perms.size(), perms.size()); for (int i = 0; i < perms.size(); i++) { if (i <= expected_perms.size()) { EXPECT_EQ(expected_perms.at(i), perms.at(i)); } } } TEST(VoxelSpaces, RotateXYZ) { auto space1 = Voxel::Space{ .space=30ul, .dim_x=3, .dim_y=3, .dim_z=3, }; auto space2 = Voxel::Space{ .space=30ul, .dim_x=3, .dim_y=3, .dim_z=3, }; auto space3 = Voxel::Space{ .space=30ul, .dim_x=3, .dim_y=3, .dim_z=3, }; Voxel::rotate90X(&space1); Voxel::rotate90Y(&space2); Voxel::rotate90Z(&space3); EXPECT_EQ(space1.space, 153ul); EXPECT_EQ(space2.space, 1067040ul); EXPECT_EQ(space3.space, 1574400ul); } TEST(VoxelSpaces, GetAllPositionsInPrism) { int dims[] = {3, 3, 3}; auto space1 = Voxel::Space{ .space=30ul, .dim_x=3, .dim_y=3, .dim_z=3, }; Voxel::cullEmptySpace(&space1); uint64_t expected_results1[] = { 30ul, 240ul, 15360ul, 122880ul, 7864320ul, 62914560ul, }; auto space2 = Voxel::Space{ .space=23ul, .dim_x=3, .dim_y=3, .dim_z=3, }; Voxel::cullEmptySpace(&space2); uint64_t expected_results2[] = { 23ul, 184ul, 11776ul, 94208ul, 6029312ul, 48234496ul, }; auto space3 = Voxel::Space{ .space=15ul, .dim_x=3, .dim_y=3, .dim_z=3, }; Voxel::cullEmptySpace(&space3); uint64_t expected_results3[] = { 15ul, 120ul, 7680ul, 61440ul, 3932160ul, 31457280ul, }; auto positions1 = Voxel::getAllPositionsInPrism(&space1, dims); auto positions2 = Voxel::getAllPositionsInPrism(&space2, dims); auto positions3 = Voxel::getAllPositionsInPrism(&space3, dims); auto mismatches1 = std::vector>(); auto mismatches2 = std::vector>(); auto mismatches3 = std::vector>(); for (int i = 0; i < 6; i++) { if (positions1[i] != expected_results1[i]) { mismatches1.push_back({ i, positions1[i], expected_results1[i] }); } if (positions2[i] != expected_results2[i]) { mismatches2.push_back({ i, positions2[i], expected_results2[i] }); } if (positions3[i] != expected_results3[i]) { mismatches3.push_back({ i, positions3[i], expected_results3[i] }); } } EXPECT_EQ(mismatches1.size(), 0); if (mismatches1.size() > 0) { std::cout << "Index - Actual - Expected" << std::endl; for (auto &mismatch : mismatches1) { std::cout << std::get<0>(mismatch) << " - " << std::get<1>(mismatch) << " - " << std::get<2>(mismatch) << std::endl; } } EXPECT_EQ(mismatches2.size(), 0); if (mismatches2.size() > 0) { std::cout << "Index - Actual - Expected" << std::endl; for (auto &mismatch : mismatches2) { std::cout << std::get<0>(mismatch) << " - " << std::get<1>(mismatch) << " - " << std::get<2>(mismatch) << std::endl; } } EXPECT_EQ(mismatches3.size(), 0); if (mismatches3.size() > 0) { std::cout << "Index - Actual - Expected" << std::endl; for (auto &mismatch : mismatches3) { std::cout << "At " << std::get<0>(mismatch) << ": " << std::get<1>(mismatch) << " != " << std::get<2>(mismatch) << std::endl; } } }