[mlpack-svn] r14106 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jan 10 13:21:25 EST 2013
Author: rcurtin
Date: 2013-01-10 13:21:25 -0500 (Thu, 10 Jan 2013)
New Revision: 14106
Added:
mlpack/trunk/src/mlpack/tests/tree_traits_test.cpp
Modified:
mlpack/trunk/src/mlpack/tests/CMakeLists.txt
Log:
Add test for tree traits.
Modified: mlpack/trunk/src/mlpack/tests/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/tests/CMakeLists.txt 2013-01-10 18:21:10 UTC (rev 14105)
+++ mlpack/trunk/src/mlpack/tests/CMakeLists.txt 2013-01-10 18:21:25 UTC (rev 14106)
@@ -7,6 +7,7 @@
arma_extend_test.cpp
aug_lagrangian_test.cpp
cli_test.cpp
+ det_test.cpp
distribution_test.cpp
emst_test.cpp
fastmks_test.cpp
@@ -34,8 +35,8 @@
sort_policy_test.cpp
sparse_coding_test.cpp
tree_test.cpp
+ tree_traits_test.cpp
union_find_test.cpp
- det_test.cpp
)
# Link dependencies of test executable.
target_link_libraries(mlpack_test
Added: mlpack/trunk/src/mlpack/tests/tree_traits_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/tree_traits_test.cpp (rev 0)
+++ mlpack/trunk/src/mlpack/tests/tree_traits_test.cpp 2013-01-10 18:21:25 UTC (rev 14106)
@@ -0,0 +1,64 @@
+/**
+ * @file tree_traits_test.cpp
+ * @author Ryan Curtin
+ *
+ * Tests for the TreeTraits class. These could all be known at compile-time,
+ * but realistically the function is to be sure that nobody changes tree traits
+ * without breaking something. Thus, people must be certain when they make a
+ * change like that (because they have to change the test too). That's the
+ * hope, at least...
+ */
+#include <mlpack/core.hpp>
+#include <mlpack/core/tree/tree_traits.hpp>
+#include <mlpack/core/tree/binary_space_tree.hpp>
+#include <mlpack/core/tree/cover_tree.hpp>
+
+#include <boost/test/unit_test.hpp>
+#include "old_boost_test_definitions.hpp"
+
+using namespace mlpack;
+using namespace mlpack::tree;
+using namespace mlpack::metric;
+
+BOOST_AUTO_TEST_SUITE(TreeTraitsTest);
+
+// Be careful! When writing new tests, always get the boolean value and store
+// it in a temporary, because the Boost unit test macros do weird things and
+// will cause bizarre problems.
+
+// Test the defaults.
+BOOST_AUTO_TEST_CASE(DefaultsTraitsTest)
+{
+ // An irrelevant non-tree type class is used here so that the default
+ // implementation of TreeTraits is chosen.
+ bool b = TreeTraits<int>::HasParentDistance;
+ BOOST_REQUIRE_EQUAL(b, false);
+ b = TreeTraits<int>::HasOverlappingChildren;
+ BOOST_REQUIRE_EQUAL(b, true);
+}
+
+// Test the binary space tree traits.
+BOOST_AUTO_TEST_CASE(BinarySpaceTreeTraitsTest)
+{
+ // ParentDistance() is not available.
+ bool b = TreeTraits<BinarySpaceTree<LMetric<2, false> > >::HasParentDistance;
+ BOOST_REQUIRE_EQUAL(b, false);
+
+ // Children are non-overlapping.
+ b = TreeTraits<BinarySpaceTree<LMetric<2, false> > >::HasOverlappingChildren;
+ BOOST_REQUIRE_EQUAL(b, false);
+}
+
+// Test the cover tree traits.
+BOOST_AUTO_TEST_CASE(CoverTreeTraitsTest)
+{
+ // ParentDistance() is available.
+ bool b = TreeTraits<CoverTree<> >::HasParentDistance;
+ BOOST_REQUIRE_EQUAL(b, true);
+
+ // Children may be overlapping.
+ b = TreeTraits<CoverTree<> >::HasOverlappingChildren;
+ BOOST_REQUIRE_EQUAL(b, true);
+}
+
+BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-svn
mailing list