From 06f56d13d14cd4b03617f7a2a8cbf6bea0fcc36c Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 8 Dec 2015 11:14:01 +0100 Subject: [PATCH] added some octTreeTest tests and a few comments in OctTree --- src/Engine/Core/OctTree.cpp | 2 ++ src/Tests/OctTreeTest.cpp | 43 ++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Engine/Core/OctTree.cpp b/src/Engine/Core/OctTree.cpp index f98720be..7481e770 100644 --- a/src/Engine/Core/OctTree.cpp +++ b/src/Engine/Core/OctTree.cpp @@ -74,6 +74,7 @@ OctTree::~OctTree() { for (OctTree*& c : m_Children) { if (c != nullptr) { + //recursively delete (this calls the deconstructor again) delete c; c = nullptr; } @@ -166,6 +167,7 @@ void OctTree::AddBox(const AABB& box) } } +//remove the content (boxes) in the tree, but dont rememove the tree-structure void OctTree::ClearBoxes() { if (hasChildren()) { diff --git a/src/Tests/OctTreeTest.cpp b/src/Tests/OctTreeTest.cpp index 5392e63c..aad95381 100644 --- a/src/Tests/OctTreeTest.cpp +++ b/src/Tests/OctTreeTest.cpp @@ -2,13 +2,55 @@ using boost::unit_test_framework::test_suite; using boost::unit_test_framework::test_case; #include //srand +//HACK! Needed for white box testing +//else we would have to "open up" the octTree class more with get/sets, public methods, etc. which is not good encapsulation-wise +//friend class and refactoringIntoNewClass is some extra work and needs to be updated when the original class is updated, and can contain bugs that +//isnt in the original class +//Reflection-inspection seems to be only available for C# +//http://stackoverflow.com/questions/6778496/how-to-do-unit-testing-on-private-members-and-methods-of-c-classes +//http://stackoverflow.com/questions/3676664/unit-testing-of-private-methods +#define private public + #include BOOST_AUTO_TEST_SUITE(octTreeTests) BOOST_AUTO_TEST_CASE(octTreeTest) { + //white box testing + //http://softwaretestingfundamentals.com/differences-between-black-box-testing-and-white-box-testing/ + //http://technologyconversations.com/2013/12/11/black-box-vs-white-box-testing/ + //simple AABB constructor check + auto minCorner = glm::vec3(0.0f, 0.0f, 0.0f); + auto maxCorner = glm::vec3(1.0f, 1.0f, 1.0f); + auto someAABB = AABB(minCorner,maxCorner); + BOOST_CHECK(someAABB.MinCorner() == minCorner); + BOOST_CHECK(someAABB.MaxCorner() == maxCorner); + BOOST_CHECK(someAABB.Center() == 0.5f * (minCorner + maxCorner)); + + //simple OctTree constructor check + auto someOctTree = OctTree(someAABB, 5); + BOOST_CHECK(someOctTree.m_Children[0] != nullptr); + //TODO: a check so it split the tree properly + + + + + //advanced AddBox check + //add a boxcontainer - which crosses the mid-split + auto someAABB2 = AABB(glm::vec3(0.45f, 0.45f, 0.45f), glm::vec3(0.55f, 0.55f, 0.55f)); + someOctTree.AddBox(someAABB2); + //clear the boxcontainer + //need to check so it added the box properly + + + someOctTree.ClearBoxes(); + //add a boxcontainer + someOctTree.AddBox(someAABB2); + + + //simple destructor check in the end, just look for memleaks, then it didnt clear the AABB structure } BOOST_AUTO_TEST_CASE(octTreeTest2) @@ -17,4 +59,3 @@ BOOST_AUTO_TEST_CASE(octTreeTest2) } BOOST_AUTO_TEST_SUITE_END() -