diff options
author | Mattes D <github@xoft.cz> | 2017-03-22 14:05:28 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-05-04 09:49:30 +0200 |
commit | c939720c103c6d4eac8a36cd26639b5b4b9f05cd (patch) | |
tree | 2990dcef8ebfda89e32b0a8cb0e567994077fb56 /tests/Generating | |
parent | Gen: Moved tests to a separate folder, unified shared sources. (diff) | |
download | cuberite-c939720c103c6d4eac8a36cd26639b5b4b9f05cd.tar cuberite-c939720c103c6d4eac8a36cd26639b5b4b9f05cd.tar.gz cuberite-c939720c103c6d4eac8a36cd26639b5b4b9f05cd.tar.bz2 cuberite-c939720c103c6d4eac8a36cd26639b5b4b9f05cd.tar.lz cuberite-c939720c103c6d4eac8a36cd26639b5b4b9f05cd.tar.xz cuberite-c939720c103c6d4eac8a36cd26639b5b4b9f05cd.tar.zst cuberite-c939720c103c6d4eac8a36cd26639b5b4b9f05cd.zip |
Diffstat (limited to '')
-rw-r--r-- | tests/Generating/CMakeLists.txt | 14 | ||||
-rw-r--r-- | tests/Generating/PieceGeneratorBFSTreeTest.cpp | 89 |
2 files changed, 103 insertions, 0 deletions
diff --git a/tests/Generating/CMakeLists.txt b/tests/Generating/CMakeLists.txt index 4efb9dbe2..269ab50ab 100644 --- a/tests/Generating/CMakeLists.txt +++ b/tests/Generating/CMakeLists.txt @@ -112,10 +112,24 @@ add_test(NAME PieceRotation-test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} C +# PieceGeneratorBFSTree test: +add_executable(PieceGeneratorBFSTree + PieceGeneratorBFSTreeTest.cpp + ${CMAKE_SOURCE_DIR}/src/Generating/PieceGeneratorBFSTree.cpp + ${CMAKE_SOURCE_DIR}/src/Generating/PieceGeneratorBFSTree.h +) +target_link_libraries(PieceGeneratorBFSTree GeneratorTestingSupport) +add_test(NAME PieceGeneratorBFSTree-test WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Server/Prefabs/PieceStructures COMMAND PieceGeneratorBFSTree) + + + + + # Put the projects into solution folders (MSVC): set_target_properties( GeneratorTestingSupport LoadablePieces + PieceGeneratorBFSTree PieceRotation PROPERTIES FOLDER Tests/Generating ) diff --git a/tests/Generating/PieceGeneratorBFSTreeTest.cpp b/tests/Generating/PieceGeneratorBFSTreeTest.cpp new file mode 100644 index 000000000..d302b1ad6 --- /dev/null +++ b/tests/Generating/PieceGeneratorBFSTreeTest.cpp @@ -0,0 +1,89 @@ +// PieceGeneratorBFSTreeTest.cpp + +// Implements the test for the cPieceGeneratorBFSTree class + +/* +Unlike most tests, this is actually not meant as much for unit-testing, but more like performance-testing. +Compile this project in Release mode, then run it in folder that has NetherFort.cubeset prefabs, too, using +a higher number of repetitions (each repetition takes time on the order of a second); investigate the +runtime performance with a profiler. + +The syntax to execute this test: +PieceGeneratorBFSTreeTest [<numRepetitions>] +numRepetitions is the number of NetherFort structures to be generated (default = 1) +*/ + + + + + +#include "Globals.h" +#include "Generating/PrefabPiecePool.h" +#include "Generating/PieceGeneratorBFSTree.h" + + + + + +static int test(int a_NumRepetitions) +{ + // Load the piece pool: + cPrefabPiecePool pool; + if (!pool.LoadFromFile("NetherFort.cubeset", true)) + { + LOGERROR("Cannot load the NetherFort cubeset. Please make sure that the NetherFort.cubeset file is present in the current dir and that it is a valid .cubeset file."); + return -1; + } + auto & generatorParams = pool.GetAllMetadata(); + auto maxDepth = GetStringMapInteger<int>(generatorParams, "MaxDepth", 5); + + // Perform repeated test of the generator: + auto start = std::chrono::high_resolution_clock::now(); + cPieceGeneratorBFSTree pg(pool, 1); + for (int i = 0; i < a_NumRepetitions; ++i) + { + cPlacedPieces placedPieces; + pg.PlacePieces(i * 512, 0, maxDepth, placedPieces); + placedPieces.clear(); + } // for i - numRepetitions + auto end = std::chrono::high_resolution_clock::now(); + + auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); + LOG("Performed %d repetition(s), took %.3f seconds", a_NumRepetitions, static_cast<double>(dur) / 1000); + return 0; +} + + + + + +int main(int argc, char * argv[]) +{ + LOGD("Starting the PieceGeneratorBFSTree test."); + + // Parse the cmdline parameters: + int numRepetitions = 1; + for (int i = 1; i < argc; ++i) + { + int rep = atoi(argv[i]); + if (rep > 0) + { + numRepetitions = rep; + } + } + LOGD("Performing %d repetitions", numRepetitions); + + auto res = test(numRepetitions); + if (res != 0) + { + LOGD("Test failed."); + return res; + } + + LOGD("The PieceGeneratorBFSTree test competed successfully."); + return 0; +} + + + + |