[mlpack-git] master: Add tests for Move and Copy constructors of SpilTrees. (f1253d3)

gitdub at mlpack.org gitdub at mlpack.org
Tue Aug 16 20:52:47 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/0f4b25acd6aaa14294c044874ba6cc0751712baa...0a19d07bd39e6223991976474bc79671ba8aa0f0

>---------------------------------------------------------------

commit f1253d37af50ab7df14a2c841c0a7345cec140e1
Author: MarcosPividori <marcos.pividori at gmail.com>
Date:   Tue Aug 16 21:52:47 2016 -0300

    Add tests for Move and Copy constructors of SpilTrees.


>---------------------------------------------------------------

f1253d37af50ab7df14a2c841c0a7345cec140e1
 src/mlpack/tests/spill_tree_test.cpp | 71 ++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/src/mlpack/tests/spill_tree_test.cpp b/src/mlpack/tests/spill_tree_test.cpp
index 277fcf1..857de82 100644
--- a/src/mlpack/tests/spill_tree_test.cpp
+++ b/src/mlpack/tests/spill_tree_test.cpp
@@ -232,6 +232,77 @@ BOOST_AUTO_TEST_CASE(SpillTreeHyperplaneTest)
 /**
  * Simple test for the move constructor.
  */
+BOOST_AUTO_TEST_CASE(SpillTreeMoveConstructorTest)
+{
+  arma::mat dataset = arma::randu<arma::mat>(3, 1000);
+  typedef SPTree<EuclideanDistance, EmptyStatistic, arma::mat> TreeType;
+
+  TreeType tree(dataset);
+
+  TreeType* left = tree.Left();
+  TreeType* right = tree.Right();
+  size_t numDesc = tree.NumDescendants();
+
+  TreeType newTree(std::move(tree));
+
+  BOOST_REQUIRE(tree.Left() == NULL);
+  BOOST_REQUIRE(tree.Right() == NULL);
+  BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 0);
+
+  BOOST_REQUIRE_EQUAL(newTree.Left(), left);
+  BOOST_REQUIRE_EQUAL(newTree.Right(), right);
+  BOOST_REQUIRE_EQUAL(newTree.NumDescendants(), numDesc);
+  if (left)
+  {
+    BOOST_REQUIRE(newTree.Left() != NULL);
+    BOOST_REQUIRE_EQUAL(newTree.Left()->Parent(), &newTree);
+  }
+  if (right)
+  {
+    BOOST_REQUIRE(newTree.Right() != NULL);
+    BOOST_REQUIRE_EQUAL(newTree.Right()->Parent(), &newTree);
+  }
+}
+
+/**
+ * Simple test for the copy constructor.
+ */
+BOOST_AUTO_TEST_CASE(SpillTreeCopyConstructorTest)
+{
+  arma::mat dataset = arma::randu<arma::mat>(3, 1000);
+  typedef SPTree<EuclideanDistance, EmptyStatistic, arma::mat> TreeType;
+
+  TreeType* tree = new TreeType(dataset);
+
+  TreeType* left = tree->Left();
+  TreeType* right = tree->Right();
+  size_t numDesc = tree->NumDescendants();
+
+  // Copy the tree.
+  TreeType newTree(*tree);
+
+  delete tree;
+
+  BOOST_REQUIRE_EQUAL(newTree.Dataset().n_rows, 3);
+  BOOST_REQUIRE_EQUAL(newTree.Dataset().n_cols, 1000);
+  BOOST_REQUIRE_EQUAL(newTree.NumDescendants(), numDesc);
+  if (left)
+  {
+    BOOST_REQUIRE(newTree.Left() != left);
+    BOOST_REQUIRE(newTree.Left() != NULL);
+    BOOST_REQUIRE_EQUAL(newTree.Left()->Parent(), &newTree);
+  }
+  if (right)
+  {
+    BOOST_REQUIRE(newTree.Right() != right);
+    BOOST_REQUIRE(newTree.Right() != NULL);
+    BOOST_REQUIRE_EQUAL(newTree.Right()->Parent(), &newTree);
+  }
+}
+
+/**
+ * Simple test for the constructor that takes a rvalue reference to the dataset.
+ */
 BOOST_AUTO_TEST_CASE(SpillTreeMoveDatasetTest)
 {
   arma::mat dataset = arma::randu<arma::mat>(3, 1000);




More information about the mlpack-git mailing list