[mlpack-git] master: Fix CoverTreeCopyConstructor test. (1652703)
gitdub at mlpack.org
gitdub at mlpack.org
Thu Aug 18 17:56:54 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/b067ee4bb6cff16be8efb1ad4923052bc12a13c5...31fe55d4c7d7cd6516b5d6c7d98ed93c5f0347fa
>---------------------------------------------------------------
commit 165270374f9e3baac3b8c837aa47429773b03a81
Author: MarcosPividori <marcos.pividori at gmail.com>
Date: Thu Aug 18 18:56:54 2016 -0300
Fix CoverTreeCopyConstructor test.
>---------------------------------------------------------------
165270374f9e3baac3b8c837aa47429773b03a81
src/mlpack/tests/tree_test.cpp | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp
index 8c0c936..35468a4 100644
--- a/src/mlpack/tests/tree_test.cpp
+++ b/src/mlpack/tests/tree_test.cpp
@@ -2078,9 +2078,10 @@ BOOST_AUTO_TEST_CASE(CoverTreeCopyConstructor)
TreeType d = c;
- // Check that everything is the same, except the dataset, which should have
- // been copied.
- BOOST_REQUIRE_NE(c.Dataset().memptr(), d.Dataset().memptr());
+ // Check that everything is the same.
+ // As the tree being copied doesn't own the dataset, they must share the same
+ // pointer.
+ BOOST_REQUIRE_EQUAL(c.Dataset().memptr(), d.Dataset().memptr());
BOOST_REQUIRE_CLOSE(c.Base(), d.Base(), 1e-50);
BOOST_REQUIRE_EQUAL(c.Point(), d.Point());
BOOST_REQUIRE_EQUAL(c.Scale(), d.Scale());
@@ -2098,8 +2099,6 @@ BOOST_AUTO_TEST_CASE(CoverTreeCopyConstructor)
BOOST_REQUIRE_EQUAL(d.Child(1).Parent(), &d);
// Check that the children are okay.
- BOOST_REQUIRE_NE(c.Child(0).Dataset().memptr(),
- d.Child(0).Dataset().memptr());
BOOST_REQUIRE_EQUAL(c.Child(0).Dataset().memptr(), c.Dataset().memptr());
BOOST_REQUIRE_CLOSE(c.Child(0).Base(), d.Child(0).Base(), 1e-50);
BOOST_REQUIRE_EQUAL(c.Child(0).Point(), d.Child(0).Point());
@@ -2109,8 +2108,6 @@ BOOST_AUTO_TEST_CASE(CoverTreeCopyConstructor)
d.Child(0).FurthestDescendantDistance());
BOOST_REQUIRE_EQUAL(c.Child(0).NumChildren(), d.Child(0).NumChildren());
- BOOST_REQUIRE_NE(c.Child(1).Dataset().memptr(),
- d.Child(1).Dataset().memptr());
BOOST_REQUIRE_EQUAL(c.Child(1).Dataset().memptr(), c.Dataset().memptr());
BOOST_REQUIRE_CLOSE(c.Child(1).Base(), d.Child(1).Base(), 1e-50);
BOOST_REQUIRE_EQUAL(c.Child(1).Point(), d.Child(1).Point());
@@ -2119,6 +2116,13 @@ BOOST_AUTO_TEST_CASE(CoverTreeCopyConstructor)
BOOST_REQUIRE_EQUAL(c.Child(1).FurthestDescendantDistance(),
d.Child(1).FurthestDescendantDistance());
BOOST_REQUIRE_EQUAL(c.Child(1).NumChildren(), d.Child(1).NumChildren());
+
+ // Check copy constructor when the tree being copied owns the dataset.
+ TreeType e(std::move(dataset), 1.3);
+ TreeType f = e;
+ // As the tree being copied owns the dataset, they must have different
+ // instances.
+ BOOST_REQUIRE_NE(e.Dataset().memptr(), f.Dataset().memptr());
}
BOOST_AUTO_TEST_CASE(CoverTreeMoveDatasetTest)
More information about the mlpack-git
mailing list