[mlpack-git] master: Test the empty constructor. (a7d8231)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Fri Nov 20 17:33:40 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/962a37fe8374913c435054aa50e12d912bdfa01c...a7d8231fe7526dcfaadae0bf37d67b50d286e45d

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

commit a7d8231fe7526dcfaadae0bf37d67b50d286e45d
Author: Ryan Curtin <ryan at ratml.org>
Date:   Fri Nov 20 22:32:57 2015 +0000

    Test the empty constructor.


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

a7d8231fe7526dcfaadae0bf37d67b50d286e45d
 src/mlpack/tests/lsh_test.cpp | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/mlpack/tests/lsh_test.cpp b/src/mlpack/tests/lsh_test.cpp
index e83b17e..70c132d 100644
--- a/src/mlpack/tests/lsh_test.cpp
+++ b/src/mlpack/tests/lsh_test.cpp
@@ -132,4 +132,27 @@ BOOST_AUTO_TEST_CASE(LSHTrainTest)
   BOOST_REQUIRE_EQUAL(distances.n_rows, 3);
 }
 
+BOOST_AUTO_TEST_CASE(EmptyConstructorTest)
+{
+  // If we create an empty LSH model and then call Search(), it should throw an
+  // exception.
+  LSHSearch<> lsh;
+
+  arma::mat dataset = arma::randu<arma::mat>(5, 50);
+  arma::mat distances;
+  arma::Mat<size_t> neighbors;
+  BOOST_REQUIRE_THROW(lsh.Search(dataset, 2, neighbors, distances),
+      std::invalid_argument);
+
+  // Now, train.
+  lsh.Train(dataset, 4, 3, 3.0, 12, 4);
+
+  lsh.Search(dataset, 3, neighbors, distances);
+
+  BOOST_REQUIRE_EQUAL(neighbors.n_cols, 50);
+  BOOST_REQUIRE_EQUAL(neighbors.n_rows, 3);
+  BOOST_REQUIRE_EQUAL(distances.n_cols, 50);
+  BOOST_REQUIRE_EQUAL(distances.n_rows, 3);
+}
+
 BOOST_AUTO_TEST_SUITE_END();



More information about the mlpack-git mailing list