[mlpack-git] master: Test move constructors. (9f51ae1)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Mon Oct 19 16:04:30 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/09cd0d67f2fdae252a8ab85324e71dbb4dfe0010...fecf1194c123ced12d56e7daad761c7b9aaac262

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

commit 9f51ae173077380fca10aeccf334fe1030663f3f
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Oct 18 10:20:04 2015 -0400

    Test move constructors.


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

9f51ae173077380fca10aeccf334fe1030663f3f
 src/mlpack/tests/tree_test.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp
index 5f6b1c4..6163bb0 100644
--- a/src/mlpack/tests/tree_test.cpp
+++ b/src/mlpack/tests/tree_test.cpp
@@ -120,6 +120,27 @@ BOOST_AUTO_TEST_CASE(HRectBoundClear)
   BOOST_REQUIRE_SMALL(b.MinWidth(), 1e-5);
 }
 
+BOOST_AUTO_TEST_CASE(HRectBoundMoveConstructor)
+{
+  HRectBound<EuclideanDistance> b(2);
+  b[0] = Range(0.0, 2.0);
+  b[1] = Range(2.0, 4.0);
+  b.MinWidth() = 1.0;
+
+  HRectBound<EuclideanDistance> b2(std::move(b));
+
+  BOOST_REQUIRE_EQUAL(b.Dim(), 0);
+  BOOST_REQUIRE_EQUAL(b2.Dim(), 2);
+
+  BOOST_REQUIRE_EQUAL(b.MinWidth(), 0.0);
+  BOOST_REQUIRE_EQUAL(b2.MinWidth(), 1.0);
+
+  BOOST_REQUIRE_SMALL(b2[0].Lo(), 1e-5);
+  BOOST_REQUIRE_CLOSE(b2[0].Hi(), 2.0, 1e-5);
+  BOOST_REQUIRE_CLOSE(b2[1].Lo(), 2.0, 1e-5);
+  BOOST_REQUIRE_CLOSE(b2[1].Hi(), 4.0, 1e-5);
+}
+
 /**
  * Ensure that we get the correct center for our bound.
  */
@@ -664,6 +685,22 @@ BOOST_AUTO_TEST_CASE(TestBallBound)
   BOOST_REQUIRE_CLOSE(b1.MaxDistance(b2.Center()), 1 + 0.3, 1e-5);
 }
 
+BOOST_AUTO_TEST_CASE(BallBoundMoveConstructor)
+{
+  BallBound<> b1(2.0, arma::vec("2 1 1"));
+  BallBound<> b2(std::move(b1));
+
+  BOOST_REQUIRE_EQUAL(b2.Dim(), 3);
+  BOOST_REQUIRE_EQUAL(b1.Dim(), 0);
+
+  BOOST_REQUIRE_CLOSE(b2.Center()[0], 2.0, 1e-5);
+  BOOST_REQUIRE_CLOSE(b2.Center()[1], 1.0, 1e-5);
+  BOOST_REQUIRE_CLOSE(b2.Center()[2], 1.0, 1e-5);
+
+  BOOST_REQUIRE_CLOSE(b2.MinWidth(), 4.0, 1e-5);
+  BOOST_REQUIRE_SMALL(b1.MinWidth(), 1e-5);
+}
+
 /**
  * Ensure that we calculate the correct minimum distance between a point and a
  * bound.
@@ -1527,6 +1564,18 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest)
 #endif // Using Armadillo 3.4.
 #endif // ARMA_HAS_SPMAT
 
+BOOST_AUTO_TEST_CASE(BinarySpaceTreeMoveConstructorTest)
+{
+  arma::mat dataset(5, 1000);
+  dataset.randu();
+
+  BinarySpaceTree<EuclideanDistance> tree(dataset);
+  BinarySpaceTree<EuclideanDistance> tree2(std::move(tree));
+
+  BOOST_REQUIRE_EQUAL(tree.NumChildren(), 0);
+  BOOST_REQUIRE_EQUAL(tree2.NumChildren(), 2);
+}
+
 template<typename TreeType>
 void RecurseTreeCountLeaves(const TreeType& node, arma::vec& counts)
 {



More information about the mlpack-git mailing list