Skip to content

Commit

Permalink
Add automated testing of the node split method
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Jul 22, 2020
1 parent c32ccd3 commit a72b77b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
46 changes: 45 additions & 1 deletion Octree/test/Octree/test_node.cpp
Expand Up @@ -2,10 +2,54 @@
#include <CGAL/Octree/Node.h>
#include <CGAL/Octree/IO.h>
#include <iostream>
#include <cassert>

typedef CGAL::Octree::Node::Node<int> Node;
typedef CGAL::Octree::Node::Node<std::vector<int>::iterator> Node;

int main(void) {

// Build a new node
Node n = Node();

// Check that its values are correct
assert(n.is_root());
assert(n.is_leaf());
assert(!n.parent());
assert(n.depth() == 0);
assert(n.location()[0] == 0 && n.location()[1] == 0 && n.location()[2] == 0);

// Split the node
n.split();

// Check that it's children's values are also correct
for (std::size_t i = 0; i < 8; ++i) {

assert(!n[i].is_root());
assert(n[i].is_leaf());
assert(*n[i].parent() == n);
assert(n[i].depth() == 1);
}

// Check that the parent has updated
assert(n.is_root());
assert(!n.is_leaf());

// Split one of the children
n[1].split();

// Check each of that child's children
for (std::size_t i = 0; i < 8; ++i) {

assert(!n[1][i].is_root());
assert(n[1][i].is_leaf());
assert(*n[1][i].parent() == n[1]);
assert(*n[1][i].parent()->parent() == n);
assert(n[1][i].depth() == 2);
}

// Check that the child's values have updated
assert(!n[1].is_root());
assert(!n[1].is_leaf());

return 0;
}
4 changes: 2 additions & 2 deletions Octree/test/Octree/test_octree_nearest_neighbor.cpp
Expand Up @@ -63,7 +63,7 @@ void naive_vs_octree(std::size_t dataset_size) {
<< "distance^2 of "
<< CGAL::squared_distance(naive_nearest, random_point) << " "
<< "with a time of "
<< naive_elapsed_time.count()
<< naive_elapsed_time.count() << "s "
<< std::endl;

// Do the same using the octree
Expand All @@ -84,7 +84,7 @@ void naive_vs_octree(std::size_t dataset_size) {
<< "distance^2 of "
<< CGAL::squared_distance(octree_nearest, random_point) << " "
<< "with a time of "
<< octree_elapsed_time.count()
<< octree_elapsed_time.count() << "s "
<< std::endl;

// Check that they produce the same answer
Expand Down

0 comments on commit a72b77b

Please sign in to comment.