From 1e706933787cfa6774dd17577516e923a28acea9 Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Fri, 21 Aug 2020 12:34:15 +0530 Subject: [PATCH 01/45] migrate _tree_test_* related test from boost to catch2 --- src/mlpack/tests/CMakeLists.txt | 22 +- src/mlpack/tests/cosine_tree_test.cpp | 42 +- src/mlpack/tests/hoeffding_tree_test.cpp | 320 +++---- .../tests/main_tests/hoeffding_tree_test.cpp | 246 +++--- src/mlpack/tests/octree_test.cpp | 163 ++-- src/mlpack/tests/rectangle_tree_test.cpp | 476 +++++------ src/mlpack/tests/spill_tree_test.cpp | 89 +- src/mlpack/tests/sumtree_test.cpp | 48 +- src/mlpack/tests/tree_test.cpp | 779 +++++++++--------- src/mlpack/tests/tree_traits_test.cpp | 44 +- src/mlpack/tests/ub_tree_test.cpp | 58 +- src/mlpack/tests/vantage_point_tree_test.cpp | 121 ++- 12 files changed, 1170 insertions(+), 1238 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index efef3834ce..e1946c4842 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -8,7 +8,6 @@ add_executable(mlpack_test cf_test.cpp cli_binding_test.cpp io_test.cpp - cosine_tree_test.cpp cv_test.cpp dbscan_test.cpp dcgan_test.cpp @@ -22,7 +21,6 @@ add_executable(mlpack_test gan_test.cpp gmm_test.cpp hmm_test.cpp - hoeffding_tree_test.cpp hpt_test.cpp hyperplane_test.cpp init_rules_test.cpp @@ -54,7 +52,6 @@ add_executable(mlpack_test nca_test.cpp nmf_test.cpp nystroem_method_test.cpp - octree_test.cpp pca_test.cpp perceptron_test.cpp prefixedoutstream_test.cpp @@ -66,7 +63,6 @@ add_executable(mlpack_test random_test.cpp range_search_test.cpp rbm_network_test.cpp - rectangle_tree_test.cpp recurrent_network_test.cpp reward_clipping_test.cpp rl_components_test.cpp @@ -77,18 +73,12 @@ add_executable(mlpack_test sort_policy_test.cpp sparse_autoencoder_test.cpp sparse_coding_test.cpp - spill_tree_test.cpp string_encoding_test.cpp - sumtree_test.cpp termination_policy_test.cpp test_function_tools.hpp test_tools.hpp timer_test.cpp - tree_test.cpp - tree_traits_test.cpp - ub_tree_test.cpp union_find_test.cpp - vantage_point_tree_test.cpp wgan_test.cpp main_tests/bayesian_linear_regression_test.cpp main_tests/cf_test.cpp @@ -104,7 +94,6 @@ add_executable(mlpack_test main_tests/hmm_test_utils.hpp main_tests/hmm_train_test.cpp main_tests/hmm_viterbi_test.cpp - main_tests/hoeffding_tree_test.cpp main_tests/kde_test.cpp main_tests/kernel_pca_test.cpp main_tests/kmeans_test.cpp @@ -143,8 +132,10 @@ add_executable(mlpack_catch_test block_krylov_svd_test.cpp convolutional_network_test.cpp convolution_test.cpp + cosine_tree_test.cpp decision_stump_test.cpp decision_tree_test.cpp + hoeffding_tree_test.cpp image_load_test.cpp imputation_test.cpp kfn_test.cpp @@ -152,22 +143,31 @@ add_executable(mlpack_catch_test linear_regression_test.cpp load_save_test.cpp main.cpp + octree_test.cpp quic_svd_test.cpp randomized_svd_test.cpp + rectangle_tree_test.cpp regularized_svd_test.cpp scaling_test.cpp serialization_catch.cpp serialization_catch.hpp softmax_regression_test.cpp + spill_tree_test.cpp split_data_test.cpp + sumtree_test.cpp svd_batch_test.cpp svd_incremental_test.cpp svdplusplus_test.cpp test_catch_tools.hpp + tree_test.cpp + tree_traits_test.cpp + ub_tree_test.cpp + vantage_point_tree_test.cpp main_tests/adaboost_test.cpp main_tests/approx_kfn_test.cpp main_tests/decision_stump_test.cpp main_tests/decision_tree_test.cpp + main_tests/hoeffding_tree_test.cpp main_tests/image_converter_test.cpp main_tests/kfn_test.cpp main_tests/knn_test.cpp diff --git a/src/mlpack/tests/cosine_tree_test.cpp b/src/mlpack/tests/cosine_tree_test.cpp index a08ee7f254..66c6f08fcd 100644 --- a/src/mlpack/tests/cosine_tree_test.cpp +++ b/src/mlpack/tests/cosine_tree_test.cpp @@ -13,10 +13,8 @@ #include #include -#include -#include "test_tools.hpp" - -BOOST_AUTO_TEST_SUITE(CosineTreeTest); +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::tree; @@ -25,7 +23,7 @@ using namespace mlpack::tree; * Constructs a cosine tree with epsilon = 1. Checks if the root node is split * further, as it shouldn't be. */ -BOOST_AUTO_TEST_CASE(CosineTreeNoSplit) +TEST_CASE("CosineTreeNoSplit", "[CosineTreeTest]") { // Initialize constants required for the test. const size_t numRows = 10; @@ -44,14 +42,14 @@ BOOST_AUTO_TEST_CASE(CosineTreeNoSplit) // Since epsilon is one, there should be no splitting and the only vector in // the basis should come from the root node. - BOOST_REQUIRE_EQUAL(basis.n_cols, 1); + REQUIRE(basis.n_cols == 1); } /** * Checks CosineTree::CosineNodeSplit() by doing a depth first search on a * random dataset and checking if it satisfies the split condition. */ -BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) +TEST_CASE("CosineNodeCosineSplit", "[CosineTreeTest]") { // Initialize constants required for the test. const size_t numRows = 500; @@ -96,7 +94,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) rightIndices = currentRight->VectorIndices(); // The columns in the popped should be split into left and right nodes. - BOOST_REQUIRE_EQUAL(currentNode->NumColumns(), leftIndices.size() + + REQUIRE(currentNode->NumColumns() == leftIndices.size() + rightIndices.size()); // Calculate the cosine values for each of the columns in the node. @@ -125,12 +123,10 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) { // Check with some precision. for (i = 0; i < leftIndices.size(); ++i) - BOOST_REQUIRE_LT(cosineMax - cosines(i), - cosines(i) - cosineMin + precision); + REQUIRE(cosineMax - cosines(i) < cosines(i) - cosineMin + precision); for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) - BOOST_REQUIRE_GT(cosineMax - cosines(k), - cosines(k) - cosineMin - precision); + REQUIRE(cosineMax - cosines(k) > cosines(k) - cosineMin - precision); } else { @@ -156,7 +152,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) numMax2Errors++; // One of the maximum cosine values should be correct - BOOST_REQUIRE_EQUAL(std::min(numMax1Errors, numMax2Errors), 0); + REQUIRE(std::min(numMax1Errors, numMax2Errors) == 0); } } } @@ -166,7 +162,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) * Checks CosineTree::ModifiedGramSchmidt() by creating a random basis for the * vector subspace and checking if all the vectors are orthogonal to each other. */ -BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) +TEST_CASE("CosineTreeModifiedGramSchmidt", "[CosineTreeTest]") { // Initialize constants required for the test. const size_t numRows = 100; @@ -201,8 +197,8 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) for (; j != basisQueue.end(); ++j) { currentNode = *j; - BOOST_REQUIRE_SMALL(arma::dot(currentNode->BasisVector(), newBasisVector), - 1e-5); + REQUIRE(arma::dot(currentNode->BasisVector(), newBasisVector) == + Approx(0.0).margin(1e-5)); } // Add the obtained vector to the basis. @@ -225,7 +221,7 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) /** * Test the copy constructor & copy assignment using Cosine trees. */ -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorCosineTreeTest) +TEST_CASE("CopyConstructorAndOperatorCosineTreeTest", "[CosineTreeTest]") { // Initialize constants required for the test. const size_t numRows = 10; @@ -318,15 +314,15 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorCosineTreeTest) for (size_t i = 0; i < v1.size(); ++i) { - BOOST_REQUIRE_EQUAL(v1.at(i), v2.at(i)); - BOOST_REQUIRE_EQUAL(v1.at(i), v3.at(i)); + REQUIRE(v1.at(i) == v2.at(i)); + REQUIRE(v1.at(i) == v3.at(i)); } } /** * Test the move constructor & move assignment using Cosine trees. */ -BOOST_AUTO_TEST_CASE(MoveConstructorAndOperatorCosineTreeTest) +TEST_CASE("MoveConstructorAndOperatorCosineTreeTest", "[CosineTreeTest]") { // Initialize constants required for the test. const size_t numRows = 10; @@ -431,9 +427,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorAndOperatorCosineTreeTest) for (size_t i = 0; i < v1.size(); ++i) { - BOOST_REQUIRE_EQUAL(v1.at(i), v2.at(i)); - BOOST_REQUIRE_EQUAL(v1.at(i), v3.at(i)); + REQUIRE(v1.at(i) == v2.at(i)); + REQUIRE(v1.at(i) == v3.at(i)); } } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/hoeffding_tree_test.cpp b/src/mlpack/tests/hoeffding_tree_test.cpp index c5b96e024a..031d2c7ad8 100644 --- a/src/mlpack/tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/hoeffding_tree_test.cpp @@ -17,9 +17,9 @@ #include #include -#include -#include "test_tools.hpp" -#include "serialization.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" +#include "serialization_catch.hpp" #include @@ -30,9 +30,7 @@ using namespace mlpack::math; using namespace mlpack::data; using namespace mlpack::tree; -BOOST_AUTO_TEST_SUITE(HoeffdingTreeTest); - -BOOST_AUTO_TEST_CASE(GiniImpurityPerfectSimpleTest) +TEST_CASE("GiniImpurityPerfectSimpleTest", "[HoeffdingTreeTest]") { // Make a simple test for Gini impurity with one class. In this case it // should always be 0. We'll assemble the count matrix by hand. @@ -44,10 +42,10 @@ BOOST_AUTO_TEST_CASE(GiniImpurityPerfectSimpleTest) counts(1, 1) = 0; // 0 points in category 1 with class 1. // Since the split gets us nothing, there should be no gain. - BOOST_REQUIRE_SMALL(GiniImpurity::Evaluate(counts), 1e-10); + REQUIRE(GiniImpurity::Evaluate(counts) == Approx(0.0).margin(1e-10)); } -BOOST_AUTO_TEST_CASE(GiniImpurityImperfectSimpleTest) +TEST_CASE("GiniImpurityImperfectSimpleTest", "[HoeffdingTreeTest]") { // Make a simple test where a split will give us perfect classification. arma::Mat counts(2, 2); // 2 categories, 2 classes. @@ -60,10 +58,10 @@ BOOST_AUTO_TEST_CASE(GiniImpurityImperfectSimpleTest) // The impurity before the split should be 0.5^2 + 0.5^2 = 0.5. // The impurity after the split should be 0. // So the gain should be 0.5. - BOOST_REQUIRE_CLOSE(GiniImpurity::Evaluate(counts), 0.5, 1e-5); + REQUIRE(GiniImpurity::Evaluate(counts) == Approx(0.5).epsilon(1e-7)); } -BOOST_AUTO_TEST_CASE(GiniImpurityBadSplitTest) +TEST_CASE("GiniImpurityBadSplitTest", "[HoeffdingTreeTest]") { // Make a simple test where a split gets us nothing. arma::Mat counts(2, 2); @@ -72,14 +70,14 @@ BOOST_AUTO_TEST_CASE(GiniImpurityBadSplitTest) counts(1, 0) = 5; counts(1, 1) = 5; - BOOST_REQUIRE_SMALL(GiniImpurity::Evaluate(counts), 1e-10); + REQUIRE(GiniImpurity::Evaluate(counts) == Approx(0.0).margin(1e-10)); } /** * A hand-crafted more difficult test for the Gini impurity, where four * categories and three classes are available. */ -BOOST_AUTO_TEST_CASE(GiniImpurityThreeClassTest) +TEST_CASE("GiniImpurityThreeClassTest", "[HoeffdingTreeTest]") { arma::Mat counts(3, 4); @@ -106,34 +104,34 @@ BOOST_AUTO_TEST_CASE(GiniImpurityThreeClassTest) // (category 2) 0.28571 * 0.66667 - // (category 2) 0.23810 * 0.34 // = 0.26145 - BOOST_REQUIRE_CLOSE(GiniImpurity::Evaluate(counts), 0.26145, 1e-3); + REQUIRE(GiniImpurity::Evaluate(counts) == Approx(0.26145).epsilon(1e-5)); } -BOOST_AUTO_TEST_CASE(GiniImpurityZeroTest) +TEST_CASE("GiniImpurityZeroTest", "[HoeffdingTreeTest]") { // When nothing has been seen, the gini impurity should be zero. arma::Mat counts = arma::zeros>(10, 10); - BOOST_REQUIRE_SMALL(GiniImpurity::Evaluate(counts), 1e-10); + REQUIRE(GiniImpurity::Evaluate(counts) == Approx(0.0).margin(1e-10)); } /** * Test that the range of Gini impurities is correct for a handful of class * sizes. */ -BOOST_AUTO_TEST_CASE(GiniImpurityRangeTest) +TEST_CASE("GiniImpurityRangeTest", "[HoeffdingTreeTest]") { - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(1), 0, 1e-5); - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(2), 0.5, 1e-5); - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(3), 0.66666667, 1e-5); - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(4), 0.75, 1e-5); - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(5), 0.8, 1e-5); - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(10), 0.9, 1e-5); - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(100), 0.99, 1e-5); - BOOST_REQUIRE_CLOSE(GiniImpurity::Range(1000), 0.999, 1e-5); + REQUIRE(GiniImpurity::Range(1) == Approx(0).epsilon(1e-7)); + REQUIRE(GiniImpurity::Range(2) == Approx(0.5).epsilon(1e-7)); + REQUIRE(GiniImpurity::Range(3) == Approx(0.66666667).epsilon(1e-7)); + REQUIRE(GiniImpurity::Range(4) == Approx(0.75).epsilon(1e-7)); + REQUIRE(GiniImpurity::Range(5) == Approx(0.8).epsilon(1e-7)); + REQUIRE(GiniImpurity::Range(10) == Approx(0.9).epsilon(1e-7)); + REQUIRE(GiniImpurity::Range(100) == Approx(0.99).epsilon(1e-7)); + REQUIRE(GiniImpurity::Range(1000) == Approx(0.999).epsilon(1e-7)); } -BOOST_AUTO_TEST_CASE(InformationGainPerfectSimpleTest) +TEST_CASE("InformationGainPerfectSimpleTest", "[HoeffdingTreeTest]") { // Make a simple test for Gini impurity with one class. In this case it // should always be 0. We'll assemble the count matrix by hand. @@ -145,10 +143,10 @@ BOOST_AUTO_TEST_CASE(InformationGainPerfectSimpleTest) counts(1, 1) = 0; // 0 points in category 1 with class 1. // Since the split gets us nothing, there should be no gain. - BOOST_REQUIRE_SMALL(InformationGain::Evaluate(counts), 1e-10); + REQUIRE(InformationGain::Evaluate(counts) == Approx(0.0).margin(1e-10)); } -BOOST_AUTO_TEST_CASE(InformationGainImperfectSimpleTest) +TEST_CASE("InformationGainImperfectSimpleTest", "[HoeffdingTreeTest]") { // Make a simple test where a split will give us perfect classification. arma::Mat counts(2, 2); // 2 categories, 2 classes. @@ -161,10 +159,10 @@ BOOST_AUTO_TEST_CASE(InformationGainImperfectSimpleTest) // The impurity before the split should be 0.5 log2(0.5) + 0.5 log2(0.5) = -1. // The impurity after the split should be 0. // So the gain should be 1. - BOOST_REQUIRE_CLOSE(InformationGain::Evaluate(counts), 1.0, 1e-5); + REQUIRE(InformationGain::Evaluate(counts) == Approx(1.0).epsilon(1e-7)); } -BOOST_AUTO_TEST_CASE(InformationGainBadSplitTest) +TEST_CASE("InformationGainBadSplitTest", "[HoeffdingTreeTest]") { // Make a simple test where a split gets us nothing. arma::Mat counts(2, 2); @@ -173,14 +171,14 @@ BOOST_AUTO_TEST_CASE(InformationGainBadSplitTest) counts(1, 0) = 5; counts(1, 1) = 5; - BOOST_REQUIRE_SMALL(InformationGain::Evaluate(counts), 1e-10); + REQUIRE(InformationGain::Evaluate(counts) == Approx(0.0).margin(1e-10)); } /** * A hand-crafted more difficult test for the Gini impurity, where four * categories and three classes are available. */ -BOOST_AUTO_TEST_CASE(InformationGainThreeClassTest) +TEST_CASE("InformationGainThreeClassTest", "[HoeffdingTreeTest]") { arma::Mat counts(3, 4); @@ -207,38 +205,39 @@ BOOST_AUTO_TEST_CASE(InformationGainThreeClassTest) // (category 2) 0.28571 * -1.5850 - // (category 3) 0.23810 * -0.92193 // = 0.64116649 - BOOST_REQUIRE_CLOSE(InformationGain::Evaluate(counts), 0.64116649, 1e-5); + REQUIRE(InformationGain::Evaluate(counts) == + Approx(0.64116649).epsilon(1e-7)); } -BOOST_AUTO_TEST_CASE(InformationGainZeroTest) +TEST_CASE("InformationGainZeroTest", "[HoeffdingTreeTest]") { // When nothing has been seen, the information gain should be zero. arma::Mat counts = arma::zeros>(10, 10); - BOOST_REQUIRE_SMALL(InformationGain::Evaluate(counts), 1e-10); + REQUIRE(InformationGain::Evaluate(counts) == Approx(0.0).margin(1e-10)); } /** * Test that the range of information gains is correct for a handful of class * sizes. */ -BOOST_AUTO_TEST_CASE(InformationGainRangeTest) +TEST_CASE("InformationGainRangeTest", "[HoeffdingTreeTest]") { - BOOST_REQUIRE_CLOSE(InformationGain::Range(1), 0, 1e-5); - BOOST_REQUIRE_CLOSE(InformationGain::Range(2), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(InformationGain::Range(3), 1.5849625, 1e-5); - BOOST_REQUIRE_CLOSE(InformationGain::Range(4), 2, 1e-5); - BOOST_REQUIRE_CLOSE(InformationGain::Range(5), 2.32192809, 1e-5); - BOOST_REQUIRE_CLOSE(InformationGain::Range(10), 3.32192809, 1e-5); - BOOST_REQUIRE_CLOSE(InformationGain::Range(100), 6.64385619, 1e-5); - BOOST_REQUIRE_CLOSE(InformationGain::Range(1000), 9.96578428, 1e-5); + REQUIRE(InformationGain::Range(1) == Approx(0).epsilon(1e-7)); + REQUIRE(InformationGain::Range(2) == Approx(1.0).epsilon(1e-7)); + REQUIRE(InformationGain::Range(3) == Approx(1.5849625).epsilon(1e-7)); + REQUIRE(InformationGain::Range(4) == Approx(2).epsilon(1e-7)); + REQUIRE(InformationGain::Range(5) == Approx(2.32192809).epsilon(1e-7)); + REQUIRE(InformationGain::Range(10) == Approx(3.32192809).epsilon(1e-7)); + REQUIRE(InformationGain::Range(100) == Approx(6.64385619).epsilon(1e-7)); + REQUIRE(InformationGain::Range(1000) == Approx(9.96578428).epsilon(1e-7)); } /** * Feed the HoeffdingCategoricalSplit class many examples, all from the same * class, and verify that the majority class is correct. */ -BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitMajorityClassTest) +TEST_CASE("HoeffdingCategoricalSplitMajorityClassTest", "[HoeffdingTreeTest]") { // Ten categories, three classes. HoeffdingCategoricalSplit split(10, 3); @@ -246,14 +245,15 @@ BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitMajorityClassTest) for (size_t i = 0; i < 500; ++i) { split.Train(mlpack::math::RandInt(0, 10), 1); - BOOST_REQUIRE_EQUAL(split.MajorityClass(), 1); + REQUIRE(split.MajorityClass() == 1); } } /** * A harder majority class example. */ -BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitHarderMajorityClassTest) +TEST_CASE("HoeffdingCategoricalSplitHarderMajorityClassTest", + "[HoeffdingTreeTest]") { // Ten categories, three classes. HoeffdingCategoricalSplit split(10, 3); @@ -263,7 +263,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitHarderMajorityClassTest) { split.Train(mlpack::math::RandInt(0, 10), 1); split.Train(mlpack::math::RandInt(0, 10), 2); - BOOST_REQUIRE_EQUAL(split.MajorityClass(), 1); + REQUIRE(split.MajorityClass() == 1); } } @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitHarderMajorityClassTest) * Ensure that the fitness function is positive when we pass some data that * would result in an improvement if it was split. */ -BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitEasyFitnessCheck) +TEST_CASE("HoeffdingCategoricalSplitEasyFitnessCheck", "[HoeffdingTreeTest]") { HoeffdingCategoricalSplit split(5, 3); @@ -288,23 +288,24 @@ BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitEasyFitnessCheck) double bestGain, secondBestGain; split.EvaluateFitnessFunction(bestGain, secondBestGain); - BOOST_REQUIRE_GT(bestGain, 0.0); - BOOST_REQUIRE_SMALL(secondBestGain, 1e-10); + REQUIRE(bestGain > 0.0); + REQUIRE(secondBestGain == Approx(0.0).margin(1e-10)); } /** * Ensure that the fitness function returns 0 (no improvement) when a split * would not get us any improvement. */ -BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitNoImprovementFitnessTest) +TEST_CASE("HoeffdingCategoricalSplitNoImprovementFitnessTest", + "[HoeffdingTreeTest]") { HoeffdingCategoricalSplit split(2, 2); // No training has yet happened, so a split would get us nothing. double bestGain, secondBestGain; split.EvaluateFitnessFunction(bestGain, secondBestGain); - BOOST_REQUIRE_SMALL(bestGain, 1e-10); - BOOST_REQUIRE_SMALL(secondBestGain, 1e-10); + REQUIRE(bestGain == Approx(0.0).margin(1e-10)); + REQUIRE(secondBestGain == Approx(0.0).margin(1e-10)); split.Train(0, 0); split.Train(1, 0); @@ -313,14 +314,14 @@ BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitNoImprovementFitnessTest) // Now, a split still gets us only 50% accuracy in each split bin. split.EvaluateFitnessFunction(bestGain, secondBestGain); - BOOST_REQUIRE_SMALL(bestGain, 1e-10); - BOOST_REQUIRE_SMALL(secondBestGain, 1e-10); + REQUIRE(bestGain == Approx(0.0).margin(1e-10)); + REQUIRE(secondBestGain == Approx(0.0).margin(1e-10)); } /** * Test that when we do split, we get reasonable split information. */ -BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitSplitTest) +TEST_CASE("HoeffdingCategoricalSplitSplitTest", "[HoeffdingTreeTest]") { HoeffdingCategoricalSplit split(3, 3); // 3 categories. @@ -333,17 +334,17 @@ BOOST_AUTO_TEST_CASE(HoeffdingCategoricalSplitSplitTest) arma::Col childMajorities; split.Split(childMajorities, splitInfo); - BOOST_REQUIRE_EQUAL(childMajorities.n_elem, 3); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(0), 0); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(1), 1); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(2), 2); + REQUIRE(childMajorities.n_elem == 3); + REQUIRE(splitInfo.CalculateDirection(0) == 0); + REQUIRE(splitInfo.CalculateDirection(1) == 1); + REQUIRE(splitInfo.CalculateDirection(2) == 2); } /** * If we feed the HoeffdingTree a ton of points of the same class, it should * not suggest that we split. */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeNoSplitTest) +TEST_CASE("HoeffdingTreeNoSplitTest", "[HoeffdingTreeTest]") { // Make all dimensions categorical. data::DatasetInfo info(3); @@ -369,7 +370,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeNoSplitTest) testPoint(2) = mlpack::math::RandInt(0, 2); split.Train(testPoint, 0); // Always label 0. - BOOST_REQUIRE_EQUAL(split.SplitCheck(), 0); + REQUIRE(split.SplitCheck() == 0); } } @@ -377,7 +378,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeNoSplitTest) * If we feed the HoeffdingTree a ton of points of two different classes, it * should very clearly suggest that we split (eventually). */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeEasySplitTest) +TEST_CASE("HoeffdingTreeEasySplitTest", "[HoeffdingTreeTest]") { // It'll be a two-dimensional dataset with two categories each. In the first // dimension, category 0 will only receive points with class 0, and category 1 @@ -398,14 +399,14 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeEasySplitTest) } // Now it should be ready to split. - BOOST_REQUIRE_EQUAL(tree.SplitCheck(), 2); - BOOST_REQUIRE_EQUAL(tree.SplitDimension(), 0); + REQUIRE(tree.SplitCheck() == 2); + REQUIRE(tree.SplitDimension() == 0); } /** * If we force a success probability of 1, it should never split. */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeProbability1SplitTest) +TEST_CASE("HoeffdingTreeProbability1SplitTest", "[HoeffdingTreeTest]") { // It'll be a two-dimensional dataset with two categories each. In the first // dimension, category 0 will only receive points with class 0, and category 1 @@ -426,8 +427,8 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeProbability1SplitTest) } // But because the success probability is 1, it should never split. - BOOST_REQUIRE_EQUAL(split.SplitCheck(), 0); - BOOST_REQUIRE_EQUAL(split.SplitDimension(), size_t(-1)); + REQUIRE(split.SplitCheck() == 0); + REQUIRE(split.SplitDimension() == size_t(-1)); } /** @@ -435,7 +436,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeProbability1SplitTest) * perfect classification, another gives almost perfect classification (with 10% * error). Splits should occur after many samples. */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeAlmostPerfectSplit) +TEST_CASE("HoeffdingTreeAlmostPerfectSplit", "[HoeffdingTreeTest]") { // Two categories and two dimensions. data::DatasetInfo info(2); @@ -461,16 +462,16 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeAlmostPerfectSplit) } // Ensure that splitting should happen. - BOOST_REQUIRE_EQUAL(split.SplitCheck(), 2); + REQUIRE(split.SplitCheck() == 2); // Make sure that it's split on the correct dimension. - BOOST_REQUIRE_EQUAL(split.SplitDimension(), 1); + REQUIRE(split.SplitDimension() == 1); } /** * Test that the HoeffdingTree class will not split if the two features are * equally good. */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeEqualSplitTest) +TEST_CASE("HoeffdingTreeEqualSplitTest", "[HoeffdingTreeTest]") { // Two categories and two dimensions. data::DatasetInfo info(2); @@ -489,7 +490,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeEqualSplitTest) } // Ensure that splitting should not happen. - BOOST_REQUIRE_EQUAL(split.SplitCheck(), 0); + REQUIRE(split.SplitCheck() == 0); } // This is used in the next test. @@ -502,7 +503,7 @@ using HoeffdingSizeTNumericSplit = HoeffdingNumericSplit("cat0", 0); @@ -549,10 +550,10 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeSimpleDatasetTest) streamTree.Train(dataset.col(i), labels[i]); // Each tree should have a single split. - BOOST_REQUIRE_EQUAL(batchTree.NumChildren(), 3); - BOOST_REQUIRE_EQUAL(streamTree.NumChildren(), 3); - BOOST_REQUIRE_EQUAL(batchTree.SplitDimension(), 1); - BOOST_REQUIRE_EQUAL(streamTree.SplitDimension(), 1); + REQUIRE(batchTree.NumChildren() == 3); + REQUIRE(streamTree.NumChildren() == 3); + REQUIRE(batchTree.SplitDimension() == 1); + REQUIRE(streamTree.SplitDimension() == 1); // Now, classify all the points in the dataset. arma::Row batchLabels(9000); @@ -564,15 +565,15 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeSimpleDatasetTest) for (size_t i = 0; i < 9000; ++i) { - BOOST_REQUIRE_EQUAL(labels[i], streamLabels[i]); - BOOST_REQUIRE_EQUAL(labels[i], batchLabels[i]); + REQUIRE(labels[i] == streamLabels[i]); + REQUIRE(labels[i] == batchLabels[i]); } } /** * Make sure that a tree that does not split on anything. */ -BOOST_AUTO_TEST_CASE(NumDescendantsTest1) +TEST_CASE("NumDescendantsTest1", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(3, 500); @@ -592,13 +593,13 @@ BOOST_AUTO_TEST_CASE(NumDescendantsTest1) for (size_t i = 0; i < 500; ++i) streamTree.Train(dataset.col(i), labels[i]); // As there is just one label, there are no descendants. - BOOST_REQUIRE_EQUAL(streamTree.NumDescendants(), 0); + REQUIRE(streamTree.NumDescendants() == 0); } /** * Test that a tree that does split has some descendants. */ -BOOST_AUTO_TEST_CASE(NumDescendantsTest2) +TEST_CASE("NumDescendantsTest2", "[HoeffdingTreeTest]") { DatasetInfo info(3); info.MapString("cat0", 0); @@ -640,14 +641,14 @@ BOOST_AUTO_TEST_CASE(NumDescendantsTest2) HoeffdingCategoricalSplit> TreeType; TreeType batchTree(dataset, info, labels, 3, false); - BOOST_REQUIRE_EQUAL(batchTree.NumDescendants(), 3); + REQUIRE(batchTree.NumDescendants() == 3); } /** * Test that the HoeffdingNumericSplit class has a fitness function value of 0 * before it's seen enough points. */ -BOOST_AUTO_TEST_CASE(HoeffdingNumericSplitFitnessFunctionTest) +TEST_CASE("HoeffdingNumericSplitFitnessFunctionTest", "[HoeffdingTreeTest]") { HoeffdingNumericSplit split(5, 10, 100); @@ -658,22 +659,23 @@ BOOST_AUTO_TEST_CASE(HoeffdingNumericSplitFitnessFunctionTest) split.Train(mlpack::math::Random(), mlpack::math::RandInt(5)); double bestGain, secondBestGain; split.EvaluateFitnessFunction(bestGain, secondBestGain); - BOOST_REQUIRE_SMALL(bestGain, 1e-10); - BOOST_REQUIRE_SMALL(secondBestGain, 1e-10); + REQUIRE(bestGain == Approx(0.0).margin(1e-10)); + REQUIRE(secondBestGain == Approx(0.0).margin(1e-10)); } } /** * Make sure the majority class is correct in the samples before binning. */ -BOOST_AUTO_TEST_CASE(HoeffdingNumericSplitPreBinningMajorityClassTest) +TEST_CASE("HoeffdingNumericSplitPreBinningMajorityClassTest", + "[HoeffdingTreeTest]") { HoeffdingNumericSplit split(3, 10, 100); for (size_t i = 0; i < 100; ++i) { split.Train(mlpack::math::Random(), 1); - BOOST_REQUIRE_EQUAL(split.MajorityClass(), 1); + REQUIRE(split.MajorityClass() == 1); } } @@ -682,7 +684,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingNumericSplitPreBinningMajorityClassTest) * HoeffdingNumericSplit bins it reasonably into two bins and returns sensible * Gini impurity numbers. */ -BOOST_AUTO_TEST_CASE(HoeffdingNumericSplitBimodalTest) +TEST_CASE("HoeffdingNumericSplitBimodalTest", "[HoeffdingTreeTest]") { // 2 classes, 2 bins, 200 samples before binning. HoeffdingNumericSplit split(2, 2, 200); @@ -695,32 +697,32 @@ BOOST_AUTO_TEST_CASE(HoeffdingNumericSplitBimodalTest) // Push the majority class to 1. split.Train(-mlpack::math::Random() - 0.3, 1); - BOOST_REQUIRE_EQUAL(split.MajorityClass(), 1); + REQUIRE(split.MajorityClass() == 1); // Push the majority class back to 0. split.Train(mlpack::math::Random() + 0.3, 0); split.Train(mlpack::math::Random() + 0.3, 0); - BOOST_REQUIRE_EQUAL(split.MajorityClass(), 0); + REQUIRE(split.MajorityClass() == 0); // Now the binning should be complete, and so the impurity should be // (0.5 * (1 - 0.5)) * 2 = 0.50 (it will be 0 in the two created children). double bestGain, secondBestGain; split.EvaluateFitnessFunction(bestGain, secondBestGain); - BOOST_REQUIRE_CLOSE(bestGain, 0.50, 0.03); - BOOST_REQUIRE_SMALL(secondBestGain, 1e-10); + REQUIRE(bestGain == Approx(0.50).epsilon(0.0003)); + REQUIRE(secondBestGain == Approx(0.0).margin(1e-10)); // Make sure that if we do create children, that the correct number of // children is created, and that the bins end up in the right place. NumericSplitInfo<> info; arma::Col childMajorities; split.Split(childMajorities, info); - BOOST_REQUIRE_EQUAL(childMajorities.n_elem, 2); + REQUIRE(childMajorities.n_elem == 2); // Now check the split info. for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_NE(info.CalculateDirection(mlpack::math::Random() + 0.3), - info.CalculateDirection(-mlpack::math::Random() - 0.3)); + REQUIRE(info.CalculateDirection(mlpack::math::Random() + 0.3) != + info.CalculateDirection(-mlpack::math::Random() - 0.3)); } } @@ -729,7 +731,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingNumericSplitBimodalTest) * less than 1.0 is class 0 and anything greater is class 1. Then make sure it * can perform a perfect split. */ -BOOST_AUTO_TEST_CASE(BinaryNumericSplitSimpleSplitTest) +TEST_CASE("BinaryNumericSplitSimpleSplitTest", "[HoeffdingTreeTest]") { BinaryNumericSplit split(2); // 2 classes. @@ -744,8 +746,8 @@ BOOST_AUTO_TEST_CASE(BinaryNumericSplitSimpleSplitTest) // impurity for the children is 0. double bestGain, secondBestGain; split.EvaluateFitnessFunction(bestGain, secondBestGain); - BOOST_REQUIRE_CLOSE(bestGain, 0.5, 1e-5); - BOOST_REQUIRE_GT(bestGain, secondBestGain); + REQUIRE(bestGain == Approx(0.5).epsilon(1e-7)); + REQUIRE(bestGain > secondBestGain); } // Now, when we ask it to split, ensure that the split value is reasonable. @@ -753,21 +755,21 @@ BOOST_AUTO_TEST_CASE(BinaryNumericSplitSimpleSplitTest) BinaryNumericSplitInfo<> splitInfo; split.Split(childMajorities, splitInfo); - BOOST_REQUIRE_EQUAL(childMajorities[0], 0); - BOOST_REQUIRE_EQUAL(childMajorities[1], 1); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(0.5), 0); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(1.5), 1); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(0.0), 0); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(-1.0), 0); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(0.9), 0); - BOOST_REQUIRE_EQUAL(splitInfo.CalculateDirection(1.1), 1); + REQUIRE(childMajorities[0] == 0); + REQUIRE(childMajorities[1] == 1); + REQUIRE(splitInfo.CalculateDirection(0.5) == 0); + REQUIRE(splitInfo.CalculateDirection(1.5) == 1); + REQUIRE(splitInfo.CalculateDirection(0.0) == 0); + REQUIRE(splitInfo.CalculateDirection(-1.0) == 0); + REQUIRE(splitInfo.CalculateDirection(0.9) == 0); + REQUIRE(splitInfo.CalculateDirection(1.1) == 1); } /** * Create a BinaryNumericSplit object, feed it samples in the same way as * before, but with four classes. */ -BOOST_AUTO_TEST_CASE(BinaryNumericSplitSimpleFourClassSplitTest) +TEST_CASE("BinaryNumericSplitSimpleFourClassSplitTest", "[HoeffdingTreeTest]") { BinaryNumericSplit split(4); // 4 classes. @@ -784,8 +786,8 @@ BOOST_AUTO_TEST_CASE(BinaryNumericSplitSimpleFourClassSplitTest) // perfect child, giving a gain of 0.75 - 3 * (1/3 * 2/3) = 0.25. double bestGain, secondBestGain; split.EvaluateFitnessFunction(bestGain, secondBestGain); - BOOST_REQUIRE_CLOSE(bestGain, 0.25, 1e-5); - BOOST_REQUIRE_GE(bestGain, secondBestGain); + REQUIRE(bestGain == Approx(0.25).epsilon(1e-7)); + REQUIRE(bestGain >= secondBestGain); } // Now, when we ask it to split, ensure that the split value is reasonable. @@ -795,14 +797,14 @@ BOOST_AUTO_TEST_CASE(BinaryNumericSplitSimpleFourClassSplitTest) // We don't really care where it splits -- it can split anywhere. But it has // to split in only two directions. - BOOST_REQUIRE_EQUAL(childMajorities.n_elem, 2); + REQUIRE(childMajorities.n_elem == 2); } /** * Create a HoeffdingTree that uses the HoeffdingNumericSplit and make sure it * can split meaningfully on the correct dimension. */ -BOOST_AUTO_TEST_CASE(NumericHoeffdingTreeTest) +TEST_CASE("NumericHoeffdingTreeTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(3, 9000); @@ -835,10 +837,10 @@ BOOST_AUTO_TEST_CASE(NumericHoeffdingTreeTest) streamTree.Train(dataset.col(i), labels[i]); // Each tree should have at least one split. - BOOST_REQUIRE_GT(batchTree.NumChildren(), 0); - BOOST_REQUIRE_GT(streamTree.NumChildren(), 0); - BOOST_REQUIRE_EQUAL(batchTree.SplitDimension(), 1); - BOOST_REQUIRE_EQUAL(streamTree.SplitDimension(), 1); + REQUIRE(batchTree.NumChildren() > 0); + REQUIRE(streamTree.NumChildren() > 0); + REQUIRE(batchTree.SplitDimension() == 1); + REQUIRE(streamTree.SplitDimension() == 1); // Now, classify all the points in the dataset. arma::Row batchLabels(9000); @@ -859,15 +861,15 @@ BOOST_AUTO_TEST_CASE(NumericHoeffdingTreeTest) } // 66% accuracy shouldn't be too much to ask... - BOOST_REQUIRE_GT(streamCorrect, 6000); - BOOST_REQUIRE_GT(batchCorrect, 6000); + REQUIRE(streamCorrect > 6000); + REQUIRE(batchCorrect > 6000); } /** * The same as the previous test, but with the numeric binary split, and with a * categorical feature. */ -BOOST_AUTO_TEST_CASE(BinaryNumericHoeffdingTreeTest) +TEST_CASE("BinaryNumericHoeffdingTreeTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(4, 9000); @@ -904,10 +906,10 @@ BOOST_AUTO_TEST_CASE(BinaryNumericHoeffdingTreeTest) streamTree.Train(dataset.col(i), labels[i]); // Each tree should have at least one split. - BOOST_REQUIRE_GT(batchTree.NumChildren(), 0); - BOOST_REQUIRE_GT(streamTree.NumChildren(), 0); - BOOST_REQUIRE_EQUAL(batchTree.SplitDimension(), 1); - BOOST_REQUIRE_EQUAL(streamTree.SplitDimension(), 1); + REQUIRE(batchTree.NumChildren() > 0); + REQUIRE(streamTree.NumChildren() > 0); + REQUIRE(batchTree.SplitDimension() == 1); + REQUIRE(streamTree.SplitDimension() == 1); // Now, classify all the points in the dataset. arma::Row batchLabels(9000); @@ -928,14 +930,14 @@ BOOST_AUTO_TEST_CASE(BinaryNumericHoeffdingTreeTest) } // Require a pretty high accuracy: 95%. - BOOST_REQUIRE_GT(streamCorrect, 8550); - BOOST_REQUIRE_GT(batchCorrect, 8550); + REQUIRE(streamCorrect > 8550); + REQUIRE(batchCorrect > 8550); } /** * Test majority probabilities. */ -BOOST_AUTO_TEST_CASE(MajorityProbabilityTest) +TEST_CASE("MajorityProbabilityTest", "[HoeffdingTreeTest]") { data::DatasetInfo info(1); HoeffdingTree<> tree(info, 3); @@ -949,15 +951,15 @@ BOOST_AUTO_TEST_CASE(MajorityProbabilityTest) double probability; tree.Classify(arma::vec("1"), prediction, probability); - BOOST_REQUIRE_EQUAL(prediction, 0); - BOOST_REQUIRE_CLOSE(probability, 1.0, 1e-5); + REQUIRE(prediction == 0); + REQUIRE(probability == Approx(1.0).epsilon(1e-7)); // Make it impure. tree.Train(arma::vec("4"), 1); tree.Classify(arma::vec("3"), prediction, probability); - BOOST_REQUIRE_EQUAL(prediction, 0); - BOOST_REQUIRE_CLOSE(probability, 0.75, 1e-5); + REQUIRE(prediction == 0); + REQUIRE(probability == Approx(0.75).epsilon(1e-7)); // Flip the majority class. tree.Train(arma::vec("4"), 1); @@ -966,14 +968,14 @@ BOOST_AUTO_TEST_CASE(MajorityProbabilityTest) tree.Train(arma::vec("4"), 1); tree.Classify(arma::vec("3"), prediction, probability); - BOOST_REQUIRE_EQUAL(prediction, 1); - BOOST_REQUIRE_CLOSE(probability, 0.625, 1e-5); + REQUIRE(prediction == 1); + REQUIRE(probability == Approx(0.625).epsilon(1e-7)); } /** * Make sure that batch training mode outperforms non-batch mode. */ -BOOST_AUTO_TEST_CASE(BatchTrainingTest) +TEST_CASE("BatchTrainingTest", "[HoeffdingTreeTest]") { // We need to create a dataset with some amount of complexity, that must be // split in a handful of ways to accurately classify the data. An expanding @@ -1049,11 +1051,11 @@ BOOST_AUTO_TEST_CASE(BatchTrainingTest) // The batch tree must be a bit better than the stream tree. But not too // much, since the accuracy is already going to be very high. - BOOST_REQUIRE_GE(batchCorrect, streamCorrect); + REQUIRE(batchCorrect >= streamCorrect); } // Make sure that changing the confidence properly propagates to all leaves. -BOOST_AUTO_TEST_CASE(ConfidenceChangeTest) +TEST_CASE("ConfidenceChangeTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(4, 9000); @@ -1090,7 +1092,7 @@ BOOST_AUTO_TEST_CASE(ConfidenceChangeTest) ++i; } - BOOST_REQUIRE_LT(i, 9000); + REQUIRE(i < 9000); // Now we have split the root node, but we need to make sure we can feed // through the rest of the points while requiring a confidence of 1.0, and @@ -1106,11 +1108,11 @@ BOOST_AUTO_TEST_CASE(ConfidenceChangeTest) } for (size_t c = 0; c < tree.NumChildren(); ++c) - BOOST_REQUIRE_EQUAL(tree.Child(c).NumChildren(), 0); + REQUIRE(tree.Child(c).NumChildren() == 0); } //! Make sure parameter changes are propagated to children. -BOOST_AUTO_TEST_CASE(ParameterChangeTest) +TEST_CASE("ParameterChangeTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(4, 9000); @@ -1153,17 +1155,17 @@ BOOST_AUTO_TEST_CASE(ParameterChangeTest) HoeffdingTree<>* node = stack.top(); stack.pop(); - BOOST_REQUIRE_CLOSE(node->SuccessProbability(), 0.7, 1e-5); - BOOST_REQUIRE_EQUAL(node->MinSamples(), 17); - BOOST_REQUIRE_EQUAL(node->MaxSamples(), 192); - BOOST_REQUIRE_EQUAL(node->CheckInterval(), 3); + REQUIRE(node->SuccessProbability() == Approx(0.7).epsilon(1e-7)); + REQUIRE(node->MinSamples() == 17); + REQUIRE(node->MaxSamples() == 192); + REQUIRE(node->CheckInterval() == 3); for (size_t i = 0; i < node->NumChildren(); ++i) stack.push(&node->Child(i)); } } -BOOST_AUTO_TEST_CASE(MultipleSerializationTest) +TEST_CASE("MultipleSerializationTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(4, 9000); @@ -1216,12 +1218,12 @@ BOOST_AUTO_TEST_CASE(MultipleSerializationTest) for (size_t i = 0; i < deepPredictions.n_elem; ++i) { - BOOST_REQUIRE_EQUAL(shallowPredictions[i], deepPredictions[i]); + REQUIRE(shallowPredictions[i] == deepPredictions[i]); } } // Test the Hoeffding tree model. -BOOST_AUTO_TEST_CASE(HoeffdingTreeModelTest) +TEST_CASE("HoeffdingTreeModelTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(4, 3000); @@ -1288,19 +1290,19 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeModelTest) for (size_t i = 0; i < 3000; ++i) { // Check consistency of predictions. - BOOST_REQUIRE_EQUAL(predictions[i], predictions2[i]); + REQUIRE(predictions[i] == predictions2[i]); if (labels[i] == predictions[i]) ++correct; } // Require at least 95% accuracy. - BOOST_REQUIRE_GT(correct, 2850); + REQUIRE(correct > 2850); } } // Test the Hoeffding tree model in batch mode. -BOOST_AUTO_TEST_CASE(HoeffdingTreeModelBatchTest) +TEST_CASE("HoeffdingTreeModelBatchTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(4, 3000); @@ -1365,18 +1367,18 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeModelBatchTest) for (size_t i = 0; i < 3000; ++i) { // Check consistency of predictions. - BOOST_REQUIRE_EQUAL(predictions[i], predictions2[i]); + REQUIRE(predictions[i] == predictions2[i]); if (labels[i] == predictions[i]) ++correct; } // Require at least 95% accuracy. - BOOST_REQUIRE_GT(correct, 2850); + REQUIRE(correct > 2850); } } -BOOST_AUTO_TEST_CASE(HoeffdingTreeModelSerializationTest) +TEST_CASE("HoeffdingTreeModelSerializationTest", "[HoeffdingTreeTest]") { // Generate data. arma::mat dataset(4, 3000); @@ -1451,15 +1453,13 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeModelSerializationTest) for (size_t i = 0; i < 3000; ++i) { // Check consistency of predictions and probabilities. - BOOST_REQUIRE_EQUAL(predictions[i], predictionsXml[i]); - BOOST_REQUIRE_EQUAL(predictions[i], predictionsText[i]); - BOOST_REQUIRE_EQUAL(predictions[i], predictionsBinary[i]); + REQUIRE(predictions[i] == predictionsXml[i]); + REQUIRE(predictions[i] == predictionsText[i]); + REQUIRE(predictions[i] == predictionsBinary[i]); - BOOST_REQUIRE_CLOSE(probabilities[i], probabilitiesXml[i], 1e-5); - BOOST_REQUIRE_CLOSE(probabilities[i], probabilitiesText[i], 1e-5); - BOOST_REQUIRE_CLOSE(probabilities[i], probabilitiesBinary[i], 1e-5); + REQUIRE(probabilities[i] == Approx(probabilitiesXml[i]).epsilon(1e-7)); + REQUIRE(probabilities[i] == Approx(probabilitiesText[i]).epsilon(1e-7)); + REQUIRE(probabilities[i] == Approx(probabilitiesBinary[i]).epsilon(1e-7)); } } } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp b/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp index f3f45cbd40..df52ab0993 100644 --- a/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp @@ -18,8 +18,8 @@ static const std::string testName = "HoeffdingTree"; #include #include "test_helper.hpp" -#include -#include "../test_tools.hpp" +#include "../catch.hpp" +#include "../test_catch_tools.hpp" using namespace mlpack; using namespace data; @@ -41,27 +41,25 @@ struct HoeffdingTreeTestFixture } }; -BOOST_FIXTURE_TEST_SUITE(HoeffdingTreeMainTest, - HoeffdingTreeTestFixture); - /** * Check that number of output points and * number of input points are equal. */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeOutputDimensionTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingTreeOutputDimensionTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); size_t testSize = testData.n_cols; @@ -75,36 +73,34 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeOutputDimensionTest) mlpackMain(); // Check that number of output points are equal to number of input points. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_cols, testSize); - BOOST_REQUIRE_EQUAL(IO::GetParam("probabilities").n_cols, - testSize); + REQUIRE(IO::GetParam>("predictions").n_cols == testSize); + REQUIRE(IO::GetParam("probabilities").n_cols == testSize); // Check number of output rows equals 1 for probabilities and predictions. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_rows, 1); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_rows, 1); + REQUIRE(IO::GetParam>("predictions").n_rows == 1); + REQUIRE(IO::GetParam("probabilities").n_rows == 1); } /** * Check that number of output points and number * of input points are equal for categorical dataset. */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeCategoricalOutputDimensionTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, + "HoeffdingTreeCategoricalOutputDimensionTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; if (!data::Load("braziltourism.arff", inputData, info)) - BOOST_FAIL("Cannot load train dataset braziltourism.arff!"); + FAIL("Cannot load train dataset braziltourism.arff!"); arma::Row labels; if (!data::Load("braziltourism_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for braziltourism_labels.txt"); + FAIL("Cannot load labels for braziltourism_labels.txt"); arma::mat testData; if (!data::Load("braziltourism_test.arff", testData, info)) - BOOST_FAIL("Cannot load test dataset braziltourism_test.arff!"); + FAIL("Cannot load test dataset braziltourism_test.arff!"); size_t testSize = testData.n_cols; @@ -118,36 +114,33 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeCategoricalOutputDimensionTest) mlpackMain(); // Check that number of output points are equal to number of input points. - BOOST_REQUIRE_EQUAL(IO::GetParam> - ("predictions").n_cols, testSize); - BOOST_REQUIRE_EQUAL(IO::GetParam("probabilities").n_cols, - testSize); + REQUIRE(IO::GetParam>("predictions").n_cols == testSize); + REQUIRE(IO::GetParam("probabilities").n_cols == testSize); // Check number of output rows equals 1 for probabilities and predictions. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_rows, 1); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_rows, 1); + REQUIRE(IO::GetParam>("predictions").n_rows == 1); + REQUIRE(IO::GetParam("probabilities").n_rows == 1); } /** * Check whether providing labels explicitly and extracting from last * dimension give the same output. */ -BOOST_AUTO_TEST_CASE(HoeffdingTreeLabelLessTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingTreeLabelLessTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Append labels to the training set. inputData.resize(inputData.n_rows+1, inputData.n_cols); @@ -165,17 +158,13 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeLabelLessTest) mlpackMain(); // Check that number of output points are equal to number of input points. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_cols, testSize); - BOOST_REQUIRE_EQUAL(IO::GetParam("probabilities").n_cols, - testSize); + REQUIRE(IO::GetParam>("predictions").n_cols == testSize); + REQUIRE(IO::GetParam("probabilities").n_cols == testSize); // Check number of output rows equals number of classes in case of // probabilities and 1 for predictions. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_rows, 1); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_rows, 1); + REQUIRE(IO::GetParam>("predictions").n_rows == 1); + REQUIRE(IO::GetParam("probabilities").n_rows == 1); // Reset passed parameters. IO::GetSingleton().Parameters()["training"].wasPassed = false; @@ -199,16 +188,12 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeLabelLessTest) mlpackMain(); // Check that number of output points are equal to number of input points. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_cols, testSize); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_cols, testSize); + REQUIRE(IO::GetParam>("predictions").n_cols == testSize); + REQUIRE(IO::GetParam("probabilities").n_cols == testSize); // Check number of output rows equals 1 for probabilities and predictions. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_rows, 1); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_rows, 1); + REQUIRE(IO::GetParam>("predictions").n_rows == 1); + REQUIRE(IO::GetParam("probabilities").n_rows == 1); // Check that initial and current predictions are same. CheckMatrices( @@ -220,20 +205,21 @@ BOOST_AUTO_TEST_CASE(HoeffdingTreeLabelLessTest) /** * Ensure that saved model can be used again. */ -BOOST_AUTO_TEST_CASE(HoeffdingModelReuseTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingModelReuseTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); size_t testSize = testData.n_cols; @@ -257,7 +243,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingModelReuseTest) IO::GetSingleton().Parameters()["test"].wasPassed = false; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input trained model. SetInputParam("test", std::make_tuple(info, testData)); @@ -267,15 +253,12 @@ BOOST_AUTO_TEST_CASE(HoeffdingModelReuseTest) mlpackMain(); // Check that number of output points are equal to number of input points. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_cols, testSize); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_cols, testSize); + REQUIRE(IO::GetParam>("predictions").n_cols == testSize); + REQUIRE(IO::GetParam("probabilities").n_cols == testSize); // Check number of output rows equals 1 for probabilities and predictions. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_rows, 1); - BOOST_REQUIRE_EQUAL(IO::GetParam("probabilities").n_rows, 1); + REQUIRE(IO::GetParam>("predictions").n_rows == 1); + REQUIRE(IO::GetParam("probabilities").n_rows == 1); // Check that initial predictions and predictions using saved model are same. CheckMatrices( @@ -287,20 +270,21 @@ BOOST_AUTO_TEST_CASE(HoeffdingModelReuseTest) /** * Ensure that saved model trained on categorical dataset can be used again. */ -BOOST_AUTO_TEST_CASE(HoeffdingModelCategoricalReuseTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingModelCategoricalReuseTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; if (!data::Load("braziltourism.arff", inputData, info)) - BOOST_FAIL("Cannot load train dataset braziltourism.arff!"); + FAIL("Cannot load train dataset braziltourism.arff!"); arma::Row labels; if (!data::Load("braziltourism_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for braziltourism_labels.txt"); + FAIL("Cannot load labels for braziltourism_labels.txt"); arma::mat testData; if (!data::Load("braziltourism_test.arff", testData, info)) - BOOST_FAIL("Cannot load test dataset braziltourism_test.arff!"); + FAIL("Cannot load test dataset braziltourism_test.arff!"); size_t testSize = testData.n_cols; @@ -324,7 +308,7 @@ BOOST_AUTO_TEST_CASE(HoeffdingModelCategoricalReuseTest) probabilities = std::move(IO::GetParam("probabilities")); if (!data::Load("braziltourism_test.arff", testData, info)) - BOOST_FAIL("Cannot load test dataset braziltourism_test.arff!"); + FAIL("Cannot load test dataset braziltourism_test.arff!"); // Input trained model. SetInputParam("test", std::make_tuple(info, testData)); @@ -334,16 +318,12 @@ BOOST_AUTO_TEST_CASE(HoeffdingModelCategoricalReuseTest) mlpackMain(); // Check that number of output points are equal to number of input points. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_cols, testSize); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_cols, testSize); + REQUIRE(IO::GetParam>("predictions").n_cols == testSize); + REQUIRE(IO::GetParam("probabilities").n_cols == testSize); // Check number of output rows equals 1 for probabilities and predictions. - BOOST_REQUIRE_EQUAL( - IO::GetParam>("predictions").n_rows, 1); - BOOST_REQUIRE_EQUAL( - IO::GetParam("probabilities").n_rows, 1); + REQUIRE(IO::GetParam>("predictions").n_rows == 1); + REQUIRE(IO::GetParam("probabilities").n_rows == 1); // Check that initial predictions and predictions using saved model are same. CheckMatrices( @@ -355,21 +335,22 @@ BOOST_AUTO_TEST_CASE(HoeffdingModelCategoricalReuseTest) /** * Ensure that small min_samples creates larger model. */ -BOOST_AUTO_TEST_CASE(HoeffdingMinSamplesTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingMinSamplesTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; int nodes; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -395,13 +376,13 @@ BOOST_AUTO_TEST_CASE(HoeffdingMinSamplesTest) bindings::tests::CleanMemory(); if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -416,29 +397,29 @@ BOOST_AUTO_TEST_CASE(HoeffdingMinSamplesTest) mlpackMain(); // Check that small min_samples creates larger model. - BOOST_REQUIRE_LT( - (IO::GetParam("output_model"))->NumNodes(), + REQUIRE((IO::GetParam("output_model"))->NumNodes() < nodes); } /** * Ensure that large max_samples creates smaller model. */ -BOOST_AUTO_TEST_CASE(HoeffdingMaxSamplesTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingMaxSamplesTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; int nodes; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -464,13 +445,13 @@ BOOST_AUTO_TEST_CASE(HoeffdingMaxSamplesTest) bindings::tests::CleanMemory(); if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -485,28 +466,29 @@ BOOST_AUTO_TEST_CASE(HoeffdingMaxSamplesTest) mlpackMain(); // Check that large max_samples creates smaller model. - BOOST_REQUIRE_LT(nodes, + REQUIRE(nodes < (IO::GetParam("output_model"))->NumNodes()); } /** * Ensure that small confidence value creates larger model. */ -BOOST_AUTO_TEST_CASE(HoeffdingConfidenceTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingConfidenceTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; int nodes; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -531,13 +513,13 @@ BOOST_AUTO_TEST_CASE(HoeffdingConfidenceTest) bindings::tests::CleanMemory(); if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -551,28 +533,29 @@ BOOST_AUTO_TEST_CASE(HoeffdingConfidenceTest) mlpackMain(); // Check that higher confidence creates smaller tree. - BOOST_REQUIRE_LT(nodes, + REQUIRE(nodes < (IO::GetParam("output_model"))->NumNodes()); } /** * Ensure that large number of passes creates larger model. */ -BOOST_AUTO_TEST_CASE(HoeffdingPassesTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingPassesTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; int nodes; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -597,13 +580,13 @@ BOOST_AUTO_TEST_CASE(HoeffdingPassesTest) bindings::tests::CleanMemory(); if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -618,27 +601,29 @@ BOOST_AUTO_TEST_CASE(HoeffdingPassesTest) mlpackMain(); // Check that model with larger number of passes has greater number of nodes. - BOOST_REQUIRE_LT(nodes, + REQUIRE(nodes < (IO::GetParam("output_model"))->NumNodes()); } /** * Ensure that the root node has 2 children when splitting strategy is binary. */ -BOOST_AUTO_TEST_CASE(HoeffdingBinarySplittingStrategyTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, + "HoeffdingBinarySplittingStrategyTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -655,28 +640,30 @@ BOOST_AUTO_TEST_CASE(HoeffdingBinarySplittingStrategyTest) mlpackMain(); // Check that number of children is 2. - BOOST_REQUIRE_EQUAL( - (IO::GetParam("output_model"))->NumNodes()-1, 2); + REQUIRE((IO::GetParam("output_model"))->NumNodes()-1 + == 2); } /** * Ensure that the number of children varies with varying 'bins' in domingos. */ -BOOST_AUTO_TEST_CASE(HoeffdingDomingosSplittingStrategyTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, + "HoeffdingDomingosSplittingStrategyTest", + "[HoeffdingTreeMainTest][BindingTest]") { arma::mat inputData; DatasetInfo info; int nodes; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -705,13 +692,13 @@ BOOST_AUTO_TEST_CASE(HoeffdingDomingosSplittingStrategyTest) bindings::tests::CleanMemory(); if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); // Input training data. SetInputParam("training", std::make_tuple(info, inputData)); @@ -727,30 +714,31 @@ BOOST_AUTO_TEST_CASE(HoeffdingDomingosSplittingStrategyTest) mlpackMain(); // Check that both models have different number of nodes. - BOOST_CHECK_NE( - (IO::GetParam("output_model"))->NumNodes(), nodes); + CHECK((IO::GetParam("output_model"))->NumNodes() != + nodes); } /** * Ensure that the model doesn't split if observations before binning * is greater than total number of samples passed. */ -BOOST_AUTO_TEST_CASE(HoeffdingBinningTest) +TEST_CASE_METHOD(HoeffdingTreeTestFixture, "HoeffdingBinningTest", + "[HoeffdingTreeMainTest][BindingTests]") { arma::mat inputData; arma::mat modData; arma::Row modLabels; DatasetInfo info; if (!data::Load("vc2.csv", inputData, info)) - BOOST_FAIL("Cannot load train dataset vc2.csv!"); + FAIL("Cannot load train dataset vc2.csv!"); arma::Row labels; if (!data::Load("vc2_labels.txt", labels)) - BOOST_FAIL("Cannot load labels for vc2_labels.txt"); + FAIL("Cannot load labels for vc2_labels.txt"); arma::mat testData; if (!data::Load("vc2_test.csv", testData, info)) - BOOST_FAIL("Cannot load test dataset vc2.csv!"); + FAIL("Cannot load test dataset vc2.csv!"); modData = inputData.cols(0, 49); modLabels = labels.cols(0, 49); @@ -772,8 +760,6 @@ BOOST_AUTO_TEST_CASE(HoeffdingBinningTest) mlpackMain(); // Check that no splitting has happened. - BOOST_REQUIRE_EQUAL( - (IO::GetParam("output_model"))->NumNodes(), 1); + REQUIRE((IO::GetParam("output_model"))->NumNodes() + == 1); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/octree_test.cpp b/src/mlpack/tests/octree_test.cpp index a15285e093..8e41e4d932 100644 --- a/src/mlpack/tests/octree_test.cpp +++ b/src/mlpack/tests/octree_test.cpp @@ -12,9 +12,9 @@ #include #include -#include -#include "test_tools.hpp" -#include "serialization.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" +#include "serialization_catch.hpp" using namespace mlpack; using namespace mlpack::math; @@ -22,28 +22,26 @@ using namespace mlpack::tree; using namespace mlpack::metric; using namespace mlpack::bound; -BOOST_AUTO_TEST_SUITE(OctreeTest); - /** * Build a quad-tree (2-d octree) on 4 points, and guarantee four points are * created. */ -BOOST_AUTO_TEST_CASE(SimpleQuadtreeTest) +TEST_CASE("SimpleQuadtreeTest", "[OctreeTest]") { // Four corners of the unit square. arma::mat dataset("0 0 1 1; 0 1 0 1"); Octree<> t(dataset, 1); - BOOST_REQUIRE_EQUAL(t.NumChildren(), 4); - BOOST_REQUIRE_EQUAL(t.Dataset().n_cols, 4); - BOOST_REQUIRE_EQUAL(t.Dataset().n_rows, 2); - BOOST_REQUIRE_EQUAL(t.NumDescendants(), 4); - BOOST_REQUIRE_EQUAL(t.NumPoints(), 0); + REQUIRE(t.NumChildren() == 4); + REQUIRE(t.Dataset().n_cols == 4); + REQUIRE(t.Dataset().n_rows == 2); + REQUIRE(t.NumDescendants() == 4); + REQUIRE(t.NumPoints() == 0); for (size_t i = 0; i < 4; ++i) { - BOOST_REQUIRE_EQUAL(t.Child(i).NumDescendants(), 1); - BOOST_REQUIRE_EQUAL(t.Child(i).NumPoints(), 1); + REQUIRE(t.Child(i).NumDescendants() == 1); + REQUIRE(t.Child(i).NumPoints() == 1); } } @@ -51,62 +49,62 @@ BOOST_AUTO_TEST_CASE(SimpleQuadtreeTest) * Build an octree on 3 points and make sure that only three children are * created. */ -BOOST_AUTO_TEST_CASE(OctreeMissingChildTest) +TEST_CASE("OctreeMissingChildTest", "[OctreeTest]") { // Only three corners of the unit square. arma::mat dataset("0 0 1; 0 1 1"); Octree<> t(dataset, 1); - BOOST_REQUIRE_EQUAL(t.NumChildren(), 3); - BOOST_REQUIRE_EQUAL(t.Dataset().n_cols, 3); - BOOST_REQUIRE_EQUAL(t.Dataset().n_rows, 2); - BOOST_REQUIRE_EQUAL(t.NumDescendants(), 3); - BOOST_REQUIRE_EQUAL(t.NumPoints(), 0); + REQUIRE(t.NumChildren() == 3); + REQUIRE(t.Dataset().n_cols == 3); + REQUIRE(t.Dataset().n_rows == 2); + REQUIRE(t.NumDescendants() == 3); + REQUIRE(t.NumPoints() == 0); for (size_t i = 0; i < 3; ++i) { - BOOST_REQUIRE_EQUAL(t.Child(i).NumDescendants(), 1); - BOOST_REQUIRE_EQUAL(t.Child(i).NumPoints(), 1); + REQUIRE(t.Child(i).NumDescendants() == 1); + REQUIRE(t.Child(i).NumPoints() == 1); } } /** * Ensure that building an empty octree does not fail. */ -BOOST_AUTO_TEST_CASE(EmptyOctreeTest) +TEST_CASE("EmptyOctreeTest", "[OctreeTest]") { arma::mat dataset; Octree<> t(dataset); - BOOST_REQUIRE_EQUAL(t.NumChildren(), 0); - BOOST_REQUIRE_EQUAL(t.Dataset().n_cols, 0); - BOOST_REQUIRE_EQUAL(t.Dataset().n_rows, 0); - BOOST_REQUIRE_EQUAL(t.NumDescendants(), 0); - BOOST_REQUIRE_EQUAL(t.NumPoints(), 0); + REQUIRE(t.NumChildren() == 0); + REQUIRE(t.Dataset().n_cols == 0); + REQUIRE(t.Dataset().n_rows == 0); + REQUIRE(t.NumDescendants() == 0); + REQUIRE(t.NumPoints() == 0); } /** * Ensure that maxLeafSize is respected. */ -BOOST_AUTO_TEST_CASE(MaxLeafSizeTest) +TEST_CASE("MaxLeafSizeTest", "[OctreeTest]") { arma::mat dataset(5, 15, arma::fill::randu); Octree<> t1(dataset, 20); Octree<> t2(std::move(dataset), 20); - BOOST_REQUIRE_EQUAL(t1.NumChildren(), 0); - BOOST_REQUIRE_EQUAL(t1.NumDescendants(), 15); - BOOST_REQUIRE_EQUAL(t1.NumPoints(), 15); + REQUIRE(t1.NumChildren() == 0); + REQUIRE(t1.NumDescendants() == 15); + REQUIRE(t1.NumPoints() == 15); - BOOST_REQUIRE_EQUAL(t2.NumChildren(), 0); - BOOST_REQUIRE_EQUAL(t2.NumDescendants(), 15); - BOOST_REQUIRE_EQUAL(t2.NumPoints(), 15); + REQUIRE(t2.NumChildren() == 0); + REQUIRE(t2.NumDescendants() == 15); + REQUIRE(t2.NumPoints() == 15); } /** * Check that the mappings given are correct. */ -BOOST_AUTO_TEST_CASE(MappingsTest) +TEST_CASE("MappingsTest", "[OctreeTest]") { // Test with both constructors. arma::mat dataset(3, 5, arma::fill::randu); @@ -118,17 +116,17 @@ BOOST_AUTO_TEST_CASE(MappingsTest) for (size_t i = 0; i < oldFromNewCopy.size(); ++i) { - BOOST_REQUIRE_SMALL(arma::norm(datacopy.col(oldFromNewCopy[i]) - - t1.Dataset().col(i)), 1e-3); - BOOST_REQUIRE_SMALL(arma::norm(datacopy.col(oldFromNewMove[i]) - - t2.Dataset().col(i)), 1e-3); + REQUIRE(arma::norm(datacopy.col(oldFromNewCopy[i]) - + t1.Dataset().col(i)) == Approx(0.0).margin(1e-3)); + REQUIRE(arma::norm(datacopy.col(oldFromNewMove[i]) - + t2.Dataset().col(i)) == Approx(0.0).margin(1e-3)); } } /** * Check that the reverse mappings are correct too. */ -BOOST_AUTO_TEST_CASE(ReverseMappingsTest) +TEST_CASE("ReverseMappingsTest", "[OctreeTest]") { // Test with both constructors. arma::mat dataset(3, 300, arma::fill::randu); @@ -141,13 +139,14 @@ BOOST_AUTO_TEST_CASE(ReverseMappingsTest) for (size_t i = 0; i < oldFromNewCopy.size(); ++i) { - BOOST_REQUIRE_SMALL(arma::norm(datacopy.col(oldFromNewCopy[i]) - - t1.Dataset().col(i)), 1e-3); - BOOST_REQUIRE_SMALL(arma::norm(datacopy.col(oldFromNewMove[i]) - - t2.Dataset().col(i)), 1e-3); + REQUIRE(arma::norm(datacopy.col(oldFromNewCopy[i]) - + t1.Dataset().col(i)) == Approx(0.0).margin(1e-3)); + REQUIRE(arma::norm(datacopy.col(oldFromNewMove[i]) - + t2.Dataset().col(i)) == Approx(0.0).margin(1e-3)); - BOOST_REQUIRE_EQUAL(newFromOldCopy[oldFromNewCopy[i]], i); - BOOST_REQUIRE_EQUAL(newFromOldMove[oldFromNewMove[i]], i); + + REQUIRE(newFromOldCopy[oldFromNewCopy[i]] == i); + REQUIRE(newFromOldMove[oldFromNewMove[i]] == i); } } @@ -160,14 +159,14 @@ void CheckOverlap(TreeType& node) // Check each combination of children. for (size_t i = 0; i < node.NumChildren(); ++i) for (size_t j = i + 1; j < node.NumChildren(); ++j) - BOOST_REQUIRE_EQUAL(node.Child(i).Bound().Overlap(node.Child(j).Bound()), + REQUIRE(node.Child(i).Bound().Overlap(node.Child(j).Bound()) == 0.0); // We need exact equality here. for (size_t i = 0; i < node.NumChildren(); ++i) CheckOverlap(node.Child(i)); } -BOOST_AUTO_TEST_CASE(OverlapTest) +TEST_CASE("OverlapTest", "[OctreeTest]") { // Test with both constructors. arma::mat dataset(3, 300, arma::fill::randu); @@ -193,8 +192,8 @@ void CheckFurthestDistances(TreeType& node) for (size_t i = 0; i < node.NumPoints(); ++i) { // Handle floating-point inaccuracies. - BOOST_REQUIRE_LE(metric::EuclideanDistance::Evaluate( - node.Dataset().col(node.Point(i)), center), + REQUIRE(metric::EuclideanDistance::Evaluate( + node.Dataset().col(node.Point(i)), center) <= node.FurthestPointDistance() * (1 + 1e-5)); } @@ -202,16 +201,16 @@ void CheckFurthestDistances(TreeType& node) for (size_t i = 0; i < node.NumDescendants(); ++i) { // Handle floating-point inaccuracies. - BOOST_REQUIRE_LE(metric::EuclideanDistance::Evaluate( + REQUIRE(metric::EuclideanDistance::Evaluate( node.Dataset().col(node.Descendant(i)), - center), node.FurthestDescendantDistance() * (1 + 1e-5)); + center) <= node.FurthestDescendantDistance() * (1 + 1e-5)); } for (size_t i = 0; i < node.NumChildren(); ++i) CheckFurthestDistances(node.Child(i)); } -BOOST_AUTO_TEST_CASE(FurthestDistanceTest) +TEST_CASE("FurthestDistanceTest", "[OctreeTest]") { // Test with both constructors. arma::mat dataset(3, 500, arma::fill::randu); @@ -231,12 +230,12 @@ BOOST_AUTO_TEST_CASE(FurthestDistanceTest) template void CheckNumChildren(TreeType& node) { - BOOST_REQUIRE_LE(node.NumChildren(), std::pow(2, node.Dataset().n_rows)); + REQUIRE(node.NumChildren() <= std::pow(2, node.Dataset().n_rows)); for (size_t i = 0; i < node.NumChildren(); ++i) CheckNumChildren(node.Child(i)); } -BOOST_AUTO_TEST_CASE(MaxNumChildrenTest) +TEST_CASE("MaxNumChildrenTest", "[OctreeTest]") { for (size_t d = 1; d < 10; ++d) { @@ -253,37 +252,39 @@ BOOST_AUTO_TEST_CASE(MaxNumChildrenTest) template void CheckSameNode(TreeType& node1, TreeType& node2) { - BOOST_REQUIRE_EQUAL(node1.NumChildren(), node2.NumChildren()); - BOOST_REQUIRE_NE(&node1.Dataset(), &node2.Dataset()); + REQUIRE(node1.NumChildren() == node2.NumChildren()); + REQUIRE(&node1.Dataset() != &node2.Dataset()); // Make sure the children actually got copied. for (size_t i = 0; i < node1.NumChildren(); ++i) - BOOST_REQUIRE_NE(&node1.Child(i), &node2.Child(i)); + REQUIRE(&node1.Child(i) != &node2.Child(i)); // Check that all the points are the same. - BOOST_REQUIRE_EQUAL(node1.NumPoints(), node2.NumPoints()); - BOOST_REQUIRE_EQUAL(node1.NumDescendants(), node2.NumDescendants()); + REQUIRE(node1.NumPoints() == node2.NumPoints()); + REQUIRE(node1.NumDescendants() == node2.NumDescendants()); for (size_t i = 0; i < node1.NumPoints(); ++i) - BOOST_REQUIRE_EQUAL(node1.Point(i), node2.Point(i)); + REQUIRE(node1.Point(i) == node2.Point(i)); for (size_t i = 0; i < node1.NumDescendants(); ++i) - BOOST_REQUIRE_EQUAL(node1.Descendant(i), node2.Descendant(i)); + REQUIRE(node1.Descendant(i) == node2.Descendant(i)); // Check that the bound is the same. - BOOST_REQUIRE_EQUAL(node1.Bound().Dim(), node2.Bound().Dim()); + REQUIRE(node1.Bound().Dim() == node2.Bound().Dim()); for (size_t d = 0; d < node1.Bound().Dim(); ++d) { - BOOST_REQUIRE_CLOSE(node1.Bound()[d].Lo(), node2.Bound()[d].Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(node1.Bound()[d].Hi(), node2.Bound()[d].Hi(), 1e-5); + REQUIRE(node1.Bound()[d].Lo() == + Approx(node2.Bound()[d].Lo()).epsilon(1e-7)); + REQUIRE(node1.Bound()[d].Hi() == + Approx(node2.Bound()[d].Hi()).epsilon(1e-7)); } // Check that the furthest point and descendant distance are the same. - BOOST_REQUIRE_CLOSE(node1.FurthestPointDistance(), - node2.FurthestPointDistance(), 1e-5); - BOOST_REQUIRE_CLOSE(node1.FurthestDescendantDistance(), - node2.FurthestDescendantDistance(), 1e-5); + REQUIRE(node1.FurthestPointDistance() == + Approx(node2.FurthestPointDistance()).epsilon(1e-7)); + REQUIRE(node1.FurthestDescendantDistance() == + Approx(node2.FurthestDescendantDistance()).epsilon(1e-7)); } -BOOST_AUTO_TEST_CASE(CopyConstructorTest) +TEST_CASE("CopyConstructorTest", "[OctreeTest]") { // Use a small random dataset. arma::mat dataset(3, 100, arma::fill::randu); @@ -297,7 +298,7 @@ BOOST_AUTO_TEST_CASE(CopyConstructorTest) /** * Test the move constructor. */ -BOOST_AUTO_TEST_CASE(MoveConstructorTest) +TEST_CASE("MoveConstructorTest", "[OctreeTest]") { // Use a small random dataset. arma::mat dataset(3, 100, arma::fill::randu); @@ -309,14 +310,14 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) Octree<> t2(std::move(t)); // Make sure the original tree has no data. - BOOST_REQUIRE_EQUAL(t.Dataset().n_rows, 0); - BOOST_REQUIRE_EQUAL(t.Dataset().n_cols, 0); - BOOST_REQUIRE_EQUAL(t.NumChildren(), 0); - BOOST_REQUIRE_EQUAL(t.NumPoints(), 0); - BOOST_REQUIRE_EQUAL(t.NumDescendants(), 0); - BOOST_REQUIRE_SMALL(t.FurthestPointDistance(), 1e-5); - BOOST_REQUIRE_SMALL(t.FurthestDescendantDistance(), 1e-5); - BOOST_REQUIRE_EQUAL(t.Bound().Dim(), 0); + REQUIRE(t.Dataset().n_rows == 0); + REQUIRE(t.Dataset().n_cols == 0); + REQUIRE(t.NumChildren() == 0); + REQUIRE(t.NumPoints() == 0); + REQUIRE(t.NumDescendants() == 0); + REQUIRE(t.FurthestPointDistance() == Approx(0.0).margin(1e-5)); + REQUIRE(t.FurthestDescendantDistance() == Approx(0.0).margin(1e-5)); + REQUIRE(t.Bound().Dim() == 0); // Check that the new tree is the same as our copy. CheckSameNode(tcopy, t2); @@ -325,7 +326,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) /** * Test serialization. */ -BOOST_AUTO_TEST_CASE(SerializationTest) +TEST_CASE("SerializationTest", "[OctreeTest]") { // Use a small random dataset. arma::mat dataset(3, 500, arma::fill::randu); @@ -345,5 +346,3 @@ BOOST_AUTO_TEST_CASE(SerializationTest) delete binaryTree; delete textTree; } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp index 63117bd858..aa487df94f 100644 --- a/src/mlpack/tests/rectangle_tree_test.cpp +++ b/src/mlpack/tests/rectangle_tree_test.cpp @@ -16,35 +16,33 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::neighbor; using namespace mlpack::tree; using namespace mlpack::metric; -BOOST_AUTO_TEST_SUITE(RectangleTreeTest); - // Test the traits on RectangleTrees. -BOOST_AUTO_TEST_CASE(RectangleTreeTraitsTest) +TEST_CASE("RectangleTreeTraitsTest", "[RectangleTreeTraitsTest]") { // Children may be overlapping. bool b = TreeTraits>::HasOverlappingChildren; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); // Points are not contained in multiple levels. b = TreeTraits>::HasSelfChildren; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); } // Test to make sure the tree can be contains the correct number of points after // it is constructed. -BOOST_AUTO_TEST_CASE(RectangleTreeConstructionCountTest) +TEST_CASE("RectangleTreeConstructionCountTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(3, 1000); // 1000 points in 3 dimensions. @@ -55,8 +53,8 @@ BOOST_AUTO_TEST_CASE(RectangleTreeConstructionCountTest) TreeType tree(dataset, 20, 6, 5, 2, 0); TreeType tree2 = tree; - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000); - BOOST_REQUIRE_EQUAL(tree2.NumDescendants(), 1000); + REQUIRE(tree.NumDescendants() == 1000); + REQUIRE(tree2.NumDescendants() == 1000); } /** @@ -92,7 +90,7 @@ std::vector GetAllPointsInTree(const TreeType& tree) // Test to ensure that none of the points in the tree are duplicates. This, // combined with the above test to see how many points are in the tree, should // ensure that we inserted all points. -BOOST_AUTO_TEST_CASE(RectangleTreeConstructionRepeatTest) +TEST_CASE("RectangleTreeConstructionRepeatTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -113,7 +111,7 @@ BOOST_AUTO_TEST_CASE(RectangleTreeConstructionRepeatTest) for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); - BOOST_REQUIRE_NE(same, true); + REQUIRE(same != true); } } @@ -134,7 +132,7 @@ void CheckContainment(const TreeType& tree) if (tree.NumChildren() == 0) { for (size_t i = 0; i < tree.Count(); ++i) - BOOST_REQUIRE(tree.Bound().Contains( + REQUIRE(tree.Bound().Contains( tree.Dataset().unsafe_col(tree.Point(i)))); } else @@ -151,7 +149,7 @@ void CheckContainment(const TreeType& tree) std::numeric_limits::max()) || tree.Bound()[j].Contains(tree.Child(i).Bound()[j]); - BOOST_REQUIRE(success); + REQUIRE(success); } CheckContainment(tree.Child(i)); @@ -178,8 +176,8 @@ void CheckExactContainment(const TreeType& tree) if (tree.Dataset().col(tree.Point(j))[i] > max) max = tree.Dataset().col(tree.Point(j))[i]; } - BOOST_REQUIRE_EQUAL(max, tree.Bound()[i].Hi()); - BOOST_REQUIRE_EQUAL(min, tree.Bound()[i].Lo()); + REQUIRE(max == tree.Bound()[i].Hi()); + REQUIRE(min == tree.Bound()[i].Lo()); } } else @@ -196,8 +194,8 @@ void CheckExactContainment(const TreeType& tree) max = tree.Child(j).Bound()[i].Hi(); } - BOOST_REQUIRE_EQUAL(max, tree.Bound()[i].Hi()); - BOOST_REQUIRE_EQUAL(min, tree.Bound()[i].Lo()); + REQUIRE(max == tree.Bound()[i].Hi()); + REQUIRE(min == tree.Bound()[i].Lo()); } for (size_t i = 0; i < tree.NumChildren(); ++i) @@ -213,14 +211,14 @@ void CheckHierarchy(const TreeType& tree) { for (size_t i = 0; i < tree.NumChildren(); ++i) { - BOOST_REQUIRE_EQUAL(&tree, tree.Child(i).Parent()); + REQUIRE(&tree == tree.Child(i).Parent()); CheckHierarchy(tree.Child(i)); } } // Test to see if the bounds of the tree are correct. (Cover all bounds and // points beneath this node of the tree). -BOOST_AUTO_TEST_CASE(RectangleTreeContainmentTest) +TEST_CASE("RectangleTreeContainmentTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -249,23 +247,23 @@ void CheckFills(const TreeType& tree) { if (tree.IsLeaf()) { - BOOST_REQUIRE(tree.Count() >= tree.MinLeafSize() || tree.Parent() == NULL); - BOOST_REQUIRE(tree.Count() <= tree.MaxLeafSize()); + REQUIRE((tree.Count() >= tree.MinLeafSize() || tree.Parent() == NULL)); + REQUIRE(tree.Count() <= tree.MaxLeafSize()); } else { for (size_t i = 0; i < tree.NumChildren(); ++i) { - BOOST_REQUIRE(tree.NumChildren() >= tree.MinNumChildren() || - tree.Parent() == NULL); - BOOST_REQUIRE(tree.NumChildren() <= tree.MaxNumChildren()); + REQUIRE((tree.NumChildren() >= tree.MinNumChildren() || + tree.Parent() == NULL)); + REQUIRE(tree.NumChildren() <= tree.MaxNumChildren()); CheckFills(tree.Child(i)); } } } // Test to ensure that the minimum and maximum fills are satisfied. -BOOST_AUTO_TEST_CASE(CheckMinAndMaxFills) +TEST_CASE("CheckMinAndMaxFills", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -339,7 +337,7 @@ size_t CheckNumDescendants(const TreeType& tree) { if (tree.IsLeaf()) { - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), tree.Count()); + REQUIRE(tree.NumDescendants() == tree.Count()); return tree.Count(); } @@ -348,14 +346,14 @@ size_t CheckNumDescendants(const TreeType& tree) for (size_t i = 0; i < tree.NumChildren(); ++i) numDescendants += CheckNumDescendants(tree.Child(i)); - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), numDescendants); + REQUIRE(tree.NumDescendants() == numDescendants); return numDescendants; } // A test to ensure that all leaf nodes are stored on the same level of the // tree. -BOOST_AUTO_TEST_CASE(TreeBalance) +TEST_CASE("TreeBalance", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -365,15 +363,15 @@ BOOST_AUTO_TEST_CASE(TreeBalance) TreeType tree(dataset, 20, 6, 5, 2, 0); - BOOST_REQUIRE_EQUAL(GetMinLevel(tree), GetMaxLevel(tree)); - BOOST_REQUIRE_EQUAL(tree.TreeDepth(), GetMinLevel(tree)); + REQUIRE(GetMinLevel(tree) == GetMaxLevel(tree)); + REQUIRE(tree.TreeDepth() == GetMinLevel(tree)); } // A test to see if point deletion is working correctly. We build a tree, then // delete numIter points and test that the query gives correct results. It is // remotely possible that this test will give a false negative if it should // happen that two points are the same distance from a third point. -BOOST_AUTO_TEST_CASE(PointDeletion) +TEST_CASE("PointDeletion", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -404,14 +402,14 @@ BOOST_AUTO_TEST_CASE(PointDeletion) for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); - BOOST_REQUIRE(!same); + REQUIRE(!same); } } for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000 - numIter); + REQUIRE(tree.NumDescendants() == 1000 - numIter); CheckContainment(tree); CheckExactContainment(tree); @@ -439,8 +437,8 @@ BOOST_AUTO_TEST_CASE(PointDeletion) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); } } @@ -450,7 +448,7 @@ BOOST_AUTO_TEST_CASE(PointDeletion) // negative if it should happen that two points are the same distance from a // third point. Note that this is extremely inefficient. You should not use // dynamic insertion until a better solution for resizing matrices is available. -BOOST_AUTO_TEST_CASE(PointDynamicAdd) +TEST_CASE("PointDynamicAdd", "[RectangleTreeTraitsTest]") { const int numIter = 50; arma::mat dataset; @@ -488,14 +486,14 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); - BOOST_REQUIRE(!same); + REQUIRE(!same); } } for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000 + numIter); + REQUIRE(tree.NumDescendants() == 1000 + numIter); CheckContainment(tree); CheckExactContainment(tree); CheckNumDescendants(tree); @@ -520,14 +518,14 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); } } // A test to ensure that the SingleTreeTraverser is working correctly by // comparing its results to the results of a naive search. -BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) +TEST_CASE("SingleTreeTraverserTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -540,7 +538,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) arma::mat> TreeType; TreeType rTree(dataset, 20, 6, 5, 2, 0); - BOOST_REQUIRE_EQUAL(rTree.NumDescendants(), 1000); + REQUIRE(rTree.NumDescendants() == 1000); CheckContainment(rTree); CheckExactContainment(rTree); @@ -560,14 +558,14 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } // A test to ensure that the SingleTreeTraverser is working correctly by // comparing its results to the results of a naive search. -BOOST_AUTO_TEST_CASE(XTreeTraverserTest) +TEST_CASE("XTreeTraverserTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; @@ -583,7 +581,7 @@ BOOST_AUTO_TEST_CASE(XTreeTraverserTest) arma::mat> TreeType; TreeType xTree(dataset, 20, 6, 5, 2, 0); - BOOST_REQUIRE_EQUAL(xTree.NumDescendants(), numP); + REQUIRE(xTree.NumDescendants() == numP); CheckContainment(xTree); CheckExactContainment(xTree); @@ -603,12 +601,12 @@ BOOST_AUTO_TEST_CASE(XTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } -BOOST_AUTO_TEST_CASE(HilbertRTreeTraverserTest) +TEST_CASE("HilbertRTreeTraverserTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; @@ -624,7 +622,7 @@ BOOST_AUTO_TEST_CASE(HilbertRTreeTraverserTest) NeighborSearchStat, arma::mat> TreeType; TreeType hilbertRTree(dataset, 20, 6, 5, 2, 0); - BOOST_REQUIRE_EQUAL(hilbertRTree.NumDescendants(), numP); + REQUIRE(hilbertRTree.NumDescendants() == numP); CheckContainment(hilbertRTree); CheckExactContainment(hilbertRTree); @@ -644,8 +642,8 @@ BOOST_AUTO_TEST_CASE(HilbertRTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } @@ -655,25 +653,30 @@ void CheckHilbertOrdering(const TreeType& tree) if (tree.IsLeaf()) { for (size_t i = 0; i < tree.NumPoints() - 1; ++i) - BOOST_REQUIRE_LE(tree.AuxiliaryInfo().HilbertValue().ComparePoints( + { + REQUIRE(tree.AuxiliaryInfo().HilbertValue().ComparePoints( tree.Dataset().col(tree.Point(i)), - tree.Dataset().col(tree.Point(i + 1))), + tree.Dataset().col(tree.Point(i + 1))) <= 0); + } - BOOST_REQUIRE_EQUAL(tree.AuxiliaryInfo().HilbertValue().CompareWith( - tree.Dataset().col(tree.Point(tree.NumPoints() - 1))), + + REQUIRE(tree.AuxiliaryInfo().HilbertValue().CompareWith( + tree.Dataset().col(tree.Point(tree.NumPoints() - 1))) == 0); } else { for (size_t i = 0; i < tree.NumChildren() - 1; ++i) - BOOST_REQUIRE_LE(tree.AuxiliaryInfo().HilbertValue().CompareValues( + { + REQUIRE(tree.AuxiliaryInfo().HilbertValue().CompareValues( tree.Child(i).AuxiliaryInfo().HilbertValue(), - tree.Child(i + 1).AuxiliaryInfo().HilbertValue()), + tree.Child(i + 1).AuxiliaryInfo().HilbertValue()) <= 0); + } - BOOST_REQUIRE_EQUAL(tree.AuxiliaryInfo().HilbertValue().CompareWith( - tree.Child(tree.NumChildren() - 1).AuxiliaryInfo().HilbertValue()), + REQUIRE(tree.AuxiliaryInfo().HilbertValue().CompareWith( + tree.Child(tree.NumChildren() - 1).AuxiliaryInfo().HilbertValue()) == 0); for (size_t i = 0; i < tree.NumChildren(); ++i) @@ -681,7 +684,7 @@ void CheckHilbertOrdering(const TreeType& tree) } } -BOOST_AUTO_TEST_CASE(HilbertRTreeOrderingTest) +TEST_CASE("HilbertRTreeOrderingTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -712,7 +715,7 @@ void CheckDiscreteHilbertValueSync(const TreeType& tree) const int equal = HilbertValue::CompareValues( value.LocalHilbertValues()->col(i), pointValue); - BOOST_REQUIRE_EQUAL(equal, 0); + REQUIRE(equal == 0); } } else @@ -722,7 +725,7 @@ void CheckDiscreteHilbertValueSync(const TreeType& tree) } } -BOOST_AUTO_TEST_CASE(DiscreteHilbertValueSyncTest) +TEST_CASE("DiscreteHilbertValueSyncTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -734,7 +737,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueSyncTest) CheckDiscreteHilbertValueSync(hilbertRTree); } -BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) +TEST_CASE("DiscreteHilbertValueTest", "[RectangleTreeTraitsTest]") { arma::vec point01(1); arma::vec point02(1); @@ -742,56 +745,47 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point01[0] = -DBL_MAX; point02[0] = DBL_MAX; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = -DBL_MAX; point02[0] = -100; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = -100; point02[0] = -1; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = -1; point02[0] = -std::numeric_limits::min(); - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = -std::numeric_limits::min(); point02[0] = 0; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = 0; point02[0] = std::numeric_limits::min(); - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = std::numeric_limits::min(); point02[0] = 1; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = 1; point02[0] = 100; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); point01[0] = 100; point02[0] = DBL_MAX; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point01, - point02), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point01, point02) == -1); arma::vec point1(2); arma::vec point2(2); @@ -802,8 +796,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point2[0] = 0; point2[1] = 0; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point1, - point2), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point1, point2) == -1); point1[0] = -1; point1[1] = -1; @@ -811,8 +804,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point2[0] = 1; point2[1] = -1; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point1, - point2), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point1, point2) == -1); point1[0] = -1; point1[1] = -1; @@ -820,8 +812,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point2[0] = -1; point2[1] = 1; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point1, - point2), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point1, point2) == -1); point1[0] = -DBL_MAX + 1; point1[1] = -DBL_MAX + 1; @@ -829,8 +820,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point2[0] = -1; point2[1] = -1; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point1, - point2), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point1, point2) == -1); point1[0] = DBL_MAX * 0.75; point1[1] = DBL_MAX * 0.75; @@ -838,8 +828,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point2[0] = DBL_MAX * 0.25; point2[1] = DBL_MAX * 0.25; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point1, - point2), 1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point1, point2) == 1); arma::vec point3(4); arma::vec point4(4); @@ -854,8 +843,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point4[2] = 1.0; point4[3] = 1.0; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point3, - point4), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point3, point4) == -1); point3[0] = -DBL_MAX; point3[1] = DBL_MAX; @@ -867,8 +855,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHilbertValueTest) point4[2] = DBL_MAX; point4[3] = DBL_MAX; - BOOST_REQUIRE_EQUAL(DiscreteHilbertValue::ComparePoints(point3, - point4), -1); + REQUIRE(DiscreteHilbertValue::ComparePoints(point3, point4) == -1); } template @@ -881,7 +868,7 @@ void CheckHilbertValue(const TreeType& tree) if (tree.IsLeaf()) { - BOOST_REQUIRE_EQUAL(value.OwnsLocalHilbertValues(), true); + REQUIRE(value.OwnsLocalHilbertValues() == true); return; } @@ -889,26 +876,26 @@ void CheckHilbertValue(const TreeType& tree) { const HilbertValue& childValue = tree.Child(i).AuxiliaryInfo().HilbertValue(); - BOOST_REQUIRE_EQUAL(value.ValueToInsert(), childValue.ValueToInsert()); + REQUIRE(value.ValueToInsert() == childValue.ValueToInsert()); } const HilbertValue& childValue = tree.Child(tree.NumChildren() - 1).AuxiliaryInfo().HilbertValue(); - BOOST_REQUIRE_EQUAL(value.LocalHilbertValues(), + REQUIRE(value.LocalHilbertValues() == childValue.LocalHilbertValues()); if (!tree.Parent()) - BOOST_REQUIRE_EQUAL(value.OwnsValueToInsert(), true); + REQUIRE(value.OwnsValueToInsert() == true); else - BOOST_REQUIRE_EQUAL(value.OwnsValueToInsert(), false); + REQUIRE(value.OwnsValueToInsert() == false); - BOOST_REQUIRE_EQUAL(value.OwnsLocalHilbertValues(), false); + REQUIRE(value.OwnsLocalHilbertValues() == false); for (size_t i = 0; i < tree.NumChildren(); ++i) CheckHilbertValue(tree.Child(i)); } -BOOST_AUTO_TEST_CASE(HilbertRTeeCopyConstructorTest) +TEST_CASE("HilbertRTeeCopyConstructorTest", "[RectangleTreeTraitsTest]") { typedef HilbertRTree, arma::mat> TreeType; @@ -928,7 +915,7 @@ BOOST_AUTO_TEST_CASE(HilbertRTeeCopyConstructorTest) CheckNumDescendants(copy); } -BOOST_AUTO_TEST_CASE(HilbertRTeeMoveConstructorTest) +TEST_CASE("HilbertRTeeMoveConstructorTest", "[RectangleTreeTraitsTest]") { typedef HilbertRTree, arma::mat> TreeType; @@ -971,14 +958,14 @@ void CheckOverlap(const TreeType& tree) if (!success) break; } - BOOST_REQUIRE_EQUAL(success, true); + REQUIRE(success == true); for (size_t i = 0; i < tree.NumChildren(); ++i) CheckOverlap(tree.Child(i)); } -BOOST_AUTO_TEST_CASE(RPlusTreeOverlapTest) +TEST_CASE("RPlusTreeOverlapTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -991,15 +978,15 @@ BOOST_AUTO_TEST_CASE(RPlusTreeOverlapTest) // Children can not be overlapping. bool b = TreeTraits::HasOverlappingChildren; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); // Ensure that all leaf nodes are at the same level. - BOOST_REQUIRE_EQUAL(GetMinLevel(rPlusTree), GetMaxLevel(rPlusTree)); - BOOST_REQUIRE_EQUAL(rPlusTree.TreeDepth(), GetMinLevel(rPlusTree)); + REQUIRE(GetMinLevel(rPlusTree) == GetMaxLevel(rPlusTree)); + REQUIRE(rPlusTree.TreeDepth() == GetMinLevel(rPlusTree)); } -BOOST_AUTO_TEST_CASE(RPlusTreeTraverserTest) +TEST_CASE("RPlusTreeTraverserTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; @@ -1015,7 +1002,7 @@ BOOST_AUTO_TEST_CASE(RPlusTreeTraverserTest) arma::mat > TreeType; TreeType rPlusTree(dataset, 20, 6, 5, 2, 0); - BOOST_REQUIRE_EQUAL(rPlusTree.NumDescendants(), numP); + REQUIRE(rPlusTree.NumDescendants() == numP); CheckContainment(rPlusTree); CheckExactContainment(rPlusTree); @@ -1036,8 +1023,8 @@ BOOST_AUTO_TEST_CASE(RPlusTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } @@ -1052,9 +1039,9 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) // Ensure that the maximum bounding rectangle contains all children. for (size_t k = 0; k < tree.Bound().Dim(); ++k) { - BOOST_REQUIRE_LE(tree.Bound()[k].Hi(), + REQUIRE(tree.Bound()[k].Hi() <= tree.AuxiliaryInfo().OuterBound()[k].Hi()); - BOOST_REQUIRE_LE(tree.AuxiliaryInfo().OuterBound()[k].Lo(), + REQUIRE(tree.AuxiliaryInfo().OuterBound()[k].Lo() <= tree.Bound()[k].Lo()); } @@ -1062,7 +1049,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) { // Ensure that the maximum bounding rectangle contains all points. for (size_t i = 0; i < tree.Count(); ++i) - BOOST_REQUIRE_EQUAL(true, + REQUIRE(true == tree.Bound().Contains(tree.Dataset().col(tree.Point(i)))); return; @@ -1089,13 +1076,13 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) if (!success) break; } - BOOST_REQUIRE_EQUAL(success, true); + REQUIRE(success == true); for (size_t i = 0; i < tree.NumChildren(); ++i) CheckRPlusPlusTreeBound(tree.Child(i)); } -BOOST_AUTO_TEST_CASE(RPlusPlusTreeBoundTest) +TEST_CASE("RPlusPlusTreeBoundTest", "[RectangleTreeTraitsTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -1109,10 +1096,10 @@ BOOST_AUTO_TEST_CASE(RPlusPlusTreeBoundTest) // Children can not be overlapping. bool b = TreeTraits::HasOverlappingChildren; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); - BOOST_REQUIRE_EQUAL(GetMinLevel(rPlusPlusTree), GetMaxLevel(rPlusPlusTree)); - BOOST_REQUIRE_EQUAL(rPlusPlusTree.TreeDepth(), GetMinLevel(rPlusPlusTree)); + REQUIRE(GetMinLevel(rPlusPlusTree) == GetMaxLevel(rPlusPlusTree)); + REQUIRE(rPlusPlusTree.TreeDepth() == GetMinLevel(rPlusPlusTree)); // Check the MinimalSplitsNumberSweep. typedef RectangleTree, arma::mat > TreeType; TreeType rPlusPlusTree(dataset, 20, 6, 5, 2, 0); - BOOST_REQUIRE_EQUAL(rPlusPlusTree.NumDescendants(), numP); + REQUIRE(rPlusPlusTree.NumDescendants() == numP); CheckContainment(rPlusPlusTree); CheckExactContainment(rPlusPlusTree); @@ -1167,15 +1154,15 @@ BOOST_AUTO_TEST_CASE(RPlusPlusTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } // Test the tree splitting. We set MaxLeafSize and MaxNumChildren rather low // to allow us to test by hand without adding hundreds of points. -BOOST_AUTO_TEST_CASE(RTreeSplitTest) +TEST_CASE("RTreeSplitTest", "[RectangleTreeTraitsTest]") { arma::mat data = arma::trans(arma::mat("0.0 0.0;" "0.0 1.0;" @@ -1194,9 +1181,9 @@ BOOST_AUTO_TEST_CASE(RTreeSplitTest) // There's technically no reason they have to be in a certain order, so we // use firstChild etc. to arbitrarily name them. - BOOST_REQUIRE_EQUAL(rTree.NumChildren(), 2); - BOOST_REQUIRE_EQUAL(rTree.NumDescendants(), 10); - BOOST_REQUIRE_EQUAL(rTree.TreeDepth(), 3); + REQUIRE(rTree.NumChildren() == 2); + REQUIRE(rTree.NumDescendants() == 10); + REQUIRE(rTree.TreeDepth() == 3); int firstChild = 0, secondChild = 1; if (rTree.Child(firstChild).NumChildren() == 2) @@ -1205,34 +1192,37 @@ BOOST_AUTO_TEST_CASE(RTreeSplitTest) secondChild = 0; } - BOOST_REQUIRE_SMALL(rTree.Child(firstChild).Bound()[0].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(firstChild).Bound()[0].Hi(), 0.1, - 1e-15); - BOOST_REQUIRE_SMALL(rTree.Child(firstChild).Bound()[1].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(firstChild).Bound()[1].Hi(), 1.0, - 1e-15); + REQUIRE(rTree.Child(firstChild).Bound()[0].Lo() == + Approx(0.0).margin(1e-15)); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[0].Lo(), 0.3, - 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[0].Hi(), 1.0, - 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[1].Lo(), 0.1, - 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[1].Hi(), 0.9, - 1e-15); + REQUIRE(rTree.Child(firstChild).Bound()[0].Hi() == + Approx(0.1).epsilon(1e-17)); + REQUIRE(rTree.Child(firstChild).Bound()[1].Lo() == + Approx(0.0).margin(1e-15)); + REQUIRE(rTree.Child(firstChild).Bound()[1].Hi() == + Approx(1.0).epsilon(1e-17)); - BOOST_REQUIRE_EQUAL(rTree.Child(firstChild).NumChildren(), 1); - BOOST_REQUIRE_SMALL( - rTree.Child(firstChild).Child(0).Bound()[0].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(firstChild).Child(0).Bound()[0].Hi(), 0.1, - 1e-15); - BOOST_REQUIRE_SMALL( - rTree.Child(firstChild).Child(0).Bound()[1].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(firstChild).Child(0).Bound()[1].Hi(), 1.0, - 1e-15); - BOOST_REQUIRE_EQUAL(rTree.Child(firstChild).Child(0).Count(), 3); + REQUIRE(rTree.Child(secondChild).Bound()[0].Lo() == + Approx(0.3).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Bound()[0].Hi() == + Approx(1.0).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Bound()[1].Lo() == + Approx(0.1).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Bound()[1].Hi() == + Approx(0.9).epsilon(1e-17)); + + REQUIRE(rTree.Child(firstChild).NumChildren() == 1); + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[0].Lo() == + Approx(0.0).margin(1e-15)); + + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[0].Hi() == + Approx(0.1).epsilon(1e-17)); + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[1].Lo() == + Approx(0.0).margin(1e-15)); + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[1].Hi() == + Approx(1.0).epsilon(1e-17)); + + REQUIRE(rTree.Child(firstChild).Child(0).Count() == 3); int firstPrime = 0, secondPrime = 1; if (rTree.Child(secondChild).Child(firstPrime).Count() == 3) @@ -1241,41 +1231,33 @@ BOOST_AUTO_TEST_CASE(RTreeSplitTest) secondPrime = 0; } - BOOST_REQUIRE_EQUAL(rTree.Child(secondChild).NumChildren(), 2); - BOOST_REQUIRE_EQUAL( - rTree.Child(secondChild).Child(firstPrime).Count(), 4); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[0].Lo(), - 0.3, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[0].Hi(), - 0.7, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[1].Lo(), - 0.3, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[1].Hi(), - 0.7, 1e-15); + REQUIRE(rTree.Child(secondChild).NumChildren() == 2); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Count() == 4); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[0].Lo() == + Approx(0.3).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[0].Hi() == + Approx(0.7).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[1].Lo() == + Approx(0.3).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[1].Hi() == + Approx(0.7).epsilon(1e-17)); - BOOST_REQUIRE_EQUAL( - rTree.Child(secondChild).Child(secondPrime).Count(), 3); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[0].Lo(), - 0.9, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[0].Hi(), - 1.0, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[1].Lo(), - 0.1, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[1].Hi(), - 0.9, 1e-15); + + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Count() == 3); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[0].Lo() == + Approx(0.9).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[0].Hi() == + Approx(1.0).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[1].Lo() == + Approx(0.1).epsilon(1e-17)); + + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[1].Hi() == + Approx(0.9).epsilon(1e-17)); } // Test the tree splitting. We set MaxLeafSize and MaxNumChildren rather low // to allow us to test by hand without adding hundreds of points. -BOOST_AUTO_TEST_CASE(RStarTreeSplitTest) +TEST_CASE("RStarTreeSplitTest", "[RectangleTreeTraitsTest]") { arma::mat data = arma::trans(arma::mat("0.0 0.0;" "0.0 1.0;" @@ -1295,9 +1277,9 @@ BOOST_AUTO_TEST_CASE(RStarTreeSplitTest) // There's technically no reason they have to be in a certain order, so we // use firstChild etc. to arbitrarily name them. - BOOST_REQUIRE_EQUAL(rTree.NumChildren(), 2); - BOOST_REQUIRE_EQUAL(rTree.NumDescendants(), 10); - BOOST_REQUIRE_EQUAL(rTree.TreeDepth(), 3); + REQUIRE(rTree.NumChildren() == 2); + REQUIRE(rTree.NumDescendants() == 10); + REQUIRE(rTree.TreeDepth() == 3); int firstChild = 0, secondChild = 1; if (rTree.Child(firstChild).NumChildren() == 2) @@ -1306,32 +1288,35 @@ BOOST_AUTO_TEST_CASE(RStarTreeSplitTest) secondChild = 0; } - BOOST_REQUIRE_SMALL(rTree.Child(firstChild).Bound()[0].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(firstChild).Bound()[0].Hi(), 0.1, - 1e-15); - BOOST_REQUIRE_SMALL(rTree.Child(firstChild).Bound()[1].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(firstChild).Bound()[1].Hi(), 1.0, - 1e-15); + REQUIRE(rTree.Child(firstChild).Bound()[0].Lo() == + Approx(0.0).margin(1e-15)); + REQUIRE(rTree.Child(firstChild).Bound()[0].Hi() == + Approx(0.1).epsilon(1e-17)); + REQUIRE(rTree.Child(firstChild).Bound()[1].Lo() == + Approx(0.0).margin(1e-15)); + REQUIRE(rTree.Child(firstChild).Bound()[1].Hi() == + Approx(1.0).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Bound()[0].Lo() == + Approx(0.3).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Bound()[0].Hi() == + Approx(1.0).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Bound()[1].Lo() == + Approx(0.1).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Bound()[1].Hi() == + Approx(0.9).epsilon(1e-17)); + REQUIRE(rTree.Child(firstChild).NumChildren() == 1); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[0].Lo(), 0.3, - 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[0].Hi(), 1.0, - 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[1].Lo(), 0.1, - 1e-15); - BOOST_REQUIRE_CLOSE(rTree.Child(secondChild).Bound()[1].Hi(), 0.9, - 1e-15); - BOOST_REQUIRE_EQUAL(rTree.Child(firstChild).NumChildren(), 1); - BOOST_REQUIRE_SMALL( - rTree.Child(firstChild).Child(0).Bound()[0].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(firstChild).Child(0).Bound()[0].Hi(), 0.1, 1e-15); - BOOST_REQUIRE_SMALL( - rTree.Child(firstChild).Child(0).Bound()[1].Lo(), 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(firstChild).Child(0).Bound()[1].Hi(), 1.0, 1e-15); - BOOST_REQUIRE_EQUAL(rTree.Child(firstChild).Child(0).Count(), 3); + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[0].Lo() == + Approx(0.0).margin(1e-15)); + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[0].Hi() == + Approx(0.1).epsilon(1e-17)); + + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[1].Lo() == + Approx(0.0).margin(1e-15)); + REQUIRE(rTree.Child(firstChild).Child(0).Bound()[1].Hi() == + Approx(1.0).epsilon(1e-17)); + REQUIRE(rTree.Child(firstChild).Child(0).Count() == 3); int firstPrime = 0, secondPrime = 1; if (rTree.Child(secondChild).Child(firstPrime).Count() == 3) @@ -1340,48 +1325,37 @@ BOOST_AUTO_TEST_CASE(RStarTreeSplitTest) secondPrime = 0; } - BOOST_REQUIRE_EQUAL(rTree.Child(secondChild).NumChildren(), 2); - BOOST_REQUIRE_EQUAL( - rTree.Child(secondChild).Child(firstPrime).Count(), 4); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[0].Lo(), - 0.3, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[0].Hi(), - 0.7, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[1].Lo(), - 0.3, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(firstPrime).Bound()[1].Hi(), - 0.7, 1e-15); - - BOOST_REQUIRE_EQUAL( - rTree.Child(secondChild).Child(secondPrime).Count(), 3); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[0].Lo(), - 0.9, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[0].Hi(), - 1.0, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[1].Lo(), - 0.1, 1e-15); - BOOST_REQUIRE_CLOSE( - rTree.Child(secondChild).Child(secondPrime).Bound()[1].Hi(), - 0.9, 1e-15); + REQUIRE(rTree.Child(secondChild).NumChildren() == 2); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Count() == 4); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[0].Lo() == + Approx(0.3).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[0].Hi() == + Approx(0.7).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[1].Lo() == + Approx(0.3).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[1].Lo() == + Approx(0.3).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(firstPrime).Bound()[1].Hi() == + Approx(0.7).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Count() == 3); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[0].Lo() == + Approx(0.9).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[0].Hi() == + Approx(1.0).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[1].Lo() == + Approx(0.1).epsilon(1e-17)); + REQUIRE(rTree.Child(secondChild).Child(secondPrime).Bound()[1].Hi() == + Approx(0.9).epsilon(1e-17)); } -BOOST_AUTO_TEST_CASE(RectangleTreeMoveDatasetTest) +TEST_CASE("RectangleTreeMoveDatasetTest", "[RectangleTreeTraitsTest]") { arma::mat dataset = arma::randu(3, 1000); typedef RTree TreeType; TreeType tree(std::move(dataset)); - BOOST_REQUIRE_EQUAL(dataset.n_elem, 0); - BOOST_REQUIRE_EQUAL(tree.Dataset().n_rows, 3); - BOOST_REQUIRE_EQUAL(tree.Dataset().n_cols, 1000); + REQUIRE(dataset.n_elem == 0); + REQUIRE(tree.Dataset().n_rows == 3); + REQUIRE(tree.Dataset().n_cols == 1000); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/spill_tree_test.cpp b/src/mlpack/tests/spill_tree_test.cpp index 83677b5078..0a1569e800 100644 --- a/src/mlpack/tests/spill_tree_test.cpp +++ b/src/mlpack/tests/spill_tree_test.cpp @@ -13,21 +13,19 @@ #include #include -#include +#include "catch.hpp" #include using namespace mlpack; using namespace mlpack::tree; using namespace mlpack::metric; -BOOST_AUTO_TEST_SUITE(SpillTreeTest); - /** * Test to make sure the tree contains the correct number of points after * it is constructed. Also, it checks some invariants in the relation between * parent and child nodes. */ -BOOST_AUTO_TEST_CASE(SpillTreeConstructionCountTest) +TEST_CASE("SpillTreeConstructionCountTest", "[SpillTreeTest]") { arma::mat dataset; dataset.randu(3, 1000); // 1000 points in 3 dimensions. @@ -38,8 +36,8 @@ BOOST_AUTO_TEST_CASE(SpillTreeConstructionCountTest) TreeType tree1(dataset, 0); TreeType tree2 = tree1; - BOOST_REQUIRE_EQUAL(tree1.NumDescendants(), 1000); - BOOST_REQUIRE_EQUAL(tree2.NumDescendants(), 1000); + REQUIRE(tree1.NumDescendants() == 1000); + REQUIRE(tree2.NumDescendants() == 1000); // When overlapping buffer is greater than 0, it is possible to have repeated // points. So, let's check node by node, that the number of descendants @@ -68,18 +66,18 @@ BOOST_AUTO_TEST_CASE(SpillTreeConstructionCountTest) } if (node->IsLeaf()) - BOOST_REQUIRE_EQUAL(node->NumPoints(), node->NumDescendants()); + REQUIRE(node->NumPoints() == node->NumDescendants()); else - BOOST_REQUIRE_EQUAL(node->NumPoints(), 0); + REQUIRE(node->NumPoints() == 0); - BOOST_REQUIRE_EQUAL(node->NumDescendants(), numDesc); + REQUIRE(node->NumDescendants() == numDesc); } } /** * Test to check that parents and children are set correctly. */ -BOOST_AUTO_TEST_CASE(SpillTreeConstructionParentTest) +TEST_CASE("SpillTreeConstructionParentTest", "[SpillTreeTest]") { arma::mat dataset; dataset.randu(3, 1000); // 1000 points in 3 dimensions. @@ -98,13 +96,13 @@ BOOST_AUTO_TEST_CASE(SpillTreeConstructionParentTest) if (node->Left()) { nodes.push(node->Left()); - BOOST_REQUIRE_EQUAL(node, node->Left()->Parent()); + REQUIRE(node == node->Left()->Parent()); } if (node->Right()) { nodes.push(node->Right()); - BOOST_REQUIRE_EQUAL(node, node->Right()->Parent()); + REQUIRE(node == node->Right()->Parent()); } } } @@ -146,8 +144,8 @@ void SpillTreeHyperplaneTestAux() for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Left()->Descendant(i); - BOOST_REQUIRE_LE( - node->Hyperplane().Project(node->Dataset().col(descIndex)), + REQUIRE( + node->Hyperplane().Project(node->Dataset().col(descIndex)) < tau); } } @@ -159,9 +157,8 @@ void SpillTreeHyperplaneTestAux() for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Right()->Descendant(i); - BOOST_REQUIRE_GT( - node->Hyperplane().Project(node->Dataset().col(descIndex)), - -tau); + REQUIRE(node->Hyperplane().Project(node->Dataset().col(descIndex)) + > -tau); } } } @@ -176,7 +173,7 @@ void SpillTreeHyperplaneTestAux() for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Left()->Descendant(i); - BOOST_REQUIRE( + REQUIRE( node->Hyperplane().Left(node->Dataset().col(descIndex))); } } @@ -188,7 +185,7 @@ void SpillTreeHyperplaneTestAux() for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Right()->Descendant(i); - BOOST_REQUIRE( + REQUIRE( node->Hyperplane().Right(node->Dataset().col(descIndex))); } } @@ -208,7 +205,7 @@ void SpillTreeHyperplaneTestAux() * left by the node's splitting hyperplane, and the same for points in the * right child. */ -BOOST_AUTO_TEST_CASE(SpillTreeHyperplaneTest) +TEST_CASE("SpillTreeHyperplaneTest", "[SpillTreeTest]") { typedef SPTree SpillType1; typedef NonOrtSPTree SpillType2; @@ -225,7 +222,7 @@ BOOST_AUTO_TEST_CASE(SpillTreeHyperplaneTest) /** * Simple test for the move constructor. */ -BOOST_AUTO_TEST_CASE(SpillTreeMoveConstructorTest) +TEST_CASE("SpillTreeMoveConstructorTest", "[SpillTreeTest]") { arma::mat dataset = arma::randu(3, 1000); typedef SPTree TreeType; @@ -238,29 +235,29 @@ BOOST_AUTO_TEST_CASE(SpillTreeMoveConstructorTest) TreeType newTree(std::move(tree)); - BOOST_REQUIRE(tree.Left() == NULL); - BOOST_REQUIRE(tree.Right() == NULL); - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 0); + REQUIRE(tree.Left() == NULL); + REQUIRE(tree.Right() == NULL); + REQUIRE(tree.NumDescendants() == 0); - BOOST_REQUIRE_EQUAL(newTree.Left(), left); - BOOST_REQUIRE_EQUAL(newTree.Right(), right); - BOOST_REQUIRE_EQUAL(newTree.NumDescendants(), numDesc); + REQUIRE(newTree.Left() == left); + REQUIRE(newTree.Right() == right); + REQUIRE(newTree.NumDescendants() == numDesc); if (left) { - BOOST_REQUIRE(newTree.Left() != NULL); - BOOST_REQUIRE_EQUAL(newTree.Left()->Parent(), &newTree); + REQUIRE(newTree.Left() != NULL); + REQUIRE(newTree.Left()->Parent() == &newTree); } if (right) { - BOOST_REQUIRE(newTree.Right() != NULL); - BOOST_REQUIRE_EQUAL(newTree.Right()->Parent(), &newTree); + REQUIRE(newTree.Right() != NULL); + REQUIRE(newTree.Right()->Parent() == &newTree); } } /** * Simple test for the copy constructor. */ -BOOST_AUTO_TEST_CASE(SpillTreeCopyConstructorTest) +TEST_CASE("SpillTreeCopyConstructorTest", "[SpillTreeTest]") { arma::mat dataset = arma::randu(3, 1000); typedef SPTree TreeType; @@ -276,36 +273,34 @@ BOOST_AUTO_TEST_CASE(SpillTreeCopyConstructorTest) delete tree; - BOOST_REQUIRE_EQUAL(newTree.Dataset().n_rows, 3); - BOOST_REQUIRE_EQUAL(newTree.Dataset().n_cols, 1000); - BOOST_REQUIRE_EQUAL(newTree.NumDescendants(), numDesc); + REQUIRE(newTree.Dataset().n_rows == 3); + REQUIRE(newTree.Dataset().n_cols == 1000); + REQUIRE(newTree.NumDescendants() == numDesc); if (left) { - BOOST_REQUIRE(newTree.Left() != left); - BOOST_REQUIRE(newTree.Left() != NULL); - BOOST_REQUIRE_EQUAL(newTree.Left()->Parent(), &newTree); + REQUIRE(newTree.Left() != left); + REQUIRE(newTree.Left() != NULL); + REQUIRE(newTree.Left()->Parent() == &newTree); } if (right) { - BOOST_REQUIRE(newTree.Right() != right); - BOOST_REQUIRE(newTree.Right() != NULL); - BOOST_REQUIRE_EQUAL(newTree.Right()->Parent(), &newTree); + REQUIRE(newTree.Right() != right); + REQUIRE(newTree.Right() != NULL); + REQUIRE(newTree.Right()->Parent() == &newTree); } } /** * Simple test for the constructor that takes a rvalue reference to the dataset. */ -BOOST_AUTO_TEST_CASE(SpillTreeMoveDatasetTest) +TEST_CASE("SpillTreeMoveDatasetTest", "[SpillTreeTest]") { arma::mat dataset = arma::randu(3, 1000); typedef SPTree TreeType; TreeType tree(std::move(dataset)); - BOOST_REQUIRE_EQUAL(dataset.n_elem, 0); - BOOST_REQUIRE_EQUAL(tree.Dataset().n_rows, 3); - BOOST_REQUIRE_EQUAL(tree.Dataset().n_cols, 1000); + REQUIRE(dataset.n_elem == 0); + REQUIRE(tree.Dataset().n_rows == 3); + REQUIRE(tree.Dataset().n_cols == 1000); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/sumtree_test.cpp b/src/mlpack/tests/sumtree_test.cpp index a6d446dcdc..e3ea279d63 100644 --- a/src/mlpack/tests/sumtree_test.cpp +++ b/src/mlpack/tests/sumtree_test.cpp @@ -13,18 +13,16 @@ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::rl; -BOOST_AUTO_TEST_SUITE(SumTreeTest); - /** * Test that we set the element. */ -BOOST_AUTO_TEST_CASE(SetElement) +TEST_CASE("SetElement", "[SumTreeTest]") { SumTree sumtree(4); sumtree.Set(0, 1.0); @@ -32,16 +30,16 @@ BOOST_AUTO_TEST_CASE(SetElement) sumtree.Set(2, 0.6); sumtree.Set(3, 0.4); - BOOST_CHECK_CLOSE(sumtree.Sum(), 2.8, 1e-8); - BOOST_CHECK_CLOSE(sumtree.Sum(0, 1), 1.0, 1e-8); - BOOST_CHECK_CLOSE(sumtree.Sum(0, 3), 2.4, 1e-8); - BOOST_CHECK_CLOSE(sumtree.Sum(1, 4), 1.8, 1e-8); + CHECK(sumtree.Sum() == Approx(2.8).epsilon(1e-10)); + CHECK(sumtree.Sum(0, 1) == Approx(1.0).epsilon(1e-10)); + CHECK(sumtree.Sum(0, 3) == Approx(2.4).epsilon(1e-10)); + CHECK(sumtree.Sum(1, 4) == Approx(1.8).epsilon(1e-10)); } /** * Test that we get the element. */ -BOOST_AUTO_TEST_CASE(GetElement) +TEST_CASE("GetElement", "[SumTreeTest]") { SumTree sumtree(4); sumtree.Set(0, 1.0); @@ -49,17 +47,17 @@ BOOST_AUTO_TEST_CASE(GetElement) sumtree.Set(2, 0.6); sumtree.Set(3, 0.4); - BOOST_CHECK_CLOSE(sumtree.Get(0), 1.0, 1e-8); - BOOST_CHECK_CLOSE(sumtree.Get(1), 0.8, 1e-8); - BOOST_CHECK_CLOSE(sumtree.Get(2), 0.6, 1e-8); - BOOST_CHECK_CLOSE(sumtree.Get(3), 0.4, 1e-8); + CHECK(sumtree.Get(0) == Approx(1.0).epsilon(1e-10)); + CHECK(sumtree.Get(1) == Approx(0.8).epsilon(1e-10)); + CHECK(sumtree.Get(2) == Approx(0.6).epsilon(1e-10)); + CHECK(sumtree.Get(3) == Approx(0.4).epsilon(1e-10)); } /** * Test that we find the highest index in the array such that * Sum(arr[0] + arr[1] + arr[2] ... + arr[i]) <= mass. */ -BOOST_AUTO_TEST_CASE(FindPrefixSum) +TEST_CASE("FindPrefixSum", "[SumTreeTest]") { SumTree sumtree(4); sumtree.Set(0, 1.0); @@ -67,17 +65,17 @@ BOOST_AUTO_TEST_CASE(FindPrefixSum) sumtree.Set(2, 0.6); sumtree.Set(3, 0.4); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(0), 0); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(1), 1); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(2.8), 3); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(3.0), 3); + CHECK(sumtree.FindPrefixSum(0) <= 0); + CHECK(sumtree.FindPrefixSum(1) <= 1); + CHECK(sumtree.FindPrefixSum(2.8) <= 3); + CHECK(sumtree.FindPrefixSum(3.0) <= 3); } /** * Test that we find the highest index in the array such that * sum(arr[0] + arr[1] + arr[2] ... + arr[i]) <= mass. */ -BOOST_AUTO_TEST_CASE(BatchUpdate) +TEST_CASE("BatchUpdate", "[SumTreeTest]") { SumTree sumtree(4); arma::ucolvec indices = {0, 1, 2, 3}; @@ -85,10 +83,8 @@ BOOST_AUTO_TEST_CASE(BatchUpdate) sumtree.BatchUpdate(indices, data); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(0), 0); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(1), 1); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(2.8), 3); - BOOST_CHECK_EQUAL(sumtree.FindPrefixSum(3.0), 3); + CHECK(sumtree.FindPrefixSum(0) <= 0); + CHECK(sumtree.FindPrefixSum(1) <= 1); + CHECK(sumtree.FindPrefixSum(2.8) <= 3); + CHECK(sumtree.FindPrefixSum(3.0) <= 3); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp index 9efb8c8769..c5a606323f 100644 --- a/src/mlpack/tests/tree_test.cpp +++ b/src/mlpack/tests/tree_test.cpp @@ -19,8 +19,8 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::math; @@ -28,47 +28,45 @@ using namespace mlpack::tree; using namespace mlpack::metric; using namespace mlpack::bound; -BOOST_AUTO_TEST_SUITE(TreeTest); - /** * Ensure that a bound, by default, is empty and has no dimensionality. */ -BOOST_AUTO_TEST_CASE(HRectBoundEmptyConstructor) +TEST_CASE("HRectBoundEmptyConstructor", "[TreeTest]") { HRectBound b; - BOOST_REQUIRE_EQUAL((int) b.Dim(), 0); - BOOST_REQUIRE_EQUAL(b.MinWidth(), 0.0); + REQUIRE((int) b.Dim() == 0); + REQUIRE(b.MinWidth() == 0.0); } /** * Ensure that when we specify the dimensionality in the constructor, it is * correct, and the bounds are all the empty set. */ -BOOST_AUTO_TEST_CASE(HRectBoundDimConstructor) +TEST_CASE("HRectBoundDimConstructor", "[TreeTest]") { HRectBound b(2); // We'll do this with 2 and 5 dimensions. - BOOST_REQUIRE_EQUAL(b.Dim(), 2); - BOOST_REQUIRE_SMALL(b[0].Width(), 1e-5); - BOOST_REQUIRE_SMALL(b[1].Width(), 1e-5); + REQUIRE(b.Dim() == 2); + REQUIRE(b[0].Width() == Approx(0.0).margin(1e-5)); + REQUIRE(b[1].Width() == Approx(0.0).margin(1e-5)); b = HRectBound(5); - BOOST_REQUIRE_EQUAL(b.Dim(), 5); - BOOST_REQUIRE_SMALL(b[0].Width(), 1e-5); - BOOST_REQUIRE_SMALL(b[1].Width(), 1e-5); - BOOST_REQUIRE_SMALL(b[2].Width(), 1e-5); - BOOST_REQUIRE_SMALL(b[3].Width(), 1e-5); - BOOST_REQUIRE_SMALL(b[4].Width(), 1e-5); + REQUIRE(b.Dim() == 5); + REQUIRE(b[0].Width() == Approx(0.0).margin(1e-5)); + REQUIRE(b[1].Width() == Approx(0.0).margin(1e-5)); + REQUIRE(b[2].Width() == Approx(0.0).margin(1e-5)); + REQUIRE(b[3].Width() == Approx(0.0).margin(1e-5)); + REQUIRE(b[4].Width() == Approx(0.0).margin(1e-5)); - BOOST_REQUIRE_EQUAL(b.MinWidth(), 0.0); + REQUIRE(b.MinWidth() == 0.0); } /** * Test the copy constructor. */ -BOOST_AUTO_TEST_CASE(HRectBoundCopyConstructor) +TEST_CASE("HRectBoundCopyConstructor", "[TreeTest]") { HRectBound b(2); b[0] = Range(0.0, 2.0); @@ -77,18 +75,18 @@ BOOST_AUTO_TEST_CASE(HRectBoundCopyConstructor) HRectBound c(b); - BOOST_REQUIRE_EQUAL(c.Dim(), 2); - BOOST_REQUIRE_SMALL(c[0].Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(c[0].Hi(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(c[1].Lo(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(c[1].Hi(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(c.MinWidth(), 0.5, 1e-5); + REQUIRE(c.Dim() == 2); + REQUIRE(c[0].Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(c[0].Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(c[1].Lo() == Approx(2.0).epsilon(1e-7)); + REQUIRE(c[1].Hi() == Approx(3.0).epsilon(1e-7)); + REQUIRE(c.MinWidth() == Approx(0.5).epsilon(1e-7)); } /** * Test the assignment operator. */ -BOOST_AUTO_TEST_CASE(HRectBoundAssignmentOperator) +TEST_CASE("HRectBoundAssignmentOperator", "[TreeTest]") { HRectBound b(2); b[0] = Range(0.0, 2.0); @@ -99,18 +97,18 @@ BOOST_AUTO_TEST_CASE(HRectBoundAssignmentOperator) c = b; - BOOST_REQUIRE_EQUAL(c.Dim(), 2); - BOOST_REQUIRE_SMALL(c[0].Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(c[0].Hi(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(c[1].Lo(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(c[1].Hi(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(c.MinWidth(), 0.5, 1e-5); + REQUIRE(c.Dim() == 2); + REQUIRE(c[0].Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(c[0].Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(c[1].Lo() == Approx(2.0).epsilon(1e-7)); + REQUIRE(c[1].Hi() == Approx(3.0).epsilon(1e-7)); + REQUIRE(c.MinWidth() == Approx(0.5).epsilon(1e-7)); } /** * Test that clearing the dimensions resets the bound to empty. */ -BOOST_AUTO_TEST_CASE(HRectBoundClear) +TEST_CASE("HRectBoundClear", "[TreeTest]") { HRectBound b(2); // We'll do this with two dimensions only. @@ -121,12 +119,12 @@ BOOST_AUTO_TEST_CASE(HRectBoundClear) // Now we just need to make sure that we clear the range. b.Clear(); - BOOST_REQUIRE_SMALL(b[0].Width(), 1e-5); - BOOST_REQUIRE_SMALL(b[1].Width(), 1e-5); - BOOST_REQUIRE_SMALL(b.MinWidth(), 1e-5); + REQUIRE(b[0].Width() == Approx(0.0).margin(1e-5)); + REQUIRE(b[1].Width() == Approx(0.0).margin(1e-5)); + REQUIRE(b.MinWidth() == Approx(0.0).margin(1e-5)); } -BOOST_AUTO_TEST_CASE(HRectBoundMoveConstructor) +TEST_CASE("HRectBoundMoveConstructor", "[TreeTest]") { HRectBound b(2); b[0] = Range(0.0, 2.0); @@ -135,22 +133,22 @@ BOOST_AUTO_TEST_CASE(HRectBoundMoveConstructor) HRectBound b2(std::move(b)); - BOOST_REQUIRE_EQUAL(b.Dim(), 0); - BOOST_REQUIRE_EQUAL(b2.Dim(), 2); + REQUIRE(b.Dim() == 0); + REQUIRE(b2.Dim() == 2); - BOOST_REQUIRE_EQUAL(b.MinWidth(), 0.0); - BOOST_REQUIRE_EQUAL(b2.MinWidth(), 1.0); + REQUIRE(b.MinWidth() == 0.0); + REQUIRE(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); + REQUIRE(b2[0].Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(b2[0].Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(b2[1].Lo() == Approx(2.0).epsilon(1e-7)); + REQUIRE(b2[1].Hi() == Approx(4.0).epsilon(1e-7)); } /** * Ensure that we get the correct center for our bound. */ -BOOST_AUTO_TEST_CASE(HRectBoundCenter) +TEST_CASE("HRectBoundCenter", "[TreeTest]") { // Create a simple 3-dimensional bound. HRectBound b(3); @@ -163,16 +161,16 @@ BOOST_AUTO_TEST_CASE(HRectBoundCenter) b.Center(center); - BOOST_REQUIRE_EQUAL(center.n_elem, 3); - BOOST_REQUIRE_CLOSE(center[0], 2.5, 1e-5); - BOOST_REQUIRE_CLOSE(center[1], -1.5, 1e-5); - BOOST_REQUIRE_CLOSE(center[2], 20.0, 1e-5); + REQUIRE(center.n_elem == 3); + REQUIRE(center[0] == Approx(2.5).epsilon(1e-7)); + REQUIRE(center[1] == Approx(-1.5).epsilon(1e-7)); + REQUIRE(center[2] == Approx(20.0).epsilon(1e-7)); } /** * Ensure the volume calculation is correct. */ -BOOST_AUTO_TEST_CASE(HRectBoundVolume) +TEST_CASE("HRectBoundVolume", "[TreeTest]") { // Create a simple 3-dimensional bound. HRectBound b(3); @@ -181,14 +179,14 @@ BOOST_AUTO_TEST_CASE(HRectBoundVolume) b[1] = Range(-2.0, -1.0); b[2] = Range(-10.0, 50.0); - BOOST_REQUIRE_CLOSE(b.Volume(), 300.0, 1e-5); + REQUIRE(b.Volume() == Approx(300.0).epsilon(1e-7)); } /** * Ensure that we calculate the correct minimum distance between a point and a * bound. */ -BOOST_AUTO_TEST_CASE(HRectBoundMinDistancePoint) +TEST_CASE("HRectBoundMinDistancePoint", "[TreeTest]") { // We'll do the calculation in five dimensions, and we'll use three cases for // the point: point is outside the bound; point is on the edge of the bound; @@ -205,22 +203,22 @@ BOOST_AUTO_TEST_CASE(HRectBoundMinDistancePoint) arma::vec point = "-2.0 0.0 10.0 3.0 3.0"; // This will be the Euclidean distance. - BOOST_REQUIRE_CLOSE(b.MinDistance(point), sqrt(95.0), 1e-5); + REQUIRE(b.MinDistance(point) == Approx(sqrt(95.0)).epsilon(1e-7)); point = "2.0 5.0 2.0 -5.0 1.0"; - BOOST_REQUIRE_SMALL(b.MinDistance(point), 1e-5); + REQUIRE(b.MinDistance(point) == Approx(0.0).margin(1e-5)); point = "1.0 2.0 0.0 -2.0 1.5"; - BOOST_REQUIRE_SMALL(b.MinDistance(point), 1e-5); + REQUIRE(b.MinDistance(point) == Approx(0.0).margin(1e-5)); } /** * Ensure that we calculate the correct minimum distance between a bound and * another bound. */ -BOOST_AUTO_TEST_CASE(HRectBoundMinDistanceBound) +TEST_CASE("HRectBoundMinDistanceBound", "[TreeTest]") { // We'll do the calculation in five dimensions, and we can use six cases. // The other bound is completely outside the bound; the other bound is on the @@ -244,8 +242,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundMinDistanceBound) c[3] = Range(2.0, 5.0); c[4] = Range(3.0, 4.0); - BOOST_REQUIRE_CLOSE(b.MinDistance(c), sqrt(22.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MinDistance(b), sqrt(22.0), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(sqrt(22.0)).epsilon(1e-7)); + REQUIRE(c.MinDistance(b) == Approx(sqrt(22.0)).epsilon(1e-7)); // The other bound is on the edge of the bound. c[0] = Range(-2.0, 0.0); @@ -254,8 +252,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundMinDistanceBound) c[3] = Range(-10.0, -5.0); c[4] = Range(2.0, 3.0); - BOOST_REQUIRE_SMALL(b.MinDistance(c), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(b), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(b) == Approx(0.0).margin(1e-5)); // The other bound partially overlaps the bound. c[0] = Range(-2.0, 1.0); @@ -264,12 +262,12 @@ BOOST_AUTO_TEST_CASE(HRectBoundMinDistanceBound) c[3] = Range(-8.0, -4.0); c[4] = Range(0.0, 4.0); - BOOST_REQUIRE_SMALL(b.MinDistance(c), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(b), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(b) == Approx(0.0).margin(1e-5)); // The other bound fully overlaps the bound. - BOOST_REQUIRE_SMALL(b.MinDistance(b), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(c), 1e-5); + REQUIRE(b.MinDistance(b) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(c) == Approx(0.0).margin(1e-5)); // The other bound is entirely inside the bound / the other bound entirely // envelops the bound. @@ -279,19 +277,19 @@ BOOST_AUTO_TEST_CASE(HRectBoundMinDistanceBound) c[3] = Range(-7.0, 0.0); c[4] = Range(0.0, 5.0); - BOOST_REQUIRE_SMALL(b.MinDistance(c), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(b), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(b) == Approx(0.0).margin(1e-5)); // Now we must be sure that the minimum distance to itself is 0. - BOOST_REQUIRE_SMALL(b.MinDistance(b), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(c), 1e-5); + REQUIRE(b.MinDistance(b) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(c) == Approx(0.0).margin(1e-5)); } /** * Ensure that we calculate the correct maximum distance between a bound and a * point. This uses the same test cases as the MinDistance test. */ -BOOST_AUTO_TEST_CASE(HRectBoundMaxDistancePoint) +TEST_CASE("HRectBoundMaxDistancePoint", "[TreeTest]") { // We'll do the calculation in five dimensions, and we'll use three cases for // the point: point is outside the bound; point is on the edge of the bound; @@ -308,22 +306,22 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistancePoint) arma::vec point = "-2.0 0.0 10.0 3.0 3.0"; // This will be the Euclidean distance. - BOOST_REQUIRE_CLOSE(b.MaxDistance(point), sqrt(253.0), 1e-5); + REQUIRE(b.MaxDistance(point) == Approx(sqrt(253.0)).epsilon(1e-7)); point = "2.0 5.0 2.0 -5.0 1.0"; - BOOST_REQUIRE_CLOSE(b.MaxDistance(point), sqrt(46.0), 1e-5); + REQUIRE(b.MaxDistance(point) == Approx(sqrt(46.0)).epsilon(1e-7)); point = "1.0 2.0 0.0 -2.0 1.5"; - BOOST_REQUIRE_CLOSE(b.MaxDistance(point), sqrt(23.25), 1e-5); + REQUIRE(b.MaxDistance(point) == Approx(sqrt(23.25)).epsilon(1e-7)); } /** * Ensure that we calculate the correct maximum distance between a bound and * another bound. This uses the same test cases as the MinDistance test. */ -BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) +TEST_CASE("HRectBoundMaxDistanceBound", "[TreeTest]") { // We'll do the calculation in five dimensions, and we can use six cases. // The other bound is completely outside the bound; the other bound is on the @@ -347,8 +345,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) c[3] = Range(2.0, 5.0); c[4] = Range(3.0, 4.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(210.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(210.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(210.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(210.0)).epsilon(1e-7)); // The other bound is on the edge of the bound. c[0] = Range(-2.0, 0.0); @@ -357,8 +355,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) c[3] = Range(-10.0, -5.0); c[4] = Range(2.0, 3.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(134.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(134.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(134.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(134.0)).epsilon(1e-7)); // The other bound partially overlaps the bound. c[0] = Range(-2.0, 1.0); @@ -367,12 +365,12 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) c[3] = Range(-8.0, -4.0); c[4] = Range(0.0, 4.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(102.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(102.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(102.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(102.0)).epsilon(1e-7)); // The other bound fully overlaps the bound. - BOOST_REQUIRE_CLOSE(b.MaxDistance(b), sqrt(46.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(c), sqrt(61.0), 1e-5); + REQUIRE(b.MaxDistance(b) == Approx(sqrt(46.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(c) == Approx(sqrt(61.0)).epsilon(1e-7)); // The other bound is entirely inside the bound / the other bound entirely // envelops the bound. @@ -382,13 +380,13 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) c[3] = Range(-7.0, 0.0); c[4] = Range(0.0, 5.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(100.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(100.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(100.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(100.0)).epsilon(1e-7)); // Identical bounds. This will be the sum of the squared widths in each // dimension. - BOOST_REQUIRE_CLOSE(b.MaxDistance(b), sqrt(46.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(c), sqrt(162.0), 1e-5); + REQUIRE(b.MaxDistance(b) == Approx(sqrt(46.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(c) == Approx(sqrt(162.0)).epsilon(1e-7)); // One last additional case. If the bound encloses only one point, the // maximum distance between it and itself is 0. @@ -397,7 +395,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) d[0] = Range(2.0, 2.0); d[1] = Range(3.0, 3.0); - BOOST_REQUIRE_SMALL(d.MaxDistance(d), 1e-5); + REQUIRE(d.MaxDistance(d) == Approx(0.0).margin(1e-5)); } /** @@ -406,7 +404,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) * and comparing the behavior to MinDistance() and MaxDistance() -- so this test * is assuming that those passed and operate correctly. */ -BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) +TEST_CASE("HRectBoundRangeDistanceBound", "[TreeTest]") { for (int i = 0; i < 50; ++i) { @@ -439,14 +437,14 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) Range r = a.RangeDistance(b); Range s = b.RangeDistance(a); - BOOST_REQUIRE_CLOSE(r.Lo(), s.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(r.Hi(), s.Hi(), 1e-5); + REQUIRE(r.Lo() == Approx(s.Lo()).epsilon(1e-7)); + REQUIRE(r.Hi() == Approx(s.Hi()).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(r.Lo(), a.MinDistance(b), 1e-5); - BOOST_REQUIRE_CLOSE(r.Hi(), a.MaxDistance(b), 1e-5); + REQUIRE(r.Lo() == Approx(a.MinDistance(b)).epsilon(1e-7)); + REQUIRE(r.Hi() == Approx(a.MaxDistance(b)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(s.Lo(), b.MinDistance(a), 1e-5); - BOOST_REQUIRE_CLOSE(s.Hi(), b.MaxDistance(a), 1e-5); + REQUIRE(s.Lo() == Approx(b.MinDistance(a)).epsilon(1e-7)); + REQUIRE(s.Hi() == Approx(b.MaxDistance(a)).epsilon(1e-7)); } } @@ -457,7 +455,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) * is assuming that those passed and operate correctly. This is for the * bound-to-point case. */ -BOOST_AUTO_TEST_CASE(HRectBoundRangeDistancePoint) +TEST_CASE("HRectBoundRangeDistancePoint", "[TreeTest]") { for (int i = 0; i < 20; ++i) { @@ -485,8 +483,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistancePoint) Range r = a.RangeDistance(point); - BOOST_REQUIRE_CLOSE(r.Lo(), a.MinDistance(point), 1e-5); - BOOST_REQUIRE_CLOSE(r.Hi(), a.MaxDistance(point), 1e-5); + REQUIRE(r.Lo() == Approx(a.MinDistance(point)).epsilon(1e-7)); + REQUIRE(r.Hi() == Approx(a.MaxDistance(point)).epsilon(1e-7)); } } } @@ -494,7 +492,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistancePoint) /** * Test that we can expand the bound to include a new point. */ -BOOST_AUTO_TEST_CASE(HRectBoundOrOperatorPoint) +TEST_CASE("HRectBoundOrOperatorPoint", "[TreeTest]") { // Because this should be independent in each dimension, we can essentially // run five test cases at once. @@ -511,23 +509,23 @@ BOOST_AUTO_TEST_CASE(HRectBoundOrOperatorPoint) b |= point; - BOOST_REQUIRE_CLOSE(b[0].Lo(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[0].Hi(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[1].Lo(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[1].Hi(), 4.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[2].Lo(), -2.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[2].Hi(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[3].Lo(), -1.0, 1e-5); - BOOST_REQUIRE_SMALL(b[3].Hi(), 1e-5); - BOOST_REQUIRE_CLOSE(b[4].Lo(), 6.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[4].Hi(), 6.0, 1e-5); - BOOST_REQUIRE_SMALL(b.MinWidth(), 1e-5); + REQUIRE(b[0].Lo() == Approx(1.0).epsilon(1e-7)); + REQUIRE(b[0].Hi() == Approx(3.0).epsilon(1e-7)); + REQUIRE(b[1].Lo() == Approx(2.0).epsilon(1e-7)); + REQUIRE(b[1].Hi() == Approx(4.0).epsilon(1e-7)); + REQUIRE(b[2].Lo() == Approx(-2.0).epsilon(1e-7)); + REQUIRE(b[2].Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(b[3].Lo() == Approx(-1.0).epsilon(1e-7)); + REQUIRE(b[3].Hi() == Approx(0.0).margin(1e-5)); + REQUIRE(b[4].Lo() == Approx(6.0).epsilon(1e-7)); + REQUIRE(b[4].Hi() == Approx(6.0).epsilon(1e-7)); + REQUIRE(b.MinWidth() == Approx(0.0).margin(1e-5)); } /** * Test that we can expand the bound to include another bound. */ -BOOST_AUTO_TEST_CASE(HRectBoundOrOperatorBound) +TEST_CASE("HRectBoundOrOperatorBound", "[TreeTest]") { // Because this should be independent in each dimension, we can run many tests // at once. @@ -558,55 +556,55 @@ BOOST_AUTO_TEST_CASE(HRectBoundOrOperatorBound) b |= c; d |= b; - BOOST_REQUIRE_CLOSE(b[0].Lo(), -3.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[0].Hi(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[0].Lo(), -3.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[0].Hi(), 3.0, 1e-5); + REQUIRE(b[0].Lo() == Approx(-3.0).epsilon(1e-7)); + REQUIRE(b[0].Hi() == Approx(3.0).epsilon(1e-7)); + REQUIRE(d[0].Lo() == Approx(-3.0).epsilon(1e-7)); + REQUIRE(d[0].Hi() == Approx(3.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b[1].Lo(), 0.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[1].Hi(), 4.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[1].Lo(), 0.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[1].Hi(), 4.0, 1e-5); + REQUIRE(b[1].Lo() == Approx(0.0).epsilon(1e-7)); + REQUIRE(b[1].Hi() == Approx(4.0).epsilon(1e-7)); + REQUIRE(d[1].Lo() == Approx(0.0).epsilon(1e-7)); + REQUIRE(d[1].Hi() == Approx(4.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b[2].Lo(), -3.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[2].Hi(), -1.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[2].Lo(), -3.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[2].Hi(), -1.0, 1e-5); + REQUIRE(b[2].Lo() == Approx(-3.0).epsilon(1e-7)); + REQUIRE(b[2].Hi() == Approx(-1.0).epsilon(1e-7)); + REQUIRE(d[2].Lo() == Approx(-3.0).epsilon(1e-7)); + REQUIRE(d[2].Hi() == Approx(-1.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b[3].Lo(), 4.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[3].Hi(), 5.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[3].Lo(), 4.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[3].Hi(), 5.0, 1e-5); + REQUIRE(b[3].Lo() == Approx(4.0).epsilon(1e-7)); + REQUIRE(b[3].Hi() == Approx(5.0).epsilon(1e-7)); + REQUIRE(d[3].Lo() == Approx(4.0).epsilon(1e-7)); + REQUIRE(d[3].Hi() == Approx(5.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b[4].Lo(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[4].Hi(), 5.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[4].Lo(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[4].Hi(), 5.0, 1e-5); + REQUIRE(b[4].Lo() == Approx(1.0).epsilon(1e-7)); + REQUIRE(b[4].Hi() == Approx(5.0).epsilon(1e-7)); + REQUIRE(d[4].Lo() == Approx(1.0).epsilon(1e-7)); + REQUIRE(d[4].Hi() == Approx(5.0).epsilon(1e-7)); - BOOST_REQUIRE_SMALL(b[5].Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(b[5].Hi(), 2.0, 1e-5); - BOOST_REQUIRE_SMALL(d[5].Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(d[5].Hi(), 2.0, 1e-5); + REQUIRE(b[5].Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(b[5].Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(d[5].Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(d[5].Hi() == Approx(2.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b[6].Lo(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[6].Hi(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[6].Lo(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[6].Hi(), 3.0, 1e-5); + REQUIRE(b[6].Lo() == Approx(1.0).epsilon(1e-7)); + REQUIRE(b[6].Hi() == Approx(3.0).epsilon(1e-7)); + REQUIRE(d[6].Lo() == Approx(1.0).epsilon(1e-7)); + REQUIRE(d[6].Hi() == Approx(3.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b[7].Lo(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(b[7].Hi(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[7].Lo(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(d[7].Hi(), 3.0, 1e-5); + REQUIRE(b[7].Lo() == Approx(1.0).epsilon(1e-7)); + REQUIRE(b[7].Hi() == Approx(3.0).epsilon(1e-7)); + REQUIRE(d[7].Lo() == Approx(1.0).epsilon(1e-7)); + REQUIRE(d[7].Hi() == Approx(3.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b.MinWidth(), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(d.MinWidth(), 1.0, 1e-5); + REQUIRE(b.MinWidth() == Approx(1.0).epsilon(1e-7)); + REQUIRE(d.MinWidth() == Approx(1.0).epsilon(1e-7)); } /** * Test that the Contains() function correctly figures out whether or not a * point is in a bound. */ -BOOST_AUTO_TEST_CASE(HRectBoundContains) +TEST_CASE("HRectBoundContains", "[TreeTest]") { // We can test a couple different points: completely outside the bound, // adjacent in one dimension to the bound, adjacent in all dimensions to the @@ -619,30 +617,30 @@ BOOST_AUTO_TEST_CASE(HRectBoundContains) // Completely outside the range. arma::vec point = "-1.0 4.0 4.0"; - BOOST_REQUIRE(!b.Contains(point)); + REQUIRE(!b.Contains(point)); // Completely outside, but one dimension is in the range. point = "-1.0 4.0 1.0"; - BOOST_REQUIRE(!b.Contains(point)); + REQUIRE(!b.Contains(point)); // Outside, but one dimension is on the edge. point = "-1.0 0.0 3.0"; - BOOST_REQUIRE(!b.Contains(point)); + REQUIRE(!b.Contains(point)); // Two dimensions are on the edge, but one is outside. point = "0.0 0.0 3.0"; - BOOST_REQUIRE(!b.Contains(point)); + REQUIRE(!b.Contains(point)); // Completely on the edge (should be contained). point = "0.0 0.0 0.0"; - BOOST_REQUIRE(b.Contains(point)); + REQUIRE(b.Contains(point)); // Inside the range. point = "0.3 1.0 0.4"; - BOOST_REQUIRE(b.Contains(point)); + REQUIRE(b.Contains(point)); } -BOOST_AUTO_TEST_CASE(TestBallBound) +TEST_CASE("TestBallBound", "[TreeTest]") { BallBound<> b1; BallBound<> b2; @@ -661,57 +659,57 @@ BOOST_AUTO_TEST_CASE(TestBallBound) b2.Center()[2] = 4; b2.Radius() = 0.4; - BOOST_REQUIRE_CLOSE(b1.MinDistance(b2), 1-0.3-0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b1.RangeDistance(b2).Hi(), 1+0.3+0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b1.RangeDistance(b2).Lo(), 1-0.3-0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b1.RangeDistance(b2).Hi(), 1+0.3+0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b1.RangeDistance(b2).Lo(), 1-0.3-0.4, 1e-5); + REQUIRE(b1.MinDistance(b2) == Approx(1-0.3-0.4).epsilon(1e-7)); + REQUIRE(b1.RangeDistance(b2).Hi() == Approx(1+0.3+0.4).epsilon(1e-7)); + REQUIRE(b1.RangeDistance(b2).Lo() == Approx(1-0.3-0.4).epsilon(1e-7)); + REQUIRE(b1.RangeDistance(b2).Hi() == Approx(1+0.3+0.4).epsilon(1e-7)); + REQUIRE(b1.RangeDistance(b2).Lo() == Approx(1-0.3-0.4).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b2.MinDistance(b1), 1-0.3-0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b2.MaxDistance(b1), 1+0.3+0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b2.RangeDistance(b1).Hi(), 1+0.3+0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b2.RangeDistance(b1).Lo(), 1-0.3-0.4, 1e-5); + REQUIRE(b2.MinDistance(b1) == Approx(1-0.3-0.4).epsilon(1e-7)); + REQUIRE(b2.MaxDistance(b1) == Approx(1+0.3+0.4).epsilon(1e-7)); + REQUIRE(b2.RangeDistance(b1).Hi() == Approx(1+0.3+0.4).epsilon(1e-7)); + REQUIRE(b2.RangeDistance(b1).Lo() == Approx(1-0.3-0.4).epsilon(1e-7)); - BOOST_REQUIRE(b1.Contains(b1.Center())); - BOOST_REQUIRE(!b1.Contains(b2.Center())); + REQUIRE(b1.Contains(b1.Center())); + REQUIRE(!b1.Contains(b2.Center())); - BOOST_REQUIRE(!b2.Contains(b1.Center())); - BOOST_REQUIRE(b2.Contains(b2.Center())); + REQUIRE(!b2.Contains(b1.Center())); + REQUIRE(b2.Contains(b2.Center())); arma::vec b2point(3); // A point that's within the radius but not the center. b2point[0] = 1.1; b2point[1] = 2.1; b2point[2] = 4.1; - BOOST_REQUIRE(b2.Contains(b2point)); + REQUIRE(b2.Contains(b2point)); - BOOST_REQUIRE_SMALL(b1.MinDistance(b1.Center()), 1e-5); - BOOST_REQUIRE_CLOSE(b1.MinDistance(b2.Center()), 1 - 0.3, 1e-5); - BOOST_REQUIRE_CLOSE(b2.MinDistance(b1.Center()), 1 - 0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b2.MaxDistance(b1.Center()), 1 + 0.4, 1e-5); - BOOST_REQUIRE_CLOSE(b1.MaxDistance(b2.Center()), 1 + 0.3, 1e-5); + REQUIRE(b1.MinDistance(b1.Center()) == Approx(0.0).margin(1e-5)); + REQUIRE(b1.MinDistance(b2.Center()) == Approx(1 - 0.3).epsilon(1e-7)); + REQUIRE(b2.MinDistance(b1.Center()) == Approx(1 - 0.4).epsilon(1e-7)); + REQUIRE(b2.MaxDistance(b1.Center()) == Approx(1 + 0.4).epsilon(1e-7)); + REQUIRE(b1.MaxDistance(b2.Center()) == Approx(1 + 0.3).epsilon(1e-7)); } -BOOST_AUTO_TEST_CASE(BallBoundMoveConstructor) +TEST_CASE("BallBoundMoveConstructor", "[TreeTest]") { 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); + REQUIRE(b2.Dim() == 3); + REQUIRE(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); + REQUIRE(b2.Center()[0] == Approx(2.0).epsilon(1e-7)); + REQUIRE(b2.Center()[1] == Approx(1.0).epsilon(1e-7)); + REQUIRE(b2.Center()[2] == Approx(1.0).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(b2.MinWidth(), 4.0, 1e-5); - BOOST_REQUIRE_SMALL(b1.MinWidth(), 1e-5); + REQUIRE(b2.MinWidth() == Approx(4.0).epsilon(1e-7)); + REQUIRE(b1.MinWidth() == Approx(0.0).margin(1e-5)); } /** * Ensure that we calculate the correct minimum distance between a point and a * bound. */ -BOOST_AUTO_TEST_CASE(HRectBoundRootMinDistancePoint) +TEST_CASE("HRectBoundRootMinDistancePoint", "[TreeTest]") { // We'll do the calculation in five dimensions, and we'll use three cases for // the point: point is outside the bound; point is on the edge of the bound; @@ -728,22 +726,22 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMinDistancePoint) arma::vec point = "-2.0 0.0 10.0 3.0 3.0"; // This will be the Euclidean distance. - BOOST_REQUIRE_CLOSE(b.MinDistance(point), sqrt(95.0), 1e-5); + REQUIRE(b.MinDistance(point) == Approx(sqrt(95.0)).epsilon(1e-7)); point = "2.0 5.0 2.0 -5.0 1.0"; - BOOST_REQUIRE_SMALL(b.MinDistance(point), 1e-5); + REQUIRE(b.MinDistance(point) == Approx(0.0).margin(1e-5)); point = "1.0 2.0 0.0 -2.0 1.5"; - BOOST_REQUIRE_SMALL(b.MinDistance(point), 1e-5); + REQUIRE(b.MinDistance(point) == Approx(0.0).margin(1e-5)); } /** * Ensure that we calculate the correct minimum distance between a bound and * another bound. */ -BOOST_AUTO_TEST_CASE(HRectBoundRootMinDistanceBound) +TEST_CASE("HRectBoundRootMinDistanceBound", "[TreeTest]") { // We'll do the calculation in five dimensions, and we can use six cases. // The other bound is completely outside the bound; the other bound is on the @@ -767,8 +765,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMinDistanceBound) c[3] = Range(2.0, 5.0); c[4] = Range(3.0, 4.0); - BOOST_REQUIRE_CLOSE(b.MinDistance(c), sqrt(22.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MinDistance(b), sqrt(22.0), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(sqrt(22.0)).epsilon(1e-7)); + REQUIRE(c.MinDistance(b) == Approx(sqrt(22.0)).epsilon(1e-7)); // The other bound is on the edge of the bound. c[0] = Range(-2.0, 0.0); @@ -777,8 +775,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMinDistanceBound) c[3] = Range(-10.0, -5.0); c[4] = Range(2.0, 3.0); - BOOST_REQUIRE_SMALL(b.MinDistance(c), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(b), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(b) == Approx(0.0).margin(1e-5)); // The other bound partially overlaps the bound. c[0] = Range(-2.0, 1.0); @@ -787,12 +785,12 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMinDistanceBound) c[3] = Range(-8.0, -4.0); c[4] = Range(0.0, 4.0); - BOOST_REQUIRE_SMALL(b.MinDistance(c), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(b), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(b) == Approx(0.0).margin(1e-5)); // The other bound fully overlaps the bound. - BOOST_REQUIRE_SMALL(b.MinDistance(b), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(c), 1e-5); + REQUIRE(b.MinDistance(b) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(c) == Approx(0.0).margin(1e-5)); // The other bound is entirely inside the bound / the other bound entirely // envelops the bound. @@ -802,19 +800,19 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMinDistanceBound) c[3] = Range(-7.0, 0.0); c[4] = Range(0.0, 5.0); - BOOST_REQUIRE_SMALL(b.MinDistance(c), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(b), 1e-5); + REQUIRE(b.MinDistance(c) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(b) == Approx(0.0).margin(1e-5)); // Now we must be sure that the minimum distance to itself is 0. - BOOST_REQUIRE_SMALL(b.MinDistance(b), 1e-5); - BOOST_REQUIRE_SMALL(c.MinDistance(c), 1e-5); + REQUIRE(b.MinDistance(b) == Approx(0.0).margin(1e-5)); + REQUIRE(c.MinDistance(c) == Approx(0.0).margin(1e-5)); } /** * Ensure that we calculate the correct maximum distance between a bound and a * point. This uses the same test cases as the MinDistance test. */ -BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistancePoint) +TEST_CASE("HRectBoundRootMaxDistancePoint", "[TreeTest]") { // We'll do the calculation in five dimensions, and we'll use three cases for // the point: point is outside the bound; point is on the edge of the bound; @@ -831,22 +829,22 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistancePoint) arma::vec point = "-2.0 0.0 10.0 3.0 3.0"; // This will be the Euclidean distance. - BOOST_REQUIRE_CLOSE(b.MaxDistance(point), sqrt(253.0), 1e-5); + REQUIRE(b.MaxDistance(point) == Approx(sqrt(253.0)).epsilon(1e-7)); point = "2.0 5.0 2.0 -5.0 1.0"; - BOOST_REQUIRE_CLOSE(b.MaxDistance(point), sqrt(46.0), 1e-5); + REQUIRE(b.MaxDistance(point) == Approx(sqrt(46.0)).epsilon(1e-7)); point = "1.0 2.0 0.0 -2.0 1.5"; - BOOST_REQUIRE_CLOSE(b.MaxDistance(point), sqrt(23.25), 1e-5); + REQUIRE(b.MaxDistance(point) == Approx(sqrt(23.25)).epsilon(1e-7)); } /** * Ensure that we calculate the correct maximum distance between a bound and * another bound. This uses the same test cases as the MinDistance test. */ -BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) +TEST_CASE("HRectBoundRootMaxDistanceBound", "[TreeTest]") { // We'll do the calculation in five dimensions, and we can use six cases. // The other bound is completely outside the bound; the other bound is on the @@ -870,8 +868,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) c[3] = Range(2.0, 5.0); c[4] = Range(3.0, 4.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(210.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(210.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(210.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(210.0)).epsilon(1e-7)); // The other bound is on the edge of the bound. c[0] = Range(-2.0, 0.0); @@ -880,8 +878,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) c[3] = Range(-10.0, -5.0); c[4] = Range(2.0, 3.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(134.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(134.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(134.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(134.0)).epsilon(1e-7)); // The other bound partially overlaps the bound. c[0] = Range(-2.0, 1.0); @@ -890,12 +888,12 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) c[3] = Range(-8.0, -4.0); c[4] = Range(0.0, 4.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(102.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(102.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(102.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(102.0)).epsilon(1e-7)); // The other bound fully overlaps the bound. - BOOST_REQUIRE_CLOSE(b.MaxDistance(b), sqrt(46.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(c), sqrt(61.0), 1e-5); + REQUIRE(b.MaxDistance(b) == Approx(sqrt(46.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(c) == Approx(sqrt(61.0)).epsilon(1e-7)); // The other bound is entirely inside the bound / the other bound entirely // envelops the bound. @@ -905,13 +903,13 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) c[3] = Range(-7.0, 0.0); c[4] = Range(0.0, 5.0); - BOOST_REQUIRE_CLOSE(b.MaxDistance(c), sqrt(100.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(b), sqrt(100.0), 1e-5); + REQUIRE(b.MaxDistance(c) == Approx(sqrt(100.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(b) == Approx(sqrt(100.0)).epsilon(1e-7)); // Identical bounds. This will be the sum of the squared widths in each // dimension. - BOOST_REQUIRE_CLOSE(b.MaxDistance(b), sqrt(46.0), 1e-5); - BOOST_REQUIRE_CLOSE(c.MaxDistance(c), sqrt(162.0), 1e-5); + REQUIRE(b.MaxDistance(b) == Approx(sqrt(46.0)).epsilon(1e-7)); + REQUIRE(c.MaxDistance(c) == Approx(sqrt(162.0)).epsilon(1e-7)); // One last additional case. If the bound encloses only one point, the // maximum distance between it and itself is 0. @@ -920,7 +918,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) d[0] = Range(2.0, 2.0); d[1] = Range(3.0, 3.0); - BOOST_REQUIRE_SMALL(d.MaxDistance(d), 1e-5); + REQUIRE(d.MaxDistance(d) == Approx(0.0).margin(1e-5)); } /** @@ -929,7 +927,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) * and comparing the behavior to MinDistance() and MaxDistance() -- so this test * is assuming that those passed and operate correctly. */ -BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) +TEST_CASE("HRectBoundRootRangeDistanceBound", "[TreeTest]") { for (int i = 0; i < 50; ++i) { @@ -962,14 +960,14 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) Range r = a.RangeDistance(b); Range s = b.RangeDistance(a); - BOOST_REQUIRE_CLOSE(r.Lo(), s.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(r.Hi(), s.Hi(), 1e-5); + REQUIRE(r.Lo() == Approx(s.Lo()).epsilon(1e-7)); + REQUIRE(r.Hi() == Approx(s.Hi()).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(r.Lo(), a.MinDistance(b), 1e-5); - BOOST_REQUIRE_CLOSE(r.Hi(), a.MaxDistance(b), 1e-5); + REQUIRE(r.Lo() == Approx(a.MinDistance(b)).epsilon(1e-7)); + REQUIRE(r.Hi() == Approx(a.MaxDistance(b)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(s.Lo(), b.MinDistance(a), 1e-5); - BOOST_REQUIRE_CLOSE(s.Hi(), b.MaxDistance(a), 1e-5); + REQUIRE(s.Lo() == Approx(b.MinDistance(a)).epsilon(1e-7)); + REQUIRE(s.Hi() == Approx(b.MaxDistance(a)).epsilon(1e-7)); } } @@ -980,7 +978,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) * is assuming that those passed and operate correctly. This is for the * bound-to-point case. */ -BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistancePoint) +TEST_CASE("HRectBoundRootRangeDistancePoint", "[TreeTest]") { for (int i = 0; i < 20; ++i) { @@ -1008,8 +1006,8 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistancePoint) Range r = a.RangeDistance(point); - BOOST_REQUIRE_CLOSE(r.Lo(), a.MinDistance(point), 1e-5); - BOOST_REQUIRE_CLOSE(r.Hi(), a.MaxDistance(point), 1e-5); + REQUIRE(r.Lo() == Approx(a.MinDistance(point)).epsilon(1e-7)); + REQUIRE(r.Hi() == Approx(a.MaxDistance(point)).epsilon(1e-7)); } } } @@ -1017,7 +1015,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistancePoint) /** * Ensure that HRectBound::Diameter() works properly. */ -BOOST_AUTO_TEST_CASE(HRectBoundDiameter) +TEST_CASE("HRectBoundDiameter", "[TreeTest]") { HRectBound> b(4); b[0] = math::Range(0.0, 1.0); @@ -1025,7 +1023,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundDiameter) b[2] = math::Range(2.0, 3.0); b[3] = math::Range(7.0, 7.0); - BOOST_REQUIRE_CLOSE(b.Diameter(), std::pow(3.0, 1.0 / 3.0), 1e-5); + REQUIRE(b.Diameter()== Approx(std::pow(3.0, 1.0 / 3.0)).epsilon(1e-7)); HRectBound> c(4); c[0] = math::Range(0.0, 1.0); @@ -1033,13 +1031,13 @@ BOOST_AUTO_TEST_CASE(HRectBoundDiameter) c[2] = math::Range(2.0, 3.0); c[3] = math::Range(0.0, 0.0); - BOOST_REQUIRE_CLOSE(c.Diameter(), 3.0, 1e-5); + REQUIRE(c.Diameter() == Approx(3.0).epsilon(1e-7)); HRectBound> d(2); d[0] = math::Range(2.2, 2.2); d[1] = math::Range(1.0, 1.0); - BOOST_REQUIRE_SMALL(d.Diameter(), 1e-5); + REQUIRE(d.Diameter() == Approx(0.0).margin(1e-5)); } /** @@ -1048,7 +1046,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundDiameter) * BinarySpaceTree<>::count_. So, let's build a simple tree and make sure they * are the same. */ -BOOST_AUTO_TEST_CASE(TreeCountMismatch) +TEST_CASE("TreeCountMismatch", "[TreeTest]") { arma::mat dataset = "2.0 5.0 9.0 4.0 8.0 7.0;" "3.0 4.0 6.0 7.0 1.0 2.0 "; @@ -1056,20 +1054,20 @@ BOOST_AUTO_TEST_CASE(TreeCountMismatch) // Leaf size of 1. KDTree rootNode(dataset, 1); - BOOST_REQUIRE(rootNode.Count() == 6); - BOOST_REQUIRE(rootNode.Left()->Count() == 3); - BOOST_REQUIRE(rootNode.Left()->Left()->Count() == 2); - BOOST_REQUIRE(rootNode.Left()->Left()->Left()->Count() == 1); - BOOST_REQUIRE(rootNode.Left()->Left()->Right()->Count() == 1); - BOOST_REQUIRE(rootNode.Left()->Right()->Count() == 1); - BOOST_REQUIRE(rootNode.Right()->Count() == 3); - BOOST_REQUIRE(rootNode.Right()->Left()->Count() == 2); - BOOST_REQUIRE(rootNode.Right()->Left()->Left()->Count() == 1); - BOOST_REQUIRE(rootNode.Right()->Left()->Right()->Count() == 1); - BOOST_REQUIRE(rootNode.Right()->Right()->Count() == 1); + REQUIRE(rootNode.Count() == 6); + REQUIRE(rootNode.Left()->Count() == 3); + REQUIRE(rootNode.Left()->Left()->Count() == 2); + REQUIRE(rootNode.Left()->Left()->Left()->Count() == 1); + REQUIRE(rootNode.Left()->Left()->Right()->Count() == 1); + REQUIRE(rootNode.Left()->Right()->Count() == 1); + REQUIRE(rootNode.Right()->Count() == 3); + REQUIRE(rootNode.Right()->Left()->Count() == 2); + REQUIRE(rootNode.Right()->Left()->Left()->Count() == 1); + REQUIRE(rootNode.Right()->Left()->Right()->Count() == 1); + REQUIRE(rootNode.Right()->Right()->Count() == 1); } -BOOST_AUTO_TEST_CASE(CheckParents) +TEST_CASE("CheckParents", "[TreeTest]") { arma::mat dataset = "2.0 5.0 9.0 4.0 8.0 7.0;" "3.0 4.0 6.0 7.0 1.0 2.0 "; @@ -1077,25 +1075,25 @@ BOOST_AUTO_TEST_CASE(CheckParents) // Leaf size of 1. KDTree rootNode(dataset, 1); - BOOST_REQUIRE_EQUAL(rootNode.Parent(), + REQUIRE(rootNode.Parent() == (KDTree*) NULL); - BOOST_REQUIRE_EQUAL(&rootNode, rootNode.Left()->Parent()); - BOOST_REQUIRE_EQUAL(&rootNode, rootNode.Right()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Left(), rootNode.Left()->Left()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Left(), rootNode.Left()->Right()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Left()->Left(), + REQUIRE(&rootNode == rootNode.Left()->Parent()); + REQUIRE(&rootNode == rootNode.Right()->Parent()); + REQUIRE(rootNode.Left() == rootNode.Left()->Left()->Parent()); + REQUIRE(rootNode.Left() == rootNode.Left()->Right()->Parent()); + REQUIRE(rootNode.Left()->Left() == rootNode.Left()->Left()->Left()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Left()->Left(), + REQUIRE(rootNode.Left()->Left() == rootNode.Left()->Left()->Right()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Right(), rootNode.Right()->Left()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Right(), rootNode.Right()->Right()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Right()->Left(), + REQUIRE(rootNode.Right() == rootNode.Right()->Left()->Parent()); + REQUIRE(rootNode.Right() == rootNode.Right()->Right()->Parent()); + REQUIRE(rootNode.Right()->Left() == rootNode.Right()->Left()->Left()->Parent()); - BOOST_REQUIRE_EQUAL(rootNode.Right()->Left(), + REQUIRE(rootNode.Right()->Left() == rootNode.Right()->Left()->Right()->Parent()); } -BOOST_AUTO_TEST_CASE(CheckDataset) +TEST_CASE("CheckDataset", "[TreeTest]") { arma::mat dataset = "2.0 5.0 9.0 4.0 8.0 7.0;" "3.0 4.0 6.0 7.0 1.0 2.0 "; @@ -1104,39 +1102,40 @@ BOOST_AUTO_TEST_CASE(CheckDataset) KDTree rootNode(dataset, 1); arma::mat* rootDataset = &rootNode.Dataset(); - BOOST_REQUIRE_EQUAL(&rootNode.Left()->Dataset(), rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Right()->Dataset(), rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Left()->Left()->Dataset(), rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Left()->Right()->Dataset(), rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Right()->Left()->Dataset(), rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Right()->Right()->Dataset(), rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Left()->Left()->Left()->Dataset(), + REQUIRE(&rootNode.Left()->Dataset() == rootDataset); + REQUIRE(&rootNode.Right()->Dataset() == rootDataset); + REQUIRE(&rootNode.Left()->Left()->Dataset() == rootDataset); + REQUIRE(&rootNode.Left()->Right()->Dataset() == rootDataset); + REQUIRE(&rootNode.Right()->Left()->Dataset() == rootDataset); + REQUIRE(&rootNode.Right()->Right()->Dataset() == rootDataset); + REQUIRE(&rootNode.Left()->Left()->Left()->Dataset() == rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Left()->Left()->Right()->Dataset(), + REQUIRE(&rootNode.Left()->Left()->Right()->Dataset() == rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Right()->Left()->Left()->Dataset(), + REQUIRE(&rootNode.Right()->Left()->Left()->Dataset() == rootDataset); - BOOST_REQUIRE_EQUAL(&rootNode.Right()->Left()->Right()->Dataset(), + REQUIRE(&rootNode.Right()->Left()->Right()->Dataset() == rootDataset); } // Ensure FurthestDescendantDistance() works. -BOOST_AUTO_TEST_CASE(FurthestDescendantDistanceTest) +TEST_CASE("FurthestDescendantDistanceTest", "[TreeTest]") { arma::mat dataset = "1; 3"; // One point. KDTree rootNode(dataset, 1); - BOOST_REQUIRE_SMALL(rootNode.FurthestDescendantDistance(), 1e-5); + REQUIRE(rootNode.FurthestDescendantDistance() == Approx(0.0).margin(1e-5)); dataset = "1 -1; 1 -1"; // Square of size [2, 2]. // Both points are contained in the one node. KDTree twoPoint(dataset); - BOOST_REQUIRE_CLOSE(twoPoint.FurthestDescendantDistance(), sqrt(2.0), 1e-5); + REQUIRE(twoPoint.FurthestDescendantDistance() == + Approx(sqrt(2.0)).epsilon(1e-7)); } // Ensure that FurthestPointDistance() works. -BOOST_AUTO_TEST_CASE(FurthestPointDistanceTest) +TEST_CASE("FurthestPointDistanceTest", "[TreeTest]") { arma::mat dataset; dataset.randu(5, 100); @@ -1154,7 +1153,7 @@ BOOST_AUTO_TEST_CASE(FurthestPointDistanceTest) nodeQueue.pop(); if (node->NumChildren() != 0) - BOOST_REQUIRE_EQUAL(node->FurthestPointDistance(), 0.0); + REQUIRE(node->FurthestPointDistance() == 0.0); else { // Get center. @@ -1172,7 +1171,7 @@ BOOST_AUTO_TEST_CASE(FurthestPointDistanceTest) // We don't require an exact value because FurthestPointDistance() can // just bound the value instead of returning the exact value. - BOOST_REQUIRE_LE(maxDist, node->FurthestPointDistance()); + REQUIRE(maxDist <= node->FurthestPointDistance()); if (node->Left()) nodeQueue.push(node->Left()); @@ -1182,7 +1181,7 @@ BOOST_AUTO_TEST_CASE(FurthestPointDistanceTest) } } -BOOST_AUTO_TEST_CASE(ParentDistanceTest) +TEST_CASE("ParentDistanceTest", "[TreeTest]") { arma::mat dataset; dataset.randu(5, 500); @@ -1193,7 +1192,7 @@ BOOST_AUTO_TEST_CASE(ParentDistanceTest) // The root's parent distance should be 0 (although maybe it doesn't actually // matter; I just want to be sure it's not an uninitialized value, which this // test *sort* of checks). - BOOST_REQUIRE_EQUAL(tree.ParentDistance(), 0.0); + REQUIRE(tree.ParentDistance() == 0.0); // Do a depth-first traversal and make sure the parent distance is the same as // we calculate. @@ -1217,15 +1216,17 @@ BOOST_AUTO_TEST_CASE(ParentDistanceTest) const double leftDistance = LMetric<2>::Evaluate(center, leftCenter); const double rightDistance = LMetric<2>::Evaluate(center, rightCenter); - BOOST_REQUIRE_CLOSE(leftDistance, node->Left()->ParentDistance(), 1e-5); - BOOST_REQUIRE_CLOSE(rightDistance, node->Right()->ParentDistance(), 1e-5); + REQUIRE(leftDistance == + Approx(node->Left()->ParentDistance()).epsilon(1e-7)); + REQUIRE(rightDistance == + Approx(node->Right()->ParentDistance()).epsilon(1e-7)); nodeStack.push(node->Left()); nodeStack.push(node->Right()); } } -BOOST_AUTO_TEST_CASE(ParentDistanceTestWithMapping) +TEST_CASE("ParentDistanceTestWithMapping", "[TreeTest]") { arma::mat dataset; dataset.randu(5, 500); @@ -1237,7 +1238,7 @@ BOOST_AUTO_TEST_CASE(ParentDistanceTestWithMapping) // The root's parent distance should be 0 (although maybe it doesn't actually // matter; I just want to be sure it's not an uninitialized value, which this // test *sort* of checks). - BOOST_REQUIRE_EQUAL(tree.ParentDistance(), 0.0); + REQUIRE(tree.ParentDistance() == 0.0); // Do a depth-first traversal and make sure the parent distance is the same as // we calculate. @@ -1261,8 +1262,10 @@ BOOST_AUTO_TEST_CASE(ParentDistanceTestWithMapping) const double leftDistance = LMetric<2>::Evaluate(center, leftCenter); const double rightDistance = LMetric<2>::Evaluate(center, rightCenter); - BOOST_REQUIRE_CLOSE(leftDistance, node->Left()->ParentDistance(), 1e-5); - BOOST_REQUIRE_CLOSE(rightDistance, node->Right()->ParentDistance(), 1e-5); + REQUIRE(leftDistance == + Approx(node->Left()->ParentDistance()).epsilon(1e-7)); + REQUIRE(rightDistance == + Approx(node->Right()->ParentDistance()).epsilon(1e-7)); nodeStack.push(node->Left()); nodeStack.push(node->Right()); @@ -1291,7 +1294,7 @@ void GenerateVectorOfTree(TreeType* node, * * Then, we do that whole process a handful of times. */ -BOOST_AUTO_TEST_CASE(KdTreeTest) +TEST_CASE("KdTreeTest", "[TreeTest]") { typedef KDTree TreeType; @@ -1319,15 +1322,15 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) const arma::mat& treeset = root.Dataset(); // Ensure the size of the tree is correct. - BOOST_REQUIRE_EQUAL(root.Count(), size); + REQUIRE(root.Count() == size); // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; ++j) { - BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); - BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); + REQUIRE(treeset(j, i) == dataset(j, newToOld[i])); + REQUIRE(treeset(j, oldToNew[i]) == dataset(j, i)); } } @@ -1346,7 +1349,7 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) for (size_t j = i + 1; j < 2 * depth && j < v.size(); ++j) if (v[i] != NULL && v[j] != NULL) - BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); + REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); depth *= 2; } @@ -1360,7 +1363,7 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) TreeType root(dataset); } -BOOST_AUTO_TEST_CASE(MaxRPTreeTest) +TEST_CASE("MaxRPTreeTest", "[TreeTest]") { typedef MaxRPTree TreeType; @@ -1388,15 +1391,15 @@ BOOST_AUTO_TEST_CASE(MaxRPTreeTest) const arma::mat& treeset = root.Dataset(); // Ensure the size of the tree is correct. - BOOST_REQUIRE_EQUAL(root.Count(), size); + REQUIRE(root.Count() == size); // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; ++j) { - BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); - BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); + REQUIRE(treeset(j, i) == dataset(j, newToOld[i])); + REQUIRE(treeset(j, oldToNew[i]) == dataset(j, i)); } } } @@ -1486,13 +1489,13 @@ void CheckMaxRPTreeSplit(const TreeType& tree) if (tree.IsLeaf()) return; - BOOST_REQUIRE_EQUAL(CheckHyperplaneSplit(tree), true); + REQUIRE(CheckHyperplaneSplit(tree) == true); CheckMaxRPTreeSplit(*tree.Left()); CheckMaxRPTreeSplit(*tree.Right()); } -BOOST_AUTO_TEST_CASE(MaxRPTreeSplitTest) +TEST_CASE("MaxRPTreeSplitTest", "[TreeTest]") { typedef MaxRPTree TreeType; arma::mat dataset; @@ -1502,7 +1505,7 @@ BOOST_AUTO_TEST_CASE(MaxRPTreeSplitTest) CheckMaxRPTreeSplit(root); } -BOOST_AUTO_TEST_CASE(RPTreeTest) +TEST_CASE("RPTreeTest", "[TreeTest]") { typedef RPTree TreeType; @@ -1530,15 +1533,15 @@ BOOST_AUTO_TEST_CASE(RPTreeTest) const arma::mat& treeset = root.Dataset(); // Ensure the size of the tree is correct. - BOOST_REQUIRE_EQUAL(root.Count(), size); + REQUIRE(root.Count() == size); // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; ++j) { - BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); - BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); + REQUIRE(treeset(j, i) == dataset(j, newToOld[i])); + REQUIRE(treeset(j, oldToNew[i]) == dataset(j, i)); } } } @@ -1571,7 +1574,7 @@ void CheckRPTreeSplit(const TreeType& tree) ElemType dist = MetricType::Evaluate(center, tree.Dataset().col(tree.Right()->Descendant(k))); - BOOST_REQUIRE_LE(maxDist, dist * + REQUIRE(maxDist <= dist * (1.0 + 10.0 * std::numeric_limits::epsilon())); } } @@ -1580,7 +1583,7 @@ void CheckRPTreeSplit(const TreeType& tree) CheckRPTreeSplit(*tree.Right()); } -BOOST_AUTO_TEST_CASE(RPTreeSplitTest) +TEST_CASE("RPTreeSplitTest", "[TreeTest]") { typedef RPTree TreeType; arma::mat dataset; @@ -1616,7 +1619,7 @@ bool CheckPointBounds(TreeType& node) * * Then, we do that whole process a handful of times. */ -BOOST_AUTO_TEST_CASE(BallTreeTest) +TEST_CASE("BallTreeTest", "[TreeTest]") { typedef BallTree TreeType; @@ -1645,15 +1648,15 @@ BOOST_AUTO_TEST_CASE(BallTreeTest) const arma::mat& treeset = root.Dataset(); // Ensure the size of the tree is correct. - BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); + REQUIRE(root.NumDescendants() == size); // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; ++j) { - BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); - BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); + REQUIRE(treeset(j, i) == dataset(j, newToOld[i])); + REQUIRE(treeset(j, oldToNew[i]) == dataset(j, i)); } } @@ -1665,7 +1668,7 @@ BOOST_AUTO_TEST_CASE(BallTreeTest) /** * Ensure that we can build a ball tree with a custom instantiated metric type. */ -BOOST_AUTO_TEST_CASE(MahalanobisBallTreeTest) +TEST_CASE("MahalanobisBallTreeTest", "[TreeTest]") { arma::mat dataset(10, 1000, arma::fill::randu); arma::mat cov = arma::eye(10, 10); @@ -1677,13 +1680,13 @@ BOOST_AUTO_TEST_CASE(MahalanobisBallTreeTest) TreeType tree(dataset); // As long as it built successfully, I am okay with that. - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000); + REQUIRE(tree.NumDescendants() == 1000); // Also test when we give oldFromNew, since this uses a different code path. std::vector oldFromNew; TreeType tree2(std::move(dataset), oldFromNew); - BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000); + REQUIRE(tree.NumDescendants() == 1000); } template @@ -1719,7 +1722,7 @@ void GenerateVectorOfTree(TreeType* node, * * Then, we do that whole process a handful of times. */ -BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) +TEST_CASE("ExhaustiveSparseKDTreeTest", "[TreeTest]") { typedef KDTree> TreeType; @@ -1750,15 +1753,15 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) const arma::sp_mat& treeset = root.Dataset(); // Ensure the size of the tree is correct. - BOOST_REQUIRE_EQUAL(root.Count(), size); + REQUIRE(root.Count() == size); // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; ++j) { - BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); - BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); + REQUIRE(treeset(j, i) == dataset(j, newToOld[i])); + REQUIRE(treeset(j, oldToNew[i]) == dataset(j, i)); } } @@ -1777,7 +1780,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) for (size_t j = i + 1; j < 2 * depth && j < v.size(); ++j) if (v[i] != NULL && v[j] != NULL) - BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); + REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); depth *= 2; } @@ -1791,7 +1794,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) TreeType root(dataset); } -BOOST_AUTO_TEST_CASE(BinarySpaceTreeMoveConstructorTest) +TEST_CASE("BinarySpaceTreeMoveConstructorTest", "[TreeTest]") { arma::mat dataset(5, 1000); dataset.randu(); @@ -1799,8 +1802,8 @@ BOOST_AUTO_TEST_CASE(BinarySpaceTreeMoveConstructorTest) BinarySpaceTree tree(dataset); BinarySpaceTree tree2(std::move(tree)); - BOOST_REQUIRE_EQUAL(tree.NumChildren(), 0); - BOOST_REQUIRE_EQUAL(tree2.NumChildren(), 2); + REQUIRE(tree.NumChildren() == 0); + REQUIRE(tree2.NumChildren() == 2); } template @@ -1832,7 +1835,7 @@ void CheckSelfChild(const TreeType& node) } // Ensure this has its own self-child. - BOOST_REQUIRE_EQUAL(found, true); + REQUIRE(found == true); } template @@ -1855,7 +1858,7 @@ void CheckCovering(const TreeType& node) double distance = MetricType::Evaluate(dataset.col(nodePoint), dataset.col(childPoint)); - BOOST_REQUIRE_LE(distance, maxDistance); + REQUIRE(distance <= maxDistance); // Check the child. CheckCovering(node.Child(i)); @@ -1865,7 +1868,7 @@ void CheckCovering(const TreeType& node) /** * Create a simple cover tree and then make sure it is valid. */ -BOOST_AUTO_TEST_CASE(SimpleCoverTreeConstructionTest) +TEST_CASE("SimpleCoverTreeConstructionTest", "[TreeTest]") { // 20-point dataset. arma::mat data = arma::trans(arma::mat("0.0 0.0;" @@ -1897,7 +1900,7 @@ BOOST_AUTO_TEST_CASE(SimpleCoverTreeConstructionTest) // The furthest point from the root will be (-5, -5), with a distance of // of sqrt(50). This means the scale of the root node should be 3 (because // 2^3 = 8). - BOOST_REQUIRE_EQUAL(tree.Scale(), 3); + REQUIRE(tree.Scale() == 3); // Now loop through the tree and ensure that each leaf is only created once. arma::vec counts; @@ -1906,7 +1909,7 @@ BOOST_AUTO_TEST_CASE(SimpleCoverTreeConstructionTest) // Each point should only have one leaf node representing it. for (size_t i = 0; i < 20; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); // Each non-leaf should have a self-child. CheckSelfChild(tree); @@ -1922,7 +1925,7 @@ BOOST_AUTO_TEST_CASE(SimpleCoverTreeConstructionTest) /** * Create a large cover tree and make sure it's accurate. */ -BOOST_AUTO_TEST_CASE(CoverTreeConstructionTest) +TEST_CASE("CoverTreeConstructionTest", "[TreeTest]") { arma::mat dataset; // 50-dimensional, 1000 point. @@ -1938,7 +1941,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeConstructionTest) RecurseTreeCountLeaves(tree, counts); for (size_t i = 0; i < 1000; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); // Each non-leaf should have a self-child. CheckSelfChild(tree); @@ -1954,7 +1957,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeConstructionTest) /** * Create a cover tree on sparse data and make sure it's accurate. */ -BOOST_AUTO_TEST_CASE(SparseCoverTreeConstructionTest) +TEST_CASE("SparseCoverTreeConstructionTest", "[TreeTest]") { arma::sp_mat dataset; // 50-dimensional, 1000 point. @@ -1970,7 +1973,7 @@ BOOST_AUTO_TEST_CASE(SparseCoverTreeConstructionTest) RecurseTreeCountLeaves(tree, counts); for (size_t i = 0; i < 1000; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); // Each non-leaf should have a self-child. CheckSelfChild(tree); @@ -1986,7 +1989,7 @@ BOOST_AUTO_TEST_CASE(SparseCoverTreeConstructionTest) /** * Test the manual constructor. */ -BOOST_AUTO_TEST_CASE(CoverTreeManualConstructorTest) +TEST_CASE("CoverTreeManualConstructorTest", "[TreeTest]") { arma::mat dataset; dataset.zeros(10, 10); @@ -1995,19 +1998,19 @@ BOOST_AUTO_TEST_CASE(CoverTreeManualConstructorTest) TreeType; TreeType node(dataset, 1.3, 3, 2, NULL, 1.5, 2.75); - BOOST_REQUIRE_EQUAL(&node.Dataset(), &dataset); - BOOST_REQUIRE_EQUAL(node.Base(), 1.3); - BOOST_REQUIRE_EQUAL(node.Point(), 3); - BOOST_REQUIRE_EQUAL(node.Scale(), 2); - BOOST_REQUIRE_EQUAL(node.Parent(), (CoverTree<>*) NULL); - BOOST_REQUIRE_EQUAL(node.ParentDistance(), 1.5); - BOOST_REQUIRE_EQUAL(node.FurthestDescendantDistance(), 2.75); + REQUIRE(&node.Dataset() == &dataset); + REQUIRE(node.Base() == 1.3); + REQUIRE(node.Point() == 3); + REQUIRE(node.Scale() == 2); + REQUIRE(node.Parent() == (CoverTree<>*) NULL); + REQUIRE(node.ParentDistance() == 1.5); + REQUIRE(node.FurthestDescendantDistance() == 2.75); } /** * Make sure cover trees work in different metric spaces. */ -BOOST_AUTO_TEST_CASE(CoverTreeAlternateMetricTest) +TEST_CASE("CoverTreeAlternateMetricTest", "[TreeTest]") { arma::mat dataset; // 5-dimensional, 300-point dataset. @@ -2023,7 +2026,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeAlternateMetricTest) RecurseTreeCountLeaves(tree, counts); for (size_t i = 0; i < 300; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); // Each non-leaf should have a self-child. CheckSelfChild(tree); @@ -2039,7 +2042,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeAlternateMetricTest) /** * Make sure copy constructor works for the cover tree. */ -BOOST_AUTO_TEST_CASE(CoverTreeCopyConstructor) +TEST_CASE("CoverTreeCopyConstructor", "[TreeTest]") { arma::mat dataset; dataset.randu(10, 10); // dataset is irrelevant. @@ -2054,51 +2057,51 @@ BOOST_AUTO_TEST_CASE(CoverTreeCopyConstructor) // 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()); - BOOST_REQUIRE_EQUAL(c.Parent(), d.Parent()); - BOOST_REQUIRE_EQUAL(c.ParentDistance(), d.ParentDistance()); - BOOST_REQUIRE_EQUAL(c.FurthestDescendantDistance(), + REQUIRE(c.Dataset().memptr() == d.Dataset().memptr()); + REQUIRE(c.Base() == Approx(d.Base()).epsilon(1e-52)); + REQUIRE(c.Point() == d.Point()); + REQUIRE(c.Scale() == d.Scale()); + REQUIRE(c.Parent() == d.Parent()); + REQUIRE(c.ParentDistance() == d.ParentDistance()); + REQUIRE(c.FurthestDescendantDistance() == d.FurthestDescendantDistance()); - BOOST_REQUIRE_EQUAL(c.NumChildren(), d.NumChildren()); - BOOST_REQUIRE_NE(&c.Child(0), &d.Child(0)); - BOOST_REQUIRE_NE(&c.Child(1), &d.Child(1)); + REQUIRE(c.NumChildren() == d.NumChildren()); + REQUIRE(&c.Child(0) != &d.Child(0)); + REQUIRE(&c.Child(1) != &d.Child(1)); - BOOST_REQUIRE_EQUAL(c.Child(0).Parent(), &c); - BOOST_REQUIRE_EQUAL(c.Child(1).Parent(), &c); - BOOST_REQUIRE_EQUAL(d.Child(0).Parent(), &d); - BOOST_REQUIRE_EQUAL(d.Child(1).Parent(), &d); + REQUIRE(c.Child(0).Parent() == &c); + REQUIRE(c.Child(1).Parent() == &c); + REQUIRE(d.Child(0).Parent() == &d); + REQUIRE(d.Child(1).Parent() == &d); // Check that the children are okay. - 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()); - BOOST_REQUIRE_EQUAL(c.Child(0).Scale(), d.Child(0).Scale()); - BOOST_REQUIRE_EQUAL(c.Child(0).ParentDistance(), d.Child(0).ParentDistance()); - BOOST_REQUIRE_EQUAL(c.Child(0).FurthestDescendantDistance(), + REQUIRE(c.Child(0).Dataset().memptr() == c.Dataset().memptr()); + REQUIRE(c.Child(0).Base() == Approx(d.Child(0).Base()).epsilon(1e-52)); + REQUIRE(c.Child(0).Point() == d.Child(0).Point()); + REQUIRE(c.Child(0).Scale() == d.Child(0).Scale()); + REQUIRE(c.Child(0).ParentDistance() == d.Child(0).ParentDistance()); + REQUIRE(c.Child(0).FurthestDescendantDistance() == d.Child(0).FurthestDescendantDistance()); - BOOST_REQUIRE_EQUAL(c.Child(0).NumChildren(), d.Child(0).NumChildren()); + REQUIRE(c.Child(0).NumChildren() == d.Child(0).NumChildren()); - 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()); - BOOST_REQUIRE_EQUAL(c.Child(1).Scale(), d.Child(1).Scale()); - BOOST_REQUIRE_EQUAL(c.Child(1).ParentDistance(), d.Child(1).ParentDistance()); - BOOST_REQUIRE_EQUAL(c.Child(1).FurthestDescendantDistance(), + REQUIRE(c.Child(1).Dataset().memptr() == c.Dataset().memptr()); + REQUIRE(c.Child(1).Base() == Approx(d.Child(1).Base()).epsilon(1e-52)); + REQUIRE(c.Child(1).Point() == d.Child(1).Point()); + REQUIRE(c.Child(1).Scale() == d.Child(1).Scale()); + REQUIRE(c.Child(1).ParentDistance() == d.Child(1).ParentDistance()); + REQUIRE(c.Child(1).FurthestDescendantDistance() == d.Child(1).FurthestDescendantDistance()); - BOOST_REQUIRE_EQUAL(c.Child(1).NumChildren(), d.Child(1).NumChildren()); + REQUIRE(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()); + REQUIRE(e.Dataset().memptr() != f.Dataset().memptr()); } -BOOST_AUTO_TEST_CASE(CoverTreeMoveDatasetTest) +TEST_CASE("CoverTreeMoveDatasetTest", "[TreeTest]") { arma::mat dataset = arma::randu(3, 1000); typedef StandardCoverTree @@ -2106,23 +2109,23 @@ BOOST_AUTO_TEST_CASE(CoverTreeMoveDatasetTest) TreeType t(std::move(dataset)); - BOOST_REQUIRE_EQUAL(dataset.n_elem, 0); - BOOST_REQUIRE_EQUAL(t.Dataset().n_rows, 3); - BOOST_REQUIRE_EQUAL(t.Dataset().n_cols, 1000); + REQUIRE(dataset.n_elem == 0); + REQUIRE(t.Dataset().n_rows == 3); + REQUIRE(t.Dataset().n_cols == 1000); EuclideanDistance ed; // Test the other constructor. dataset = arma::randu(3, 1000); TreeType t2(std::move(dataset), ed); - BOOST_REQUIRE_EQUAL(dataset.n_elem, 0); - BOOST_REQUIRE_EQUAL(t2.Dataset().n_rows, 3); - BOOST_REQUIRE_EQUAL(t2.Dataset().n_cols, 1000); + REQUIRE(dataset.n_elem == 0); + REQUIRE(t2.Dataset().n_rows == 3); + REQUIRE(t2.Dataset().n_cols == 1000); } /** * Make sure copy constructor works right for the binary space tree. */ -BOOST_AUTO_TEST_CASE(BinarySpaceTreeCopyConstructor) +TEST_CASE("BinarySpaceTreeCopyConstructor", "[TreeTest]") { arma::mat data("1"); typedef KDTree TreeType; @@ -2143,25 +2146,25 @@ BOOST_AUTO_TEST_CASE(BinarySpaceTreeCopyConstructor) TreeType c(b); // Ensure everything copied correctly. - BOOST_REQUIRE_EQUAL(b.Begin(), c.Begin()); - BOOST_REQUIRE_EQUAL(b.Count(), c.Count()); - BOOST_REQUIRE_NE(b.Left(), c.Left()); - BOOST_REQUIRE_NE(b.Right(), c.Right()); + REQUIRE(b.Begin() == c.Begin()); + REQUIRE(b.Count() == c.Count()); + REQUIRE(b.Left() != c.Left()); + REQUIRE(b.Right() != c.Right()); // Check the children. - BOOST_REQUIRE_EQUAL(b.Left()->Begin(), c.Left()->Begin()); - BOOST_REQUIRE_EQUAL(b.Left()->Count(), c.Left()->Count()); - BOOST_REQUIRE_EQUAL(b.Left()->Left(), (TreeType*) NULL); - BOOST_REQUIRE_EQUAL(b.Left()->Left(), c.Left()->Left()); - BOOST_REQUIRE_EQUAL(b.Left()->Right(), (TreeType*) NULL); - BOOST_REQUIRE_EQUAL(b.Left()->Right(), c.Left()->Right()); + REQUIRE(b.Left()->Begin() == c.Left()->Begin()); + REQUIRE(b.Left()->Count() == c.Left()->Count()); + REQUIRE(b.Left()->Left() == (TreeType*) NULL); + REQUIRE(b.Left()->Left() == c.Left()->Left()); + REQUIRE(b.Left()->Right() == (TreeType*) NULL); + REQUIRE(b.Left()->Right() == c.Left()->Right()); - BOOST_REQUIRE_EQUAL(b.Right()->Begin(), c.Right()->Begin()); - BOOST_REQUIRE_EQUAL(b.Right()->Count(), c.Right()->Count()); - BOOST_REQUIRE_EQUAL(b.Right()->Left(), (TreeType*) NULL); - BOOST_REQUIRE_EQUAL(b.Right()->Left(), c.Right()->Left()); - BOOST_REQUIRE_EQUAL(b.Right()->Right(), (TreeType*) NULL); - BOOST_REQUIRE_EQUAL(b.Right()->Right(), c.Right()->Right()); + REQUIRE(b.Right()->Begin() == c.Right()->Begin()); + REQUIRE(b.Right()->Count() == c.Right()->Count()); + REQUIRE(b.Right()->Left() == (TreeType*) NULL); + REQUIRE(b.Right()->Left() == c.Right()->Left()); + REQUIRE(b.Right()->Right() == (TreeType*) NULL); + REQUIRE(b.Right()->Right() == c.Right()->Right()); // Clean memory (we built the tree by hand, so this is what we have to do // since the destructor won't free the children's datasets). @@ -2237,19 +2240,19 @@ void CheckDescendants(TreeType* node) // In a cover tree, the number of leaves should be the number of descendant // points. const size_t numLeaves = NumLeaves(node); - BOOST_REQUIRE_EQUAL(numLeaves, node->NumDescendants()); + REQUIRE(numLeaves == node->NumDescendants()); // Now check that each descendant is somewhere in the tree. for (size_t i = 0; i < node->NumDescendants(); ++i) { Log::Debug << "Check for descendant " << node->Descendant(i) << " (i " << i << ").\n"; - BOOST_REQUIRE_EQUAL(FindIndex(node, node->Descendant(i)), true); + REQUIRE(FindIndex(node, node->Descendant(i)) == true); } // Now check that every actual descendant is accessible through the // Descendant() function. - BOOST_REQUIRE_EQUAL(CheckAccessibility(node, node), true); + REQUIRE(CheckAccessibility(node, node) == true); // Now check that there are no duplicates in the list of descendants. std::vector descendants; @@ -2262,7 +2265,7 @@ void CheckDescendants(TreeType* node) // Check that there are no duplicates (this is easy because it's sorted). for (size_t i = 1; i < descendants.size(); ++i) - BOOST_REQUIRE_NE(descendants[i], descendants[i - 1]); + REQUIRE(descendants[i] != descendants[i - 1]); // Now perform these same checks for the children. for (size_t i = 0; i < node->NumChildren(); ++i) @@ -2273,7 +2276,7 @@ void CheckDescendants(TreeType* node) * Make sure Descendant() and NumDescendants() works properly for the cover * tree. */ -BOOST_AUTO_TEST_CASE(CoverTreeDescendantTest) +TEST_CASE("CoverTreeDescendantTest", "[TreeTest]") { arma::mat dataset; dataset.randu(3, 100); @@ -2284,5 +2287,3 @@ BOOST_AUTO_TEST_CASE(CoverTreeDescendantTest) // using the recursive function above. CheckDescendants(&tree); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/tree_traits_test.cpp b/src/mlpack/tests/tree_traits_test.cpp index fedf0ce1f1..caa642c71f 100644 --- a/src/mlpack/tests/tree_traits_test.cpp +++ b/src/mlpack/tests/tree_traits_test.cpp @@ -19,82 +19,78 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.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 of each // trait 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) +TEST_CASE("DefaultsTraitsTest", "[TreeTraitsTestt]") { // An irrelevant non-tree type class is used here so that the default // implementation of TreeTraits is chosen. bool b = TreeTraits::HasOverlappingChildren; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); b = TreeTraits::HasSelfChildren; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); b = TreeTraits::FirstPointIsCentroid; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); b = TreeTraits::RearrangesDataset; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); b = TreeTraits::BinaryTree; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); } // Test the binary space tree traits. -BOOST_AUTO_TEST_CASE(BinarySpaceTreeTraitsTest) +TEST_CASE("BinarySpaceTreeTraitsTest", "[TreeTraitsTestt]") { typedef BinarySpaceTree> TreeType; // Children are non-overlapping. bool b = TreeTraits::HasOverlappingChildren; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); // Points are not contained at multiple levels. b = TreeTraits::HasSelfChildren; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); // The first point is not the centroid. b = TreeTraits::FirstPointIsCentroid; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); // The dataset gets rearranged at build time. b = TreeTraits::RearrangesDataset; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); // It is a binary tree. b = TreeTraits::BinaryTree; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); } // Test the cover tree traits. -BOOST_AUTO_TEST_CASE(CoverTreeTraitsTest) +TEST_CASE("CoverTreeTraitsTest", "[TreeTraitsTestt]") { // Children may be overlapping. bool b = TreeTraits>::HasOverlappingChildren; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); // The cover tree has self-children. b = TreeTraits>::HasSelfChildren; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); // The first point is the center of the node. b = TreeTraits>::FirstPointIsCentroid; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); b = TreeTraits>::RearrangesDataset; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); b = TreeTraits>::BinaryTree; - BOOST_REQUIRE_EQUAL(b, false); // Not necessarily binary. + REQUIRE(b == false); // Not necessarily binary. } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/ub_tree_test.cpp b/src/mlpack/tests/ub_tree_test.cpp index b1fb57b0bf..6df70e5627 100644 --- a/src/mlpack/tests/ub_tree_test.cpp +++ b/src/mlpack/tests/ub_tree_test.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include "catch.hpp" using namespace mlpack; using namespace mlpack::math; @@ -23,9 +23,7 @@ using namespace mlpack::metric; using namespace mlpack::bound; using namespace mlpack::neighbor; -BOOST_AUTO_TEST_SUITE(UBTreeTest); - -BOOST_AUTO_TEST_CASE(AddressTest) +TEST_CASE("AddressTest", "[UBTreeTest]") { typedef double ElemType; typedef typename std::conditional TreeType; arma::mat dataset(8, 1000); @@ -115,7 +113,7 @@ void CheckBound(const TreeType& tree) arma::Col point = tree.Dataset().col(tree.Descendant(i)); // Check that the point is contained in the bound. - BOOST_REQUIRE_EQUAL(true, tree.Bound().Contains(point)); + REQUIRE(true == tree.Bound().Contains(point)); const arma::Mat& loBound = tree.Bound().LoBound(); const arma::Mat& hiBound = tree.Bound().HiBound(); @@ -138,7 +136,7 @@ void CheckBound(const TreeType& tree) break; } - BOOST_REQUIRE_EQUAL(success, true); + REQUIRE(success == true); } if (!tree.IsLeaf()) @@ -148,7 +146,7 @@ void CheckBound(const TreeType& tree) } } -BOOST_AUTO_TEST_CASE(UBTreeBoundTest) +TEST_CASE("UBTreeBoundTest", "[UBTreeTest]") { typedef UBTree TreeType; arma::mat dataset(8, 1000); @@ -190,16 +188,16 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) minDist = dist; } - BOOST_REQUIRE_LE(tree.Bound().MinDistance(point), minDist * + REQUIRE(tree.Bound().MinDistance(point) <= minDist * (1.0 + 10 * std::numeric_limits::epsilon())); - BOOST_REQUIRE_LE(maxDist, tree.Bound().MaxDistance(point) * + REQUIRE(maxDist <= tree.Bound().MaxDistance(point) * (1.0 + 10 * std::numeric_limits::epsilon())); math::RangeType r = tree.Bound().RangeDistance(point); - BOOST_REQUIRE_LE(r.Lo(), minDist * + REQUIRE(r.Lo() <= minDist * (1.0 + 10 * std::numeric_limits::epsilon())); - BOOST_REQUIRE_LE(maxDist, r.Hi() * + REQUIRE(maxDist <= r.Hi() * (1.0 + 10 * std::numeric_limits::epsilon())); } @@ -228,16 +226,16 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) minDist = dist; } - BOOST_REQUIRE_LE(tree.Bound().MinDistance(node->Bound()), minDist * + REQUIRE(tree.Bound().MinDistance(node->Bound()) <= minDist * (1.0 + 10 * std::numeric_limits::epsilon())); - BOOST_REQUIRE_LE(maxDist, tree.Bound().MaxDistance(node->Bound()) * + REQUIRE(maxDist <= tree.Bound().MaxDistance(node->Bound()) * (1.0 + 10 * std::numeric_limits::epsilon())); math::RangeType r = tree.Bound().RangeDistance(node->Bound()); - BOOST_REQUIRE_LE(r.Lo(), minDist * + REQUIRE(r.Lo() <= minDist * (1.0 + 10 * std::numeric_limits::epsilon())); - BOOST_REQUIRE_LE(maxDist, r.Hi() * + REQUIRE(maxDist <= r.Hi() * (1.0 + 10 * std::numeric_limits::epsilon())); } if (!node->IsLeaf()) @@ -248,7 +246,7 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) } } -BOOST_AUTO_TEST_CASE(UBTreeDistanceTest) +TEST_CASE("UBTreeDistanceTest", "[UBTreeTest]") { typedef UBTree TreeType; arma::mat dataset(8, 200); @@ -260,7 +258,7 @@ BOOST_AUTO_TEST_CASE(UBTreeDistanceTest) } -BOOST_AUTO_TEST_CASE(UBTreeTest) +TEST_CASE("UBTreeTest", "[UBTreeTest]") { typedef UBTree TreeType; @@ -289,21 +287,21 @@ BOOST_AUTO_TEST_CASE(UBTreeTest) const arma::mat& treeset = root.Dataset(); // Ensure the size of the tree is correct. - BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); + REQUIRE(root.NumDescendants() == size); // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; ++j) { - BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); - BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); + REQUIRE(treeset(j, i) == dataset(j, newToOld[i])); + REQUIRE(treeset(j, oldToNew[i]) == dataset(j, i)); } } } } -BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) +TEST_CASE("SingleUBTreeTraverserTest", "[UBTreeTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -325,12 +323,12 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } -BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) +TEST_CASE("DualUBTreeTraverserTest", "[UBTreeTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -352,9 +350,7 @@ BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/vantage_point_tree_test.cpp b/src/mlpack/tests/vantage_point_tree_test.cpp index b31d679692..b531b49fd3 100644 --- a/src/mlpack/tests/vantage_point_tree_test.cpp +++ b/src/mlpack/tests/vantage_point_tree_test.cpp @@ -14,8 +14,8 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::math; @@ -24,112 +24,109 @@ using namespace mlpack::neighbor; using namespace mlpack::metric; using namespace mlpack::bound; -BOOST_AUTO_TEST_SUITE(VantagePointTreeTest); - -BOOST_AUTO_TEST_CASE(VPTreeTraitsTest) +TEST_CASE("VPTreeTraitsTest", "[VantagePointTreeTest]") { typedef VPTree TreeType; bool b = TreeTraits::HasOverlappingChildren; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); b = TreeTraits::FirstPointIsCentroid; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); b = TreeTraits::HasSelfChildren; - BOOST_REQUIRE_EQUAL(b, false); + REQUIRE(b == false); b = TreeTraits::RearrangesDataset; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); b = TreeTraits::BinaryTree; - BOOST_REQUIRE_EQUAL(b, true); + REQUIRE(b == true); } -BOOST_AUTO_TEST_CASE(HollowBallBoundTest) +TEST_CASE("HollowBallBoundTest", "[VantagePointTreeTest]") { HollowBallBound b(2, 4, arma::vec("1.0 2.0 3.0 4.0 5.0")); - BOOST_REQUIRE_EQUAL(b.Contains(arma::vec("1.0 2.0 3.0 7.0 5.0")), true); + REQUIRE(b.Contains(arma::vec("1.0 2.0 3.0 7.0 5.0")) == true); - BOOST_REQUIRE_EQUAL(b.Contains(arma::vec("1.0 2.0 3.0 9.0 5.0")), false); + REQUIRE(b.Contains(arma::vec("1.0 2.0 3.0 9.0 5.0")) == false); - BOOST_REQUIRE_EQUAL(b.Contains(arma::vec("1.0 2.0 3.0 5.0 5.0")), false); + REQUIRE(b.Contains(arma::vec("1.0 2.0 3.0 5.0 5.0")) == false); HollowBallBound b2(0.5, 1, arma::vec("1.0 2.0 3.0 7.0 5.0")); - BOOST_REQUIRE_EQUAL(b.Contains(b2), true); + REQUIRE(b.Contains(b2) == true); b2 = HollowBallBound(2.5, 3.5, arma::vec("1.0 2.0 3.0 4.5 5.0")); - BOOST_REQUIRE_EQUAL(b.Contains(b2), true); + REQUIRE(b.Contains(b2) == true); b2 = HollowBallBound(2.0, 3.5, arma::vec("1.0 2.0 3.0 4.5 5.0")); - BOOST_REQUIRE_EQUAL(b.Contains(b2), false); + REQUIRE(b.Contains(b2) == false); - BOOST_REQUIRE_CLOSE(b.MinDistance(arma::vec("1.0 2.0 8.0 4.0 5.0")), 1.0, - 1e-5); - BOOST_REQUIRE_CLOSE(b.MinDistance(arma::vec("1.0 2.0 4.0 4.0 5.0")), 1.0, - 1e-5); - BOOST_REQUIRE_CLOSE(b.MinDistance(arma::vec("1.0 2.0 3.0 4.0 5.0")), 2.0, - 1e-5); - BOOST_REQUIRE_CLOSE(b.MinDistance(arma::vec("1.0 2.0 5.0 4.0 5.0")), 0.0, - 1e-5); - BOOST_REQUIRE_CLOSE(b.MinDistance(arma::vec("5.0 2.0 3.0 4.0 5.0")), 0.0, - 1e-5); - BOOST_REQUIRE_CLOSE(b.MinDistance(arma::vec("3.0 2.0 3.0 4.0 5.0")), 0.0, - 1e-5); - - BOOST_REQUIRE_CLOSE(b.MaxDistance(arma::vec("1.0 2.0 4.0 4.0 5.0")), 5.0, - 1e-5); - BOOST_REQUIRE_CLOSE(b.MaxDistance(arma::vec("1.0 2.0 8.0 4.0 5.0")), 9.0, - 1e-5); - BOOST_REQUIRE_CLOSE(b.MaxDistance(arma::vec("1.0 2.0 3.0 4.0 5.0")), 4.0, - 1e-5); + REQUIRE(b.MinDistance(arma::vec("1.0 2.0 8.0 4.0 5.0")) == + Approx(1.0).epsilon(1e-7)); + REQUIRE(b.MinDistance(arma::vec("1.0 2.0 4.0 4.0 5.0")) == + Approx(1.0).epsilon(1e-7)); + REQUIRE(b.MinDistance(arma::vec("1.0 2.0 3.0 4.0 5.0")) == + Approx(2.0).epsilon(1e-7)); + REQUIRE(b.MinDistance(arma::vec("1.0 2.0 5.0 4.0 5.0")) == + Approx(0.0).epsilon(1e-7)); + REQUIRE(b.MinDistance(arma::vec("5.0 2.0 3.0 4.0 5.0")) == + Approx(0.0).epsilon(1e-7)); + REQUIRE(b.MinDistance(arma::vec("3.0 2.0 3.0 4.0 5.0")) == + Approx(0.0).epsilon(1e-7)); + REQUIRE(b.MaxDistance(arma::vec("1.0 2.0 4.0 4.0 5.0")) == + Approx(5.0).epsilon(1e-7)); + REQUIRE(b.MaxDistance(arma::vec("1.0 2.0 8.0 4.0 5.0")) == + Approx(9.0).epsilon(1e-7)); + REQUIRE(b.MaxDistance(arma::vec("1.0 2.0 3.0 4.0 5.0")) == + Approx(4.0).epsilon(1e-7)); b2 = HollowBallBound(3, 4, arma::vec("1.0 2.0 3.0 5.0 5.0")); - BOOST_REQUIRE_CLOSE(b.MinDistance(b2), 0.0, 1e-5); + REQUIRE(b.MinDistance(b2) == Approx(0.0).epsilon(1e-7)); b2 = HollowBallBound(1, 2, arma::vec("1.0 2.0 3.0 4.0 5.0")); - BOOST_REQUIRE_CLOSE(b.MinDistance(b2), 0.0, 1e-5); + REQUIRE(b.MinDistance(b2) == Approx(0.0).epsilon(1e-7)); b2 = HollowBallBound(0.5, 1.0, arma::vec("1.0 2.5 3.0 4.0 5.0")); - BOOST_REQUIRE_CLOSE(b.MinDistance(b2), 0.5, 1e-5); + REQUIRE(b.MinDistance(b2) == Approx(0.5).epsilon(1e-7)); b2 = HollowBallBound(0.5, 1.0, arma::vec("1.0 8.0 3.0 4.0 5.0")); - BOOST_REQUIRE_CLOSE(b.MinDistance(b2), 1.0, 1e-5); + REQUIRE(b.MinDistance(b2) == Approx(1.0).epsilon(1e-7)); b2 = HollowBallBound(0.5, 2.0, arma::vec("1.0 8.0 3.0 4.0 5.0")); - BOOST_REQUIRE_CLOSE(b.MinDistance(b2), 0.0, 1e-5); + REQUIRE(b.MinDistance(b2) == Approx(0.0).epsilon(1e-7)); b2 = HollowBallBound(0.5, 2.0, arma::vec("1.0 8.0 3.0 4.0 5.0")); - BOOST_REQUIRE_CLOSE(b.MaxDistance(b2), 12.0, 1e-5); + REQUIRE(b.MaxDistance(b2) == Approx(12.0).epsilon(1e-7)); b2 = HollowBallBound(0.5, 2.0, arma::vec("1.0 3.0 3.0 4.0 5.0")); - BOOST_REQUIRE_CLOSE(b.MaxDistance(b2), 7.0, 1e-5); + REQUIRE(b.MaxDistance(b2) == Approx(7.0).epsilon(1e-7)); HollowBallBound b1 = b; b2 = HollowBallBound(1.0, 2.0, arma::vec("1.0 2.5 3.0 4.0 5.0")); b1 |= b2; - BOOST_REQUIRE_CLOSE(b1.InnerRadius(), 0.5, 1e-5); + REQUIRE(b1.InnerRadius() == Approx(0.5).epsilon(1e-7)); b1 = b; b2 = HollowBallBound(0.5, 2.0, arma::vec("1.0 3.0 3.0 4.0 5.0")); b1 |= b2; - BOOST_REQUIRE_CLOSE(b1.InnerRadius(), 0.0, 1e-5); + REQUIRE(b1.InnerRadius() == Approx(0.0).epsilon(1e-7)); b1 = b; b2 = HollowBallBound(0.5, 4.0, arma::vec("1.0 3.0 3.0 4.0 5.0")); b1 |= b2; - BOOST_REQUIRE_CLOSE(b1.OuterRadius(), 5.0, 1e-5); + REQUIRE(b1.OuterRadius() == Approx(5.0).epsilon(1e-7)); } template @@ -147,10 +144,10 @@ void CheckBound(TreeType& tree) tree.Bound().HollowCenter(), tree.Dataset().col(tree.Point(i))); - BOOST_REQUIRE_LE(tree.Bound().InnerRadius(), hollowDist * + REQUIRE(tree.Bound().InnerRadius() <= hollowDist * (1.0 + 10.0 * std::numeric_limits::epsilon())); - BOOST_REQUIRE_LE(dist, tree.Bound().OuterRadius() * + REQUIRE(dist <= tree.Bound().OuterRadius() * (1.0 + 10.0 * std::numeric_limits::epsilon())); } } @@ -165,10 +162,10 @@ void CheckBound(TreeType& tree) tree.Bound().HollowCenter(), tree.Dataset().col(tree.Descendant(i))); - BOOST_REQUIRE_LE(tree.Bound().InnerRadius(), hollowDist * + REQUIRE(tree.Bound().InnerRadius() <= hollowDist * (1.0 + 10.0 * std::numeric_limits::epsilon())); - BOOST_REQUIRE_LE(dist, tree.Bound().OuterRadius() * + REQUIRE(dist <= tree.Bound().OuterRadius() * (1.0 + 10.0 * std::numeric_limits::epsilon())); } @@ -177,7 +174,7 @@ void CheckBound(TreeType& tree) } } -BOOST_AUTO_TEST_CASE(VPTreeBoundTest) +TEST_CASE("VPTreeBoundTest", "[VantagePointTreeTest]") { typedef VPTree TreeType; @@ -188,7 +185,7 @@ BOOST_AUTO_TEST_CASE(VPTreeBoundTest) CheckBound(tree); } -BOOST_AUTO_TEST_CASE(VPTreeTest) +TEST_CASE("VPTreeTest", "[VantagePointTreeTest]") { typedef VPTree TreeType; @@ -217,21 +214,21 @@ BOOST_AUTO_TEST_CASE(VPTreeTest) const arma::mat& treeset = root.Dataset(); // Ensure the size of the tree is correct. - BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); + REQUIRE(root.NumDescendants() == size); // Check the forward and backward mappings for correctness. for (size_t i = 0; i < size; ++i) { for (size_t j = 0; j < dimensions; ++j) { - BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); - BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); + REQUIRE(treeset(j, i) == dataset(j, newToOld[i])); + REQUIRE(treeset(j, oldToNew[i]) == dataset(j, i)); } } } } -BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) +TEST_CASE("SingleVPTreeTraverserTest", "[VantagePointTreeTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -253,12 +250,12 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } -BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) +TEST_CASE("DualVPTreeTraverserTest", "[VantagePointTreeTest]") { arma::mat dataset; dataset.randu(8, 1000); // 1000 points in 8 dimensions. @@ -280,9 +277,7 @@ BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) for (size_t i = 0; i < neighbors1.size(); ++i) { - BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); - BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); + REQUIRE(neighbors1[i] == neighbors2[i]); + REQUIRE(distances1[i] == distances2[i]); } } - -BOOST_AUTO_TEST_SUITE_END(); From 610658f3ec69cebbf53a16a7b3c9ae579a126d54 Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Wed, 26 Aug 2020 01:11:15 +0530 Subject: [PATCH 02/45] migrate IO and CLI test --- src/mlpack/tests/CMakeLists.txt | 4 +- src/mlpack/tests/cli_binding_test.cpp | 172 ++++++------ src/mlpack/tests/io_test.cpp | 361 ++++++++++++++------------ 3 files changed, 279 insertions(+), 258 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index e882cc767e..60a879553b 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -6,8 +6,6 @@ add_executable(mlpack_test bayesian_linear_regression_test.cpp callback_test.cpp cf_test.cpp - cli_binding_test.cpp - io_test.cpp cosine_tree_test.cpp dbscan_test.cpp dcgan_test.cpp @@ -137,6 +135,7 @@ add_executable(mlpack_catch_test bias_svd_test.cpp binarize_test.cpp block_krylov_svd_test.cpp + cli_binding_test.cpp convolutional_network_test.cpp convolution_test.cpp cv_test.cpp @@ -144,6 +143,7 @@ add_executable(mlpack_catch_test decision_tree_test.cpp image_load_test.cpp imputation_test.cpp + io_test.cpp kfn_test.cpp knn_test.cpp linear_regression_test.cpp diff --git a/src/mlpack/tests/cli_binding_test.cpp b/src/mlpack/tests/cli_binding_test.cpp index bb21bf2ad1..391a0bfe1a 100644 --- a/src/mlpack/tests/cli_binding_test.cpp +++ b/src/mlpack/tests/cli_binding_test.cpp @@ -13,8 +13,8 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace std; using namespace mlpack; @@ -22,42 +22,40 @@ using namespace mlpack::bindings; using namespace mlpack::bindings::cli; using namespace mlpack::kernel; -BOOST_AUTO_TEST_SUITE(CLIBindingTest); - /** * Ensure that we can construct a CLIOption object, and that it will add itself * to the CLI instance. */ -BOOST_AUTO_TEST_CASE(CLIOptionTest) +TEST_CASE("CLIOptionTest", "[CLIOptionTest]") { IO::ClearSettings(); CLIOption co1(0.0, "test", "test2", "t", "double", false, true, false); // Now check that it's in CLI. - BOOST_REQUIRE_GT(IO::Parameters().count("test"), 0); - BOOST_REQUIRE_GT(IO::Aliases().count('t'), 0); - BOOST_REQUIRE_EQUAL(IO::Parameters()["test"].desc, "test2"); - BOOST_REQUIRE_EQUAL(IO::Parameters()["test"].name, "test"); - BOOST_REQUIRE_EQUAL(IO::Parameters()["test"].alias, 't'); - BOOST_REQUIRE_EQUAL(IO::Parameters()["test"].noTranspose, false); - BOOST_REQUIRE_EQUAL(IO::Parameters()["test"].required, false); - BOOST_REQUIRE_EQUAL(IO::Parameters()["test"].input, true); - BOOST_REQUIRE_EQUAL(IO::Parameters()["test"].cppType, "double"); + REQUIRE(IO::Parameters().count("test") > 0); + REQUIRE(IO::Aliases().count('t') > 0); + REQUIRE(IO::Parameters()["test"].desc == "test2"); + REQUIRE(IO::Parameters()["test"].name == "test"); + REQUIRE(IO::Parameters()["test"].alias == 't'); + REQUIRE(IO::Parameters()["test"].noTranspose == false); + REQUIRE(IO::Parameters()["test"].required == false); + REQUIRE(IO::Parameters()["test"].input == true); + REQUIRE(IO::Parameters()["test"].cppType == "double"); CLIOption co2(arma::mat(), "mat", "mat2", "m", "arma::mat", true, true, true); // Now check that it's in CLI. - BOOST_REQUIRE_GT(IO::Parameters().count("mat"), 0); - BOOST_REQUIRE_GT(IO::Aliases().count('m'), 0); - BOOST_REQUIRE_EQUAL(IO::Parameters()["mat"].desc, "mat2"); - BOOST_REQUIRE_EQUAL(IO::Parameters()["mat"].name, "mat"); - BOOST_REQUIRE_EQUAL(IO::Parameters()["mat"].alias, 'm'); - BOOST_REQUIRE_EQUAL(IO::Parameters()["mat"].noTranspose, true); - BOOST_REQUIRE_EQUAL(IO::Parameters()["mat"].required, true); - BOOST_REQUIRE_EQUAL(IO::Parameters()["mat"].input, true); - BOOST_REQUIRE_EQUAL(IO::Parameters()["mat"].cppType, "arma::mat"); + REQUIRE(IO::Parameters().count("mat") > 0); + REQUIRE(IO::Aliases().count('m') > 0); + REQUIRE(IO::Parameters()["mat"].desc == "mat2"); + REQUIRE(IO::Parameters()["mat"].name == "mat"); + REQUIRE(IO::Parameters()["mat"].alias == 'm'); + REQUIRE(IO::Parameters()["mat"].noTranspose == true); + REQUIRE(IO::Parameters()["mat"].required == true); + REQUIRE(IO::Parameters()["mat"].input == true); + REQUIRE(IO::Parameters()["mat"].cppType == "arma::mat"); IO::ClearSettings(); } @@ -65,7 +63,7 @@ BOOST_AUTO_TEST_CASE(CLIOptionTest) /** * Make sure GetParam() works. */ -BOOST_AUTO_TEST_CASE(GetParamDoubleTest) +TEST_CASE("GetParamDoubleTest", "[CLIOptionTest]") { util::ParamData d; double x = 5.0; @@ -75,10 +73,10 @@ BOOST_AUTO_TEST_CASE(GetParamDoubleTest) GetParam((util::ParamData&) d, (const void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(*output, 5.0); + REQUIRE(*output == 5.0); } -BOOST_AUTO_TEST_CASE(GetParamLoadedMatTest) +TEST_CASE("GetParamLoadedMatTest", "[CLIOptionTest]") { util::ParamData d; // Create value. @@ -94,13 +92,13 @@ BOOST_AUTO_TEST_CASE(GetParamLoadedMatTest) GetParam((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(output->n_rows, 5); - BOOST_REQUIRE_EQUAL(output->n_cols, 5); + REQUIRE(output->n_rows == 5); + REQUIRE(output->n_cols == 5); for (size_t i = 0; i < 25; ++i) - BOOST_REQUIRE_EQUAL((*output)[i], 1.0); + REQUIRE((*output)[i] == 1.0); } -BOOST_AUTO_TEST_CASE(GetParamUnloadedMatTest) +TEST_CASE("GetParamUnloadedMatTest", "[CLIOptionTest]") { util::ParamData d; // Create value. @@ -120,15 +118,15 @@ BOOST_AUTO_TEST_CASE(GetParamUnloadedMatTest) GetParam((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(output->n_rows, 5); - BOOST_REQUIRE_EQUAL(output->n_cols, 5); + REQUIRE(output->n_rows == 5); + REQUIRE(output->n_cols == 5); for (size_t i = 0; i < 25; ++i) - BOOST_REQUIRE_EQUAL((*output)[i], 1.0); + REQUIRE((*output)[i] == 1.0); remove("test.csv"); } -BOOST_AUTO_TEST_CASE(GetParamUmatTest) +TEST_CASE("GetParamUmatTest", "[CLIOptionTest]") { util::ParamData d; // Create value. @@ -145,13 +143,13 @@ BOOST_AUTO_TEST_CASE(GetParamUmatTest) GetParam>((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(output->n_rows, 5); - BOOST_REQUIRE_EQUAL(output->n_cols, 5); + REQUIRE(output->n_rows == 5); + REQUIRE(output->n_cols == 5); for (size_t i = 0; i < 25; ++i) - BOOST_REQUIRE_EQUAL((*output)[i], 1.0); + REQUIRE((*output)[i] == 1.0); } -BOOST_AUTO_TEST_CASE(GetParamUnloadedUmatTest) +TEST_CASE("GetParamUnloadedUmatTest", "[CLIOptionTest]") { util::ParamData d; // Create value. @@ -171,15 +169,15 @@ BOOST_AUTO_TEST_CASE(GetParamUnloadedUmatTest) GetParam>((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(output->n_rows, 5); - BOOST_REQUIRE_EQUAL(output->n_cols, 5); + REQUIRE(output->n_rows == 5); + REQUIRE(output->n_cols == 5); for (size_t i = 0; i < 25; ++i) - BOOST_REQUIRE_EQUAL((*output)[i], 1.0); + REQUIRE((*output)[i] == 1.0); remove("test.csv"); } -BOOST_AUTO_TEST_CASE(GetParamDatasetInfoMatTest) +TEST_CASE("GetParamDatasetInfoMatTest", "[CLIOptionTest]") { util::ParamData d; @@ -215,20 +213,20 @@ BOOST_AUTO_TEST_CASE(GetParamDatasetInfoMatTest) GetParam>((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(get<0>(*output).Dimensionality(), 3); - BOOST_REQUIRE_EQUAL((int) get<0>(*output).Type(0), + REQUIRE(get<0>(*output).Dimensionality() == 3); + REQUIRE((int) get<0>(*output).Type(0) == (int) data::Datatype::numeric); - BOOST_REQUIRE_EQUAL((int) get<0>(*output).Type(1), + REQUIRE((int) get<0>(*output).Type(1) == (int) data::Datatype::numeric); - BOOST_REQUIRE_EQUAL((int) get<0>(*output).Type(2), + REQUIRE((int) get<0>(*output).Type(2) == (int) data::Datatype::categorical); - BOOST_REQUIRE_EQUAL(get<1>(*output).n_rows, 3); - BOOST_REQUIRE_EQUAL(get<1>(*output).n_cols, 7); + REQUIRE(get<1>(*output).n_rows == 3); + REQUIRE(get<1>(*output).n_cols == 7); remove("test.csv"); } -BOOST_AUTO_TEST_CASE(GetParamModelTest) +TEST_CASE("GetParamModelTest", "[CLIOptionTest]") { util::ParamData d; @@ -249,13 +247,13 @@ BOOST_AUTO_TEST_CASE(GetParamModelTest) GetParam((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL((*output)->Bandwidth(), 5.0); + REQUIRE((*output)->Bandwidth() == 5.0); remove("kernel.bin"); delete *output; } -BOOST_AUTO_TEST_CASE(RawParamDoubleTest) +TEST_CASE("RawParamDoubleTest", "[CLIOptionTest]") { // This should function the same as GetParam for doubles. util::ParamData d; @@ -266,10 +264,10 @@ BOOST_AUTO_TEST_CASE(RawParamDoubleTest) GetParam((util::ParamData&) d, (const void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(*output, 5.0); + REQUIRE(*output == 5.0); } -BOOST_AUTO_TEST_CASE(RawParamMatTest) +TEST_CASE("RawParamMatTest", "[CLIOptionTest]") { // This should return the matrix as-is without loading. util::ParamData d; @@ -286,13 +284,13 @@ BOOST_AUTO_TEST_CASE(RawParamMatTest) GetRawParam((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(output->n_rows, 5); - BOOST_REQUIRE_EQUAL(output->n_cols, 5); + REQUIRE(output->n_rows == 5); + REQUIRE(output->n_cols == 5); for (size_t i = 0; i < 25; ++i) - BOOST_REQUIRE_EQUAL((*output)[i], 1.0); + REQUIRE((*output)[i] == 1.0); } -BOOST_AUTO_TEST_CASE(GetRawParamModelTest) +TEST_CASE("GetRawParamModelTest", "[CLIOptionTest]") { util::ParamData d; @@ -311,10 +309,10 @@ BOOST_AUTO_TEST_CASE(GetRawParamModelTest) GetRawParam>((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(get<0>(*output)->Bandwidth(), 5.0); + REQUIRE(get<0>(*output)->Bandwidth() == 5.0); } -BOOST_AUTO_TEST_CASE(GetRawParamDatasetInfoTest) +TEST_CASE("GetRawParamDatasetInfoTest", "[CLIOptionTest]") { util::ParamData d; @@ -339,13 +337,13 @@ BOOST_AUTO_TEST_CASE(GetRawParamDatasetInfoTest) GetRawParam>((util::ParamData&) d, (void*) NULL, (void*) &output); - BOOST_REQUIRE_EQUAL(get<0>(*output).Dimensionality(), 3); - BOOST_REQUIRE_EQUAL(get<1>(*output).n_rows, 3); - BOOST_REQUIRE_EQUAL(get<1>(*output).n_cols, 3); + REQUIRE(get<0>(*output).Dimensionality() == 3); + REQUIRE(get<1>(*output).n_rows == 3); + REQUIRE(get<1>(*output).n_cols == 3); } // Check that we can successfully write a matrix to file. -BOOST_AUTO_TEST_CASE(OutputParamMatTest) +TEST_CASE("OutputParamMatTest", "[CLIOptionTest]") { util::ParamData d; @@ -363,7 +361,7 @@ BOOST_AUTO_TEST_CASE(OutputParamMatTest) (void*) NULL); arma::mat m2; - BOOST_REQUIRE(data::Load("test.csv", m2)); + REQUIRE(data::Load("test.csv", m2)); CheckMatrices(m, m2); @@ -371,7 +369,7 @@ BOOST_AUTO_TEST_CASE(OutputParamMatTest) } // Check that we can successfully write an unsigned matrix to file. -BOOST_AUTO_TEST_CASE(OutputParamUmatTest) +TEST_CASE("OutputParamUmatTest", "[CLIOptionTest]") { util::ParamData d; @@ -389,7 +387,7 @@ BOOST_AUTO_TEST_CASE(OutputParamUmatTest) (void*) NULL); arma::Mat m2; - BOOST_REQUIRE(data::Load("test.csv", m2)); + REQUIRE(data::Load("test.csv", m2)); CheckMatrices(m, m2); @@ -397,7 +395,7 @@ BOOST_AUTO_TEST_CASE(OutputParamUmatTest) } // Check that we can successfully write a model to file. -BOOST_AUTO_TEST_CASE(OutputParamModelTest) +TEST_CASE("OutputParamModelTest", "[CLIOptionTest]") { util::ParamData d; @@ -414,15 +412,15 @@ BOOST_AUTO_TEST_CASE(OutputParamModelTest) (void*) NULL); GaussianKernel gk2(1.0); - BOOST_REQUIRE(data::Load("kernel.bin", "model", gk2)); + REQUIRE(data::Load("kernel.bin", "model", gk2)); - BOOST_REQUIRE_EQUAL(gk.Bandwidth(), gk2.Bandwidth()); + REQUIRE(gk.Bandwidth() == gk2.Bandwidth()); remove("kernel.bin"); } // Test setting a primitive type parameter. -BOOST_AUTO_TEST_CASE(SetParamDoubleTest) +TEST_CASE("SetParamDoubleTest", "[CLIOptionTest]") { util::ParamData d; @@ -440,11 +438,11 @@ BOOST_AUTO_TEST_CASE(SetParamDoubleTest) GetParam((util::ParamData&) d, (const void*) NULL, (void*) &dd3); - BOOST_REQUIRE_EQUAL((*dd3), dd2); + REQUIRE((*dd3) == dd2); } // Test that setting a flag works. -BOOST_AUTO_TEST_CASE(SetParamBoolTest) +TEST_CASE("SetParamBoolTest", "[CLIOptionTest]") { util::ParamData d; @@ -458,11 +456,11 @@ BOOST_AUTO_TEST_CASE(SetParamBoolTest) boost::any a(b2); SetParam((util::ParamData&) d, (const void*) &a, (void*) NULL); - BOOST_REQUIRE_EQUAL(boost::any_cast(d.value), true); + REQUIRE(boost::any_cast(d.value) == true); } // Test that calling SetParam on a matrix sets the string correctly. -BOOST_AUTO_TEST_CASE(SetParamMatrixTest) +TEST_CASE("SetParamMatrixTest", "[CLIOptionTest]") { util::ParamData d; @@ -481,11 +479,11 @@ BOOST_AUTO_TEST_CASE(SetParamMatrixTest) // Make sure the change went through. tuple& t = *boost::any_cast>(&d.value); - BOOST_REQUIRE_EQUAL(get<1>(t), "new.csv"); + REQUIRE(get<1>(t) == "new.csv"); } // Test that calling SetParam on a model sets the string correctly. -BOOST_AUTO_TEST_CASE(SetParamModelTest) +TEST_CASE("SetParamModelTest", "[CLIOptionTest]") { util::ParamData d; @@ -505,12 +503,12 @@ BOOST_AUTO_TEST_CASE(SetParamModelTest) tuple& t = *boost::any_cast>(&d.value); - BOOST_REQUIRE_EQUAL(get<1>(t), "new_kernel.bin"); + REQUIRE(get<1>(t) == "new_kernel.bin"); } // Test that calling SetParam on a mat/DatasetInfo successfully sets the // filename. -BOOST_AUTO_TEST_CASE(SetParamDatasetInfoMatTest) +TEST_CASE("SetParamDatasetInfoMatTest", "[CLIOptionTest]") { util::ParamData d; @@ -535,12 +533,12 @@ BOOST_AUTO_TEST_CASE(SetParamDatasetInfoMatTest) tuple, string>& t3 = *boost::any_cast, string>>(&d.value); - BOOST_REQUIRE_EQUAL(get<1>(t3), "new_filename.csv"); + REQUIRE(get<1>(t3) == "new_filename.csv"); } // Test that GetAllocatedMemory() will properly return NULL for a non-model // type. -BOOST_AUTO_TEST_CASE(GetAllocatedMemoryNonModelTest) +TEST_CASE("GetAllocatedMemoryNonModelTest", "[CLIOptionTest]") { util::ParamData d; @@ -553,7 +551,7 @@ BOOST_AUTO_TEST_CASE(GetAllocatedMemoryNonModelTest) GetAllocatedMemory((util::ParamData&) d, (const void*) NULL, (void*) &result); - BOOST_REQUIRE_EQUAL(result, (void*) NULL); + REQUIRE(result == (void*) NULL); // Also test with a matrix type. arma::mat test(10, 10, arma::fill::ones); @@ -566,12 +564,12 @@ BOOST_AUTO_TEST_CASE(GetAllocatedMemoryNonModelTest) GetAllocatedMemory((util::ParamData&) d, (const void*) NULL, (void*) &result); - BOOST_REQUIRE_EQUAL(result, (void*) NULL); + REQUIRE(result == (void*) NULL); } // Test that GetAllocatedMemory() will properly return pointers for a // serializable model type. -BOOST_AUTO_TEST_CASE(GetAllocatedMemoryModelTest) +TEST_CASE("GetAllocatedMemoryModelTest", "[CLIOptionTest]") { util::ParamData d; @@ -586,12 +584,12 @@ BOOST_AUTO_TEST_CASE(GetAllocatedMemoryModelTest) GetAllocatedMemory((util::ParamData&) d, (const void*) NULL, (void*) &result); - BOOST_REQUIRE_EQUAL(&g, (GaussianKernel*) result); + REQUIRE(&g == (GaussianKernel*) result); } // Test that calling DeleteAllocatedMemory() on non-model types does not delete // pointers. -BOOST_AUTO_TEST_CASE(DeleteAllocatedMemoryNonModelTest) +TEST_CASE("DeleteAllocatedMemoryNonModelTest", "[CLIOptionTest]") { util::ParamData d; @@ -613,7 +611,7 @@ BOOST_AUTO_TEST_CASE(DeleteAllocatedMemoryNonModelTest) // Test that DeleteAllocatedMemory() will properly delete pointers for a // serializable model type. -BOOST_AUTO_TEST_CASE(DeleteAllocatedMemoryModelTest) +TEST_CASE("DeleteAllocatedMemoryModelTest", "[CLIOptionTest]") { // This test will just delete it, and we'll hope that it worked and that // valgrind won't throw any issues (so really we can't *quite* test this in @@ -630,5 +628,3 @@ BOOST_AUTO_TEST_CASE(DeleteAllocatedMemoryModelTest) DeleteAllocatedMemory((util::ParamData&) d, (const void*) NULL, (void*) NULL); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/io_test.cpp b/src/mlpack/tests/io_test.cpp index 766e36facc..6479feace4 100644 --- a/src/mlpack/tests/io_test.cpp +++ b/src/mlpack/tests/io_test.cpp @@ -29,8 +29,8 @@ static const std::string testName = ""; #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::util; @@ -46,8 +46,6 @@ struct IOTestDestroyer IOTestDestroyer() { IO::ClearSettings(); } }; -BOOST_FIXTURE_TEST_SUITE(IOTest, IOTestDestroyer); - /** * Before running a test that uses the CLI options, we have to add the default * options that are required for CLI to function, since it will be destroyed at @@ -72,7 +70,8 @@ void AddRequiredCLIOptions() * Tests that CLI works as intended, namely that IO::Add propagates * successfully. */ -BOOST_AUTO_TEST_CASE(TestCLIAdd) +TEST_CASE_METHOD(IOTestDestroyer, "TestCLIAdd", + "[IOTest]") { AddRequiredCLIOptions(); @@ -81,19 +80,18 @@ BOOST_AUTO_TEST_CASE(TestCLIAdd) CLIOption b(false, "global/bool", "True or false.", "a", "bool"); // IO::HasParam should return false here. - BOOST_REQUIRE(!IO::HasParam("global/bool")); + REQUIRE(!IO::HasParam("global/bool")); // Check that our aliasing works. - BOOST_REQUIRE_EQUAL(IO::HasParam("global/bool"), - IO::HasParam("a")); - BOOST_REQUIRE_EQUAL(IO::GetParam("global/bool"), - IO::GetParam("a")); + REQUIRE(IO::HasParam("global/bool") == IO::HasParam("a")); + REQUIRE(IO::GetParam("global/bool") == IO::GetParam("a")); } /** * Tests that the various PARAM_* macros work properly. */ -BOOST_AUTO_TEST_CASE(TestOption) +TEST_CASE_METHOD(IOTestDestroyer, "TestOption", + "[IOTest]") { AddRequiredCLIOptions(); @@ -101,13 +99,14 @@ BOOST_AUTO_TEST_CASE(TestOption) // this. PARAM_IN(int, "test_parent/test", "test desc", "", 42, false); - BOOST_REQUIRE_EQUAL(IO::GetParam("test_parent/test"), 42); + REQUIRE(IO::GetParam("test_parent/test") == 42); } /** * Test that duplicate flags are filtered out correctly. */ -BOOST_AUTO_TEST_CASE(TestDuplicateFlag) +TEST_CASE_METHOD(IOTestDestroyer, "TestDuplicateFlag", + "[IOTest]") { AddRequiredCLIOptions(); @@ -120,14 +119,15 @@ BOOST_AUTO_TEST_CASE(TestDuplicateFlag) argv[2] = "--test"; // This should not throw an exception. - BOOST_REQUIRE_NO_THROW( + REQUIRE_NOTHROW( ParseCommandLine(argc, const_cast(argv))); } /** * Test that duplicate options throw an exception. */ -BOOST_AUTO_TEST_CASE(TestDuplicateParam) +TEST_CASE_METHOD(IOTestDestroyer, "TestDuplicateParam", + "[IOTest]") { AddRequiredCLIOptions(); @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(TestDuplicateParam) // This should throw an exception. Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(ParseCommandLine(argc, const_cast(argv)), + REQUIRE_THROWS_AS(ParseCommandLine(argc, const_cast(argv)), std::runtime_error); Log::Fatal.ignoreInput = false; } @@ -149,16 +149,17 @@ BOOST_AUTO_TEST_CASE(TestDuplicateParam) /** * Ensure that a Boolean option which we define is set correctly. */ -BOOST_AUTO_TEST_CASE(TestBooleanOption) +TEST_CASE_METHOD(IOTestDestroyer, "TestBooleanOption", + "[IOTest]") { AddRequiredCLIOptions(); PARAM_FLAG("flag_test", "flag test description", ""); - BOOST_REQUIRE_EQUAL(IO::HasParam("flag_test"), false); + REQUIRE(IO::HasParam("flag_test") == false); // Now check that CLI reflects that it is false by default. - BOOST_REQUIRE_EQUAL(IO::GetParam("flag_test"), false); + REQUIRE(IO::GetParam("flag_test") == false); // Now, if we specify this flag, it should be true. int argc = 2; @@ -168,14 +169,15 @@ BOOST_AUTO_TEST_CASE(TestBooleanOption) ParseCommandLine(argc, const_cast(argv)); - BOOST_REQUIRE_EQUAL(IO::GetParam("flag_test"), true); - BOOST_REQUIRE_EQUAL(IO::HasParam("flag_test"), true); + REQUIRE(IO::GetParam("flag_test") == true); + REQUIRE(IO::HasParam("flag_test") == true); } /** * Test that a vector option works correctly. */ -BOOST_AUTO_TEST_CASE(TestVectorOption) +TEST_CASE_METHOD(IOTestDestroyer, "TestVectorOption", + "[IOTest]") { AddRequiredCLIOptions(); @@ -191,20 +193,21 @@ BOOST_AUTO_TEST_CASE(TestVectorOption) ParseCommandLine(argc, const_cast(argv)); - BOOST_REQUIRE(IO::HasParam("test_vec")); + REQUIRE(IO::HasParam("test_vec")); vector v = IO::GetParam>("test_vec"); - BOOST_REQUIRE_EQUAL(v.size(), 3); - BOOST_REQUIRE_EQUAL(v[0], 1); - BOOST_REQUIRE_EQUAL(v[1], 2); - BOOST_REQUIRE_EQUAL(v[2], 4); + REQUIRE(v.size() == 3); + REQUIRE(v[0] == 1); + REQUIRE(v[1] == 2); + REQUIRE(v[2] == 4); } /** * Test that we can use a vector option by specifying it many times. */ -BOOST_AUTO_TEST_CASE(TestVectorOption2) +TEST_CASE_METHOD(IOTestDestroyer, "TestVectorOption2", + "[IOTest]") { AddRequiredCLIOptions(); @@ -222,17 +225,18 @@ BOOST_AUTO_TEST_CASE(TestVectorOption2) ParseCommandLine(argc, const_cast(argv)); - BOOST_REQUIRE(IO::HasParam("test2_vec")); + REQUIRE(IO::HasParam("test2_vec")); vector v = IO::GetParam>("test2_vec"); - BOOST_REQUIRE_EQUAL(v.size(), 3); - BOOST_REQUIRE_EQUAL(v[0], 1); - BOOST_REQUIRE_EQUAL(v[1], 2); - BOOST_REQUIRE_EQUAL(v[2], 4); + REQUIRE(v.size() == 3); + REQUIRE(v[0] == 1); + REQUIRE(v[1] == 2); + REQUIRE(v[2] == 4); } -BOOST_AUTO_TEST_CASE(InputColVectorParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "InputColVectorParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -250,24 +254,25 @@ BOOST_AUTO_TEST_CASE(InputColVectorParamTest) ParseCommandLine(argc, const_cast(argv)); // The --vector parameter should exist. - BOOST_REQUIRE(IO::HasParam("vector")); + REQUIRE(IO::HasParam("vector")); // The --vector_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("vector_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("vector_file"), runtime_error); Log::Fatal.ignoreInput = false; arma::vec vec1 = IO::GetParam("vector"); arma::vec vec2 = IO::GetParam("vector"); - BOOST_REQUIRE_EQUAL(vec1.n_rows, 63); - BOOST_REQUIRE_EQUAL(vec2.n_rows, 63); + REQUIRE(vec1.n_rows == 63); + REQUIRE(vec2.n_rows == 63); for (size_t i = 0; i < vec1.n_elem; ++i) - BOOST_REQUIRE_CLOSE(vec1[i], vec2[i], 1e-10); + REQUIRE(vec1[i] == Approx(vec2[i]).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(InputUnsignedColVectorParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "InputUnsignedColVectorParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -285,24 +290,25 @@ BOOST_AUTO_TEST_CASE(InputUnsignedColVectorParamTest) ParseCommandLine(argc, const_cast(argv)); // The --vector parameter should exist. - BOOST_REQUIRE(IO::HasParam("vector")); + REQUIRE(IO::HasParam("vector")); // The --vector_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("vector_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("vector_file"), runtime_error); Log::Fatal.ignoreInput = false; arma::Col vec1 = IO::GetParam>("vector"); arma::Col vec2 = IO::GetParam>("vector"); - BOOST_REQUIRE_EQUAL(vec1.n_rows, 63); - BOOST_REQUIRE_EQUAL(vec2.n_rows, 63); + REQUIRE(vec1.n_rows == 63); + REQUIRE(vec2.n_rows == 63); for (size_t i = 0; i < vec1.n_elem; ++i) - BOOST_REQUIRE_EQUAL(vec1[i], vec2[i]); + REQUIRE(vec1[i] == vec2[i]); } -BOOST_AUTO_TEST_CASE(InputRowVectorParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "InputRowVectorParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -320,24 +326,25 @@ BOOST_AUTO_TEST_CASE(InputRowVectorParamTest) ParseCommandLine(argc, const_cast(argv)); // The --vector parameter should exist. - BOOST_REQUIRE(IO::HasParam("row")); + REQUIRE(IO::HasParam("row")); // The --vector_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("row_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("row_file"), runtime_error); Log::Fatal.ignoreInput = false; arma::rowvec vec1 = IO::GetParam("row"); arma::rowvec vec2 = IO::GetParam("row"); - BOOST_REQUIRE_EQUAL(vec1.n_cols, 7); - BOOST_REQUIRE_EQUAL(vec2.n_cols, 7); + REQUIRE(vec1.n_cols == 7); + REQUIRE(vec2.n_cols == 7); for (size_t i = 0; i < vec1.n_elem; ++i) - BOOST_REQUIRE_CLOSE(vec1[i], vec2[i], 1e-10); + REQUIRE(vec1[i] == Approx(vec2[i]).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(InputUnsignedRowVectorParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "InputUnsignedRowVectorParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -355,24 +362,25 @@ BOOST_AUTO_TEST_CASE(InputUnsignedRowVectorParamTest) ParseCommandLine(argc, const_cast(argv)); // The --vector parameter should exist. - BOOST_REQUIRE(IO::HasParam("row")); + REQUIRE(IO::HasParam("row")); // The --vector_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("row_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("row_file"), runtime_error); Log::Fatal.ignoreInput = false; arma::Row vec1 = IO::GetParam>("row"); arma::Row vec2 = IO::GetParam>("row"); - BOOST_REQUIRE_EQUAL(vec1.n_cols, 7); - BOOST_REQUIRE_EQUAL(vec2.n_cols, 7); + REQUIRE(vec1.n_cols == 7); + REQUIRE(vec2.n_cols == 7); for (size_t i = 0; i < vec1.n_elem; ++i) - BOOST_REQUIRE_EQUAL(vec1[i], vec2[i]); + REQUIRE(vec1[i] == vec2[i]); } -BOOST_AUTO_TEST_CASE(OutputColParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "OutputColParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -390,11 +398,11 @@ BOOST_AUTO_TEST_CASE(OutputColParamTest) ParseCommandLine(argc, const_cast(argv)); // The --vector parameter should exist. - BOOST_REQUIRE(IO::HasParam("vector")); + REQUIRE(IO::HasParam("vector")); // The --vector_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("vector_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("vector_file"), runtime_error); Log::Fatal.ignoreInput = false; // Since it's an output parameter, we don't need any input and don't need to @@ -411,15 +419,16 @@ BOOST_AUTO_TEST_CASE(OutputColParamTest) arma::vec dataset2; data::Load("test.csv", dataset2); - BOOST_REQUIRE_EQUAL(dataset.n_rows, dataset2.n_rows); + REQUIRE(dataset.n_rows == dataset2.n_rows); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_CLOSE(dataset[i], dataset2[i], 1e-10); + REQUIRE(dataset[i] == Approx(dataset2[i]).epsilon(1e-12)); // Remove the file. remove("test.csv"); } -BOOST_AUTO_TEST_CASE(OutputUnsignedColParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "OutputUnsignedColParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -437,11 +446,11 @@ BOOST_AUTO_TEST_CASE(OutputUnsignedColParamTest) ParseCommandLine(argc, const_cast(argv)); // The --vector parameter should exist. - BOOST_REQUIRE(IO::HasParam("vector")); + REQUIRE(IO::HasParam("vector")); // The --vector_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("vector_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("vector_file"), runtime_error); Log::Fatal.ignoreInput = false; // Since it's an output parameter, we don't need any input and don't need to @@ -458,15 +467,16 @@ BOOST_AUTO_TEST_CASE(OutputUnsignedColParamTest) arma::Col dataset2; data::Load("test.csv", dataset2); - BOOST_REQUIRE_EQUAL(dataset.n_rows, dataset2.n_rows); + REQUIRE(dataset.n_rows == dataset2.n_rows); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_EQUAL(dataset[i], dataset2[i]); + REQUIRE(dataset[i] == dataset2[i]); // Remove the file. remove("test.csv"); } -BOOST_AUTO_TEST_CASE(OutputRowParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "OutputRowParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -484,11 +494,11 @@ BOOST_AUTO_TEST_CASE(OutputRowParamTest) ParseCommandLine(argc, const_cast(argv)); // The --row parameter should exist. - BOOST_REQUIRE(IO::HasParam("row")); + REQUIRE(IO::HasParam("row")); // The --row_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("row_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("row_file"), runtime_error); Log::Fatal.ignoreInput = false; // Since it's an output parameter, we don't need any input and don't need to @@ -505,15 +515,16 @@ BOOST_AUTO_TEST_CASE(OutputRowParamTest) arma::rowvec dataset2; data::Load("test.csv", dataset2); - BOOST_REQUIRE_EQUAL(dataset.n_cols, dataset2.n_cols); + REQUIRE(dataset.n_cols == dataset2.n_cols); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_CLOSE(dataset[i], dataset2[i], 1e-10); + REQUIRE(dataset[i] == Approx(dataset2[i]).epsilon(1e-12)); // Remove the file. remove("test.csv"); } -BOOST_AUTO_TEST_CASE(OutputUnsignedRowParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "OutputUnsignedRowParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -531,11 +542,11 @@ BOOST_AUTO_TEST_CASE(OutputUnsignedRowParamTest) ParseCommandLine(argc, const_cast(argv)); // The --row parameter should exist. - BOOST_REQUIRE(IO::HasParam("row")); + REQUIRE(IO::HasParam("row")); // The --row_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("row_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("row_file"), runtime_error); Log::Fatal.ignoreInput = false; // Since it's an output parameter, we don't need any input and don't need to @@ -552,15 +563,16 @@ BOOST_AUTO_TEST_CASE(OutputUnsignedRowParamTest) arma::Row dataset2; data::Load("test.csv", dataset2); - BOOST_REQUIRE_EQUAL(dataset.n_cols, dataset2.n_cols); + REQUIRE(dataset.n_cols == dataset2.n_cols); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_EQUAL(dataset[i], dataset2[i]); + REQUIRE(dataset[i] == dataset2[i]); // Remove the file. remove("test.csv"); } -BOOST_AUTO_TEST_CASE(InputMatrixParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "InputMatrixParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -579,26 +591,27 @@ BOOST_AUTO_TEST_CASE(InputMatrixParamTest) ParseCommandLine(argc, const_cast(argv)); // The --matrix parameter should exist. - BOOST_REQUIRE(IO::HasParam("matrix")); + REQUIRE(IO::HasParam("matrix")); // The --matrix_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("matrix_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("matrix_file"), runtime_error); Log::Fatal.ignoreInput = false; arma::mat dataset = IO::GetParam("matrix"); arma::mat dataset2 = IO::GetParam("matrix"); - BOOST_REQUIRE_EQUAL(dataset.n_rows, 3); - BOOST_REQUIRE_EQUAL(dataset.n_cols, 1000); - BOOST_REQUIRE_EQUAL(dataset2.n_rows, 3); - BOOST_REQUIRE_EQUAL(dataset2.n_cols, 1000); + REQUIRE(dataset.n_rows == 3); + REQUIRE(dataset.n_cols == 1000); + REQUIRE(dataset2.n_rows == 3); + REQUIRE(dataset2.n_cols == 1000); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_CLOSE(dataset[i], dataset2[i], 1e-10); + REQUIRE(dataset[i] == Approx(dataset2[i]).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(InputMatrixNoTransposeParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "InputMatrixNoTransposeParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -617,26 +630,27 @@ BOOST_AUTO_TEST_CASE(InputMatrixNoTransposeParamTest) ParseCommandLine(argc, const_cast(argv)); // The --matrix parameter should exist. - BOOST_REQUIRE(IO::HasParam("matrix")); + REQUIRE(IO::HasParam("matrix")); // The --matrix_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("matrix_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("matrix_file"), runtime_error); Log::Fatal.ignoreInput = false; arma::mat dataset = IO::GetParam("matrix"); arma::mat dataset2 = IO::GetParam("matrix"); - BOOST_REQUIRE_EQUAL(dataset.n_rows, 1000); - BOOST_REQUIRE_EQUAL(dataset.n_cols, 3); - BOOST_REQUIRE_EQUAL(dataset2.n_rows, 1000); - BOOST_REQUIRE_EQUAL(dataset2.n_cols, 3); + REQUIRE(dataset.n_rows == 1000); + REQUIRE(dataset.n_cols == 3); + REQUIRE(dataset2.n_rows == 1000); + REQUIRE(dataset2.n_cols == 3); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_CLOSE(dataset[i], dataset2[i], 1e-10); + REQUIRE(dataset[i] == Approx(dataset2[i]).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(OutputMatrixParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -654,11 +668,11 @@ BOOST_AUTO_TEST_CASE(OutputMatrixParamTest) ParseCommandLine(argc, const_cast(argv)); // The --matrix parameter should exist. - BOOST_REQUIRE(IO::HasParam("matrix")); + REQUIRE(IO::HasParam("matrix")); // The --matrix_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("matrix_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("matrix_file"), runtime_error); Log::Fatal.ignoreInput = false; // Since it's an output parameter, we don't need any input and don't need to @@ -675,16 +689,17 @@ BOOST_AUTO_TEST_CASE(OutputMatrixParamTest) arma::mat dataset2; data::Load("test.csv", dataset2); - BOOST_REQUIRE_EQUAL(dataset.n_cols, dataset2.n_cols); - BOOST_REQUIRE_EQUAL(dataset.n_rows, dataset2.n_rows); + REQUIRE(dataset.n_cols == dataset2.n_cols); + REQUIRE(dataset.n_rows == dataset2.n_rows); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_CLOSE(dataset[i], dataset2[i], 1e-10); + REQUIRE(dataset[i] == Approx(dataset2[i]).epsilon(1e-12)); // Remove the file. remove("test.csv"); } -BOOST_AUTO_TEST_CASE(OutputMatrixNoTransposeParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixNoTransposeParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -702,11 +717,11 @@ BOOST_AUTO_TEST_CASE(OutputMatrixNoTransposeParamTest) ParseCommandLine(argc, const_cast(argv)); // The --matrix parameter should exist. - BOOST_REQUIRE(IO::HasParam("matrix")); + REQUIRE(IO::HasParam("matrix")); // The --matrix_file parameter should not exist (it should be transparent from // inside the program). Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(IO::HasParam("matrix_file"), runtime_error); + REQUIRE_THROWS_AS(IO::HasParam("matrix_file"), runtime_error); Log::Fatal.ignoreInput = false; // Since it's an output parameter, we don't need any input and don't need to @@ -723,16 +738,17 @@ BOOST_AUTO_TEST_CASE(OutputMatrixNoTransposeParamTest) arma::mat dataset2; data::Load("test.csv", dataset2, true, false); - BOOST_REQUIRE_EQUAL(dataset.n_cols, dataset2.n_cols); - BOOST_REQUIRE_EQUAL(dataset.n_rows, dataset2.n_rows); + REQUIRE(dataset.n_cols == dataset2.n_cols); + REQUIRE(dataset.n_rows == dataset2.n_rows); for (size_t i = 0; i < dataset.n_elem; ++i) - BOOST_REQUIRE_CLOSE(dataset[i], dataset2[i], 1e-10); + REQUIRE(dataset[i] == Approx(dataset2[i]).epsilon(1e-12)); // Remove the file. remove("test.csv"); } -BOOST_AUTO_TEST_CASE(IntParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "IntParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -747,11 +763,12 @@ BOOST_AUTO_TEST_CASE(IntParamTest) ParseCommandLine(argc, const_cast(argv)); - BOOST_REQUIRE(IO::HasParam("int")); - BOOST_REQUIRE_EQUAL(IO::GetParam("int"), 3); + REQUIRE(IO::HasParam("int")); + REQUIRE(IO::GetParam("int") == 3); } -BOOST_AUTO_TEST_CASE(StringParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "StringParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -766,11 +783,12 @@ BOOST_AUTO_TEST_CASE(StringParamTest) ParseCommandLine(argc, const_cast(argv)); - BOOST_REQUIRE(IO::HasParam("string")); - BOOST_REQUIRE_EQUAL(IO::GetParam("string"), string("3")); + REQUIRE(IO::HasParam("string")); + REQUIRE(IO::GetParam("string") == string("3")); } -BOOST_AUTO_TEST_CASE(DoubleParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "DoubleParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -785,11 +803,12 @@ BOOST_AUTO_TEST_CASE(DoubleParamTest) ParseCommandLine(argc, const_cast(argv)); - BOOST_REQUIRE(IO::HasParam("double")); - BOOST_REQUIRE_CLOSE(IO::GetParam("double"), 3.12, 1e-10); + REQUIRE(IO::HasParam("double")); + REQUIRE(IO::GetParam("double") == Approx(3.12).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(RequiredOptionTest) +TEST_CASE_METHOD(IOTestDestroyer, "RequiredOptionTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -801,12 +820,13 @@ BOOST_AUTO_TEST_CASE(RequiredOptionTest) int argc = 1; Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(ParseCommandLine(argc, const_cast(argv)), + REQUIRE_THROWS_AS(ParseCommandLine(argc, const_cast(argv)), runtime_error); Log::Fatal.ignoreInput = false; } -BOOST_AUTO_TEST_CASE(UnknownOptionTest) +TEST_CASE_METHOD(IOTestDestroyer, "UnknownOptionTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -817,7 +837,7 @@ BOOST_AUTO_TEST_CASE(UnknownOptionTest) int argc = 2; Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(ParseCommandLine(argc, const_cast(argv)), + REQUIRE_THROWS_AS(ParseCommandLine(argc, const_cast(argv)), runtime_error); Log::Fatal.ignoreInput = false; } @@ -825,7 +845,8 @@ BOOST_AUTO_TEST_CASE(UnknownOptionTest) /** * Test that GetPrintableParam() works. */ -BOOST_AUTO_TEST_CASE(UnmappedParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "UnmappedParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -850,15 +871,15 @@ BOOST_AUTO_TEST_CASE(UnmappedParamTest) ParseCommandLine(argc, const_cast(argv)); // Now check that we can get unmapped parameters. - BOOST_REQUIRE_EQUAL(IO::GetPrintableParam("matrix"), + REQUIRE(IO::GetPrintableParam("matrix") == "'test_data_3_1000.csv' (3x1000 matrix)"); // This will have size 0x0 since it's an output parameter, and it hasn't been // set since ParseCommandLine() was called. - BOOST_REQUIRE_EQUAL(IO::GetPrintableParam("matrix2"), + REQUIRE(IO::GetPrintableParam("matrix2") == "'file2.csv' (0x0 matrix)"); - BOOST_REQUIRE_EQUAL(IO::GetPrintableParam("kernel"), + REQUIRE(IO::GetPrintableParam("kernel") == "kernel.txt"); - BOOST_REQUIRE_EQUAL(IO::GetPrintableParam("kernel2"), + REQUIRE(IO::GetPrintableParam("kernel2") == "kernel2.txt"); remove("kernel.txt"); @@ -868,7 +889,8 @@ BOOST_AUTO_TEST_CASE(UnmappedParamTest) * Test that we can serialize a model and then deserialize it through the CLI * interface. */ -BOOST_AUTO_TEST_CASE(SerializationTest) +TEST_CASE_METHOD(IOTestDestroyer, "IOSerializationTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -902,7 +924,7 @@ BOOST_AUTO_TEST_CASE(SerializationTest) // Load the kernel from file. GaussianKernel* gk2 = IO::GetParam("kernel"); - BOOST_REQUIRE_CLOSE(gk2->Bandwidth(), 0.5, 1e-5); + REQUIRE(gk2->Bandwidth() == Approx(0.5).epsilon(1e-7)); // Clean up the memory... delete gk2; @@ -914,7 +936,8 @@ BOOST_AUTO_TEST_CASE(SerializationTest) /** * Test that an exception is thrown when a required model is not specified. */ -BOOST_AUTO_TEST_CASE(RequiredModelTest) +TEST_CASE_METHOD(IOTestDestroyer, "RequiredModelTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -927,7 +950,7 @@ BOOST_AUTO_TEST_CASE(RequiredModelTest) int argc = 1; Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(ParseCommandLine(argc, const_cast(argv)), + REQUIRE_THROWS_AS(ParseCommandLine(argc, const_cast(argv)), runtime_error); Log::Fatal.ignoreInput = false; } @@ -935,7 +958,8 @@ BOOST_AUTO_TEST_CASE(RequiredModelTest) /** * Test that we can load both a dataset and its associated info. */ -BOOST_AUTO_TEST_CASE(MatrixAndDatasetInfoTest) +TEST_CASE_METHOD(IOTestDestroyer, "MatrixAndDatasetInfoTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -975,32 +999,32 @@ BOOST_AUTO_TEST_CASE(MatrixAndDatasetInfoTest) DatasetInfo info = move(get<0>(IO::GetParam("dataset"))); arma::mat dataset = move(get<1>(IO::GetParam("dataset"))); - BOOST_REQUIRE_EQUAL(info.Dimensionality(), 3); + REQUIRE(info.Dimensionality() == 3); - BOOST_REQUIRE(info.Type(0) == Datatype::categorical); - BOOST_REQUIRE_EQUAL(info.NumMappings(0), 3); - BOOST_REQUIRE(info.Type(1) == Datatype::numeric); - BOOST_REQUIRE(info.Type(2) == Datatype::categorical); - BOOST_REQUIRE_EQUAL(info.NumMappings(2), 2); + REQUIRE(info.Type(0) == Datatype::categorical); + REQUIRE(info.NumMappings(0) == 3); + REQUIRE(info.Type(1) == Datatype::numeric); + REQUIRE(info.Type(2) == Datatype::categorical); + REQUIRE(info.NumMappings(2) == 2); - BOOST_REQUIRE_EQUAL(dataset.n_rows, 3); - BOOST_REQUIRE_EQUAL(dataset.n_cols, 4); + REQUIRE(dataset.n_rows == 3); + REQUIRE(dataset.n_cols == 4); // The first dimension must all be different (except the ones that are the // same). - BOOST_REQUIRE_EQUAL(dataset(0, 0), dataset(0, 3)); - BOOST_REQUIRE_NE(dataset(0, 0), dataset(0, 1)); - BOOST_REQUIRE_NE(dataset(0, 1), dataset(0, 2)); - BOOST_REQUIRE_NE(dataset(0, 2), dataset(0, 0)); + REQUIRE(dataset(0, 0) == dataset(0, 3)); + REQUIRE(dataset(0, 0) != dataset(0, 1)); + REQUIRE(dataset(0, 1) != dataset(0, 2)); + REQUIRE(dataset(0, 2) != dataset(0, 0)); - BOOST_REQUIRE_CLOSE(dataset(1, 0), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(1, 1), 2.34, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(1, 2), 1.03e5, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(1, 3), -1.3, 1e-5); + REQUIRE(dataset(1, 0) == Approx(1.0).epsilon(1e-7)); + REQUIRE(dataset(1, 1) == Approx(2.34).epsilon(1e-7)); + REQUIRE(dataset(1, 2) == Approx(1.03e5).epsilon(1e-7)); + REQUIRE(dataset(1, 3) == Approx(-1.3).epsilon(1e-7)); - BOOST_REQUIRE_EQUAL(dataset(2, 0), dataset(2, 2)); - BOOST_REQUIRE_EQUAL(dataset(2, 1), dataset(2, 3)); - BOOST_REQUIRE_NE(dataset(2, 0), dataset(2, 1)); + REQUIRE(dataset(2, 0) == dataset(2, 2)); + REQUIRE(dataset(2, 1) == dataset(2, 3)); + REQUIRE(dataset(2, 0) != dataset(2, 1)); remove("test.arff"); } @@ -1008,7 +1032,8 @@ BOOST_AUTO_TEST_CASE(MatrixAndDatasetInfoTest) /** * Test that we can access a parameter before we load it. */ -BOOST_AUTO_TEST_CASE(RawIntegralParameter) +TEST_CASE_METHOD(IOTestDestroyer, "RawIntegralParameter", + "[IOTest]") { AddRequiredCLIOptions(); @@ -1024,14 +1049,15 @@ BOOST_AUTO_TEST_CASE(RawIntegralParameter) IO::GetRawParam("double") = 3.0; // Now when we get it, it should be what we just set it to. - BOOST_REQUIRE_CLOSE(IO::GetParam("double"), 3.0, 1e-5); + REQUIRE(IO::GetParam("double") == Approx(3.0).epsilon(1e-7)); } /** * Test that we can load a dataset with a pre-set mapping through * IO::GetRawParam(). */ -BOOST_AUTO_TEST_CASE(RawDatasetInfoLoadParameter) +TEST_CASE_METHOD(IOTestDestroyer, "RawDatasetInfoLoadParameter", + "[IOTest]") { AddRequiredCLIOptions(); @@ -1082,18 +1108,18 @@ BOOST_AUTO_TEST_CASE(RawDatasetInfoLoadParameter) std::get<1>(IO::GetParam>("tuple")); // Check the values. - BOOST_REQUIRE_CLOSE(dataset(0, 0), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(1, 0), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(2, 0), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(0, 1), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(1, 1), 2.34, 1e-5); - BOOST_REQUIRE_SMALL(dataset(2, 1), 1e-5); - BOOST_REQUIRE_SMALL(dataset(0, 2), 1e-5); - BOOST_REQUIRE_CLOSE(dataset(1, 2), 1.03e+5, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(2, 2), 1.0, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(0, 3), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(dataset(1, 3), -1.3, 1e-5); - BOOST_REQUIRE_SMALL(dataset(2, 3), 1e-5); + REQUIRE(dataset(0, 0) == Approx(2.0).epsilon(1e-7)); + REQUIRE(dataset(1, 0) == Approx(1.0).epsilon(1e-7)); + REQUIRE(dataset(2, 0) == Approx(1.0).epsilon(1e-7)); + REQUIRE(dataset(0, 1) == Approx(1.0).epsilon(1e-7)); + REQUIRE(dataset(1, 1) == Approx(2.34).epsilon(1e-7)); + REQUIRE(dataset(2, 1) == Approx(0.0).margin(1e-5)); + REQUIRE(dataset(0, 2) == Approx(0.0).margin(1e-5)); + REQUIRE(dataset(1, 2) == Approx(1.03e+5).epsilon(1e-7)); + REQUIRE(dataset(2, 2) == Approx(1.0).epsilon(1e-7)); + REQUIRE(dataset(0, 3) == Approx(2.0).epsilon(1e-7)); + REQUIRE(dataset(1, 3) == Approx(-1.3).epsilon(1e-7)); + REQUIRE(dataset(2, 3) == Approx(0.0).margin(1e-5)); remove("test.arff"); } @@ -1101,7 +1127,8 @@ BOOST_AUTO_TEST_CASE(RawDatasetInfoLoadParameter) /** * Make sure typenames are properly stored. */ -BOOST_AUTO_TEST_CASE(CppNameTest) +TEST_CASE_METHOD(IOTestDestroyer, "CppNameTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -1110,9 +1137,7 @@ BOOST_AUTO_TEST_CASE(CppNameTest) PARAM_DOUBLE_IN("double", "Test double", "d", 0.0); // Check that the C++ typenames are right. - BOOST_REQUIRE_EQUAL(IO::Parameters().at("matrix").cppType, "arma::mat"); - BOOST_REQUIRE_EQUAL(IO::Parameters().at("help").cppType, "bool"); - BOOST_REQUIRE_EQUAL(IO::Parameters().at("double").cppType, "double"); + REQUIRE(IO::Parameters().at("matrix").cppType == "arma::mat"); + REQUIRE(IO::Parameters().at("help").cppType == "bool"); + REQUIRE(IO::Parameters().at("double").cppType == "double"); } - -BOOST_AUTO_TEST_SUITE_END(); From db0c5e718a9242e6e23dd36e07fa2750a9db564b Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Wed, 26 Aug 2020 01:16:55 +0530 Subject: [PATCH 03/45] try to fix style issues --- src/mlpack/tests/sumtree_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/sumtree_test.cpp b/src/mlpack/tests/sumtree_test.cpp index e3ea279d63..bfc350b3de 100644 --- a/src/mlpack/tests/sumtree_test.cpp +++ b/src/mlpack/tests/sumtree_test.cpp @@ -65,10 +65,10 @@ TEST_CASE("FindPrefixSum", "[SumTreeTest]") sumtree.Set(2, 0.6); sumtree.Set(3, 0.4); - CHECK(sumtree.FindPrefixSum(0) <= 0); - CHECK(sumtree.FindPrefixSum(1) <= 1); - CHECK(sumtree.FindPrefixSum(2.8) <= 3); - CHECK(sumtree.FindPrefixSum(3.0) <= 3); + CHECK(sumtree.FindPrefixSum(0) <= 0.0); + CHECK(sumtree.FindPrefixSum(1) <= 1.0); + CHECK(sumtree.FindPrefixSum(2.8) <= 3.0); + CHECK(sumtree.FindPrefixSum(3.0) <= 3.0); } /** From d392d50c8eab850dedd17e5d154d94470b53083d Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Thu, 27 Aug 2020 02:19:12 +0530 Subject: [PATCH 04/45] merge master --- src/mlpack/tests/octree_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/octree_test.cpp b/src/mlpack/tests/octree_test.cpp index 8e41e4d932..72f48762d7 100644 --- a/src/mlpack/tests/octree_test.cpp +++ b/src/mlpack/tests/octree_test.cpp @@ -326,7 +326,7 @@ TEST_CASE("MoveConstructorTest", "[OctreeTest]") /** * Test serialization. */ -TEST_CASE("SerializationTest", "[OctreeTest]") +TEST_CASE("OctreeSerializationTest", "[OctreeTest]") { // Use a small random dataset. arma::mat dataset(3, 500, arma::fill::randu); From e48cc600c123fd898dc0d82a7036033ec34599c2 Mon Sep 17 00:00:00 2001 From: jeffin sam Date: Sun, 30 Aug 2020 01:15:55 +0530 Subject: [PATCH 05/45] Apply suggestions from code review Co-authored-by: Marcus Edel --- src/mlpack/tests/cli_binding_test.cpp | 1 - src/mlpack/tests/io_test.cpp | 28 +++++++++------------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/mlpack/tests/cli_binding_test.cpp b/src/mlpack/tests/cli_binding_test.cpp index 391a0bfe1a..1c8aea1c33 100644 --- a/src/mlpack/tests/cli_binding_test.cpp +++ b/src/mlpack/tests/cli_binding_test.cpp @@ -14,7 +14,6 @@ #include #include "catch.hpp" -#include "test_catch_tools.hpp" using namespace std; using namespace mlpack; diff --git a/src/mlpack/tests/io_test.cpp b/src/mlpack/tests/io_test.cpp index 6479feace4..fbea8ab605 100644 --- a/src/mlpack/tests/io_test.cpp +++ b/src/mlpack/tests/io_test.cpp @@ -30,7 +30,6 @@ static const std::string testName = ""; #include #include "catch.hpp" -#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::util; @@ -70,8 +69,7 @@ void AddRequiredCLIOptions() * Tests that CLI works as intended, namely that IO::Add propagates * successfully. */ -TEST_CASE_METHOD(IOTestDestroyer, "TestCLIAdd", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "TestCLIAdd", "[IOTest]") { AddRequiredCLIOptions(); @@ -90,8 +88,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "TestCLIAdd", /** * Tests that the various PARAM_* macros work properly. */ -TEST_CASE_METHOD(IOTestDestroyer, "TestOption", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "TestOption", "[IOTest]") { AddRequiredCLIOptions(); @@ -105,8 +102,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "TestOption", /** * Test that duplicate flags are filtered out correctly. */ -TEST_CASE_METHOD(IOTestDestroyer, "TestDuplicateFlag", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "TestDuplicateFlag", "[IOTest]") { AddRequiredCLIOptions(); @@ -523,8 +519,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "OutputRowParamTest", remove("test.csv"); } -TEST_CASE_METHOD(IOTestDestroyer, "OutputUnsignedRowParamTest", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "OutputUnsignedRowParamTest", "[IOTest]") { AddRequiredCLIOptions(); @@ -698,8 +693,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixParamTest", remove("test.csv"); } -TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixNoTransposeParamTest", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixNoTransposeParamTest", "[IOTest]") { AddRequiredCLIOptions(); @@ -807,8 +801,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "DoubleParamTest", REQUIRE(IO::GetParam("double") == Approx(3.12).epsilon(1e-12)); } -TEST_CASE_METHOD(IOTestDestroyer, "RequiredOptionTest", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "RequiredOptionTest", "[IOTest]") { AddRequiredCLIOptions(); @@ -889,8 +882,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "UnmappedParamTest", * Test that we can serialize a model and then deserialize it through the CLI * interface. */ -TEST_CASE_METHOD(IOTestDestroyer, "IOSerializationTest", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "IOSerializationTest", "[IOTest]") { AddRequiredCLIOptions(); @@ -1032,8 +1024,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "MatrixAndDatasetInfoTest", /** * Test that we can access a parameter before we load it. */ -TEST_CASE_METHOD(IOTestDestroyer, "RawIntegralParameter", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "RawIntegralParameter", "[IOTest]") { AddRequiredCLIOptions(); @@ -1056,8 +1047,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "RawIntegralParameter", * Test that we can load a dataset with a pre-set mapping through * IO::GetRawParam(). */ -TEST_CASE_METHOD(IOTestDestroyer, "RawDatasetInfoLoadParameter", - "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "RawDatasetInfoLoadParameter", "[IOTest]") { AddRequiredCLIOptions(); From 66b46f20b5477ad02ad06a5ebbec2e389d1cf226 Mon Sep 17 00:00:00 2001 From: jeffin sam Date: Tue, 29 Sep 2020 23:31:55 +0530 Subject: [PATCH 06/45] Update src/mlpack/tests/main_tests/hoeffding_tree_test.cpp Co-authored-by: Ryan Curtin --- src/mlpack/tests/main_tests/hoeffding_tree_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp b/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp index df52ab0993..af4373fb66 100644 --- a/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/main_tests/hoeffding_tree_test.cpp @@ -640,8 +640,8 @@ TEST_CASE_METHOD(HoeffdingTreeTestFixture, mlpackMain(); // Check that number of children is 2. - REQUIRE((IO::GetParam("output_model"))->NumNodes()-1 - == 2); + REQUIRE( + (IO::GetParam("output_model"))->NumNodes() - 1 == 2); } /** From fbd67be808045a2ed990f8945f008306669ddc33 Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Wed, 30 Sep 2020 00:14:47 +0530 Subject: [PATCH 07/45] fix conflicts --- src/mlpack/tests/cli_binding_test.cpp | 1 + src/mlpack/tests/io_test.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/cli_binding_test.cpp b/src/mlpack/tests/cli_binding_test.cpp index 1c8aea1c33..391a0bfe1a 100644 --- a/src/mlpack/tests/cli_binding_test.cpp +++ b/src/mlpack/tests/cli_binding_test.cpp @@ -14,6 +14,7 @@ #include #include "catch.hpp" +#include "test_catch_tools.hpp" using namespace std; using namespace mlpack; diff --git a/src/mlpack/tests/io_test.cpp b/src/mlpack/tests/io_test.cpp index fe3564f8a7..9bf3df03a3 100644 --- a/src/mlpack/tests/io_test.cpp +++ b/src/mlpack/tests/io_test.cpp @@ -686,7 +686,8 @@ TEST_CASE_METHOD(IOTestDestroyer, "RequiredInputMatrixParamAliasTest", } // Make sure that when we don't pass a required matrix, parsing fails. -BOOST_AUTO_TEST_CASE(RequiredUnspecifiedInputMatrixParamTest) +TEST_CASE_METHOD(IOTestDestroyer, "RequiredUnspecifiedInputMatrixParamTest", + "[IOTest]") { AddRequiredCLIOptions(); @@ -701,13 +702,11 @@ BOOST_AUTO_TEST_CASE(RequiredUnspecifiedInputMatrixParamTest) // The const-cast is a little hacky but should be fine... Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(ParseCommandLine(argc, const_cast(argv)), + REQUIRE_THROWS_AS(ParseCommandLine(argc, const_cast(argv)), std::exception); Log::Fatal.ignoreInput = false; } -BOOST_AUTO_TEST_CASE(InputMatrixNoTransposeParamTest) ->>>>>>> 64dda1387dd997cf570c15b1123f7a41e4d65b06 TEST_CASE_METHOD(IOTestDestroyer, "InputMatrixNoTransposeParamTest", "[IOTest]") { From 8f18aeaf6973f33efc92e7cb9fc2dd075c3f6617 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Thu, 1 Oct 2020 22:30:28 +0530 Subject: [PATCH 08/45] range_search_test to catch2 --- src/mlpack/tests/CMakeLists.txt | 4 +- src/mlpack/tests/range_search_test.cpp | 835 ++++++++++++------------- 2 files changed, 418 insertions(+), 421 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index ce9ef730da..483f650a25 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -55,7 +55,6 @@ add_executable(mlpack_test radical_test.cpp random_forest_test.cpp random_test.cpp - range_search_test.cpp rectangle_tree_test.cpp reward_clipping_test.cpp rl_components_test.cpp @@ -105,7 +104,6 @@ add_executable(mlpack_test main_tests/perceptron_test.cpp main_tests/radical_test.cpp main_tests/random_forest_test.cpp - main_tests/range_search_test.cpp main_tests/test_helper.hpp ) @@ -146,6 +144,7 @@ add_executable(mlpack_catch_test one_hot_encoding_test.cpp quic_svd_test.cpp randomized_svd_test.cpp + range_search_test.cpp rbm_network_test.cpp recurrent_network_test.cpp regularized_svd_test.cpp @@ -179,6 +178,7 @@ add_executable(mlpack_catch_test main_tests/preprocess_split_test.cpp main_tests/softmax_regression_test.cpp main_tests/sparse_coding_test.cpp + main_tests/range_search_test.cpp main_tests/test_helper.hpp ) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 33dd5c56ca..b9e3f47c1c 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -13,8 +13,9 @@ #include #include #include -#include -#include "test_tools.hpp" + +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::range; @@ -24,8 +25,6 @@ using namespace mlpack::bound; using namespace mlpack::metric; using namespace std; -BOOST_AUTO_TEST_SUITE(RangeSearchTest); - // Get our results into a sorted format, so we can actually then test for // correctness. void SortResults(const vector>& neighbors, @@ -62,7 +61,7 @@ void CleanTree(TreeType& node) * dataset is in one dimension for simplicity -- the correct functionality of * distance functions is not tested here. */ -BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) +TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") { // Set up our data. arma::mat data(1, 11); @@ -111,109 +110,109 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) vector>> sortedOutput; SortResults(neighbors, distances, sortedOutput); - BOOST_REQUIRE(sortedOutput[newFromOld[0]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][1].first, 0.27, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][2].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][3].first, 0.40, 1e-5); + REQUIRE(sortedOutput[newFromOld[0]].size() == 4); + REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[0]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[0]][1].first == Approx(0.27).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[0]][2].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[0]][3].first == Approx(0.40).epsilon(1e-7)); // Neighbors of point 1. - BOOST_REQUIRE(sortedOutput[newFromOld[1]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][1].first, 0.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][2].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][3].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][3].first, 0.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][4].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][4].first, 0.57, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][5].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][5].first, 0.65, 1e-5); + REQUIRE(sortedOutput[newFromOld[1]].size() == 6); + REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[1]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[1]][1].first == Approx(0.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[1]][2].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][3].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[1]][3].first == Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][4].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[1]][4].first == Approx(0.57).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][5].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[1]][5].first == Approx(0.65).epsilon(1e-7)); // Neighbors of point 2. - BOOST_REQUIRE(sortedOutput[newFromOld[2]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][1].first, 0.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][2].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][3].first, 0.37, 1e-5); + REQUIRE(sortedOutput[newFromOld[2]].size() == 4); + REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[2]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[2]][1].first == Approx(0.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[2]][2].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[2]][3].first == Approx(0.37).epsilon(1e-7)); // Neighbors of point 3. - BOOST_REQUIRE(sortedOutput[newFromOld[3]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][0].first, 0.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][1].first, 0.35, 1e-5); + REQUIRE(sortedOutput[newFromOld[3]].size() == 2); + REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[3]][0].first == Approx(0.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[3]][1].first == Approx(0.35).epsilon(1e-7)); // Neighbors of point 4. - BOOST_REQUIRE(sortedOutput[newFromOld[4]].size() == 0); + REQUIRE(sortedOutput[newFromOld[4]].size() == 0); // Neighbors of point 5. - BOOST_REQUIRE(sortedOutput[newFromOld[5]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][0].first, 0.27, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][1].first, 0.37, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][2].first, 0.57, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][3].first, 0.67, 1e-5); + REQUIRE(sortedOutput[newFromOld[5]].size() == 4); + REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[5]][0].first == Approx(0.27).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[5]][1].first == Approx(0.37).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[5]][2].first == Approx(0.57).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[5]][3].first == Approx(0.67).epsilon(1e-7)); // Neighbors of point 6. - BOOST_REQUIRE(sortedOutput[newFromOld[6]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][0].first, 0.70, 1e-5); + REQUIRE(sortedOutput[newFromOld[6]].size() == 1); + REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[6]][0].first == Approx(0.70).epsilon(1e-7)); // Neighbors of point 7. - BOOST_REQUIRE(sortedOutput[newFromOld[7]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][0].first, 0.70, 1e-5); + REQUIRE(sortedOutput[newFromOld[7]].size() == 1); + REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[7]][0].first == Approx(0.70).epsilon(1e-7)); // Neighbors of point 8. - BOOST_REQUIRE(sortedOutput[newFromOld[8]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][1].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][2].first, 0.40, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][3].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][3].first, 0.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][4].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][4].first, 0.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][5].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][5].first, 0.67, 1e-5); + REQUIRE(sortedOutput[newFromOld[8]].size() == 6); + REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[8]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[8]][1].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[8]][2].first == Approx(0.40).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][3].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[8]][3].first == Approx(0.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][4].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[8]][4].first == Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][5].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[8]][5].first == Approx(0.67).epsilon(1e-7)); // Neighbors of point 9. - BOOST_REQUIRE(sortedOutput[newFromOld[9]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][1].first, 0.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][2].first, 0.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][3].first, 0.55, 1e-5); + REQUIRE(sortedOutput[newFromOld[9]].size() == 4); + REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[9]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[9]][1].first == Approx(0.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[9]][2].first == Approx(0.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[9]][3].first == Approx(0.55).epsilon(1e-7)); // Neighbors of point 10. - BOOST_REQUIRE(sortedOutput[newFromOld[10]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][1].first, 0.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][2].first, 0.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][3].first, 0.65, 1e-5); + REQUIRE(sortedOutput[newFromOld[10]].size() == 4); + REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(0.65).epsilon(1e-7)); // Now do it again with a different range: [sqrt(0.5) 1.0]. if (rs->ReferenceTree()) @@ -222,61 +221,61 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) SortResults(neighbors, distances, sortedOutput); // Neighbors of point 0. - BOOST_REQUIRE(sortedOutput[newFromOld[0]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][0].first, 0.85, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][1].first, 0.95, 1e-5); + REQUIRE(sortedOutput[newFromOld[0]].size() == 2); + REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[0]][0].first == Approx(0.85).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[0]][1].first == Approx(0.95).epsilon(1e-7)); // Neighbors of point 1. - BOOST_REQUIRE(sortedOutput[newFromOld[1]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][0].first, 0.90, 1e-5); + REQUIRE(sortedOutput[newFromOld[1]].size() == 1); + REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[1]][0].first == Approx(0.90).epsilon(1e-7)); // Neighbors of point 2. - BOOST_REQUIRE(sortedOutput[newFromOld[2]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][0].first, 0.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][1].first, 0.85, 1e-5); + REQUIRE(sortedOutput[newFromOld[2]].size() == 2); + REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[2]][0].first == Approx(0.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[2]][1].first == Approx(0.85).epsilon(1e-7)); // Neighbors of point 3. - BOOST_REQUIRE(sortedOutput[newFromOld[3]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][0].first, 0.80, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][1].first, 0.90, 1e-5); + REQUIRE(sortedOutput[newFromOld[3]].size() == 2); + REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[3]][0].first == Approx(0.80).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[3]][1].first == Approx(0.90).epsilon(1e-7)); // Neighbors of point 4. - BOOST_REQUIRE(sortedOutput[newFromOld[4]].size() == 0); + REQUIRE(sortedOutput[newFromOld[4]].size() == 0); // Neighbors of point 5. - BOOST_REQUIRE(sortedOutput[newFromOld[5]].size() == 0); + REQUIRE(sortedOutput[newFromOld[5]].size() == 0); // Neighbors of point 6. - BOOST_REQUIRE(sortedOutput[newFromOld[6]].size() == 0); + REQUIRE(sortedOutput[newFromOld[6]].size() == 0); // Neighbors of point 7. - BOOST_REQUIRE(sortedOutput[newFromOld[7]].size() == 0); + REQUIRE(sortedOutput[newFromOld[7]].size() == 0); // Neighbors of point 8. - BOOST_REQUIRE(sortedOutput[newFromOld[8]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][0].first, 0.80, 1e-5); + REQUIRE(sortedOutput[newFromOld[8]].size() == 1); + REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[8]][0].first == Approx(0.80).epsilon(1e-7)); // Neighbors of point 9. - BOOST_REQUIRE(sortedOutput[newFromOld[9]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][0].first, 0.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][1].first, 0.85, 1e-5); + REQUIRE(sortedOutput[newFromOld[9]].size() == 2); + REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[9]][0].first == Approx(0.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[9]][1].first == Approx(0.85).epsilon(1e-7)); // Neighbors of point 10. - BOOST_REQUIRE(sortedOutput[newFromOld[10]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][0].first, 0.85, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][1].first, 0.95, 1e-5); + REQUIRE(sortedOutput[newFromOld[10]].size() == 2); + REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.85).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.95).epsilon(1e-7)); // Now do it again with a different range: [1.0 inf]. if (rs->ReferenceTree()) @@ -286,161 +285,161 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) SortResults(neighbors, distances, sortedOutput); // Neighbors of point 0. - BOOST_REQUIRE(sortedOutput[newFromOld[0]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][0].first, 1.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][1].first, 1.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][2].first, 2.05, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][3].first, 5.00, 1e-5); + REQUIRE(sortedOutput[newFromOld[0]].size() == 4); + REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[0]][0].first == Approx(1.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[0]][1].first == Approx(1.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[0]][2].first == Approx(2.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[0]][3].first == Approx(5.00).epsilon(1e-7)); // Neighbors of point 1. - BOOST_REQUIRE(sortedOutput[newFromOld[1]].size() == 3); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][0].first, 1.65, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][1].first, 2.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][2].first, 4.70, 1e-5); + REQUIRE(sortedOutput[newFromOld[1]].size() == 3); + REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[1]][0].first == Approx(1.65).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[1]][1].first == Approx(2.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[1]][2].first == Approx(4.70).epsilon(1e-7)); // Neighbors of point 2. - BOOST_REQUIRE(sortedOutput[newFromOld[2]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][0].first, 1.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][1].first, 1.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][2].first, 2.15, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][3].first, 4.90, 1e-5); + REQUIRE(sortedOutput[newFromOld[2]].size() == 4); + REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[2]][0].first == Approx(1.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[2]][1].first == Approx(1.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[2]][2].first == Approx(2.15).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[2]][3].first == Approx(4.90).epsilon(1e-7)); // Neighbors of point 3. - BOOST_REQUIRE(sortedOutput[newFromOld[3]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][0].first, 1.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][1].first, 1.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][2].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][2].first, 1.47, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][3].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][3].first, 2.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][4].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][4].first, 3.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][5].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][5].first, 3.80, 1e-5); + REQUIRE(sortedOutput[newFromOld[3]].size() == 6); + REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[3]][0].first == Approx(1.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[3]][1].first == Approx(1.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][2].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[3]][2].first == Approx(1.47).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][3].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[3]][3].first == Approx(2.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][4].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[3]][4].first == Approx(3.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][5].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[3]][5].first == Approx(3.80).epsilon(1e-7)); // Neighbors of point 4. - BOOST_REQUIRE(sortedOutput[newFromOld[4]].size() == 10); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][0].first, 3.80, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][1].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][1].first, 4.05, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][2].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][2].first, 4.15, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][3].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][3].first, 4.60, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][4].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][4].first, 4.70, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][5].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][5].first, 4.90, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][6].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][6].first, 5.00, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][7].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][7].first, 5.27, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][8].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][8].first, 6.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][9].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][9].first, 7.05, 1e-5); + REQUIRE(sortedOutput[newFromOld[4]].size() == 10); + REQUIRE(sortedOutput[newFromOld[4]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[4]][0].first == Approx(3.80).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][1].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[4]][1].first == Approx(4.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][2].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[4]][2].first == Approx(4.15).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][3].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[4]][3].first == Approx(4.60).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][4].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[4]][4].first == Approx(4.70).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][5].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[4]][5].first == Approx(4.90).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][6].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[4]][6].first == Approx(5.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][7].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[4]][7].first == Approx(5.27).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][8].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[4]][8].first == Approx(6.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][9].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[4]][9].first == Approx(7.05).epsilon(1e-7)); // Neighbors of point 5. - BOOST_REQUIRE(sortedOutput[newFromOld[5]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][0].first, 1.08, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][1].first, 1.12, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][2].first, 1.22, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][3].first, 1.47, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][4].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][4].first, 1.78, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][5].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][5].first, 5.27, 1e-5); + REQUIRE(sortedOutput[newFromOld[5]].size() == 6); + REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[5]][0].first == Approx(1.08).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[5]][1].first == Approx(1.12).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[5]][2].first == Approx(1.22).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[5]][3].first == Approx(1.47).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][4].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[5]][4].first == Approx(1.78).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][5].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[5]][5].first == Approx(5.27).epsilon(1e-7)); // Neighbors of point 6. - BOOST_REQUIRE(sortedOutput[newFromOld[6]].size() == 9); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][0].first, 1.78, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][1].first, 2.05, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][2].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][2].first, 2.15, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][3].first, 2.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][4].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][4].first, 2.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][5].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][5].first, 2.90, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][6].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][6].first, 3.00, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][7].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][7].first, 3.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][8].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][8].first, 7.05, 1e-5); + REQUIRE(sortedOutput[newFromOld[6]].size() == 9); + REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[6]][0].first == Approx(1.78).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[6]][1].first == Approx(2.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][2].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[6]][2].first == Approx(2.15).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[6]][3].first == Approx(2.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][4].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[6]][4].first == Approx(2.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][5].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[6]][5].first == Approx(2.90).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][6].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[6]][6].first == Approx(3.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][7].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[6]][7].first == Approx(3.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][8].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[6]][8].first == Approx(7.05).epsilon(1e-7)); // Neighbors of point 7. - BOOST_REQUIRE(sortedOutput[newFromOld[7]].size() == 9); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][0].first, 1.08, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][1].first, 1.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][2].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][2].first, 1.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][3].first, 1.65, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][4].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][4].first, 1.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][5].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][5].first, 2.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][6].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][6].first, 2.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][7].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][7].first, 2.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][8].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][8].first, 6.35, 1e-5); + REQUIRE(sortedOutput[newFromOld[7]].size() == 9); + REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[7]][0].first == Approx(1.08).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[7]][1].first == Approx(1.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][2].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[7]][2].first == Approx(1.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[7]][3].first == Approx(1.65).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][4].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[7]][4].first == Approx(1.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][5].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[7]][5].first == Approx(2.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][6].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[7]][6].first == Approx(2.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][7].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[7]][7].first == Approx(2.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][8].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[7]][8].first == Approx(6.35).epsilon(1e-7)); // Neighbors of point 8. - BOOST_REQUIRE(sortedOutput[newFromOld[8]].size() == 3); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][0].first, 1.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][1].first, 2.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][2].first, 4.60, 1e-5); + REQUIRE(sortedOutput[newFromOld[8]].size() == 3); + REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[8]][0].first == Approx(1.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[8]][1].first == Approx(2.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[8]][2].first == Approx(4.60).epsilon(1e-7)); // Neighbors of point 9. - BOOST_REQUIRE(sortedOutput[newFromOld[9]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][0].first, 1.12, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][1].first, 2.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][2].first, 2.90, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][3].first, 4.15, 1e-5); + REQUIRE(sortedOutput[newFromOld[9]].size() == 4); + REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[9]][0].first == Approx(1.12).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[9]][1].first == Approx(2.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[9]][2].first == Approx(2.90).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[9]][3].first == Approx(4.15).epsilon(1e-7)); // Neighbors of point 10. - BOOST_REQUIRE(sortedOutput[newFromOld[10]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][0].first, 1.22, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][1].first, 2.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][2].first, 3.00, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][3].first, 4.05, 1e-5); + REQUIRE(sortedOutput[newFromOld[10]].size() == 4); + REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(1.22).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(2.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(3.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(4.05).epsilon(1e-7)); // Clean the memory. delete rs; @@ -455,13 +454,13 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) * * Errors are produced if the results are not identical. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) +TEST_CASE("DualTreeVsNaive1", "[RangeSearchTest]") { arma::mat dataForTree; // Hard-coded filename: bad! if (!data::Load("test_data_3_1000.csv", dataForTree)) - BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + FAIL("Cannot load test dataset test_data_3_1000.csv!"); // Set up matrices to work with. arma::mat dualQuery(dataForTree); @@ -487,13 +486,13 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) for (size_t i = 0; i < sortedTree.size(); ++i) { - BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); + REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); for (size_t j = 0; j < sortedTree[i].size(); ++j) { - BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, - 1e-5); + REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); + REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon + (1e-5)); } } } @@ -504,14 +503,14 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) * * Errors are produced if the results are not identical. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) +TEST_CASE("DualTreeVsNaive2", "[RangeSearchTest]") { arma::mat dataForTree; // Hard-coded filename: bad! // Code duplication: also bad! if (!data::Load("test_data_3_1000.csv", dataForTree)) - BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + FAIL("Cannot load test dataset test_data_3_1000.csv!"); // Set up matrices to work with. arma::mat dualQuery(dataForTree); @@ -536,13 +535,13 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) for (size_t i = 0; i < sortedTree.size(); ++i) { - BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); + REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); for (size_t j = 0; j < sortedTree[i].size(); ++j) { - BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, - 1e-5); + REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); + REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon + (1e-5)); } } } @@ -553,14 +552,14 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) * * Errors are produced if the results are not identical. */ -BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) +TEST_CASE("SingleTreeVsNaive", "[RangeSearchTest]") { arma::mat dataForTree; // Hard-coded filename: bad! // Code duplication: also bad! if (!data::Load("test_data_3_1000.csv", dataForTree)) - BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + FAIL("Cannot load test dataset test_data_3_1000.csv!"); // Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?). arma::mat singleQuery(dataForTree); @@ -585,13 +584,13 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) for (size_t i = 0; i < sortedTree.size(); ++i) { - BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); + REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); for (size_t j = 0; j < sortedTree[i].size(); ++j) { - BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, - 1e-5); + REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); + REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon + (1e-5)); } } } @@ -600,7 +599,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) * Ensure that dual tree range search with cover trees works by comparing * with the kd-tree implementation. */ -BOOST_AUTO_TEST_CASE(CoverTreeTest) +TEST_CASE("CoverTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -662,11 +661,11 @@ BOOST_AUTO_TEST_CASE(CoverTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, coverSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, coverSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), coverSorted[i].size()); + REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } } } @@ -675,7 +674,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeTest) * Ensure that dual tree range search with cover trees works when using * two datasets. */ -BOOST_AUTO_TEST_CASE(CoverTreeTwoDatasetsTest) +TEST_CASE("CoverTreeTwoDatasetsTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -740,11 +739,11 @@ BOOST_AUTO_TEST_CASE(CoverTreeTwoDatasetsTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, coverSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, coverSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), coverSorted[i].size()); + REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } } } @@ -752,7 +751,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeTwoDatasetsTest) /** * Ensure that single-tree cover tree range search works. */ -BOOST_AUTO_TEST_CASE(CoverTreeSingleTreeTest) +TEST_CASE("CoverTreeSingleTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -814,11 +813,11 @@ BOOST_AUTO_TEST_CASE(CoverTreeSingleTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, coverSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, coverSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), coverSorted[i].size()); + REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } } } @@ -826,7 +825,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeSingleTreeTest) /** * Ensure that single-tree ball tree range search works. */ -BOOST_AUTO_TEST_CASE(SingleBallTreeTest) +TEST_CASE("SingleBallTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -888,11 +887,11 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, ballSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, ballSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), ballSorted[i].size()); + REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } } } @@ -901,7 +900,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) * Ensure that dual tree range search with ball trees works by comparing * with the kd-tree implementation. */ -BOOST_AUTO_TEST_CASE(DualBallTreeTest) +TEST_CASE("DualBallTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -962,11 +961,11 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, ballSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, ballSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), ballSorted[i].size()); + REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } } } @@ -975,7 +974,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) * Ensure that dual tree range search with ball trees works when using * two datasets. */ -BOOST_AUTO_TEST_CASE(DualBallTreeTest2) +TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -1038,12 +1037,12 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest2) // Now compare the results. for (size_t i = 0; i < kdSorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), ballSorted[i].size()); + REQUIRE(kdSorted[i].size() == ballSorted[i].size()); for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, ballSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, ballSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1053,7 +1052,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest2) * Make sure that no results are returned when we build a range search object * with no reference set. */ -BOOST_AUTO_TEST_CASE(EmptySearchTest) +TEST_CASE("EmptySearchTest", "[RangeSearchTest]") { RangeSearch rs; @@ -1062,20 +1061,20 @@ BOOST_AUTO_TEST_CASE(EmptySearchTest) rs.Search(math::Range(0.0, 10.0), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), 0); - BOOST_REQUIRE_EQUAL(distances.size(), 0); + REQUIRE(neighbors.size() == 0); + REQUIRE(distances.size() == 0); // Now check with a query set. arma::mat querySet = arma::randu(3, 100); - BOOST_REQUIRE_THROW(rs.Search(querySet, math::Range(0.0, 10.0), neighbors, + REQUIRE_THROWS_AS(rs.Search(querySet, math::Range(0.0, 10.0), neighbors, distances), std::invalid_argument); } /** * Make sure things work right after Train() is called. */ -BOOST_AUTO_TEST_CASE(TrainTest) +TEST_CASE("TrainTest", "[RangeSearchTest]") { RangeSearch<> empty; @@ -1090,8 +1089,8 @@ BOOST_AUTO_TEST_CASE(TrainTest) empty.Search(math::Range(0.5, 0.7), neighbors, distances); baseline.Search(math::Range(0.5, 0.7), baselineNeighbors, baselineDistances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1101,11 +1100,11 @@ BOOST_AUTO_TEST_CASE(TrainTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), baselineSorted[i].size()); + REQUIRE(sorted[i].size() == baselineSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, baselineSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, baselineSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1113,7 +1112,7 @@ BOOST_AUTO_TEST_CASE(TrainTest) /** * Test training when a tree is given. */ -BOOST_AUTO_TEST_CASE(TrainTreeTest) +TEST_CASE("TrainTreeTest", "[RangeSearchTest]") { // Avoid mappings by using the cover tree. typedef RangeSearch RSType; @@ -1131,8 +1130,8 @@ BOOST_AUTO_TEST_CASE(TrainTreeTest) empty.Search(math::Range(0.5, 0.7), neighbors, distances); baseline.Search(math::Range(0.5, 0.7), baselineNeighbors, baselineDistances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1142,11 +1141,11 @@ BOOST_AUTO_TEST_CASE(TrainTreeTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), baselineSorted[i].size()); + REQUIRE(sorted[i].size() == baselineSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, baselineSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, baselineSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1154,20 +1153,20 @@ BOOST_AUTO_TEST_CASE(TrainTreeTest) /** * Test that training with a tree throws an exception when in naive mode. */ -BOOST_AUTO_TEST_CASE(NaiveTrainTreeTest) +TEST_CASE("NaiveTrainTreeTest", "[RangeSearchTest]") { RangeSearch<> empty(true); arma::mat dataset = arma::randu(5, 100); RangeSearch<>::Tree tree(dataset); - BOOST_REQUIRE_THROW(empty.Train(&tree), std::invalid_argument); + REQUIRE_THROWS_AS(empty.Train(&tree), std::invalid_argument); } /** * Test that the move constructor works. */ -BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) +TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(3, 100); arma::mat copy(dataset); @@ -1175,9 +1174,9 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) RangeSearch<> movers(std::move(copy)); RangeSearch<> rs(dataset); - BOOST_REQUIRE_EQUAL(copy.n_elem, 0); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_rows, 3); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_cols, 100); + REQUIRE(copy.n_elem == 0); + REQUIRE(movers.ReferenceSet().n_rows == 3); + REQUIRE(movers.ReferenceSet().n_cols == 100); vector> moveNeighbors, neighbors; vector> moveDistances, distances; @@ -1185,8 +1184,8 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) movers.Search(math::Range(0.5, 0.7), moveNeighbors, moveDistances); rs.Search(math::Range(0.5, 0.7), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), moveNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), moveDistances.size()); + REQUIRE(neighbors.size() == moveNeighbors.size()); + REQUIRE(distances.size() == moveDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1196,11 +1195,11 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), moveSorted[i].size()); + REQUIRE(sorted[i].size() == moveSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, moveSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, moveSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == moveSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1208,7 +1207,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) /** * Test that the std::move() Train() function works. */ -BOOST_AUTO_TEST_CASE(MoveTrainTest) +TEST_CASE("MoveTrainTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(3, 100); arma::mat copy(dataset); @@ -1217,9 +1216,9 @@ BOOST_AUTO_TEST_CASE(MoveTrainTest) movers.Train(std::move(copy)); RangeSearch<> rs(dataset); - BOOST_REQUIRE_EQUAL(copy.n_elem, 0); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_rows, 3); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_cols, 100); + REQUIRE(copy.n_elem == 0); + REQUIRE(movers.ReferenceSet().n_rows == 3); + REQUIRE(movers.ReferenceSet().n_cols == 100); vector> moveNeighbors, neighbors; vector> moveDistances, distances; @@ -1227,8 +1226,8 @@ BOOST_AUTO_TEST_CASE(MoveTrainTest) movers.Search(math::Range(0.5, 0.7), moveNeighbors, moveDistances); rs.Search(math::Range(0.5, 0.7), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), moveNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), moveDistances.size()); + REQUIRE(neighbors.size() == moveNeighbors.size()); + REQUIRE(distances.size() == moveDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1238,16 +1237,16 @@ BOOST_AUTO_TEST_CASE(MoveTrainTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), moveSorted[i].size()); + REQUIRE(sorted[i].size() == moveSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, moveSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, moveSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == moveSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } -BOOST_AUTO_TEST_CASE(RSModelTest) +TEST_CASE("RSModelTest", "[RangeSearchTest]") { // Ensure that we can build an RSModel and get correct results. arma::mat queryData = arma::randu(10, 50); @@ -1314,27 +1313,27 @@ BOOST_AUTO_TEST_CASE(RSModelTest) models[i].Search(std::move(queryCopy), math::Range(0.25, 0.75), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); vector>> sorted; SortResults(neighbors, distances, sorted); for (size_t k = 0; k < sorted.size(); ++k) { - BOOST_REQUIRE_EQUAL(sorted[k].size(), baselineSorted[k].size()); + REQUIRE(sorted[k].size() == baselineSorted[k].size()); for (size_t l = 0; l < sorted[k].size(); ++l) { - BOOST_REQUIRE_EQUAL(sorted[k][l].second, baselineSorted[k][l].second); - BOOST_REQUIRE_CLOSE(sorted[k][l].first, baselineSorted[k][l].first, - 1e-5); + REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon + (1e-7)); } } } } } -BOOST_AUTO_TEST_CASE(RSModelMonochromaticTest) +TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") { // Ensure that we can build an RSModel and get correct results. arma::mat referenceData = arma::randu(10, 200); @@ -1397,20 +1396,20 @@ BOOST_AUTO_TEST_CASE(RSModelMonochromaticTest) models[i].Search(math::Range(0.25, 0.5), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); vector>> sorted; SortResults(neighbors, distances, sorted); for (size_t k = 0; k < sorted.size(); ++k) { - BOOST_REQUIRE_EQUAL(sorted[k].size(), baselineSorted[k].size()); + REQUIRE(sorted[k].size() == baselineSorted[k].size()); for (size_t l = 0; l < sorted[k].size(); ++l) { - BOOST_REQUIRE_EQUAL(sorted[k][l].second, baselineSorted[k][l].second); - BOOST_REQUIRE_CLOSE(sorted[k][l].first, baselineSorted[k][l].first, - 1e-5); + REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon + (1e-7)); } } } @@ -1421,7 +1420,7 @@ BOOST_AUTO_TEST_CASE(RSModelMonochromaticTest) * Make sure that the neighborPtr matrix isn't accidentally deleted. * See issue #478. */ -BOOST_AUTO_TEST_CASE(NeighborPtrDeleteTest) +TEST_CASE("NeighborPtrDeleteTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 100); @@ -1438,14 +1437,14 @@ BOOST_AUTO_TEST_CASE(NeighborPtrDeleteTest) // These will (hopefully) fail is either the neighbors or the distances matrix // has been accidentally deleted. - BOOST_REQUIRE_EQUAL(neighbors.size(), 50); - BOOST_REQUIRE_EQUAL(distances.size(), 50); + REQUIRE(neighbors.size() == 50); + REQUIRE(distances.size() == 50); } /** * Test copy constructor and copy operator. */ -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) +TEST_CASE("CopyConstructorAndOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<> rs(std::move(dataset)); @@ -1463,26 +1462,26 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) rs3.Search(math::Range(0.2, 0.3), neighbors3, distances3); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(distances.size(), distances3.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors3.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(distances.size() == distances3.size()); + REQUIRE(neighbors.size() == neighbors2.size()); + REQUIRE(neighbors.size() == neighbors3.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(distances[i].size(), distances3[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors3[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(distances[i].size() == distances3[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); + REQUIRE(neighbors[i].size() == neighbors3[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors3[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors3[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); - BOOST_REQUIRE_CLOSE(distances[i][j], distances3[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); + REQUIRE(distances[i][j] == Approx(distances3[i][j]).epsilon(1e-7)); } } } @@ -1490,7 +1489,7 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) /** * Test move constructor. */ -BOOST_AUTO_TEST_CASE(MoveConstructorTest) +TEST_CASE("MoveConstructorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); @@ -1508,20 +1507,20 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } @@ -1529,7 +1528,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) /** * Test move operator. */ -BOOST_AUTO_TEST_CASE(MoveOperatorTest) +TEST_CASE("MoveOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); @@ -1547,20 +1546,20 @@ BOOST_AUTO_TEST_CASE(MoveOperatorTest) rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } @@ -1569,7 +1568,7 @@ BOOST_AUTO_TEST_CASE(MoveOperatorTest) * Test copy constructor and copy operator in naive mode (so there are no * trees). */ -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) +TEST_CASE("CopyConstructorAndOperatorNaiveTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<> rs(std::move(dataset), true); @@ -1578,8 +1577,8 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) RangeSearch<> rs2(rs); RangeSearch<> rs3 = rs; - BOOST_REQUIRE_EQUAL(rs2.Naive(), true); - BOOST_REQUIRE_EQUAL(rs3.Naive(), true); + REQUIRE(rs2.Naive() == true); + REQUIRE(rs3.Naive() == true); // Get results. vector> distances, distances2, distances3; @@ -1590,26 +1589,26 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) rs3.Search(math::Range(0.2, 0.3), neighbors3, distances3); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(distances.size(), distances3.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors3.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(distances.size() == distances3.size()); + REQUIRE(neighbors.size() == neighbors2.size()); + REQUIRE(neighbors.size() == neighbors3.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(distances[i].size(), distances3[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors3[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(distances[i].size() == distances3[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); + REQUIRE(neighbors[i].size() == neighbors3[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors3[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors3[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); - BOOST_REQUIRE_CLOSE(distances[i][j], distances3[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); + REQUIRE(distances[i][j] == Approx(distances3[i][j]).epsilon(1e-7)); } } } @@ -1617,7 +1616,7 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) /** * Test move constructor. */ -BOOST_AUTO_TEST_CASE(MoveConstructorNaiveTest) +TEST_CASE("MoveConstructorNaiveTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset), true); @@ -1630,27 +1629,27 @@ BOOST_AUTO_TEST_CASE(MoveConstructorNaiveTest) RangeSearch<> rs2(std::move(*rs)); - BOOST_REQUIRE_EQUAL(rs2.Naive(), true); + REQUIRE(rs2.Naive() == true); delete rs; rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } @@ -1658,7 +1657,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorNaiveTest) /** * Test move operator. */ -BOOST_AUTO_TEST_CASE(MoveOperatorNaiveTest) +TEST_CASE("MoveOperatorNaiveTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset), true); @@ -1671,29 +1670,27 @@ BOOST_AUTO_TEST_CASE(MoveOperatorNaiveTest) RangeSearch<> rs2 = std::move(*rs); - BOOST_REQUIRE_EQUAL(rs2.Naive(), true); + REQUIRE(rs2.Naive() == true); delete rs; rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } - -BOOST_AUTO_TEST_SUITE_END(); From b54e84f8d0a9bf40d5704334b245160961d74fe6 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Thu, 1 Oct 2020 22:43:43 +0530 Subject: [PATCH 09/45] main_tests/range_search_test to catch2 --- .../tests/main_tests/range_search_test.cpp | 101 ++++++++++-------- .../tests/main_tests/range_search_utils.hpp | 14 +-- 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/mlpack/tests/main_tests/range_search_test.cpp b/src/mlpack/tests/main_tests/range_search_test.cpp index 8102aae4e9..552ff4eba4 100644 --- a/src/mlpack/tests/main_tests/range_search_test.cpp +++ b/src/mlpack/tests/main_tests/range_search_test.cpp @@ -17,7 +17,7 @@ static const std::string testName = "RangeSearchMain"; #include "test_helper.hpp" #include #include "range_search_utils.hpp" -#include +#include "../catch.hpp" using namespace mlpack; @@ -37,34 +37,35 @@ struct RangeSearchTestFixture } }; -BOOST_FIXTURE_TEST_SUITE(RangeSearchMainTest, RangeSearchTestFixture); - /** * Check that we have to specify a reference set or input model. */ -BOOST_AUTO_TEST_CASE(RangeSearchNoReference) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchNoReference", + "[RangeSearchMainTest][BindingTests]" { Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; } /** * Check that we cannot pass an incorrect parameter. */ -BOOST_AUTO_TEST_CASE(RangeSearchWrongParameter) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchWrongParameter", + "[RangeSearchMainTest][BindingTests]" { string wrongString = "abc"; Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(SetInputParam("RST", wrongString), std::runtime_error); + REQUIRE_THROWS_AS(SetInputParam("RST", wrongString), std::runtime_error); Log::Fatal.ignoreInput = false; } /** * Check that we have to specify a query if an input model is specified. */ -BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchInputModelNoQuery", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -72,7 +73,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) string neighborsFile = "neighbors.csv"; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -86,7 +87,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) SetInputParam("input_model", move(IO::GetParam("output_model"))); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; remove(neighborsFile.c_str()); @@ -96,7 +97,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) /** * Check that we cannot specify a tree type which is not available or wrong. */ -BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchDifferentTree", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -104,7 +106,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) string neighborsFile = "neighbors.csv"; string wrongTreeType = "RST"; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -114,7 +116,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) SetInputParam("tree_type", wrongTreeType); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; remove(neighborsFile.c_str()); @@ -124,7 +126,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) /** * Check that we cannot specify both a reference set and input model. */ -BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchBothReferenceAndModel", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -132,9 +135,9 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) string neighborsFile = "neighbors.csv"; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -149,7 +152,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) SetInputParam("query", move(queryData)); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; remove(neighborsFile.c_str()); @@ -161,7 +164,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) * by comparing with pre-calculated neighbor and distance values, when no query * set is specified. */ -BOOST_AUTO_TEST_CASE(RangeSearchTest) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchTest", + "[RangeSearchMainTest][BindingTests]" { arma::mat x = {{0, 3, 3, 4, 3, 1}, {4, 4, 4, 5, 5, 2}, @@ -208,7 +212,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchTest) * Check that the correct output is returned for a small synthetic input case, * when a query set is provided. */ -BOOST_AUTO_TEST_CASE(RangeSeachTestwithQuery) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSeachTestwithQuery", + "[RangeSearchMainTest][BindingTests]" { arma::mat queryData = {{5, 3, 1}, {4, 2, 4}, {3, 1, 7}}; arma::mat x = {{0, 3, 3, 4, 3, 1}, @@ -252,7 +257,8 @@ BOOST_AUTO_TEST_CASE(RangeSeachTestwithQuery) * Train a model using a synthetic dataset and then output the model, and ensure * it can be used again. */ -BOOST_AUTO_TEST_CASE(ModelCheck) +TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -262,9 +268,9 @@ BOOST_AUTO_TEST_CASE(ModelCheck) vector> distances, distancetemp; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -292,7 +298,7 @@ BOOST_AUTO_TEST_CASE(ModelCheck) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancetemp); - BOOST_REQUIRE_EQUAL(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) == ModelToString(IO::GetParam("output_model"))); remove(neighborsFile.c_str()); @@ -303,11 +309,12 @@ BOOST_AUTO_TEST_CASE(ModelCheck) * Check that the models are different but the results are the same for three * different leaf size parameters. */ -BOOST_AUTO_TEST_CASE(LeafValueTesting) +TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -349,7 +356,7 @@ BOOST_AUTO_TEST_CASE(LeafValueTesting) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel1), + REQUIRE(ModelToString(outputModel1) != ModelToString(IO::GetParam("output_model"))); if (i != leafSizes.size() - 1) @@ -367,7 +374,8 @@ BOOST_AUTO_TEST_CASE(LeafValueTesting) * different tree types. We use the default kd-tree as the base model to * compare against. */ -BOOST_AUTO_TEST_CASE(TreeTypeTesting) +TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -381,9 +389,9 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) "max-rp", "ub", "oct"}; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); // Define base parameters with the kd-tree. SetInputParam("tree_type", trees[0]); @@ -403,9 +411,9 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) for (size_t i = 1; i < trees.size(); ++i) { if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -422,7 +430,7 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel1), + REQUIRE(ModelToString(outputModel1) != ModelToString(IO::GetParam("output_model"))); if (i != trees.size() - 1) @@ -439,7 +447,8 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) * Project the data onto a random basis and ensure that this gives identical * results to non-projected data but different models. */ -BOOST_AUTO_TEST_CASE(RandomBasisTesting) +TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -447,9 +456,9 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting) arma::mat queryData, inputData; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -470,7 +479,7 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting) mlpackMain(); - BOOST_REQUIRE_NE(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) != ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -482,7 +491,8 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting) /** * Ensure that naive mode gives the same result, but different models. */ -BOOST_AUTO_TEST_CASE(NaiveModeTest) +TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -493,9 +503,9 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest) vector> distances, distancestemp; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -524,7 +534,7 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) != ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -536,7 +546,8 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest) /** * Ensure that single-tree mode gives the same result but different models. */ -BOOST_AUTO_TEST_CASE(SingleModeTest) +TEST_CASE_METHOD(RangeSearchTestFixture, "SingleModeTest", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -547,9 +558,9 @@ BOOST_AUTO_TEST_CASE(SingleModeTest) vector> distances, distancestemp; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -577,7 +588,7 @@ BOOST_AUTO_TEST_CASE(SingleModeTest) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) != ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -585,5 +596,3 @@ BOOST_AUTO_TEST_CASE(SingleModeTest) remove(neighborsFile.c_str()); remove(distanceFile.c_str()); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/range_search_utils.hpp b/src/mlpack/tests/main_tests/range_search_utils.hpp index 8f1385eafb..f628b741ff 100644 --- a/src/mlpack/tests/main_tests/range_search_utils.hpp +++ b/src/mlpack/tests/main_tests/range_search_utils.hpp @@ -12,10 +12,10 @@ #ifndef MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP #define MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP -#include #include #include #include +#include "../catch.hpp" /** * Convert a model to a string using the text_oarchive of boost::serialization. @@ -42,15 +42,15 @@ inline void CheckMatrices(std::vector>& vec1, std::vector>& vec2, const double tolerance = 1e-3) { - BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); + REQUIRE(vec1.size() == vec2.size()); for (size_t i = 0; i < vec1.size(); ++i) { - BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); + REQUIRE(vec1[i].size() == vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); for (size_t j = 0 ; j < vec1[i].size(); ++j) { - BOOST_REQUIRE_CLOSE(vec1[i][j], vec2[i][j], tolerance); + REQUIRE(vec1[i][j] == Approx(vec2[i][j]).epsilon(tolerance)); } } } @@ -64,15 +64,15 @@ inline void CheckMatrices(std::vector>& vec1, inline void CheckMatrices(std::vector>& vec1, std::vector>& vec2) { - BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); + REQUIRE(vec1.size() == vec2.size()); for (size_t i = 0; i < vec1.size(); ++i) { - BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); + REQUIRE(vec1[i].size() == vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); for (size_t j = 0; j < vec1[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(vec1[i][j], vec2[i][j]); + REQUIRE(vec1[i][j] == vec2[i][j]); } } } From 256aabf6c3ced749952e37c5c2090c0f5b9b64b4 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Thu, 1 Oct 2020 23:15:52 +0530 Subject: [PATCH 10/45] errors fixed --- .../tests/main_tests/range_search_test.cpp | 26 +++++++++---------- src/mlpack/tests/range_search_test.cpp | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mlpack/tests/main_tests/range_search_test.cpp b/src/mlpack/tests/main_tests/range_search_test.cpp index 552ff4eba4..b32478da23 100644 --- a/src/mlpack/tests/main_tests/range_search_test.cpp +++ b/src/mlpack/tests/main_tests/range_search_test.cpp @@ -41,7 +41,7 @@ struct RangeSearchTestFixture * Check that we have to specify a reference set or input model. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchNoReference", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { Log::Fatal.ignoreInput = true; REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); @@ -52,7 +52,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchNoReference", * Check that we cannot pass an incorrect parameter. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchWrongParameter", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string wrongString = "abc"; @@ -65,7 +65,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchWrongParameter", * Check that we have to specify a query if an input model is specified. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchInputModelNoQuery", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -98,7 +98,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchInputModelNoQuery", * Check that we cannot specify a tree type which is not available or wrong. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchDifferentTree", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -127,7 +127,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchDifferentTree", * Check that we cannot specify both a reference set and input model. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchBothReferenceAndModel", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -165,7 +165,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchBothReferenceAndModel", * set is specified. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchTest", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat x = {{0, 3, 3, 4, 3, 1}, {4, 4, 4, 5, 5, 2}, @@ -213,7 +213,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchTest", * when a query set is provided. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSeachTestwithQuery", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat queryData = {{5, 3, 1}, {4, 2, 4}, {3, 1, 7}}; arma::mat x = {{0, 3, 3, 4, 3, 1}, @@ -258,7 +258,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSeachTestwithQuery", * it can be used again. */ TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -310,7 +310,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", * different leaf size parameters. */ TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData; if (!data::Load("iris.csv", inputData)) @@ -375,7 +375,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", * compare against. */ TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -448,7 +448,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", * results to non-projected data but different models. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -492,7 +492,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", * Ensure that naive mode gives the same result, but different models. */ TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -547,7 +547,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", * Ensure that single-tree mode gives the same result but different models. */ TEST_CASE_METHOD(RangeSearchTestFixture, "SingleModeTest", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index b9e3f47c1c..2f40600405 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1074,7 +1074,7 @@ TEST_CASE("EmptySearchTest", "[RangeSearchTest]") /** * Make sure things work right after Train() is called. */ -TEST_CASE("TrainTest", "[RangeSearchTest]") +TEST_CASE("RangeTrainTest", "[RangeSearchTest]") { RangeSearch<> empty; From 0787f348d3f212a341246f3cc8a10d3e390f1d41 Mon Sep 17 00:00:00 2001 From: Anush V Kini Date: Fri, 2 Oct 2020 00:15:56 +0530 Subject: [PATCH 11/45] Moved metric test from Boost to Catch2Migration --- src/mlpack/tests/CMakeLists.txt | 2 +- src/mlpack/tests/metric_test.cpp | 108 +++++++++++++++---------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index f4fff0dd8f..68fc2de828 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -37,7 +37,6 @@ add_executable(mlpack_test matrix_completion_test.cpp maximal_inputs_test.cpp mean_shift_test.cpp - metric_test.cpp mlpack_test.cpp mock_categorical_data.hpp nbc_test.cpp @@ -137,6 +136,7 @@ add_executable(mlpack_catch_test load_save_test.cpp loss_functions_test.cpp main.cpp + metric_test.cpp nca_test.cpp one_hot_encoding_test.cpp pca_test.cpp diff --git a/src/mlpack/tests/metric_test.cpp b/src/mlpack/tests/metric_test.cpp index dffe3211fc..e758a7e16c 100644 --- a/src/mlpack/tests/metric_test.cpp +++ b/src/mlpack/tests/metric_test.cpp @@ -10,21 +10,19 @@ */ #include #include -#include +#include "catch.hpp" #include #include #include -#include "test_tools.hpp" +#include "test_catch_tools.hpp" using namespace std; using namespace mlpack::metric; -BOOST_AUTO_TEST_SUITE(MetricTest); - /** * Simple test for L-1 metric. */ -BOOST_AUTO_TEST_CASE(L1MetricTest) +TEST_CASE("L1MetricTest", "[MetricTest]") { arma::vec a1(5); a1.randn(); @@ -40,17 +38,17 @@ BOOST_AUTO_TEST_CASE(L1MetricTest) ManhattanDistance lMetric; - BOOST_REQUIRE_CLOSE((double) arma::accu(arma::abs(a1 - b1)), - lMetric.Evaluate(a1, b1), 1e-5); + REQUIRE((double) arma::accu(arma::abs(a1 - b1)) == + Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE((double) arma::accu(arma::abs(a2 - b2)), - lMetric.Evaluate(a2, b2), 1e-5); + REQUIRE((double) arma::accu(arma::abs(a2 - b2)) == + Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); } /** * Simple test for L-2 metric. */ -BOOST_AUTO_TEST_CASE(L2MetricTest) +TEST_CASE("L2MetricTest", "[MetricTest]") { arma::vec a1(5); a1.randn(); @@ -66,17 +64,17 @@ BOOST_AUTO_TEST_CASE(L2MetricTest) EuclideanDistance lMetric; - BOOST_REQUIRE_CLOSE((double) sqrt(arma::accu(arma::square(a1 - b1))), - lMetric.Evaluate(a1, b1), 1e-5); + REQUIRE((double) sqrt(arma::accu(arma::square(a1 - b1))) == + Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE((double) sqrt(arma::accu(arma::square(a2 - b2))), - lMetric.Evaluate(a2, b2), 1e-5); + REQUIRE((double) sqrt(arma::accu(arma::square(a2 - b2))) == + Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); } /** * Simple test for L-Infinity metric. */ -BOOST_AUTO_TEST_CASE(LINFMetricTest) +TEST_CASE("LINFMetricTest", "[MetricTest]") { arma::vec a1(5); a1.randn(); @@ -92,50 +90,54 @@ BOOST_AUTO_TEST_CASE(LINFMetricTest) ChebyshevDistance lMetric; - BOOST_REQUIRE_CLOSE((double) arma::as_scalar(arma::max(arma::abs(a1 - b1))), - lMetric.Evaluate(a1, b1), 1e-5); + REQUIRE((double) arma::as_scalar(arma::max(arma::abs(a1 - b1))) == + Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE((double) arma::as_scalar(arma::max(arma::abs(a2 - b2))), - lMetric.Evaluate(a2, b2), 1e-5); + REQUIRE((double) arma::as_scalar(arma::max(arma::abs(a2 - b2))) == + Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); } /** * Simple test for IoU metric. */ -BOOST_AUTO_TEST_CASE(IoUMetricTest) +TEST_CASE("IoUMetricTest", "[MetricTest]") { arma::vec bbox1(4), bbox2(4); bbox1 << 1 << 2 << 100 << 200; bbox2 << 1 << 2 << 100 << 200; // IoU of same bounding boxes equals 1.0. - BOOST_REQUIRE_CLOSE(1.0, IoU<>::Evaluate(bbox1, bbox2), 1e-4); + REQUIRE(1.0 == Approx(IoU<>::Evaluate(bbox1, bbox2)).epsilon(1e-6)); // Use coordinate system to represent bounding boxes. // Bounding boxes represent {x0, y0, x1, y1}. bbox1 << 39 << 63 << 203 << 112; bbox2 << 54 << 66 << 198 << 114; // Value calculated using Python interpreter. - BOOST_REQUIRE_CLOSE(IoU::Evaluate(bbox1, bbox2), 0.7980093, 1e-4); + REQUIRE(IoU::Evaluate(bbox1, bbox2) == + Approx(0.7980093).epsilon(1e-6)); bbox1 << 31 << 69 << 201 << 125; bbox2 << 18 << 63 << 235 << 135; // Value calculated using Python interpreter. - BOOST_REQUIRE_CLOSE(IoU::Evaluate(bbox1, bbox2), 0.612479577, 1e-4); + REQUIRE(IoU::Evaluate(bbox1, bbox2) == + Approx(0.612479577).epsilon(1e-6)); // Use hieght - width representation of bounding boxes. // Bounding boxes represent {x0, y0, h, w}. bbox1 << 49 << 75 << 154 << 50; bbox2 << 42 << 78 << 144 << 48; // Value calculated using Python interpreter. - BOOST_REQUIRE_CLOSE(IoU<>::Evaluate(bbox1, bbox2), 0.7898879, 1e-4); + REQUIRE(IoU<>::Evaluate(bbox1, bbox2) == + Approx(0.7898879).epsilon(1e-6)); bbox1 << 35 << 51 << 161 << 59; bbox2 << 36 << 60 << 144 << 48; // Value calculated using Python interpreter. - BOOST_REQUIRE_CLOSE(IoU<>::Evaluate(bbox1, bbox2), 0.7309670, 1e-4); + REQUIRE(IoU<>::Evaluate(bbox1, bbox2) == + Approx(0.7309670).epsilon(1e-6)); } -BOOST_AUTO_TEST_CASE(NMSMetricTest) +TEST_CASE("NMSMetricTest", "[MetricTest]") { arma::mat bbox, selectedBoundingBox, desiredBoundingBox; arma::vec bbox1(4), bbox2(4), bbox3(4); @@ -172,13 +174,13 @@ BOOST_AUTO_TEST_CASE(NMSMetricTest) selectedBoundingBox = bbox.cols(selectedIndices); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_cols, 2); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_rows, 4); + REQUIRE(selectedBoundingBox.n_cols == 2); + REQUIRE(selectedBoundingBox.n_rows == 4); CheckMatrices(desiredBoundingBox, selectedBoundingBox); for (size_t i = 0; i < desiredIndices.n_elem; i++) { - BOOST_REQUIRE_EQUAL(desiredIndices[i], selectedIndices[i]); + REQUIRE(desiredIndices[i] == selectedIndices[i]); } // Clean up. @@ -201,8 +203,8 @@ BOOST_AUTO_TEST_CASE(NMSMetricTest) selectedBoundingBox = bbox.cols(selectedIndices); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_cols, 2); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_rows, 4); + REQUIRE(selectedBoundingBox.n_cols == 2); + REQUIRE(selectedBoundingBox.n_rows == 4); CheckMatrices(desiredBoundingBox, selectedBoundingBox); // Clean up. @@ -233,8 +235,8 @@ BOOST_AUTO_TEST_CASE(NMSMetricTest) selectedBoundingBox = bbox.cols(selectedIndices); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_cols, 2); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_rows, 4); + REQUIRE(selectedBoundingBox.n_cols == 2); + REQUIRE(selectedBoundingBox.n_rows == 4); CheckMatrices(desiredBoundingBox, selectedBoundingBox); // Clean up. @@ -266,8 +268,8 @@ BOOST_AUTO_TEST_CASE(NMSMetricTest) selectedIndices); selectedBoundingBox = bbox.cols(selectedIndices); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_cols, 2); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_rows, 4); + REQUIRE(selectedBoundingBox.n_cols == 2); + REQUIRE(selectedBoundingBox.n_rows == 4); CheckMatrices(desiredBoundingBox, selectedBoundingBox); // Clean up. @@ -297,15 +299,15 @@ BOOST_AUTO_TEST_CASE(NMSMetricTest) selectedIndices, 0.7); selectedBoundingBox = bbox.cols(selectedIndices); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_cols, 2); - BOOST_REQUIRE_EQUAL(selectedBoundingBox.n_rows, 4); + REQUIRE(selectedBoundingBox.n_cols == 2); + REQUIRE(selectedBoundingBox.n_rows == 4); CheckMatrices(desiredBoundingBox, selectedBoundingBox); } /** * */ -BOOST_AUTO_TEST_CASE(BLEUScoreTest) +TEST_CASE("BLEUScoreTest", "[MetricTest]") { typedef typename std::vector WordVector; std::vector> referenceCorpus @@ -330,34 +332,32 @@ BOOST_AUTO_TEST_CASE(BLEUScoreTest) //! We are not using smoothing function here. bleu.Evaluate(referenceCorpus, translationCorpus); - BOOST_REQUIRE_CLOSE_FRACTION(bleu.BLEUScore(), 0.0, 1e-05); - BOOST_REQUIRE_EQUAL(bleu.BrevityPenalty(), 1.0); - BOOST_REQUIRE_EQUAL(bleu.Ratio(), 1.0); - BOOST_REQUIRE_EQUAL(bleu.TranslationLength(), 12); - BOOST_REQUIRE_EQUAL(bleu.ReferenceLength(), 12); + REQUIRE(bleu.BLEUScore() == Approx(0.0).epsilon(1e-7)); + REQUIRE(bleu.BrevityPenalty() == 1.0); + REQUIRE(bleu.Ratio() == 1.0); + REQUIRE(bleu.TranslationLength() == 12); + REQUIRE(bleu.ReferenceLength() == 12); std::vector expectedPrecision = {0.666666f, 0.5555555f, 0.3333333f, 0.0f}; for (size_t i = 0; i < bleu.Precisions().size(); ++i) { - BOOST_REQUIRE_CLOSE_FRACTION(bleu.Precisions()[i], - expectedPrecision[i], 1e-04); + REQUIRE(bleu.Precisions()[i] == + Approx((double)expectedPrecision[i]).epsilon(1e-4)); } //! We will use smoothing function here by setting smooth to true. bleu.Evaluate(referenceCorpus, translationCorpus, true); - BOOST_REQUIRE_CLOSE_FRACTION(bleu.BLEUScore(), 0.459307, 1e-05); - BOOST_REQUIRE_EQUAL(bleu.BrevityPenalty(), 1.0); - BOOST_REQUIRE_EQUAL(bleu.Ratio(), 1.0); - BOOST_REQUIRE_EQUAL(bleu.TranslationLength(), 12); - BOOST_REQUIRE_EQUAL(bleu.ReferenceLength(), 12); + REQUIRE(bleu.BLEUScore() == Approx(0.459307).epsilon(1e-3)); + REQUIRE(bleu.BrevityPenalty() == 1.0); + REQUIRE(bleu.Ratio() == 1.0); + REQUIRE(bleu.TranslationLength() == 12); + REQUIRE(bleu.ReferenceLength() == 12); expectedPrecision = {0.692308f, 0.6f, 0.428571f, 0.25f}; for (size_t i = 0; i < bleu.Precisions().size(); ++i) { - BOOST_REQUIRE_CLOSE_FRACTION(bleu.Precisions()[i], - expectedPrecision[i], 1e-04); + REQUIRE(bleu.Precisions()[i] == + Approx(expectedPrecision[i]).epsilon(1e-5)); } } - -BOOST_AUTO_TEST_SUITE_END(); From dccc1fa61a647d461f88aa0dbd753ce57c144910 Mon Sep 17 00:00:00 2001 From: Anush V Kini Date: Fri, 2 Oct 2020 10:16:29 +0530 Subject: [PATCH 12/45] Style Fixes --- src/mlpack/tests/metric_test.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/metric_test.cpp b/src/mlpack/tests/metric_test.cpp index e758a7e16c..d3db1a71c1 100644 --- a/src/mlpack/tests/metric_test.cpp +++ b/src/mlpack/tests/metric_test.cpp @@ -127,14 +127,12 @@ TEST_CASE("IoUMetricTest", "[MetricTest]") bbox1 << 49 << 75 << 154 << 50; bbox2 << 42 << 78 << 144 << 48; // Value calculated using Python interpreter. - REQUIRE(IoU<>::Evaluate(bbox1, bbox2) == - Approx(0.7898879).epsilon(1e-6)); + REQUIRE(IoU<>::Evaluate(bbox1, bbox2) == Approx(0.7898879).epsilon(1e-6)); bbox1 << 35 << 51 << 161 << 59; bbox2 << 36 << 60 << 144 << 48; // Value calculated using Python interpreter. - REQUIRE(IoU<>::Evaluate(bbox1, bbox2) == - Approx(0.7309670).epsilon(1e-6)); + REQUIRE(IoU<>::Evaluate(bbox1, bbox2) == Approx(0.7309670).epsilon(1e-6)); } TEST_CASE("NMSMetricTest", "[MetricTest]") From 9604b272d0fbb081b4c10d30dba51d83cc038c2e Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Sat, 3 Oct 2020 11:01:54 +0530 Subject: [PATCH 13/45] Migrate Augmentated_rnn and Async_Learning Test to catch2 --- src/mlpack/tests/CMakeLists.txt | 5 ++--- src/mlpack/tests/async_learning_test.cpp | 18 +++++++--------- .../tests/augmented_rnns_tasks_test.cpp | 21 +++++++------------ 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index bf68f3c64b..1dddf2577c 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -1,7 +1,5 @@ # mlpack test executable. add_executable(mlpack_test - async_learning_test.cpp - augmented_rnns_tasks_test.cpp callback_test.cpp cf_test.cpp cli_binding_test.cpp @@ -112,6 +110,8 @@ add_executable(mlpack_catch_test ann_visitor_test.cpp armadillo_svd_test.cpp arma_extend_test.cpp + async_learning_test.cpp + augmented_rnns_tasks_test.cpp bayesian_linear_regression_test.cpp bias_svd_test.cpp binarize_test.cpp @@ -227,7 +227,6 @@ add_custom_command(TARGET mlpack_test # The list of long running parallel tests set(parallel_tests - "AsyncLearningTest;" "LocalCoordinateCodingTest;" "GMMTest;" "CFTest;" diff --git a/src/mlpack/tests/async_learning_test.cpp b/src/mlpack/tests/async_learning_test.cpp index e3acc87add..4e8f03e9e3 100644 --- a/src/mlpack/tests/async_learning_test.cpp +++ b/src/mlpack/tests/async_learning_test.cpp @@ -24,17 +24,15 @@ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" using namespace mlpack; using namespace mlpack::ann; using namespace mlpack::rl; -BOOST_AUTO_TEST_SUITE(AsyncLearningTest); // Test async one step q-learning in Cart Pole. -BOOST_AUTO_TEST_CASE(OneStepQLearningTest) +TEST_CASE("OneStepQLearningTest", "[AsyncLearningTest]") { /** * This is for the Travis CI server, in your own machine you should use more @@ -106,11 +104,11 @@ BOOST_AUTO_TEST_CASE(OneStepQLearningTest) } } - BOOST_REQUIRE_EQUAL(success, true); + REQUIRE(success == true); } // Test async one step Sarsa in Cart Pole. -BOOST_AUTO_TEST_CASE(OneStepSarsaTest) +TEST_CASE("OneStepSarsaTest", "[AsyncLearningTest]") { /** * This is for the Travis CI server, in your own machine you shuold use more @@ -184,11 +182,11 @@ BOOST_AUTO_TEST_CASE(OneStepSarsaTest) } } - BOOST_REQUIRE_EQUAL(success, true); + REQUIRE(success == true); } // Test async n step q-learning in Cart Pole. -BOOST_AUTO_TEST_CASE(NStepQLearningTest) +TEST_CASE("NStepQLearningTest", "[AsyncLearningTest]") { /** * This is for the Travis CI server, in your own machine you shuold use more @@ -233,7 +231,7 @@ BOOST_AUTO_TEST_CASE(NStepQLearningTest) { size_t maxEpisode = 100000; if (testEpisodes > maxEpisode) - BOOST_REQUIRE(false); + REQUIRE(false); testEpisodes++; rewards[pos++] = reward; pos %= rewards.n_elem; @@ -249,5 +247,3 @@ BOOST_AUTO_TEST_CASE(NStepQLearningTest) agent.Train(measure); Log::Debug << "Total test episodes: " << testEpisodes << std::endl; } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/augmented_rnns_tasks_test.cpp b/src/mlpack/tests/augmented_rnns_tasks_test.cpp index c8856a7570..1dca6d10b2 100644 --- a/src/mlpack/tests/augmented_rnns_tasks_test.cpp +++ b/src/mlpack/tests/augmented_rnns_tasks_test.cpp @@ -22,8 +22,7 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" using std::vector; using std::pair; @@ -219,12 +218,11 @@ class HardCodedAddModel } }; -BOOST_AUTO_TEST_SUITE(AugmentedRNNsTasks); // Test of CopyTask instance generator. // The data from generator is fed to the dummy hard-coded model above // that should be able to solve the task perfectly. -BOOST_AUTO_TEST_CASE(CopyTaskTest) +TEST_CASE("CopyTaskTest", "[AugmentedRNNsTasks]") { // Check the setup on various lengths... for (size_t maxLen = 2; maxLen <= 16; ++maxLen) @@ -242,8 +240,7 @@ BOOST_AUTO_TEST_CASE(CopyTaskTest) arma::field predResponse; model.Predict(testPredictor, predResponse); // A single failure is a failure. - BOOST_REQUIRE_GE(SequencePrecision(testResponse, predResponse), - 0.99); + REQUIRE(SequencePrecision(testResponse, predResponse) >= 0.99); } } } @@ -251,7 +248,7 @@ BOOST_AUTO_TEST_CASE(CopyTaskTest) // Test of SortTask instance generator. // The data from generator is fed to the dummy hard-coded model above // that should be able to solve the task perfectly. -BOOST_AUTO_TEST_CASE(SortTaskTest) +TEST_CASE("SortTaskTest", "[AugmentedRNNsTasks]") { size_t bitLen = 5; for (size_t maxLen = 2; maxLen <= 16; ++maxLen) @@ -266,15 +263,14 @@ BOOST_AUTO_TEST_CASE(SortTaskTest) arma::field predResponse; model.Predict(testPredictor, predResponse); // A single failure is a failure. - BOOST_REQUIRE_GE(SequencePrecision(testResponse, predResponse), - 0.99); + REQUIRE(SequencePrecision(testResponse, predResponse) >= 0.99); } } // Test of AddTask instance generator. // The data from generator is fed to the dummy hard-coded model above // that should be able to solve the task perfectly. -BOOST_AUTO_TEST_CASE(AddTaskTest) +TEST_CASE("AddTaskTest", "[AugmentedRNNsTasks]") { for (size_t bitLen = 2; bitLen <= 16; ++bitLen) { @@ -288,9 +284,6 @@ BOOST_AUTO_TEST_CASE(AddTaskTest) arma::field predResponse; model.Predict(testPredictor, predResponse); // A single failure is a failure. - BOOST_REQUIRE_GE(SequencePrecision(testResponse, predResponse), - 0.99); + REQUIRE(SequencePrecision(testResponse, predResponse) >= 0.99); } } - -BOOST_AUTO_TEST_SUITE_END(); From 7720289b34d75fc78071de399f24147ab28d999b Mon Sep 17 00:00:00 2001 From: Anush V Kini Date: Sat, 3 Oct 2020 18:45:01 +0530 Subject: [PATCH 14/45] Removed mean_shift_test.cpp from mlpack_tests in CMakeLists.txt --- src/mlpack/tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index ceb4804f87..4a06149cf5 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -36,7 +36,6 @@ add_executable(mlpack_test math_test.cpp matrix_completion_test.cpp maximal_inputs_test.cpp - mean_shift_test.cpp mlpack_test.cpp mock_categorical_data.hpp nbc_test.cpp From 6cc078d20ccd3be3400070c284744e0b015bc1ff Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Sat, 3 Oct 2020 19:46:34 +0530 Subject: [PATCH 15/45] Migrate det and distribution test to catch2 --- src/mlpack/tests/CMakeLists.txt | 4 +- src/mlpack/tests/det_test.cpp | 469 +++++++++---------- src/mlpack/tests/distribution_test.cpp | 618 +++++++++++++------------ 3 files changed, 558 insertions(+), 533 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index bf68f3c64b..17e90b6e65 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -8,8 +8,6 @@ add_executable(mlpack_test io_test.cpp cosine_tree_test.cpp dcgan_test.cpp - det_test.cpp - distribution_test.cpp drusilla_select_test.cpp emst_test.cpp fastmks_test.cpp @@ -122,6 +120,8 @@ add_executable(mlpack_catch_test dbscan_test.cpp decision_stump_test.cpp decision_tree_test.cpp + det_test.cpp + distribution_test.cpp feedforward_network_test.cpp image_load_test.cpp imputation_test.cpp diff --git a/src/mlpack/tests/det_test.cpp b/src/mlpack/tests/det_test.cpp index 4a16bbd060..c0989768eb 100644 --- a/src/mlpack/tests/det_test.cpp +++ b/src/mlpack/tests/det_test.cpp @@ -11,8 +11,7 @@ * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" // This trick does not work on Windows. We will have to comment out the tests // that depend on it. @@ -33,13 +32,11 @@ using namespace mlpack; using namespace mlpack::det; using namespace std; -BOOST_AUTO_TEST_SUITE(DETTest); - // Tests for the private functions. We cannot perform these if we are on // Windows because we cannot make private functions accessible using the macro // trick above. #ifndef _WIN32 -BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) +TEST_CASE("TestGetMaxMinVals", "[DETTest]") { arma::mat testData(3, 5); @@ -49,15 +46,15 @@ BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) DTree tree(testData); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[0], 7); - BOOST_REQUIRE_EQUAL(tree.MinVals()[0], 3); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[1], 7); - BOOST_REQUIRE_EQUAL(tree.MinVals()[1], 0); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[2], 8); - BOOST_REQUIRE_EQUAL(tree.MinVals()[2], 1); + REQUIRE(tree.MaxVals()[0] == 7); + REQUIRE(tree.MinVals()[0] == 3); + REQUIRE(tree.MaxVals()[1] == 7); + REQUIRE(tree.MinVals()[1] == 0); + REQUIRE(tree.MaxVals()[2] == 8); + REQUIRE(tree.MinVals()[2] == 1); } -BOOST_AUTO_TEST_CASE(TestComputeNodeError) +TEST_CASE("TestComputeNodeError", "[DETTest]") { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -65,17 +62,18 @@ BOOST_AUTO_TEST_CASE(TestComputeNodeError) DTree testDTree(maxVals, minVals, 5); double trueNodeError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE((double) testDTree.logNegError, trueNodeError, 1e-10); + REQUIRE((double) testDTree.logNegError == + Approx(trueNodeError).epsilon(1e-12)); testDTree.start = 3; testDTree.end = 5; double nodeError = testDTree.LogNegativeError(5); trueNodeError = 2 * log(2.0 / 5.0) - log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(nodeError, trueNodeError, 1e-10); + REQUIRE(nodeError == Approx(trueNodeError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestWithinRange) +TEST_CASE("TestWithinRange", "[DETTest]") { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -85,14 +83,14 @@ BOOST_AUTO_TEST_CASE(TestWithinRange) arma::vec testQuery(3); testQuery << 4.5 << 2.5 << 2; - BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), true); + REQUIRE(testDTree.WithinRange(testQuery) == true); testQuery << 8.5 << 2.5 << 2; - BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), false); + REQUIRE(testDTree.WithinRange(testQuery) == false); } -BOOST_AUTO_TEST_CASE(TestFindSplit) +TEST_CASE("TestFindSplit", "[DETTest]") { arma::mat testData(3, 5); @@ -108,20 +106,21 @@ BOOST_AUTO_TEST_CASE(TestFindSplit) size_t trueDim = 2; double trueSplit = 5.5; double trueLeftError = 2 * log(2.0 / 5.0) - (log(7.0) + log(4.0) + log(4.5)); - double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + log(2.5)); + double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + + log(2.5)); testDTree.logVolume = log(7.0) + log(4.0) + log(7.0); - BOOST_REQUIRE(testDTree.FindSplit( + REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - BOOST_REQUIRE(trueDim == obDim); - BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); + REQUIRE(trueDim == obDim); + REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); - BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); - BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); + REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); + REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSplitData) +TEST_CASE("TestSplitData", "[DETTest]") { arma::mat testData(3, 5); @@ -140,16 +139,16 @@ BOOST_AUTO_TEST_CASE(TestSplitData) size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - BOOST_REQUIRE_EQUAL(splitInd, 2); // 2 points on left side. + REQUIRE(splitInd == 2); // 2 points on left side. - BOOST_REQUIRE_EQUAL(oTest[0], 1); - BOOST_REQUIRE_EQUAL(oTest[1], 4); - BOOST_REQUIRE_EQUAL(oTest[2], 3); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 5); + REQUIRE(oTest[0] == 1); + REQUIRE(oTest[1] == 4); + REQUIRE(oTest[2] == 3); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 5); } -BOOST_AUTO_TEST_CASE(TestSparseFindSplit) +TEST_CASE("TestSparseFindSplit", "[DETTest]") { arma::mat realData(4, 7); @@ -173,17 +172,17 @@ BOOST_AUTO_TEST_CASE(TestSparseFindSplit) (log(7.0) + log(6.5) + log(8.0) + log(6.0)); testDTree.logVolume = log(7.0) + log(7.0) + log(8.0) + log(6.0); - BOOST_REQUIRE(testDTree.FindSplit( + REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - BOOST_REQUIRE(trueDim == obDim); - BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); + REQUIRE(trueDim == obDim); + REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); - BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); - BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); + REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); + REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSparseSplitData) +TEST_CASE("TestSparseSplitData", "[DETTest]") { arma::mat realData(4, 7); @@ -205,22 +204,22 @@ BOOST_AUTO_TEST_CASE(TestSparseSplitData) size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - BOOST_REQUIRE_EQUAL(splitInd, 3); // 2 points on left side. + REQUIRE(splitInd == 3); // 2 points on left side. - BOOST_REQUIRE_EQUAL(oTest[0], 1); - BOOST_REQUIRE_EQUAL(oTest[1], 4); - BOOST_REQUIRE_EQUAL(oTest[2], 3); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 5); - BOOST_REQUIRE_EQUAL(oTest[5], 6); - BOOST_REQUIRE_EQUAL(oTest[6], 7); + REQUIRE(oTest[0] == 1); + REQUIRE(oTest[1] == 4); + REQUIRE(oTest[2] == 3); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 5); + REQUIRE(oTest[5] == 6); + REQUIRE(oTest[6] == 7); } #endif // Tests for the public functions. -BOOST_AUTO_TEST_CASE(TestGrow) +TEST_CASE("TestGrow", "[DETTest]") { arma::mat testData(3, 5); @@ -244,34 +243,36 @@ BOOST_AUTO_TEST_CASE(TestGrow) DTree testDTree(testData); double alpha = testDTree.Grow(testData, oTest, false, 2, 1); - BOOST_REQUIRE_EQUAL(oTest[0], 0); - BOOST_REQUIRE_EQUAL(oTest[1], 3); - BOOST_REQUIRE_EQUAL(oTest[2], 1); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 4); + REQUIRE(oTest[0] == 0); + REQUIRE(oTest[1] == 3); + REQUIRE(oTest[2] == 1); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 4); // Test the structure of the tree. - BOOST_REQUIRE(testDTree.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree.Right()->Right()->Right() == NULL); + REQUIRE(testDTree.Left()->Left() == NULL); + REQUIRE(testDTree.Left()->Right() == NULL); + REQUIRE(testDTree.Right()->Left()->Left() == NULL); + REQUIRE(testDTree.Right()->Left()->Right() == NULL); + REQUIRE(testDTree.Right()->Right()->Left() == NULL); + REQUIRE(testDTree.Right()->Right()->Right() == NULL); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 3); + REQUIRE(testDTree.SubtreeLeaves() == 3); - BOOST_REQUIRE(testDTree.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree.SplitDim() == 2); + REQUIRE(testDTree.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree.Right()->SplitDim() == 1); + REQUIRE(testDTree.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); // Test node errors for every node (these are private functions). #ifndef _WIN32 - BOOST_REQUIRE_CLOSE(testDTree.logNegError, rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Left()->logNegError, lError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->logNegError, rError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->Left()->logNegError, rlError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->Right()->logNegError, rrError, 1e-10); + REQUIRE(testDTree.logNegError == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left()->logNegError == Approx(lError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->logNegError == Approx(rError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->Left()->logNegError == + Approx(rlError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->Right()->logNegError == + Approx(rrError).epsilon(1e-12)); #endif // Test alpha. @@ -281,10 +282,10 @@ BOOST_AUTO_TEST_CASE(TestGrow) rAlpha = std::log(-(std::exp(rError) - (std::exp(rlError) + std::exp(rrError)))); - BOOST_REQUIRE_CLOSE(alpha, min(rootAlpha, rAlpha), 1e-10); + REQUIRE(alpha == Approx(min(rootAlpha, rAlpha)).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) +TEST_CASE("TestPruneAndUpdate", "[DETTest]") { arma::mat testData(3, 5); @@ -298,18 +299,19 @@ BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); + REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); - BOOST_REQUIRE(testDTree.Left() == NULL); - BOOST_REQUIRE(testDTree.Right() == NULL); + REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeavesLogNegError() == + Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left() == NULL); + REQUIRE(testDTree.Right() == NULL); } -BOOST_AUTO_TEST_CASE(TestComputeValue) +TEST_CASE("TestComputeValue", "[DETTest]") { arma::mat testData(3, 5); @@ -334,22 +336,22 @@ BOOST_AUTO_TEST_CASE(TestComputeValue) double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestVariableImportance) +TEST_CASE("TestVariableImportance", "[DETTest]") { arma::mat testData(3, 5); @@ -377,12 +379,14 @@ BOOST_AUTO_TEST_CASE(TestVariableImportance) testDTree.ComputeVariableImportance(imps); - BOOST_REQUIRE_CLOSE((double) 0.0, imps[0], 1e-10); - BOOST_REQUIRE_CLOSE((double) (rError - (rlError + rrError)), imps[1], 1e-10); - BOOST_REQUIRE_CLOSE((double) (rootError - (lError + rError)), imps[2], 1e-10); + REQUIRE((double) 0.0 == Approx(imps[0]).epsilon(1e-12)); + REQUIRE((double) (rError - (rlError + rrError)) == + Approx(imps[1]).epsilon(1e-12)); + REQUIRE((double) (rootError - (lError + rError)) == + Approx(imps[2]).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) +TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]") { arma::mat realData(3, 5); @@ -399,18 +403,19 @@ BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); + REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); - BOOST_REQUIRE(testDTree.Left() == NULL); - BOOST_REQUIRE(testDTree.Right() == NULL); + REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeavesLogNegError() == + Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left() == NULL); + REQUIRE(testDTree.Right() == NULL); } -BOOST_AUTO_TEST_CASE(TestSparseComputeValue) +TEST_CASE("TestSparseComputeValue", "[DETTest]") { arma::mat realData(3, 5); @@ -438,25 +443,25 @@ BOOST_AUTO_TEST_CASE(TestSparseComputeValue) double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); } /** * These are not yet implemented. * -BOOST_AUTO_TEST_CASE(TestTagTree) +TEST_CASE("TestTagTree", "[DETTest]") { MatType testData(3, 5); @@ -469,7 +474,7 @@ BOOST_AUTO_TEST_CASE(TestTagTree) delete testDTree; } -BOOST_AUTO_TEST_CASE(TestFindBucket) +TEST_CASE("TestFindBucket", "[DETTest]") { MatType testData(3, 5); @@ -484,24 +489,24 @@ BOOST_AUTO_TEST_CASE(TestFindBucket) // Test functions in dt_utils.hpp -BOOST_AUTO_TEST_CASE(TestTrainer) +TEST_CASE("TestTrainer", "[DETTest]") { } -BOOST_AUTO_TEST_CASE(TestPrintVariableImportance) +TEST_CASE("TestPrintVariableImportance", "[DETTest]") { } -BOOST_AUTO_TEST_CASE(TestPrintLeafMembership) +TEST_CASE("TestPrintLeafMembership", "[DETTest]") { } */ // Test the copy constructor and the copy operator. -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) +TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -544,76 +549,76 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) delete testDTree; // Test the data of copied tree (using copy constructor). - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the data of the copied tree (using the copy operator). - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[2], minVals2); + REQUIRE(testDTree3.MaxVals()[0] == maxVals0); + REQUIRE(testDTree3.MinVals()[0] == minVals0); + REQUIRE(testDTree3.MaxVals()[1] == maxVals1); + REQUIRE(testDTree3.MinVals()[1] == minVals1); + REQUIRE(testDTree3.MaxVals()[2] == maxVals2); + REQUIRE(testDTree3.MinVals()[2] == minVals2); // Test the structure of the tree copied using the copy constructor. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the structure of the tree copied using the copy operator. - BOOST_REQUIRE(testDTree3.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Right()->Right() == NULL); + REQUIRE(testDTree3.Left()->Left() == NULL); + REQUIRE(testDTree3.Left()->Right() == NULL); + REQUIRE(testDTree3.Right()->Left()->Left() == NULL); + REQUIRE(testDTree3.Right()->Left()->Right() == NULL); + REQUIRE(testDTree3.Right()->Right()->Left() == NULL); + REQUIRE(testDTree3.Right()->Right()->Right() == NULL); // Test the data of the tree copied using the copy constructor. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); // Test the data of the tree copied using the copy operator. - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree3.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree3.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree3.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree3.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree3.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree3.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree3.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree3.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree3.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree3.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree3.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree3.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree3.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree3.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree3.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree3.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree3.SplitDim() == 2); + REQUIRE(testDTree3.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree3.Right()->SplitDim() == 1); + REQUIRE(testDTree3.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } // Test the move constructor. -BOOST_AUTO_TEST_CASE(MoveConstructorTest) +TEST_CASE("MoveConstructorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -653,50 +658,50 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) DTree testDTree2(std::move(*testDTree)); // Check default values of the original tree. - BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); - BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); - BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); + REQUIRE(testDTree->LogNegError() == -DBL_MAX); + REQUIRE(testDTree->Left() == (DTree*) NULL); + REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the structure of the moved tree. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } // Test the move operator. -BOOST_AUTO_TEST_CASE(MoveOperatorTest) +TEST_CASE("MoveOperatorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -736,46 +741,44 @@ BOOST_AUTO_TEST_CASE(MoveOperatorTest) DTree testDTree2 = std::move(*testDTree); // Check default values of the original tree. - BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); - BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); - BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); + REQUIRE(testDTree->LogNegError() == -DBL_MAX); + REQUIRE(testDTree->Left() == (DTree*) NULL); + REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the structure of the moved tree. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 35103130b9..ab7d606a9f 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -19,17 +19,15 @@ #include #include -#include -#include "test_tools.hpp" -#include "serialization.hpp" +#include "catch.hpp" +#include "serialization_catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::distribution; using namespace mlpack::metric; using namespace mlpack::math; -BOOST_AUTO_TEST_SUITE(DistributionTest); - /*********************************/ /** Discrete Distribution Tests **/ /*********************************/ @@ -37,38 +35,38 @@ BOOST_AUTO_TEST_SUITE(DistributionTest); /** * Make sure we initialize correctly. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionConstructorTest) +TEST_CASE("DiscreteDistributionConstructorTest", "[DistributionTest]") { DiscreteDistribution d(5); - BOOST_REQUIRE_EQUAL(d.Probabilities().n_elem, 5); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); + REQUIRE(d.Probabilities().n_elem == 5); + REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); } /** * Make sure we get the probabilities of observations right. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionProbabilityTest) +TEST_CASE("DiscreteDistributionProbabilityTest", "[DistributionTest]") { DiscreteDistribution d(5); d.Probabilities() = "0.2 0.4 0.1 0.1 0.2"; - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.4, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.1, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.1, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.4).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.1).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.1).epsilon(1e-7)); + REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); } /** * Make sure we get random observations correct. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) +TEST_CASE("DiscreteDistributionRandomTest", "[DistributionTest]") { DiscreteDistribution d(arma::Col("3")); @@ -85,15 +83,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) actualProb /= accu(actualProb); // 8% tolerance, because this can be a noisy process. - BOOST_REQUIRE_CLOSE(actualProb(0), 0.3, 8.0); - BOOST_REQUIRE_CLOSE(actualProb(1), 0.6, 8.0); - BOOST_REQUIRE_CLOSE(actualProb(2), 0.1, 8.0); + REQUIRE(actualProb(0) == Approx(0.3).epsilon(0.08)); + REQUIRE(actualProb(1) == Approx(0.6).epsilon(0.08)); + REQUIRE(actualProb(2) == Approx(0.1).epsilon(0.08)); } /** * Make sure we can estimate from observations correctly. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) +TEST_CASE("DiscreteDistributionTrainTest", "[DistributionTest]") { DiscreteDistribution d(4); @@ -101,16 +99,16 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) d.Train(obs); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.375, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.125, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.375).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.125).epsilon(1e-7)); } /** * Estimate from observations with probabilities. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) +TEST_CASE("DiscreteDistributionTrainProbTest", "[DistributionTest]") { DiscreteDistribution d(3); @@ -120,15 +118,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) d.Train(obs, prob); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.5, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.5).epsilon(1e-7)); } /** * Achieve multidimensional probability distribution. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) +TEST_CASE("MultiDiscreteDistributionTrainProbTest", "[DistributionTest]") { DiscreteDistribution d("10 10 10"); @@ -137,29 +135,29 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) "0 0 0 1 1 2 2 2 2 2;"); d.Train(obs); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.009, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.015, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.054, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.009).epsilon(1e-7)); + REQUIRE(d.Probability("0 1 2") == Approx(0.015).epsilon(1e-7)); + REQUIRE(d.Probability("2 1 0") == Approx(0.054).epsilon(1e-7)); } /** * Make sure we initialize multidimensional probability distribution * correctly. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionConstructorTest) +TEST_CASE("MultiDiscreteDistributionConstructorTest", "[DistributionTest]") { DiscreteDistribution d("4 4 4 4"); - BOOST_REQUIRE_EQUAL(d.Probabilities(0).size(), 4); - BOOST_REQUIRE_EQUAL(d.Dimensionality(), 4); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0 0"), 0.00390625, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2 3"), 0.00390625, 1e-5); + REQUIRE(d.Probabilities(0).size() == 4); + REQUIRE(d.Dimensionality() == 4); + REQUIRE(d.Probability("0 0 0 0") == Approx(0.00390625).epsilon(1e-7)); + REQUIRE(d.Probability("0 1 2 3") == Approx(0.00390625).epsilon(1e-7)); } /** * Achieve multidimensional probability distribution. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) +TEST_CASE("MultiDiscreteDistributionTrainTest", "[DistributionTest]") { std::vector pro; pro.push_back(arma::vec("0.1, 0.3, 0.6")); @@ -168,16 +166,16 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) DiscreteDistribution d(pro); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.0083333, 1e-3); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.0166666, 1e-3); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.05, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.0083333).epsilon(1e-5)); + REQUIRE(d.Probability("0 1 2") == Approx(0.0166666).epsilon(1e-5)); + REQUIRE(d.Probability("2 1 0") == Approx(0.05).epsilon(1e-7)); } /** * Estimate multidimensional probability distribution from observations with * probabilities. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) +TEST_CASE("MultiDiscreteDistributionTrainProTest", "[DistributionTest]") { DiscreteDistribution d("5 5 5"); @@ -189,16 +187,16 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) d.Train(obs, prob); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.00390625, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1 0 1"), 0.0078125, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.015625, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.00390625).epsilon(1e-7)); + REQUIRE(d.Probability("1 0 1") == Approx(0.0078125).epsilon(1e-7)); + REQUIRE(d.Probability("2 1 0") == Approx(0.015625).epsilon(1e-7)); } /** * Test the LogProbability() function, for multiple points in the multivariate * Discrete case. */ -BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) +TEST_CASE("DiscreteLogProbabilityTest", "[DistributionTest]") { // Same case as before. DiscreteDistribution d("5 5"); @@ -210,17 +208,17 @@ BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) d.LogProbability(obs, logProb); - BOOST_REQUIRE_EQUAL(logProb.n_elem, 2); + REQUIRE(logProb.n_elem == 2); - BOOST_REQUIRE_CLOSE(logProb(0), -3.2188758248682, 1e-3); - BOOST_REQUIRE_CLOSE(logProb(1), -3.2188758248682, 1e-3); + REQUIRE(logProb(0) == Approx(-3.2188758248682).epsilon(1e-5)); + REQUIRE(logProb(1) == Approx(-3.2188758248682).epsilon(1e-5)); } /** * Test the Probability() function, for multiple points in the multivariate * Discrete case. */ -BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) +TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") { // Same case as before. DiscreteDistribution d("5 5"); @@ -232,10 +230,10 @@ BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) d.Probability(obs, prob); - BOOST_REQUIRE_EQUAL(prob.n_elem, 2); + REQUIRE(prob.n_elem == 2); - BOOST_REQUIRE_CLOSE(prob(0), 0.0400000000000, 1e-3); - BOOST_REQUIRE_CLOSE(prob(1), 0.0400000000000, 1e-3); + REQUIRE(prob(0) == Approx(0.0400000000000).epsilon(1e-5)); + REQUIRE(prob(1) == Approx(0.0400000000000).epsilon(1e-5)); } /*********************************/ @@ -245,32 +243,33 @@ BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) /** * Make sure Gaussian distributions are initialized correctly. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionEmptyConstructor) +TEST_CASE("GaussianDistributionEmptyConstructor", "[DistributionTest]") { GaussianDistribution d; - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); + REQUIRE(d.Mean().n_elem == 0); + REQUIRE(d.Covariance().n_elem == 0); } /** * Make sure Gaussian distributions are initialized to the correct * dimensionality. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionDimensionalityConstructor) +TEST_CASE("GaussianDistributionDimensionalityConstructor", + "[DistributionTest]") { GaussianDistribution d(4); - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_rows, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_cols, 4); + REQUIRE(d.Mean().n_elem == 4); + REQUIRE(d.Covariance().n_rows == 4); + REQUIRE(d.Covariance().n_cols == 4); } /** * Make sure Gaussian distributions are initialized correctly when we give a * mean and covariance. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) +TEST_CASE("GaussianDistributionDistributionConstructor", "[DistributionTest]") { arma::vec mean(3); arma::mat covariance(3, 3); @@ -283,17 +282,17 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) GaussianDistribution d(mean, covariance); for (size_t i = 0; i < 3; ++i) - BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); + REQUIRE(d.Mean()[i] == Approx(mean[i]).epsilon(1e-7)); for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) - BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); + REQUIRE(d.Covariance()(i, j) == Approx(covariance(i, j)).epsilon(1e-7)); } /** * Make sure the probability of observations is correct. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) +TEST_CASE("GaussianDistributionProbabilityTest", "[DistributionTest]") { arma::vec mean("5 6 3 3 2"); arma::mat cov("6 1 1 1 2;" @@ -304,52 +303,63 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) GaussianDistribution d(mean, cov); - BOOST_REQUIRE_CLOSE(d.LogProbability("0 1 2 3 4"), -13.432076798791542, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("3 2 3 7 8"), -15.814880322345738, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 2 0 8 1"), -13.754462857772776, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 1 5 0 1"), -13.283283233107898, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("3 0 5 1 0"), -13.800326511545279, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("4 0 6 1 0"), -14.900192463287908, 1e-5); + REQUIRE(d.LogProbability("0 1 2 3 4") == + Approx(-13.432076798791542).epsilon(1e-7)); + REQUIRE(d.LogProbability("3 2 3 7 8") == + Approx(-15.814880322345738).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 2 0 8 1") == + Approx(-13.754462857772776).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 1 5 0 1") == + Approx(-13.283283233107898).epsilon(1e-7)); + REQUIRE(d.LogProbability("3 0 5 1 0") == + Approx(-13.800326511545279).epsilon(1e-7)); + REQUIRE(d.LogProbability("4 0 6 1 0") == + Approx(-14.900192463287908).epsilon(1e-7)); } /** * Test GaussianDistribution::Probability() in the univariate case. */ -BOOST_AUTO_TEST_CASE(GaussianUnivariateProbabilityTest) +TEST_CASE("GaussianUnivariateProbabilityTest", "[DistributionTest]") { GaussianDistribution g(arma::vec("0.0"), arma::mat("1.0")); // Simple case. - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.398942280401433, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.241970724519143, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.241970724519143, - 1e-5); + REQUIRE(g.Probability(arma::vec("0.0")) == + Approx(0.398942280401433).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.241970724519143).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.241970724519143).epsilon(1e-7)); // A few more cases... arma::mat covariance; covariance = 2.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.282094791773878, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.219695644733861, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.219695644733861, - 1e-5); + REQUIRE(g.Probability(arma::vec("0.0")) == + Approx(0.282094791773878).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.219695644733861).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.219695644733861).epsilon(1e-7)); g.Mean().fill(1.0); covariance = 1.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.398942280401433, 1e-5); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.398942280401433).epsilon(1e-7)); covariance = 2.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.103776874355149, - 1e-5); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.103776874355149).epsilon(1e-7)); } /** * Test GaussianDistribution::Probability() in the multivariate case. */ -BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) +TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") { // Simple case. arma::vec mean = "0 0"; @@ -358,37 +368,37 @@ BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) GaussianDistribution g(mean, cov); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.159154943091895, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.159154943091895).epsilon(1e-7)); arma::mat covariance; covariance = "2 0; 0 2"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); x = "1 1"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0482661763150270, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0482661763150270, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0482661763150270).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(0.0482661763150270).epsilon(1e-7)); g.Mean() = "1 1"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(-x) == Approx(0.0795774715459477).epsilon(1e-7)); g.Mean() = "1 1"; covariance = "2 1.5; 1.5 4"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.066372199406187285, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.066372199406187285).epsilon(1e-7)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.066372199406187285, 1e-5); + REQUIRE(g.Probability(-x) == Approx(0.066372199406187285).epsilon(1e-7)); g.Mean() = "1 1"; x = "-1 4"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.00072147262356379415, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.00085851785428674523, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.00072147262356379415).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(0.00085851785428674523).epsilon(1e-7)); // Higher-dimensional case. x = "0 1 2 3 4"; @@ -401,19 +411,19 @@ BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) "2 0 1 0 6"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 1.4673143531128877e-06, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 7.7404143494891786e-09, 1e-8); + REQUIRE(g.Probability(x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 1.4673143531128877e-06, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(x), 7.7404143494891786e-09, 1e-8); + REQUIRE(g.Probability(-x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); + REQUIRE(g.Probability(x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. */ -BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) +TEST_CASE("GaussianMultipointMultivariateProbabilityTest", "[DistributionTest]") { // Same case as before. arma::vec mean = "5 6 3 3 2"; @@ -433,20 +443,20 @@ BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) GaussianDistribution g(mean, cov); g.LogProbability(points, phis); - BOOST_REQUIRE_EQUAL(phis.n_elem, 6); + REQUIRE(phis.n_elem == 6); - BOOST_REQUIRE_CLOSE(phis(0), -13.432076798791542, 1e-5); - BOOST_REQUIRE_CLOSE(phis(1), -15.814880322345738, 1e-5); - BOOST_REQUIRE_CLOSE(phis(2), -13.754462857772776, 1e-5); - BOOST_REQUIRE_CLOSE(phis(3), -13.283283233107898, 1e-5); - BOOST_REQUIRE_CLOSE(phis(4), -13.800326511545279, 1e-5); - BOOST_REQUIRE_CLOSE(phis(5), -14.900192463287908, 1e-5); + REQUIRE(phis(0) == Approx(-13.432076798791542).epsilon(1e-7)); + REQUIRE(phis(1) == Approx(-15.814880322345738).epsilon(1e-7)); + REQUIRE(phis(2) == Approx(-13.754462857772776).epsilon(1e-7)); + REQUIRE(phis(3) == Approx(-13.283283233107898).epsilon(1e-7)); + REQUIRE(phis(4) == Approx(-13.800326511545279).epsilon(1e-7)); + REQUIRE(phis(5) == Approx(-14.900192463287908).epsilon(1e-7)); } /** * Make sure random observations follow the probability distribution correctly. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) +TEST_CASE("GaussianDistributionRandomTest", "[DistributionTest]") { arma::vec mean("1.0 2.25"); arma::mat cov("0.85 0.60;" @@ -464,19 +474,19 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - BOOST_REQUIRE_CLOSE(obsMean[0], mean[0], 10.0); - BOOST_REQUIRE_CLOSE(obsMean[1], mean[1], 10.0); + REQUIRE(obsMean[0] == Approx(mean[0]).epsilon(0.1)); + REQUIRE(obsMean[1] == Approx(mean[1]).epsilon(0.1)); - BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0, 0), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(0, 1), cov(0, 1), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(1, 0), cov(1, 0), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1, 1), 10.0); + REQUIRE(obsCov(0, 0) == Approx(cov(0, 0)).epsilon(0.1)); + REQUIRE(obsCov(0, 1) == Approx(cov(0, 1)).epsilon(0.1)); + REQUIRE(obsCov(1, 0) == Approx(cov(1, 0)).epsilon(0.1)); + REQUIRE(obsCov(1, 1) == Approx(cov(1, 1)).epsilon(0.1)); } /** * Make sure that we can properly estimate from given observations. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) +TEST_CASE("GaussianDistributionTrainTest", "[DistributionTest]") { arma::vec mean("1.0 3.0 0.0 2.5"); arma::mat cov("3.0 0.0 1.0 4.0;" @@ -502,18 +512,22 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) // Check that everything is estimated right. for (size_t i = 0; i < 4; ++i) - BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); + REQUIRE(d.Mean()[i] - actualMean[i] == Approx(0.0).margin(1e-5)); for (size_t i = 0; i < 4; ++i) for (size_t j = 0; j < 4; ++j) - BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); + { + REQUIRE(d.Covariance()(i, j) - actualCov(i, j) == + Approx(0.0).margin(1e-5)); + } } /** * This test verifies the fitting of GaussianDistribution works properly when * probabilities for each sample is given. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) +TEST_CASE("GaussianDistributionTrainWithProbabilitiesTest", + "[DistributionTest]") { arma::vec mean = ("5.0"); arma::vec cov = ("2.0"); @@ -538,18 +552,19 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) GaussianDistribution guDist2; guDist2.Train(rdata); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 6); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 6); + REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(0.06)); + REQUIRE(guDist.Covariance()[0] == + Approx(guDist2.Covariance()[0]).epsilon(0.06)); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean[0], 6); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov[0], 6); + REQUIRE(guDist.Mean()[0] == Approx(mean[0]).epsilon(0.06)); + REQUIRE(guDist.Covariance()[0] == Approx(cov[0]).epsilon(0.06)); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) +TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") { arma::vec mean = ("5.0"); arma::vec cov = ("4.0"); @@ -573,8 +588,9 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) GaussianDistribution guDist2; guDist2.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 1e-15); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 1e-2); + REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(1e-17)); + REQUIRE(guDist.Covariance()[0] == + Approx(guDist2.Covariance()[0]).epsilon(1e-4)); } /** @@ -585,7 +601,8 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) * We expect that the distribution we recover after training to be the same as * the second normal distribution (the one with high probabilities). */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) +TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", + "[DistributionTest]") { arma::vec mean1 = ("5.0"); arma::vec cov1 = ("4.0"); @@ -626,8 +643,8 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) GaussianDistribution guDist; guDist.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean1[0], 5); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov1[0], 5); + REQUIRE(guDist.Mean()[0] == Approx(mean1[0]).epsilon(0.05)); + REQUIRE(guDist.Covariance()[0] == Approx(cov1[0]).epsilon(0.05)); } /******************************/ @@ -637,7 +654,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) * Make sure that using an object to fit one reference set and then asking * to fit another works properly. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) +TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") { // Create a gamma distribution random generator. double alphaReal = 5.3; @@ -659,8 +676,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) gDist.Train(rdata); // Training must estimate d pairs of alpha and beta parameters. - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); + REQUIRE(gDist.Dimensionality() == d); + REQUIRE(gDist.Dimensionality() == d); // Create a N' x d' gamma distribution, fit results without new object. size_t N2 = 350; @@ -676,15 +693,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) gDist.Train(rdata2); // Training must estimate d' pairs of alpha and beta parameters. - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); + REQUIRE(gDist.Dimensionality() == d2); + REQUIRE(gDist.Dimensionality() == d2); } /** * This test verifies that the fitting procedure for GammaDistribution works * properly when probabilities for each sample is given. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) +TEST_CASE("GammaDistributionTrainWithProbabilitiesTest", "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -711,24 +728,24 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) GammaDistribution gDist2; gDist2.Train(rdata); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1.5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1.5); + REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(0.015)); + REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(0.015)); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1.5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1.5); + REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(0.015)); + REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(0.015)); - BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(0), 3.0); - BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(0), 3.0); + REQUIRE(alphaReal == Approx(gDist.Alpha(0)).epsilon(0.03)); + REQUIRE(betaReal == Approx(gDist.Beta(0)).epsilon(0.03)); - BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(1), 3.0); - BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(1), 3.0); + REQUIRE(alphaReal == Approx(gDist.Alpha(1)).epsilon(0.03)); + REQUIRE(betaReal == Approx(gDist.Beta(1)).epsilon(0.03)); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) +TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -753,11 +770,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) arma::vec allProbabilities1(N, arma::fill::ones); gDist2.Train(rdata, allProbabilities1); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1e-5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1e-5); + REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(1e-7)); + REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1e-5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1e-5); + REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(1e-7)); + REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(1e-7)); } /** @@ -767,7 +784,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) * gamma distribution recovered has the same parameters as the second gamma * distribution with high probabilities. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) +TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", + "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -807,11 +825,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) GammaDistribution gDist; gDist.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(0), 5); - BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(0), 5); + REQUIRE(alphaReal2 == Approx(gDist.Alpha(0)).epsilon(0.05)); + REQUIRE(betaReal2 == Approx(gDist.Beta(0)).epsilon(0.05)); - BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(1), 5); - BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(1), 5); + REQUIRE(alphaReal2 == Approx(gDist.Alpha(1)).epsilon(0.05)); + REQUIRE(betaReal2 == Approx(gDist.Beta(1)).epsilon(0.05)); } /** @@ -820,7 +838,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) * with different alpha/beta parameters so we make sure we don't have some weird * bug that always converges to the same number. */ -BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) +TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") { // Offset from the actual alpha/beta. 10% is quite a relaxed tolerance since // the random points we generate are few (for test speed) and might be fitted @@ -848,8 +866,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) gDist.Train(rdata); // Estimated parameter must be close to real. - BOOST_REQUIRE_CLOSE(gDist.Alpha(0), alphaReal, errorTolerance); - BOOST_REQUIRE_CLOSE(gDist.Beta(0), betaReal, errorTolerance); + REQUIRE(gDist.Alpha(0) == Approx(alphaReal).epsilon(errorTolerance / 100)); + REQUIRE(gDist.Beta(0) == Approx(betaReal).epsilon(errorTolerance / 100)); /** Iteration 2 (different parameter set) **/ @@ -869,15 +887,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) gDist2.Train(rdata2); // Estimated parameter must be close to real. - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), alphaReal2, errorTolerance); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), betaReal2, errorTolerance); + REQUIRE(gDist2.Alpha(0) == Approx(alphaReal2).epsilon(errorTolerance / 100)); + REQUIRE(gDist2.Beta(0) == Approx(betaReal2).epsilon(errorTolerance / 100)); } /** * Test that Train() and the constructor that takes data give the same resulting * distribution. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) +TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") { const arma::mat data = arma::randu(10, 500); @@ -887,8 +905,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_CLOSE(d1.Alpha(i), d2.Alpha(i), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Beta(i), d2.Beta(i), 1e-5); + REQUIRE(d1.Alpha(i) == Approx(d2.Alpha(i)).epsilon(1e-7)); + REQUIRE(d1.Beta(i) == Approx(d2.Beta(i)).epsilon(1e-7)); } } @@ -896,7 +914,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) * Test that Train() with a dataset and Train() with dataset statistics return * the same results. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) +TEST_CASE("GammaDistributionTrainStatisticsTest", "[DistributionTest]") { const arma::mat data = arma::randu(1, 500); @@ -910,15 +928,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) const arma::vec logMeanx = arma::log(meanx); d2.Train(logMeanx, meanLogx, meanx); - BOOST_REQUIRE_CLOSE(d1.Alpha(0), d2.Alpha(0), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Beta(0), d2.Beta(0), 1e-5); + REQUIRE(d1.Alpha(0) == Approx(d2.Alpha(0)).epsilon(1e-7)); + REQUIRE(d1.Beta(0) == Approx(d2.Beta(0)).epsilon(1e-7)); } /** * Tests that Random() generates points that can be reasonably well fit by the * distribution that generated them. */ -BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) +TEST_CASE("GammaDistributionRandomTest", "[DistributionTest]") { const arma::vec a("2.0 2.5 3.0"), b("0.4 0.6 1.3"); const size_t numPoints = 2000; @@ -934,12 +952,12 @@ BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) GammaDistribution d2(data); for (size_t i = 0; i < 3; ++i) { - BOOST_REQUIRE_CLOSE(d2.Alpha(i), a(i), 10); // Within 10% - BOOST_REQUIRE_CLOSE(d2.Beta(i), b(i), 10); + REQUIRE(d2.Alpha(i) == Approx(a(i)).epsilon(0.1)); // Within 10% + REQUIRE(d2.Beta(i) == Approx(b(i)).epsilon(0.1)); } } -BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) +TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -949,16 +967,16 @@ BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.Probability(x1, prob1); - BOOST_REQUIRE_CLOSE(prob1(0), 0.267575, 1e-3); + REQUIRE(prob1(0) == Approx(0.267575).epsilon(1e-5)); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.Probability(x2, prob2); - BOOST_REQUIRE_CLOSE(prob2(0), 0.189043, 1e-3); + REQUIRE(prob2(0) == Approx(0.189043).epsilon(1e-5)); // Check that the overload that returns the probability for 1 dimension // agrees. - BOOST_REQUIRE_CLOSE(prob2(0), d2.Probability(2.94, 0), 1e-5); + REQUIRE(prob2(0) == Approx(d2.Probability(2.94, 0)).epsilon(1e-7)); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -971,11 +989,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.Probability(x3, prob3); - BOOST_REQUIRE_CLOSE(prob3(0), 0.04408, 1e-2); - BOOST_REQUIRE_CLOSE(prob3(1), 0.026165, 1e-2); + REQUIRE(prob3(0) == Approx(0.04408).epsilon(1e-4)); + REQUIRE(prob3(1) == Approx(0.026165).epsilon(1e-4)); } -BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) +TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -985,16 +1003,16 @@ BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.LogProbability(x1, logprob1); - BOOST_REQUIRE_CLOSE(logprob1(0), std::log(0.267575), 1e-3); + REQUIRE(logprob1(0) == Approx(std::log(0.267575)).epsilon(1e-5)); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.LogProbability(x2, logprob2); - BOOST_REQUIRE_CLOSE(logprob2(0), std::log(0.189043), 1e-3); + REQUIRE(logprob2(0) == Approx(std::log(0.189043)).epsilon(1e-5)); // Check that the overload that returns the log probability for // 1 dimension agrees. - BOOST_REQUIRE_CLOSE(logprob2(0), d2.LogProbability(2.94, 0), 1e-5); + REQUIRE(logprob2(0) == Approx(d2.LogProbability(2.94, 0)).epsilon(1e-7)); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -1008,14 +1026,14 @@ BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.LogProbability(x3, logprob3); - BOOST_REQUIRE_CLOSE(logprob3(0), std::log(0.04408), 1e-3); - BOOST_REQUIRE_CLOSE(logprob3(1), std::log(0.026165), 1e-3); + REQUIRE(logprob3(0) == Approx(std::log(0.04408)).epsilon(1e-5)); + REQUIRE(logprob3(1) == Approx(std::log(0.026165)).epsilon(1e-5)); } /** * Discrete Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) +TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") { // I assume that I am properly saving vectors, so, this should be // straightforward. @@ -1036,15 +1054,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) const double prob = t.Probability(obs); if (prob == 0.0) { - BOOST_REQUIRE_SMALL(xmlT.Probability(obs), 1e-8); - BOOST_REQUIRE_SMALL(textT.Probability(obs), 1e-8); - BOOST_REQUIRE_SMALL(binaryT.Probability(obs), 1e-8); + REQUIRE(xmlT.Probability(obs) == Approx(0.0).margin(1e-8)); + REQUIRE(textT.Probability(obs) == Approx(0.0).margin(1e-8)); + REQUIRE(binaryT.Probability(obs) == Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(prob, xmlT.Probability(obs), 1e-8); - BOOST_REQUIRE_CLOSE(prob, textT.Probability(obs), 1e-8); - BOOST_REQUIRE_CLOSE(prob, binaryT.Probability(obs), 1e-8); + REQUIRE(prob == Approx(xmlT.Probability(obs)).epsilon(1e-10)); + REQUIRE(prob == Approx(textT.Probability(obs)).epsilon(1e-10)); + REQUIRE(prob == Approx(binaryT.Probability(obs)).epsilon(1e-10)); } } } @@ -1052,7 +1070,7 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) /** * Gaussian Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTest) +TEST_CASE("GaussianDistributionTest", "[DistributionTest]") { arma::vec mean(10); mean.randu(); @@ -1066,9 +1084,9 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) SerializeObjectAll(g, xmlG, textG, binaryG); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), xmlG.Dimensionality()); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), textG.Dimensionality()); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), binaryG.Dimensionality()); + REQUIRE(g.Dimensionality() == xmlG.Dimensionality()); + REQUIRE(g.Dimensionality() == textG.Dimensionality()); + REQUIRE(g.Dimensionality() == binaryG.Dimensionality()); // First, check the means. CheckMatrices(g.Mean(), xmlG.Mean(), textG.Mean(), binaryG.Mean()); @@ -1088,18 +1106,21 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) if (prob == 0.0) { - BOOST_REQUIRE_SMALL(xmlG.Probability(randomObs.unsafe_col(i)), 1e-8); - BOOST_REQUIRE_SMALL(textG.Probability(randomObs.unsafe_col(i)), 1e-8); - BOOST_REQUIRE_SMALL(binaryG.Probability(randomObs.unsafe_col(i)), 1e-8); + REQUIRE(xmlG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); + REQUIRE(textG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); + REQUIRE(binaryG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(prob, xmlG.Probability(randomObs.unsafe_col(i)), - 1e-8); - BOOST_REQUIRE_CLOSE(prob, textG.Probability(randomObs.unsafe_col(i)), - 1e-8); - BOOST_REQUIRE_CLOSE(prob, binaryG.Probability(randomObs.unsafe_col(i)), - 1e-8); + REQUIRE(prob == + Approx(xmlG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + REQUIRE(prob == + Approx(textG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + REQUIRE(prob == + Approx(binaryG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); } } } @@ -1107,7 +1128,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) /** * Laplace Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) +TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") { arma::vec mean(20); mean.randu(); @@ -1117,9 +1138,9 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) SerializeObjectAll(l, xmlL, textL, binaryL); - BOOST_REQUIRE_CLOSE(l.Scale(), xmlL.Scale(), 1e-8); - BOOST_REQUIRE_CLOSE(l.Scale(), textL.Scale(), 1e-8); - BOOST_REQUIRE_CLOSE(l.Scale(), binaryL.Scale(), 1e-8); + REQUIRE(l.Scale() == Approx(xmlL.Scale()).epsilon(1e-10)); + REQUIRE(l.Scale() == Approx(textL.Scale()).epsilon(1e-10)); + REQUIRE(l.Scale() == Approx(binaryL.Scale()).epsilon(1e-10)); CheckMatrices(l.Mean(), xmlL.Mean(), textL.Mean(), binaryL.Mean()); } @@ -1127,15 +1148,15 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) /** * Laplace Distribution Probability Test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) +TEST_CASE("LaplaceDistributionProbabilityTest", "[DistributionTest]") { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("0.0")), - 0.500000000000000, 1e-5); - BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("1.0")), - 0.183939720585721, 1e-5); + REQUIRE(l.Probability(arma::vec("0.0")) == + Approx(0.500000000000000).epsilon(1e-7)); + REQUIRE(l.Probability(arma::vec("1.0")) == + Approx(0.183939720585721).epsilon(1e-7)); arma::mat points = "0.0 1.0;"; @@ -1143,24 +1164,24 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) l.Probability(points, probabilities); - BOOST_REQUIRE_EQUAL(probabilities.n_elem, 2); + REQUIRE(probabilities.n_elem == 2); - BOOST_REQUIRE_CLOSE(probabilities(0), 0.500000000000000, 1e-5); - BOOST_REQUIRE_CLOSE(probabilities(1), 0.183939720585721, 1e-5); + REQUIRE(probabilities(0) == Approx(0.500000000000000).epsilon(1e-7)); + REQUIRE(probabilities(1) == Approx(0.183939720585721).epsilon(1e-7)); } /** * Laplace Distribution Log Probability Test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) +TEST_CASE("LaplaceDistributionLogProbabilityTest", "[DistributionTest]") { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("0.0")), - -0.693147180559945, 1e-5); - BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("1.0")), - -1.693147180559946, 1e-5); + REQUIRE(l.LogProbability(arma::vec("0.0")) == + Approx(-0.693147180559945).epsilon(1e-7)); + REQUIRE(l.LogProbability(arma::vec("1.0")) == + Approx(-1.693147180559946).epsilon(1e-7)); arma::mat points = "0.0 1.0;"; @@ -1168,18 +1189,19 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) l.LogProbability(points, logProbabilities); - BOOST_REQUIRE_EQUAL(logProbabilities.n_elem, 2); + REQUIRE(logProbabilities.n_elem == 2); - BOOST_REQUIRE_CLOSE(logProbabilities(0), -0.693147180559945, - 1e-5); - BOOST_REQUIRE_CLOSE(logProbabilities(1), -1.693147180559946, - 1e-5); + REQUIRE(logProbabilities(0) == + Approx(-0.693147180559945).epsilon(1e-7)); + + REQUIRE(logProbabilities(1) == + Approx(-1.693147180559946).epsilon(1e-7)); } /** * Mahalanobis Distance serialization test. */ -BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) +TEST_CASE("MahalanobisDistanceTest", "[DistributionTest]") { MahalanobisDistance<> d; d.Covariance().randu(50, 50); @@ -1198,7 +1220,7 @@ BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) /** * Regression distribution serialization test. */ -BOOST_AUTO_TEST_CASE(RegressionDistributionTest) +TEST_CASE("RegressionDistributionTest", "[DistributionTest]") { // Generate some random data. arma::mat data; @@ -1225,15 +1247,15 @@ BOOST_AUTO_TEST_CASE(RegressionDistributionTest) // Check the regression function. if (rd.Rf().Lambda() == 0.0) { - BOOST_REQUIRE_SMALL(xmlRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_SMALL(textRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_SMALL(binaryRd.Rf().Lambda(), 1e-8); + REQUIRE(xmlRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + REQUIRE(textRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + REQUIRE(binaryRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), xmlRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), textRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), binaryRd.Rf().Lambda(), 1e-8); + REQUIRE(rd.Rf().Lambda() == Approx(xmlRd.Rf().Lambda()).epsilon(1e-10)); + REQUIRE(rd.Rf().Lambda() == Approx(textRd.Rf().Lambda()).epsilon(1e-10)); + REQUIRE(rd.Rf().Lambda() == Approx(binaryRd.Rf().Lambda()).epsilon(1e-10)); } CheckMatrices(rd.Rf().Parameters(), @@ -1250,31 +1272,32 @@ BOOST_AUTO_TEST_CASE(RegressionDistributionTest) * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionEmptyConstructor) +TEST_CASE("DiagonalGaussianDistributionEmptyConstructor", "[DistributionTest]") { DiagonalGaussianDistribution d; - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); + REQUIRE(d.Mean().n_elem == 0); + REQUIRE(d.Covariance().n_elem == 0); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized to * the correct dimensionality. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionDimensionalityConstructor) +TEST_CASE("DiagonalGaussianDistributionDimensionalityConstructor", + "[DistributionTest]") { DiagonalGaussianDistribution d(4); - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 4); + REQUIRE(d.Mean().n_elem == 4); + REQUIRE(d.Covariance().n_elem == 4); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly when we give a mean and covariance. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) +TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") { arma::vec mean = arma::randu(3); arma::vec covariance = arma::randu(3); @@ -1284,8 +1307,8 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) // Make sure the mean and covariance is correct. for (size_t i = 0; i < 3; ++i) { - BOOST_REQUIRE_CLOSE(d.Mean()(i), mean(i), 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(i), covariance(i), 1e-5); + REQUIRE(d.Mean()(i) == Approx(mean(i)).epsilon(1e-7)); + REQUIRE(d.Covariance()(i) == Approx(covariance(i)).epsilon(1e-7)); } } @@ -1293,7 +1316,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) * Make sure the probability of observations is correct. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) +TEST_CASE("DiagonalGaussianDistributionProbabilityTest", "[DistributionTest]") { arma::vec mean("2 5 3 4 1"); arma::vec cov("3 1 5 3 2"); @@ -1301,56 +1324,56 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) DiagonalGaussianDistribution d(mean, cov); // Observations lists randomly selected. - BOOST_REQUIRE_CLOSE(d.LogProbability("3 5 2 7 8"), -20.861264167855161, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("7 8 4 0 5"), -22.277930834521829, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("6 8 7 7 5"), -21.111264167855161, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 9 5 6 3"), -16.911264167855162, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("5 8 2 9 7"), -26.111264167855161, - 1e-5); + REQUIRE(d.LogProbability("3 5 2 7 8") == + Approx(-20.861264167855161).epsilon(1e-7)); + REQUIRE(d.LogProbability("7 8 4 0 5") == + Approx(-22.277930834521829).epsilon(1e-7)); + REQUIRE(d.LogProbability("6 8 7 7 5") == + Approx(-21.111264167855161).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 9 5 6 3") == + Approx(-16.9112641678551621).epsilon(1e-7)); + REQUIRE(d.LogProbability("5 8 2 9 7") == + Approx(-26.111264167855161).epsilon(1e-7)); } /** * Test DiagonalGaussianDistribution::Probability() in the univariate case. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianUnivariateProbabilityTest) +TEST_CASE("DiagonalGaussianUnivariateProbabilityTest", "[DistributionTest]") { DiagonalGaussianDistribution d(arma::vec("0.0"), arma::vec("1.0")); // Mean: 0.0, Covariance: 1.0 - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.3989422804014327, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.24197072451914337, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.24197072451914337, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.3989422804014327).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.24197072451914337).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.24197072451914337).epsilon(1e-7)); // Mean: 0.0, Covariance: 2.0 d.Covariance("2.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.28209479177387814, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.21969564473386122, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.21969564473386122, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.28209479177387814).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.21969564473386122).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.21969564473386122).epsilon(1e-7)); // Mean: 1.0, Covariance: 1.0 d.Mean() = "1.0"; d.Covariance("1.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.24197072451914337, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.3989422804014327, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.053990966513188056, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.24197072451914337).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.3989422804014327).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.053990966513188056).epsilon(1e-7)); // Mean: 1.0, Covariance: 2.0 d.Covariance("2.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.21969564473386122, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.28209479177387814, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.10377687435514872, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.21969564473386122).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.28209479177387814).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.10377687435514872).epsilon(1e-7)); } /** * Test DiagonalGaussianDistribution::Probability() in the multivariate case. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) +TEST_CASE("DiagonalGaussianMultivariateProbabilityTest", "[DistributionTest]") { arma::vec mean("0 0"); arma::vec cov("2 2"); @@ -1358,27 +1381,28 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) DiagonalGaussianDistribution d(mean, cov); - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.079577471545947673, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.079577471545947673).epsilon(1e-7)); obs = "1 1"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.048266176315026957, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.048266176315026957).epsilon(1e-7)); d.Mean() = "1 3"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.029274915762159581, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability(-obs), 0.00053618878559782773, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.029274915762159581).epsilon(1e-7)); + REQUIRE(d.Probability(-obs) == Approx(0.00053618878559782773).epsilon(1e-7)); // Higher dimensional case. d.Mean() = "1 3 6 2 7"; d.Covariance("3 1 5 3 2"); obs = "2 5 7 3 8"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 7.2790083003378082e-05, 1e-5); + REQUIRE(d.Probability(obs) == Approx(7.2790083003378082e-05).epsilon(1e-7)); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) +TEST_CASE("DiagonalGaussianMultipointMultivariateProbabilityTest", + "[DistributionTest]") { arma::vec mean = "2 5 3 7 2"; arma::vec cov("9 2 1 4 8"); @@ -1391,20 +1415,20 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) DiagonalGaussianDistribution d(mean, cov); d.LogProbability(points, phis); - BOOST_REQUIRE_EQUAL(phis.n_elem, 6); + REQUIRE(phis.n_elem == 6); - BOOST_REQUIRE_CLOSE(phis(0), -12.453302051926864, 1e-5); - BOOST_REQUIRE_CLOSE(phis(1), -10.147746496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(2), -13.210246496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(3), -19.724135385260197, 1e-5); - BOOST_REQUIRE_CLOSE(phis(4), -21.585246496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(5), -13.647746496371308, 1e-5); + REQUIRE(phis(0) == Approx(-12.453302051926864).epsilon(1e-7)); + REQUIRE(phis(1) == Approx(-10.147746496371308).epsilon(1e-7)); + REQUIRE(phis(2) == Approx(-13.210246496371308).epsilon(1e-7)); + REQUIRE(phis(3) == Approx(-19.724135385260197).epsilon(1e-7)); + REQUIRE(phis(4) == Approx(-21.585246496371308).epsilon(1e-7)); + REQUIRE(phis(5) == Approx(-13.647746496371308).epsilon(1e-7)); } /** * Make sure random observations follow the probability distribution correctly. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) +TEST_CASE("DiagonalGaussianDistributionRandomTest", "[DistributionTest]") { arma::vec mean("2.5 1.25"); arma::vec cov("0.50 0.25"); @@ -1421,17 +1445,17 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - BOOST_REQUIRE_CLOSE(obsMean(0), mean(0), 10.0); - BOOST_REQUIRE_CLOSE(obsMean(1), mean(1), 10.0); + REQUIRE(obsMean(0) == Approx(mean(0)).epsilon(0.1)); + REQUIRE(obsMean(1) == Approx(mean(1)).epsilon(0.1)); - BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0), 10); - BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1), 10); + REQUIRE(obsCov(0, 0) == Approx(cov(0)).epsilon(0.1)); + REQUIRE(obsCov(1, 1) == Approx(cov(1)).epsilon(0.1)); } /** * Make sure that we can properly estimate from given observations. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) +TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1454,8 +1478,8 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) // Check that the estimated parameters are right. for (size_t i = 0; i < 4; ++i) { - BOOST_REQUIRE_SMALL(d.Mean()(i) - actualMean(i), 1e-5); - BOOST_REQUIRE_SMALL(d.Covariance()(i) - actualCov(i, i), 1e-5); + REQUIRE(d.Mean()(i) - actualMean(i) == Approx(0.0).margin(1e-5)); + REQUIRE(d.Covariance()(i) - actualCov(i, i) == Approx(0.0).margin(1e-5)); } } @@ -1463,7 +1487,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) * Make sure the unbiased estimator of the weighted sample works correctly. * The values were calculated using 'cov.wt' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) +TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") { // Generate the observations. arma::mat observations("3 5 2 7;" @@ -1478,15 +1502,15 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) // Estimate the parameters. d.Train(observations, probs); - BOOST_REQUIRE_CLOSE(d.Mean()(0), 4.5, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(1), 4.4, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(2), 3.5, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(3), 6.8, 1e-5); + REQUIRE(d.Mean()(0) == Approx(4.5).epsilon(1e-7)); + REQUIRE(d.Mean()(1) == Approx(4.4).epsilon(1e-7)); + REQUIRE(d.Mean()(2) == Approx(3.5).epsilon(1e-7)); + REQUIRE(d.Mean()(3) == Approx(6.8).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(d.Covariance()(0), 3.78571428571428603, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(1), 6.34285714285714253, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(2), 6.64285714285714235, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(3), 2.22857142857142865, 1e-5); + REQUIRE(d.Covariance()(0) == Approx(3.78571428571428603).epsilon(1e-7)); + REQUIRE(d.Covariance()(1) == Approx(6.34285714285714253).epsilon(1e-7)); + REQUIRE(d.Covariance()(2) == Approx(6.64285714285714235).epsilon(1e-7)); + REQUIRE(d.Covariance()(3) == Approx(2.22857142857142865).epsilon(1e-7)); } /** @@ -1494,7 +1518,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) * the weighted mean and covariance reduce to the unweighted sample mean and * covariance. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) +TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1516,9 +1540,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) // Check if these are equal. for (size_t i = 0; i < 4; ++i) { - BOOST_REQUIRE_CLOSE(d1.Mean()(i), d2.Mean()(i), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Covariance()(i), d2.Covariance()(i), 1e-5); + REQUIRE(d1.Mean()(i) == Approx(d2.Mean()(i)).epsilon(1e-7)); + REQUIRE(d1.Covariance()(i) == Approx(d2.Covariance()(i)).epsilon(1e-7)); } } - -BOOST_AUTO_TEST_SUITE_END(); From 7f8fe869a553378cc2e8a39f12cdf0a52d94c5f7 Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Sun, 4 Oct 2020 11:41:11 +0530 Subject: [PATCH 16/45] Migrate layers_names, line_alg and lars test to catch2 --- src/mlpack/tests/CMakeLists.txt | 7 +- src/mlpack/tests/lars_test.cpp | 92 +++++++++++++-------------- src/mlpack/tests/layer_names_test.cpp | 73 ++++++++++----------- src/mlpack/tests/lin_alg_test.cpp | 79 ++++++++++++----------- 4 files changed, 121 insertions(+), 130 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index bf68f3c64b..d8bc3dc9e6 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -24,9 +24,6 @@ add_executable(mlpack_test kde_test.cpp krann_search_test.cpp ksinit_test.cpp - lars_test.cpp - layer_names_test.cpp - lin_alg_test.cpp linear_svm_test.cpp lmnn_test.cpp local_coordinate_coding_test.cpp @@ -131,6 +128,9 @@ add_executable(mlpack_catch_test kfn_test.cpp kmeans_test.cpp knn_test.cpp + lars_test.cpp + layer_names_test.cpp + lin_alg_test.cpp linear_regression_test.cpp load_save_test.cpp loss_functions_test.cpp @@ -232,7 +232,6 @@ set(parallel_tests "GMMTest;" "CFTest;" "HMMTest;" - "LARSTest;" "LogisticRegressionTest;" "GmmTrainMainTest;" "LinearSVMTest") diff --git a/src/mlpack/tests/lars_test.cpp b/src/mlpack/tests/lars_test.cpp index cbbe5687a3..4a525fad4b 100644 --- a/src/mlpack/tests/lars_test.cpp +++ b/src/mlpack/tests/lars_test.cpp @@ -10,19 +10,15 @@ * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ -// Note: We don't use BOOST_REQUIRE_CLOSE in the code below because we need -// to use FPC_WEAK, and it's not at all intuitive how to do that. #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::regression; -BOOST_AUTO_TEST_SUITE(LARSTest); - void GenerateProblem( arma::mat& X, arma::rowvec& y, size_t nPoints, size_t nDims) { @@ -40,17 +36,17 @@ void LARSVerifyCorrectness(arma::vec beta, arma::vec errCorr, double lambda) if (beta(j) == 0) { // Make sure that |errCorr(j)| <= lambda. - BOOST_REQUIRE_SMALL(std::max(fabs(errCorr(j)) - lambda, 0.0), tol); + REQUIRE(std::max(fabs(errCorr(j)) - lambda, 0.0) == Approx(0.0).margin(tol)); } else if (beta(j) < 0) { // Make sure that errCorr(j) == lambda. - BOOST_REQUIRE_SMALL(errCorr(j) - lambda, tol); + REQUIRE(errCorr(j) - lambda == Approx(0.0).margin(tol)); } else // beta(j) > 0 { // Make sure that errCorr(j) == -lambda. - BOOST_REQUIRE_SMALL(errCorr(j) + lambda, tol); + REQUIRE(errCorr(j) + lambda == Approx(0.0).margin(tol)); } } } @@ -85,23 +81,23 @@ void LassoTest(size_t nPoints, size_t nDims, bool elasticNet, bool useCholesky) } } -BOOST_AUTO_TEST_CASE(LARSTestLassoCholesky) +TEST_CASE("LARSTestLassoCholesky", "[LARSTest]") { LassoTest(100, 10, false, true); } -BOOST_AUTO_TEST_CASE(LARSTestLassoGram) +TEST_CASE("LARSTestLassoGram", "[LARSTest]") { LassoTest(100, 10, false, false); } -BOOST_AUTO_TEST_CASE(LARSTestElasticNetCholesky) +TEST_CASE("LARSTestElasticNetCholesky", "[LARSTest]") { LassoTest(100, 10, true, true); } -BOOST_AUTO_TEST_CASE(LARSTestElasticNetGram) +TEST_CASE("LARSTestElasticNetGram", "[LARSTest]") { LassoTest(100, 10, true, false); } @@ -109,7 +105,7 @@ BOOST_AUTO_TEST_CASE(LARSTestElasticNetGram) // Ensure that LARS doesn't crash when the data has linearly dependent features // (meaning that there is a singularity). This test uses the Cholesky // factorization. -BOOST_AUTO_TEST_CASE(CholeskySingularityTest) +TEST_CASE("CholeskySingularityTest", "[LARSTest]") { arma::mat X; arma::mat Y; @@ -133,7 +129,7 @@ BOOST_AUTO_TEST_CASE(CholeskySingularityTest) } // Same as the above test but with no cholesky factorization. -BOOST_AUTO_TEST_CASE(NoCholeskySingularityTest) +TEST_CASE("NoCholeskySingularityTest", "[LARSTest]") { arma::mat X; arma::mat Y; @@ -158,7 +154,7 @@ BOOST_AUTO_TEST_CASE(NoCholeskySingularityTest) } // Make sure that Predict() provides reasonable enough solutions. -BOOST_AUTO_TEST_CASE(PredictTest) +TEST_CASE("PredictTest", "[LARSTest]") { for (size_t i = 0; i < 2; ++i) { @@ -185,20 +181,20 @@ BOOST_AUTO_TEST_CASE(PredictTest) lars.Predict(X, predictions); arma::vec adjPred = X * predictions.t(); - BOOST_REQUIRE_EQUAL(predictions.n_elem, 1000); + REQUIRE(predictions.n_elem == 1000); for (size_t i = 0; i < betaOptPred.n_elem; ++i) { if (std::abs(betaOptPred[i]) < 1e-5) - BOOST_REQUIRE_SMALL(adjPred[i], 1e-5); + REQUIRE(adjPred[i] == Approx(0.0).margin(1e-5)); else - BOOST_REQUIRE_CLOSE(adjPred[i], betaOptPred[i], 1e-5); + REQUIRE(adjPred[i] == Approx( betaOptPred[i]).epsilon(1e-7)); } } } } } -BOOST_AUTO_TEST_CASE(PredictRowMajorTest) +TEST_CASE("PredictRowMajorTest", "[LARSTest]") { arma::mat X; arma::rowvec y; @@ -217,20 +213,20 @@ BOOST_AUTO_TEST_CASE(PredictRowMajorTest) lars.Predict(X, colMajorPred); lars.Predict(X.t(), rowMajorPred, true); - BOOST_REQUIRE_EQUAL(colMajorPred.n_elem, rowMajorPred.n_elem); + REQUIRE(colMajorPred.n_elem == rowMajorPred.n_elem); for (size_t i = 0; i < colMajorPred.n_elem; ++i) { if (std::abs(colMajorPred[i]) < 1e-5) - BOOST_REQUIRE_SMALL(rowMajorPred[i], 1e-5); + REQUIRE(rowMajorPred[i] == Approx(0.0).margin(1e-5)); else - BOOST_REQUIRE_CLOSE(colMajorPred[i], rowMajorPred[i], 1e-5); + REQUIRE(colMajorPred[i] == Approx( rowMajorPred[i]).epsilon(1e-7)); } } /** * Make sure that if we train twice, there is no issue. */ -BOOST_AUTO_TEST_CASE(RetrainTest) +TEST_CASE("RetrainTest", "[LARSTest]") { arma::mat origX; arma::rowvec origY; @@ -257,7 +253,7 @@ BOOST_AUTO_TEST_CASE(RetrainTest) * Make sure if we train twice using the Cholesky decomposition, there is no * issue. */ -BOOST_AUTO_TEST_CASE(RetrainCholeskyTest) +TEST_CASE("RetrainCholeskyTest", "[LARSTest]") { arma::mat origX; arma::rowvec origY; @@ -284,7 +280,7 @@ BOOST_AUTO_TEST_CASE(RetrainCholeskyTest) * Make sure that we get correct solution coefficients when running training * and accessing solution coefficients separately. */ -BOOST_AUTO_TEST_CASE(TrainingAndAccessingBetaTest) +TEST_CASE("TrainingAndAccessingBetaTest", "[LARSTest]") { arma::mat X; arma::rowvec y; @@ -298,16 +294,16 @@ BOOST_AUTO_TEST_CASE(TrainingAndAccessingBetaTest) LARS lars2; lars2.Train(X, y); - BOOST_REQUIRE_EQUAL(beta.n_elem, lars2.Beta().n_elem); + REQUIRE(beta.n_elem == lars2.Beta().n_elem); for (size_t i = 0; i < beta.n_elem; ++i) - BOOST_REQUIRE_CLOSE(beta[i], lars2.Beta()[i], 1e-5); + REQUIRE(beta[i] == Approx( lars2.Beta()[i]).epsilon(1e-7)); } /** * Make sure that we learn the same when running training separately and through * constructor. Test it with default parameters. */ -BOOST_AUTO_TEST_CASE(TrainingConstructorWithDefaultsTest) +TEST_CASE("TrainingConstructorWithDefaultsTest", "[LARSTest]") { arma::mat X; arma::rowvec y; @@ -320,16 +316,16 @@ BOOST_AUTO_TEST_CASE(TrainingConstructorWithDefaultsTest) LARS lars2(X, y); - BOOST_REQUIRE_EQUAL(beta.n_elem, lars2.Beta().n_elem); + REQUIRE(beta.n_elem == lars2.Beta().n_elem); for (size_t i = 0; i < beta.n_elem; ++i) - BOOST_REQUIRE_CLOSE(beta[i], lars2.Beta()[i], 1e-5); + REQUIRE(beta[i] == Approx( lars2.Beta()[i]).epsilon(1e-7)); } /** * Make sure that we learn the same when running training separately and through * constructor. Test it with non default parameters. */ -BOOST_AUTO_TEST_CASE(TrainingConstructorWithNonDefaultsTest) +TEST_CASE("TrainingConstructorWithNonDefaultsTest", "[LARSTest]") { arma::mat X; arma::rowvec y; @@ -347,15 +343,15 @@ BOOST_AUTO_TEST_CASE(TrainingConstructorWithNonDefaultsTest) LARS lars2(X, y, transposeData, useCholesky, lambda1, lambda2); - BOOST_REQUIRE_EQUAL(beta.n_elem, lars2.Beta().n_elem); + REQUIRE(beta.n_elem == lars2.Beta().n_elem); for (size_t i = 0; i < beta.n_elem; ++i) - BOOST_REQUIRE_CLOSE(beta[i], lars2.Beta()[i], 1e-5); + REQUIRE(beta[i] == Approx( lars2.Beta()[i]).epsilon(1e-7)); } /** * Test that LARS::Train() returns finite error value. */ -BOOST_AUTO_TEST_CASE(LARSTrainReturnCorrelation) +TEST_CASE("LARSTrainReturnCorrelation", "[LARSTest]") { arma::mat X; arma::mat Y; @@ -373,35 +369,35 @@ BOOST_AUTO_TEST_CASE(LARSTrainReturnCorrelation) arma::vec betaOpt1; double error = lars1.Train(X, y, betaOpt1); - BOOST_REQUIRE_EQUAL(std::isfinite(error), true); + REQUIRE(std::isfinite(error) == true); // Test without Cholesky decomposition and with lasso. LARS lars2(false, lambda1, 0.0); arma::vec betaOpt2; error = lars2.Train(X, y, betaOpt2); - BOOST_REQUIRE_EQUAL(std::isfinite(error), true); + REQUIRE(std::isfinite(error) == true); // Test with Cholesky decomposition and with elasticnet. LARS lars3(true, lambda1, lambda2); arma::vec betaOpt3; error = lars3.Train(X, y, betaOpt3); - BOOST_REQUIRE_EQUAL(std::isfinite(error), true); + REQUIRE(std::isfinite(error) == true); // Test without Cholesky decomposition and with elasticnet. LARS lars4(false, lambda1, lambda2); arma::vec betaOpt4; error = lars4.Train(X, y, betaOpt4); - BOOST_REQUIRE_EQUAL(std::isfinite(error), true); + REQUIRE(std::isfinite(error) == true); } /** * Test that LARS::ComputeError() returns error value less than 1 * and greater than 0. */ -BOOST_AUTO_TEST_CASE(LARSTestComputeError) +TEST_CASE("LARSTestComputeError", "[LARSTest]") { arma::mat X; arma::mat Y; @@ -416,15 +412,15 @@ BOOST_AUTO_TEST_CASE(LARSTestComputeError) double train1 = lars1.Train(X, y, betaOpt1); double cost = lars1.ComputeError(X, y); - BOOST_REQUIRE_EQUAL(cost <= 1, true); - BOOST_REQUIRE_EQUAL(cost >= 0, true); - BOOST_REQUIRE_EQUAL(cost == train1, true); + REQUIRE(cost <= 1); + REQUIRE(cost >= 0); + REQUIRE(cost == train1); } /** * Simple test for LARS copy constructor. */ -BOOST_AUTO_TEST_CASE(LARSCopyConstructorTest) +TEST_CASE("LARSCopyConstructorTest", "[LARSTest]") { arma::mat features, Y; arma::rowvec targets; @@ -447,13 +443,13 @@ BOOST_AUTO_TEST_CASE(LARSCopyConstructorTest) // The output of both models should be the same. CheckMatrices(predictions, predictionsFromCopiedModel); // Check if we can train the model again. - BOOST_REQUIRE_NO_THROW(models[0].Train(features, targets)); + REQUIRE_NOTHROW(models[0].Train(features, targets)); // Check if we can train the copied model. mlpack::regression::LARS glm2(false, 0.1, 0.1); models.emplace_back(glm2); // Call the copy constructor. - BOOST_REQUIRE_NO_THROW(glm2.Train(features, targets)); - BOOST_REQUIRE_NO_THROW(models[1].Train(features, targets)); + REQUIRE_NOTHROW(glm2.Train(features, targets)); + REQUIRE_NOTHROW(models[1].Train(features, targets)); // Create a copy using assignment operator. mlpack::regression::LARS glm3 = glm2; @@ -462,5 +458,3 @@ BOOST_AUTO_TEST_CASE(LARSCopyConstructorTest) // The output of both models should be the same. CheckMatrices(predictions, predictionsFromCopiedModel); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/layer_names_test.cpp b/src/mlpack/tests/layer_names_test.cpp index 23722e2b75..7cec416479 100644 --- a/src/mlpack/tests/layer_names_test.cpp +++ b/src/mlpack/tests/layer_names_test.cpp @@ -15,18 +15,15 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" using namespace mlpack; using namespace ann; -BOOST_AUTO_TEST_SUITE(LayerNamesTest); - /** * Test if the LayerNameVisitor works properly. */ -BOOST_AUTO_TEST_CASE(LayerNameVisitorTest) +TEST_CASE("LayerNameVisitorTest", "[LayerNamesTest]") { LayerTypes<> atrousConvolution = new AtrousConvolution<>(); LayerTypes<> alphaDropout = new AlphaDropout<>(); @@ -63,69 +60,69 @@ BOOST_AUTO_TEST_CASE(LayerNameVisitorTest) // Bilinear interpolation is not yet supported by the string converter. LayerTypes<> unsupportedLayer = new BilinearInterpolation<>(); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), atrousConvolution) == "atrousconvolution"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), alphaDropout) == "alphadropout"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), batchNorm) == "batchnorm"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), constant) == "constant"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), convolution) == "convolution"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), dropConnect) == "dropconnect"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), dropout) == "dropout"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), flexibleReLU) == "flexiblerelu"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), layerNorm) == "layernorm"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), linear) == "linear"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), linearNoBias) == "linearnobias"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), maxPooling) == "maxpooling"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), meanPooling) == "meanpooling"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), multiplyConstant) == "multiplyconstant"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), reLULayer) == "relu"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), transposedConvolution) == "transposedconvolution"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), identityLayer) == "identity"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), tanHLayer) == "tanh"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), eLU) == "elu"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), hardTanH) == "hardtanh"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), leakyReLU) == "leakyrelu"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), pReLU) == "prelu"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), sigmoidLayer) == "sigmoid"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), logSoftMax) == "logsoftmax"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), unsupportedLayer) == "unsupported"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), lstmLayer) == "lstm"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), creluLayer) == "crelu"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), highwayLayer) == "highway"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), gruLayer) == "gru"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), glimpseLayer) == "glimpse"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), fastlstmLayer) == "fastlstm"); - BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(), + REQUIRE(boost::apply_visitor(LayerNameVisitor(), weightnormLayer) == "weightnorm"); // Delete all instances. boost::apply_visitor(DeleteVisitor(), atrousConvolution); @@ -161,5 +158,3 @@ BOOST_AUTO_TEST_CASE(LayerNameVisitorTest) boost::apply_visitor(DeleteVisitor(), fastlstmLayer); boost::apply_visitor(DeleteVisitor(), weightnormLayer); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index 47a4448804..1ed30a60f0 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -14,20 +14,18 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace arma; using namespace mlpack; using namespace mlpack::math; -BOOST_AUTO_TEST_SUITE(LinAlgTest); - /** * Test for linalg__private::Center(). There are no edge cases here, so we'll * just try it once for now. */ -BOOST_AUTO_TEST_CASE(TestCenterA) +TEST_CASE("TestCenterA", "[LinAlgTest]") { mat tmp(5, 5); // [[0 0 0 0 0] @@ -52,10 +50,13 @@ BOOST_AUTO_TEST_CASE(TestCenterA) // [-8 -4 0 4 8]] for (int row = 0; row < 5; row++) for (int col = 0; col < 5; col++) - BOOST_REQUIRE_CLOSE(tmp_out(row, col), (double) (col - 2) * row, 1e-5); + { + REQUIRE(tmp_out(row, col) == + Approx((double) (col - 2) * row).epsilon(1e-7)); + } } -BOOST_AUTO_TEST_CASE(TestCenterB) +TEST_CASE("TestCenterB", "[LinAlgTest]") { mat tmp(5, 6); for (int row = 0; row < 5; row++) @@ -75,10 +76,13 @@ BOOST_AUTO_TEST_CASE(TestCenterB) // [-10 -6 -2 2 6 10 ]] for (int row = 0; row < 5; row++) for (int col = 0; col < 6; col++) - BOOST_REQUIRE_CLOSE(tmp_out(row, col), (double) (col - 2.5) * row, 1e-5); + { + REQUIRE(tmp_out(row, col) == + Approx((double) (col - 2.5) * row).epsilon(1e-7)); + } } -BOOST_AUTO_TEST_CASE(TestOrthogonalize) +TEST_CASE("TestOrthogonalize", "[LinAlgTest]") { // Generate a random matrix; then, orthogonalize it and test if it's // orthogonal. @@ -96,18 +100,18 @@ BOOST_AUTO_TEST_CASE(TestOrthogonalize) if (row == col) { if (std::abs(test(row, col)) > 1e-10) - BOOST_REQUIRE_CLOSE(test(row, col), ival, 1e-10); + REQUIRE(test(row, col) == Approx(ival).epsilon(1e-11)); } else { - BOOST_REQUIRE_SMALL(test(row, col), 1e-10); + REQUIRE(test(row, col) == Approx(0.0).margin(1e-10)); } } } } // Test RemoveRows(). -BOOST_AUTO_TEST_CASE(TestRemoveRows) +TEST_CASE("TestRemoveRows", "[LinAlgTest]") { // Run this test several times. for (size_t run = 0; run < 10; ++run) @@ -150,7 +154,7 @@ BOOST_AUTO_TEST_CASE(TestRemoveRows) else { // Compare. - BOOST_REQUIRE_EQUAL(accu(input.row(row) == output.row(outputRow)), 200); + REQUIRE(accu(input.row(row) == output.row(outputRow)) == 200); // Increment output row counter. ++outputRow; @@ -159,7 +163,7 @@ BOOST_AUTO_TEST_CASE(TestRemoveRows) } } -BOOST_AUTO_TEST_CASE(TestSvecSmat) +TEST_CASE("TestSvecSmat", "[LinAlgTest]") { arma::mat X(3, 3); X(0, 0) = 0; X(0, 1) = 1, X(0, 2) = 2; @@ -168,23 +172,24 @@ BOOST_AUTO_TEST_CASE(TestSvecSmat) arma::vec sx; Svec(X, sx); - BOOST_REQUIRE_CLOSE(sx(0), 0, 1e-7); - BOOST_REQUIRE_CLOSE(sx(1), M_SQRT2 * 1., 1e-7); - BOOST_REQUIRE_CLOSE(sx(2), M_SQRT2 * 2., 1e-7); - BOOST_REQUIRE_CLOSE(sx(3), 3., 1e-7); - BOOST_REQUIRE_CLOSE(sx(4), M_SQRT2 * 4., 1e-7); - BOOST_REQUIRE_CLOSE(sx(5), 5., 1e-7); + REQUIRE(sx(0) == Approx(0).epsilon(1e-9)); + REQUIRE(sx(1) == Approx(M_SQRT2 * 1.).epsilon(1e-9)); + REQUIRE(sx(2) == Approx(M_SQRT2 * 2.).epsilon(1e-9)); + REQUIRE(sx(3) == Approx(3.).epsilon(1e-9)); + REQUIRE(sx(4) == Approx(M_SQRT2 * 4.).epsilon(1e-9)); + REQUIRE(sx(5) == Approx(5.).epsilon(1e-9)); arma::mat Xtest; Smat(sx, Xtest); - BOOST_REQUIRE_EQUAL(Xtest.n_rows, 3); - BOOST_REQUIRE_EQUAL(Xtest.n_cols, 3); + REQUIRE(Xtest.n_rows == 3); + REQUIRE(Xtest.n_cols == 3); for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) - BOOST_REQUIRE_CLOSE(X(i, j), Xtest(i, j), 1e-7); + REQUIRE(X(i, j) == Approx(Xtest(i, j)).epsilon(1e-9)); + } -BOOST_AUTO_TEST_CASE(TestSparseSvec) +TEST_CASE("TestSparseSvec", "[LinAlgTest]") { arma::sp_mat X; X.zeros(3, 3); @@ -200,15 +205,15 @@ BOOST_AUTO_TEST_CASE(TestSparseSvec) const double v4 = sx(4); const double v5 = sx(5); - BOOST_REQUIRE_CLOSE(v0, 0, 1e-7); - BOOST_REQUIRE_CLOSE(v1, M_SQRT2 * 1., 1e-7); - BOOST_REQUIRE_CLOSE(v2, 0, 1e-7); - BOOST_REQUIRE_CLOSE(v3, 0, 1e-7); - BOOST_REQUIRE_CLOSE(v4, 0, 1e-7); - BOOST_REQUIRE_CLOSE(v5, 0, 1e-7); + REQUIRE(v0 == Approx(0).epsilon(1e-9)); + REQUIRE(v1 == Approx(M_SQRT2 * 1.).epsilon(1e-9)); + REQUIRE(v2 == Approx(0).epsilon(1e-9)); + REQUIRE(v3 == Approx(0).epsilon(1e-9)); + REQUIRE(v4 == Approx(0).epsilon(1e-9)); + REQUIRE(v5 == Approx(0).epsilon(1e-9)); } -BOOST_AUTO_TEST_CASE(TestSymKronIdSimple) +TEST_CASE("TestSymKronIdSimple", "[LinAlgTest]") { arma::mat A(3, 3); A(0, 0) = 1; A(0, 1) = 2, A(0, 2) = 3; @@ -226,12 +231,12 @@ BOOST_AUTO_TEST_CASE(TestSymKronIdSimple) arma::vec rhs; Svec(Rhs, rhs); - BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem); + REQUIRE(lhs.n_elem == rhs.n_elem); for (size_t j = 0; j < lhs.n_elem; ++j) - BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5); + REQUIRE(lhs(j) == Approx(rhs(j)).epsilon(1e-7)); } -BOOST_AUTO_TEST_CASE(TestSymKronId) +TEST_CASE("TestSymKronId", "[LinAlgTest]") { const size_t n = 10; arma::mat A = arma::randu(n, n); @@ -252,10 +257,8 @@ BOOST_AUTO_TEST_CASE(TestSymKronId) arma::vec rhs; Svec(Rhs, rhs); - BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem); + REQUIRE(lhs.n_elem == rhs.n_elem); for (size_t j = 0; j < lhs.n_elem; ++j) - BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5); + REQUIRE(lhs(j) == Approx(rhs(j)).epsilon(1e-7)); } } - -BOOST_AUTO_TEST_SUITE_END(); From ae884356b6618599d6c82fe5fc67a39d8b5295d1 Mon Sep 17 00:00:00 2001 From: Anush V Kini Date: Sun, 4 Oct 2020 12:03:25 +0530 Subject: [PATCH 17/45] Fixed epsilon values in metric_test --- src/mlpack/tests/metric_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mlpack/tests/metric_test.cpp b/src/mlpack/tests/metric_test.cpp index d3db1a71c1..0ffc36d5ba 100644 --- a/src/mlpack/tests/metric_test.cpp +++ b/src/mlpack/tests/metric_test.cpp @@ -330,7 +330,7 @@ TEST_CASE("BLEUScoreTest", "[MetricTest]") //! We are not using smoothing function here. bleu.Evaluate(referenceCorpus, translationCorpus); - REQUIRE(bleu.BLEUScore() == Approx(0.0).epsilon(1e-7)); + REQUIRE(bleu.BLEUScore() == Approx(0.0).epsilon(1e-5)); REQUIRE(bleu.BrevityPenalty() == 1.0); REQUIRE(bleu.Ratio() == 1.0); REQUIRE(bleu.TranslationLength() == 12); @@ -346,7 +346,7 @@ TEST_CASE("BLEUScoreTest", "[MetricTest]") //! We will use smoothing function here by setting smooth to true. bleu.Evaluate(referenceCorpus, translationCorpus, true); - REQUIRE(bleu.BLEUScore() == Approx(0.459307).epsilon(1e-3)); + REQUIRE(bleu.BLEUScore() == Approx(0.459307).epsilon(1e-5)); REQUIRE(bleu.BrevityPenalty() == 1.0); REQUIRE(bleu.Ratio() == 1.0); REQUIRE(bleu.TranslationLength() == 12); @@ -356,6 +356,6 @@ TEST_CASE("BLEUScoreTest", "[MetricTest]") for (size_t i = 0; i < bleu.Precisions().size(); ++i) { REQUIRE(bleu.Precisions()[i] == - Approx(expectedPrecision[i]).epsilon(1e-5)); + Approx(expectedPrecision[i]).epsilon(1e-4)); } } From 2347fa8d6cc3d5e3df08d8e68ed26e3b7b9de6d7 Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Sun, 4 Oct 2020 12:22:17 +0530 Subject: [PATCH 18/45] Migrate sort_policy, sfinae and string related test to catch2 --- src/mlpack/tests/CMakeLists.txt | 6 +- src/mlpack/tests/sfinae_test.cpp | 12 +- src/mlpack/tests/sort_policy_test.cpp | 95 +++++++------- src/mlpack/tests/string_encoding_test.cpp | 146 +++++++++++----------- 4 files changed, 123 insertions(+), 136 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index bf68f3c64b..7761bc3fa7 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -57,10 +57,7 @@ add_executable(mlpack_test serialization.cpp serialization.hpp serialization_test.cpp - sfinae_test.cpp - sort_policy_test.cpp spill_tree_test.cpp - string_encoding_test.cpp sumtree_test.cpp termination_policy_test.cpp test_function_tools.hpp @@ -148,10 +145,13 @@ add_executable(mlpack_catch_test scaling_test.cpp serialization_catch.cpp serialization_catch.hpp + sfinae_test.cpp softmax_regression_test.cpp + sort_policy_test.cpp sparse_autoencoder_test.cpp sparse_coding_test.cpp split_data_test.cpp + string_encoding_test.cpp svd_batch_test.cpp svd_incremental_test.cpp svdplusplus_test.cpp diff --git a/src/mlpack/tests/sfinae_test.cpp b/src/mlpack/tests/sfinae_test.cpp index 10a3aafadb..fce327996d 100644 --- a/src/mlpack/tests/sfinae_test.cpp +++ b/src/mlpack/tests/sfinae_test.cpp @@ -13,9 +13,7 @@ #include #include -#include - -BOOST_AUTO_TEST_SUITE(SFINAETest); +#include "catch.hpp" class A { @@ -97,7 +95,7 @@ HAS_ANY_METHOD_FORM(Model, HasModel); * Test at compile time the presence of methods of the specified forms with the * stated number of additional arguments. */ -BOOST_AUTO_TEST_CASE(HasMethodFormWithNAdditionalArgsTest) +TEST_CASE("HasMethodFormWithNAdditionalArgsTest", "[SFINAETest]") { static_assert(!HasM::WithNAdditionalArgs<0>::value, "value should be false"); @@ -145,7 +143,7 @@ BOOST_AUTO_TEST_CASE(HasMethodFormWithNAdditionalArgsTest) /* * Test at compile time the presence of methods of the specified forms. */ -BOOST_AUTO_TEST_CASE(HasMethodFormTest) +TEST_CASE("HasMethodFormTest", "[SFINAETest]") { static_assert(HasM::value, "value should be true"); @@ -168,7 +166,7 @@ BOOST_AUTO_TEST_CASE(HasMethodFormTest) * Test at compile time, for the presence/absence of a specific member * function in a class. */ -BOOST_AUTO_TEST_CASE(HasMethodNameTest) +TEST_CASE("HasMethodNameTest", "[SFINAETest]") { static_assert(!HasModel::value, "value should be false"); @@ -176,5 +174,3 @@ BOOST_AUTO_TEST_CASE(HasMethodNameTest) static_assert(HasModel::value, "value should be true"); static_assert(HasModel::value, "value should be true"); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/sort_policy_test.cpp b/src/mlpack/tests/sort_policy_test.cpp index 403903a68d..6418135f8e 100644 --- a/src/mlpack/tests/sort_policy_test.cpp +++ b/src/mlpack/tests/sort_policy_test.cpp @@ -16,8 +16,7 @@ #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" using namespace mlpack; using namespace mlpack::neighbor; @@ -25,47 +24,45 @@ using namespace mlpack::bound; using namespace mlpack::tree; using namespace mlpack::metric; -BOOST_AUTO_TEST_SUITE(SortPolicyTest); - // Tests for NearestNeighborSort /** * Ensure the best distance for nearest neighbors is 0. */ -BOOST_AUTO_TEST_CASE(NnsBestDistance) +TEST_CASE("NnsBestDistance", "[SortPolicyTest]") { - BOOST_REQUIRE(NearestNeighborSort::BestDistance() == 0); + REQUIRE(NearestNeighborSort::BestDistance() == 0); } /** * Ensure the worst distance for nearest neighbors is DBL_MAX. */ -BOOST_AUTO_TEST_CASE(NnsWorstDistance) +TEST_CASE("NnsWorstDistance", "[SortPolicyTest]") { - BOOST_REQUIRE(NearestNeighborSort::WorstDistance() == DBL_MAX); + REQUIRE(NearestNeighborSort::WorstDistance() == DBL_MAX); } /** * Make sure the comparison works for values strictly less than the reference. */ -BOOST_AUTO_TEST_CASE(NnsIsBetterStrict) +TEST_CASE("NnsIsBetterStrict", "[SortPolicyTest]") { - BOOST_REQUIRE(NearestNeighborSort::IsBetter(5.0, 6.0) == true); + REQUIRE(NearestNeighborSort::IsBetter(5.0, 6.0) == true); } /** * Warn in case the comparison is not strict. */ -BOOST_AUTO_TEST_CASE(NnsIsBetterNotStrict) +TEST_CASE("NnsIsBetterNotStrict", "[SortPolicyTest]") { - BOOST_WARN(NearestNeighborSort::IsBetter(6.0, 6.0) == true); + CHECK(NearestNeighborSort::IsBetter(6.0, 6.0) == true); } /** * Very simple sanity check to ensure that bounds are working alright. We will * use a one-dimensional bound for simplicity. */ -BOOST_AUTO_TEST_CASE(NnsNodeToNodeDistance) +TEST_CASE("NnsNodeToNodeDistance", "[SortPolicyTest]") { // Well, there's no easy way to make HRectBounds the way we want, so we have // to make them and then expand the region to include new points. @@ -89,8 +86,8 @@ BOOST_AUTO_TEST_CASE(NnsNodeToNodeDistance) nodeTwo.Bound() |= utility; // This should use the L2 distance. - BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, - &nodeTwo), 4.0, 1e-5); + REQUIRE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + Approx(4.0).epsilon(1e-7)); // And another just to be sure, from the other side. nodeTwo.Bound().Clear(); @@ -100,8 +97,8 @@ BOOST_AUTO_TEST_CASE(NnsNodeToNodeDistance) nodeTwo.Bound() |= utility; // Again, the distance is the L2 distance. - BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, - &nodeTwo), 1.0, 1e-5); + REQUIRE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + Approx(1.0).epsilon(1e-7)); // Now, when the bounds overlap. nodeTwo.Bound().Clear(); @@ -110,15 +107,15 @@ BOOST_AUTO_TEST_CASE(NnsNodeToNodeDistance) utility[0] = 0.5; nodeTwo.Bound() |= utility; - BOOST_REQUIRE_SMALL(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, - &nodeTwo), 1e-5); + REQUIRE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + Approx(0.0).margin(1e-5)); } /** * Another very simple sanity check for the point-to-node case, again in one * dimension. */ -BOOST_AUTO_TEST_CASE(NnsPointToNodeDistance) +TEST_CASE("NnsPointToNodeDistance", "[SortPolicyTest]") { // Well, there's no easy way to make HRectBounds the way we want, so we have // to make them and then expand the region to include new points. @@ -137,20 +134,20 @@ BOOST_AUTO_TEST_CASE(NnsPointToNodeDistance) point[0] = -0.5; // The distance is the L2 distance. - BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestPointToNodeDistance(point, - &node), 0.5, 1e-5); + REQUIRE(NearestNeighborSort::BestPointToNodeDistance(point, &node) == + Approx(0.5).epsilon(1e-7)); // Now from the other side of the bound. point[0] = 1.5; - BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestPointToNodeDistance(point, - &node), 0.5, 1e-5); + REQUIRE(NearestNeighborSort::BestPointToNodeDistance(point, &node) == + Approx(0.5).epsilon(1e-7)); // And now when the point is inside the bound. point[0] = 0.5; - BOOST_REQUIRE_SMALL(NearestNeighborSort::BestPointToNodeDistance(point, - &node), 1e-5); + REQUIRE(NearestNeighborSort::BestPointToNodeDistance(point, &node) == + Approx(0.0).margin(1e-5)); } // Tests for FurthestNeighborSort @@ -158,40 +155,40 @@ BOOST_AUTO_TEST_CASE(NnsPointToNodeDistance) /** * Ensure the best distance for furthest neighbors is DBL_MAX. */ -BOOST_AUTO_TEST_CASE(FnsBestDistance) +TEST_CASE("FnsBestDistance", "[SortPolicyTest]") { - BOOST_REQUIRE(FurthestNeighborSort::BestDistance() == DBL_MAX); + REQUIRE(FurthestNeighborSort::BestDistance() == DBL_MAX); } /** * Ensure the worst distance for furthest neighbors is 0. */ -BOOST_AUTO_TEST_CASE(FnsWorstDistance) +TEST_CASE("FnsWorstDistance", "[SortPolicyTest]") { - BOOST_REQUIRE(FurthestNeighborSort::WorstDistance() == 0); + REQUIRE(FurthestNeighborSort::WorstDistance() == 0); } /** * Make sure the comparison works for values strictly less than the reference. */ -BOOST_AUTO_TEST_CASE(FnsIsBetterStrict) +TEST_CASE("FnsIsBetterStrict", "[SortPolicyTest]") { - BOOST_REQUIRE(FurthestNeighborSort::IsBetter(5.0, 4.0) == true); + REQUIRE(FurthestNeighborSort::IsBetter(5.0, 4.0) == true); } /** * Warn in case the comparison is not strict. */ -BOOST_AUTO_TEST_CASE(FnsIsBetterNotStrict) +TEST_CASE("FnsIsBetterNotStrict", "[SortPolicyTest]") { - BOOST_WARN(FurthestNeighborSort::IsBetter(6.0, 6.0) == true); + CHECK(FurthestNeighborSort::IsBetter(6.0, 6.0) == true); } /** * Very simple sanity check to ensure that bounds are working alright. We will * use a one-dimensional bound for simplicity. */ -BOOST_AUTO_TEST_CASE(FnsNodeToNodeDistance) +TEST_CASE("FnsNodeToNodeDistance", "[SortPolicyTest]") { // Well, there's no easy way to make HRectBounds the way we want, so we have // to make them and then expand the region to include new points. @@ -214,8 +211,8 @@ BOOST_AUTO_TEST_CASE(FnsNodeToNodeDistance) nodeTwo.Bound() |= utility; // This should use the L2 distance. - BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne, - &nodeTwo), 6.0, 1e-5); + REQUIRE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + Approx(6.0).epsilon(1e-7)); // And another just to be sure, from the other side. nodeTwo.Bound().Clear(); @@ -225,8 +222,8 @@ BOOST_AUTO_TEST_CASE(FnsNodeToNodeDistance) nodeTwo.Bound() |= utility; // Again, the distance is the L2 distance. - BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne, - &nodeTwo), 3.0, 1e-5); + REQUIRE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + Approx(3.0).epsilon(1e-7)); // Now, when the bounds overlap. nodeTwo.Bound().Clear(); @@ -235,15 +232,15 @@ BOOST_AUTO_TEST_CASE(FnsNodeToNodeDistance) utility[0] = 0.5; nodeTwo.Bound() |= utility; - BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne, - &nodeTwo), 1.5, 1e-5); + REQUIRE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + Approx(1.5).epsilon(1e-7)); } /** * Another very simple sanity check for the point-to-node case, again in one * dimension. */ -BOOST_AUTO_TEST_CASE(FnsPointToNodeDistance) +TEST_CASE("FnsPointToNodeDistance", "[SortPolicyTest]") { // Well, there's no easy way to make HRectBounds the way we want, so we have // to make them and then expand the region to include new points. @@ -262,20 +259,18 @@ BOOST_AUTO_TEST_CASE(FnsPointToNodeDistance) point[0] = -0.5; // The distance is the L2 distance. - BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestPointToNodeDistance(point, - &node), 1.5, 1e-5); + REQUIRE(FurthestNeighborSort::BestPointToNodeDistance(point, &node) == + Approx(1.5).epsilon(1e-7)); // Now from the other side of the bound. point[0] = 1.5; - BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestPointToNodeDistance(point, - &node), 1.5, 1e-5); + REQUIRE(FurthestNeighborSort::BestPointToNodeDistance(point, &node) == + Approx(1.5).epsilon(1e-7)); // And now when the point is inside the bound. point[0] = 0.5; - BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestPointToNodeDistance(point, - &node), 0.5, 1e-5); + REQUIRE(FurthestNeighborSort::BestPointToNodeDistance(point, &node) == + Approx(0.5).epsilon(1e-7)); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/string_encoding_test.cpp b/src/mlpack/tests/string_encoding_test.cpp index b50eea8e6d..45c5555d39 100644 --- a/src/mlpack/tests/string_encoding_test.cpp +++ b/src/mlpack/tests/string_encoding_test.cpp @@ -20,15 +20,14 @@ #include #include #include -#include "test_tools.hpp" -#include "serialization.hpp" +#include "test_catch_tools.hpp" +#include "catch.hpp" +#include "serialization_catch.hpp" using namespace mlpack; using namespace mlpack::data; using namespace std; -BOOST_AUTO_TEST_SUITE(StringEncodingTest); - //! Common input for some tests. static vector stringEncodingInput = { "mlpack is an intuitive, fast, and flexible C++ machine learning library " @@ -64,21 +63,21 @@ void CheckVectors(const vector>& a, const vector>& b, const ValueType tolerance = 1e-5) { - BOOST_REQUIRE_EQUAL(a.size(), b.size()); + REQUIRE(a.size() == b.size()); for (size_t i = 0; i < a.size(); ++i) { - BOOST_REQUIRE_EQUAL(a[i].size(), b[i].size()); + REQUIRE(a[i].size() == b[i].size()); for (size_t j = 0; j < a[i].size(); ++j) - BOOST_REQUIRE_CLOSE(a[i][j], b[i][j], tolerance); + REQUIRE(a[i][j] == Approx(b[i][j]).epsilon(tolerance / 100)); } } /** * Test the dictionary encoding algorithm. */ -BOOST_AUTO_TEST_CASE(DictionaryEncodingTest) +TEST_CASE("DictionaryEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -97,7 +96,7 @@ BOOST_AUTO_TEST_CASE(DictionaryEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } arma::mat expected = { @@ -115,7 +114,7 @@ BOOST_AUTO_TEST_CASE(DictionaryEncodingTest) /** * Test the dictionary encoding algorithm with unicode characters. */ -BOOST_AUTO_TEST_CASE(UnicodeDictionaryEncodingTest) +TEST_CASE("UnicodeDictionaryEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -134,7 +133,7 @@ BOOST_AUTO_TEST_CASE(UnicodeDictionaryEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } arma::mat expected = { @@ -149,7 +148,7 @@ BOOST_AUTO_TEST_CASE(UnicodeDictionaryEncodingTest) /** * Test the one pass modification of the dictionary encoding algorithm. */ -BOOST_AUTO_TEST_CASE(OnePassDictionaryEncodingTest) +TEST_CASE("OnePassDictionaryEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -169,7 +168,7 @@ BOOST_AUTO_TEST_CASE(OnePassDictionaryEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } vector> expected = { @@ -179,14 +178,14 @@ BOOST_AUTO_TEST_CASE(OnePassDictionaryEncodingTest) { 36, 37, 14, 38, 39, 8, 40, 1, 41, 42, 43, 44, 6, 45, 13 } }; - BOOST_REQUIRE(output == expected); + REQUIRE(output == expected); } /** * Test the SplitByAnyOf tokenizer. */ -BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerTest) +TEST_CASE("SplitByAnyOfTokenizerTest", "[StringEncodingTest]") { std::vector tokens; boost::string_view line(stringEncodingInput[0]); @@ -204,16 +203,16 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerTest) "bindings", "to", "other", "languages" }; - BOOST_REQUIRE_EQUAL(tokens.size(), expected.size()); + REQUIRE(tokens.size() == expected.size()); for (size_t i = 0; i < tokens.size(); ++i) - BOOST_REQUIRE_EQUAL(tokens[i], expected[i]); + REQUIRE(tokens[i] == expected[i]); } /** * Test the SplitByAnyOf tokenizer in case of unicode characters. */ -BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerUnicodeTest) +TEST_CASE("SplitByAnyOfTokenizerUnicodeTest", "[StringEncodingTest]") { vector expectedUtf8Tokens = { "\xF0\x9F\x84\xBC\xF0\x9F\x84\xBB\xF0\x9F\x84\xBF\xF0\x9F\x84\xB0" @@ -236,16 +235,16 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerUnicodeTest) token = tokenizer(line); } - BOOST_REQUIRE_EQUAL(tokens.size(), expectedUtf8Tokens.size()); + REQUIRE(tokens.size() == expectedUtf8Tokens.size()); for (size_t i = 0; i < tokens.size(); ++i) - BOOST_REQUIRE_EQUAL(tokens[i], expectedUtf8Tokens[i]); + REQUIRE(tokens[i] == expectedUtf8Tokens[i]); } /** * Test the CharExtract tokenizer. */ -BOOST_AUTO_TEST_CASE(DictionaryEncodingIndividualCharactersTest) +TEST_CASE("DictionaryEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -270,7 +269,7 @@ BOOST_AUTO_TEST_CASE(DictionaryEncodingIndividualCharactersTest) * Test the one pass modification of the dictionary encoding algorithm * in case of individual character encoding. */ -BOOST_AUTO_TEST_CASE(OnePassDictionaryEncodingIndividualCharactersTest) +TEST_CASE("OnePassDictionaryEncodingIndividualCharactersTest", "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -289,13 +288,13 @@ BOOST_AUTO_TEST_CASE(OnePassDictionaryEncodingIndividualCharactersTest) { 1, 2, 4 } }; - BOOST_REQUIRE(output == expected); + REQUIRE(output == expected); } /** * Test the functionality of copy constructor. */ -BOOST_AUTO_TEST_CASE(StringEncodingCopyTest) +TEST_CASE("StringEncodingCopyTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; arma::sp_mat output; @@ -318,12 +317,12 @@ BOOST_AUTO_TEST_CASE(StringEncodingCopyTest) const DictionaryType& copiedDictionary = encoderCopy.Dictionary(); - BOOST_REQUIRE_EQUAL(naiveDictionary.size(), copiedDictionary.Size()); + REQUIRE(naiveDictionary.size() == copiedDictionary.Size()); for (const pair& keyValue : naiveDictionary) { - BOOST_REQUIRE(copiedDictionary.HasToken(keyValue.first)); - BOOST_REQUIRE_EQUAL(copiedDictionary.Value(keyValue.first), + REQUIRE(copiedDictionary.HasToken(keyValue.first)); + REQUIRE(copiedDictionary.Value(keyValue.first) == keyValue.second); } } @@ -331,7 +330,7 @@ BOOST_AUTO_TEST_CASE(StringEncodingCopyTest) /** * Test the move assignment operator. */ -BOOST_AUTO_TEST_CASE(StringEncodingMoveTest) +TEST_CASE("StringEncodingMoveTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; arma::sp_mat output; @@ -354,12 +353,12 @@ BOOST_AUTO_TEST_CASE(StringEncodingMoveTest) const DictionaryType& copiedDictionary = encoderCopy.Dictionary(); - BOOST_REQUIRE_EQUAL(naiveDictionary.size(), copiedDictionary.Size()); + REQUIRE(naiveDictionary.size() == copiedDictionary.Size()); for (const pair& keyValue : naiveDictionary) { - BOOST_REQUIRE(copiedDictionary.HasToken(keyValue.first)); - BOOST_REQUIRE_EQUAL(copiedDictionary.Value(keyValue.first), + REQUIRE(copiedDictionary.HasToken(keyValue.first)); + REQUIRE(copiedDictionary.Value(keyValue.first) == keyValue.second); } } @@ -377,16 +376,16 @@ void CheckDictionaries(const StringEncodingDictionary& expected, const MapType& mapping = obtained.Mapping(); const MapType& expectedMapping = expected.Mapping(); - BOOST_REQUIRE_EQUAL(mapping.size(), expectedMapping.size()); + REQUIRE(mapping.size() == expectedMapping.size()); for (auto& keyVal : expectedMapping) { - BOOST_REQUIRE_EQUAL(mapping.at(keyVal.first), keyVal.second); + REQUIRE(mapping.at(keyVal.first) == keyVal.second); } for (auto& keyVal : mapping) { - BOOST_REQUIRE_EQUAL(expectedMapping.at(keyVal.first), keyVal.second); + REQUIRE(expectedMapping.at(keyVal.first) == keyVal.second); } } @@ -413,14 +412,14 @@ void CheckDictionaries( const MapType& expectedMapping = expected.Mapping(); const MapType& mapping = obtained.Mapping(); - BOOST_REQUIRE_EQUAL(tokens.size(), expectedTokens.size()); - BOOST_REQUIRE_EQUAL(mapping.size(), expectedMapping.size()); - BOOST_REQUIRE_EQUAL(mapping.size(), tokens.size()); + REQUIRE(tokens.size() == expectedTokens.size()); + REQUIRE(mapping.size() == expectedMapping.size()); + REQUIRE(mapping.size() == tokens.size()); for (size_t i = 0; i < tokens.size(); ++i) { - BOOST_REQUIRE_EQUAL(tokens[i], expectedTokens[i]); - BOOST_REQUIRE_EQUAL(expectedMapping.at(tokens[i]), mapping.at(tokens[i])); + REQUIRE(tokens[i] == expectedTokens[i]); + REQUIRE(expectedMapping.at(tokens[i]) == mapping.at(tokens[i])); } } @@ -438,11 +437,11 @@ void CheckDictionaries(const StringEncodingDictionary& expected, const MapType& expectedMapping = expected.Mapping(); const MapType& mapping = obtained.Mapping(); - BOOST_REQUIRE_EQUAL(expected.Size(), obtained.Size()); + REQUIRE(expected.Size() == obtained.Size()); for (size_t i = 0; i < mapping.size(); ++i) { - BOOST_REQUIRE_EQUAL(mapping[i], expectedMapping[i]); + REQUIRE(mapping[i] == expectedMapping[i]); } } @@ -450,7 +449,7 @@ void CheckDictionaries(const StringEncodingDictionary& expected, * Serialization test for the general template of the StringEncodingDictionary * class. */ -BOOST_AUTO_TEST_CASE(StringEncodingDictionarySerialization) +TEST_CASE("StringEncodingDictionarySerialization", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -485,7 +484,7 @@ BOOST_AUTO_TEST_CASE(StringEncodingDictionarySerialization) * Serialization test for the dictionary encoding algorithm with * the SplitByAnyOf tokenizer. */ -BOOST_AUTO_TEST_CASE(SplitByAnyOfDictionaryEncodingSerialization) +TEST_CASE("SplitByAnyOfDictionaryEncodingSerialization", "[StringEncodingTest]") { using EncoderType = DictionaryEncoding; @@ -515,7 +514,7 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfDictionaryEncodingSerialization) * Serialization test for the dictionary encoding algorithm with * the CharExtract tokenizer. */ -BOOST_AUTO_TEST_CASE(CharExtractDictionaryEncodingSerialization) +TEST_CASE("CharExtractDictionaryEncodingSerialization", "[StringEncodingTest]") { using EncoderType = DictionaryEncoding; @@ -544,7 +543,7 @@ BOOST_AUTO_TEST_CASE(CharExtractDictionaryEncodingSerialization) /** * Test the Bag of Words encoding algorithm. */ -BOOST_AUTO_TEST_CASE(BagOfWordsEncodingTest) +TEST_CASE("BagOfWordsEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -563,7 +562,7 @@ BOOST_AUTO_TEST_CASE(BagOfWordsEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } /* The expected values were obtained by the following Python script: @@ -619,7 +618,7 @@ BOOST_AUTO_TEST_CASE(BagOfWordsEncodingTest) /** * Test the Bag of Words encoding algorithm. The output is saved into a vector. */ -BOOST_AUTO_TEST_CASE(VectorBagOfWordsEncodingTest) +TEST_CASE("VectorBagOfWordsEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -639,7 +638,7 @@ BOOST_AUTO_TEST_CASE(VectorBagOfWordsEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } /* The expected values were obtained by the same script as in @@ -653,13 +652,13 @@ BOOST_AUTO_TEST_CASE(VectorBagOfWordsEncodingTest) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; - BOOST_REQUIRE(output == expected); + REQUIRE(output == expected); } /** * Test the Bag of Words algorithm for individual characters. */ -BOOST_AUTO_TEST_CASE(BagOfWordsEncodingIndividualCharactersTest) +TEST_CASE("BagOfWordsEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -685,7 +684,7 @@ BOOST_AUTO_TEST_CASE(BagOfWordsEncodingIndividualCharactersTest) * Test the Bag of Words encoding algorithm in case of individual * characters encoding. The output type is vector>. */ -BOOST_AUTO_TEST_CASE(VectorBagOfWordsEncodingIndividualCharactersTest) +TEST_CASE("VectorBagOfWordsEncodingIndividualCharactersTest", "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -704,7 +703,7 @@ BOOST_AUTO_TEST_CASE(VectorBagOfWordsEncodingIndividualCharactersTest) { 1, 1, 0, 1, 0 } }; - BOOST_REQUIRE(output == expected); + REQUIRE(output == expected); } /** @@ -712,7 +711,7 @@ BOOST_AUTO_TEST_CASE(VectorBagOfWordsEncodingIndividualCharactersTest) * and the smooth inverse document frequency type. These parameters are * the default ones. */ -BOOST_AUTO_TEST_CASE(RawCountSmoothIdfEncodingTest) +TEST_CASE("RawCountSmoothIdfEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -730,7 +729,7 @@ BOOST_AUTO_TEST_CASE(RawCountSmoothIdfEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } /* The expected values were obtained by the following Python script: @@ -814,7 +813,7 @@ BOOST_AUTO_TEST_CASE(RawCountSmoothIdfEncodingTest) * and the smooth inverse document frequency type. These parameters are * the default ones. The output type is vector>. */ -BOOST_AUTO_TEST_CASE(VectorRawCountSmoothIdfEncodingTest) +TEST_CASE("VectorRawCountSmoothIdfEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -834,7 +833,7 @@ BOOST_AUTO_TEST_CASE(VectorRawCountSmoothIdfEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } /* The expected values were obtained by the same script as in @@ -862,7 +861,7 @@ BOOST_AUTO_TEST_CASE(VectorRawCountSmoothIdfEncodingTest) * raw count term frequency type and the smooth inverse document frequency type. * These parameters are the default ones. */ -BOOST_AUTO_TEST_CASE(RawCountSmoothIdfEncodingIndividualCharactersTest) +TEST_CASE("RawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -943,7 +942,7 @@ BOOST_AUTO_TEST_CASE(RawCountSmoothIdfEncodingIndividualCharactersTest) * These parameters are the default ones. The output type is * vector>. */ -BOOST_AUTO_TEST_CASE(VectorRawCountSmoothIdfEncodingIndividualCharactersTest) +TEST_CASE("VectorRawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -971,7 +970,7 @@ BOOST_AUTO_TEST_CASE(VectorRawCountSmoothIdfEncodingIndividualCharactersTest) * Test the Tf-Idf encoding algorithm with the raw count term frequency type * and the non-smooth inverse document frequency type. */ -BOOST_AUTO_TEST_CASE(TfIdfRawCountEncodingTest) +TEST_CASE("TfIdfRawCountEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -991,7 +990,7 @@ BOOST_AUTO_TEST_CASE(TfIdfRawCountEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } /* The expected values were obtained by almost the same script as in @@ -1021,7 +1020,7 @@ BOOST_AUTO_TEST_CASE(TfIdfRawCountEncodingTest) * and the non-smooth inverse document frequency type. The output type is * vector>. */ -BOOST_AUTO_TEST_CASE(VectorTfIdfRawCountEncodingTest) +TEST_CASE("VectorTfIdfRawCountEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -1040,7 +1039,7 @@ BOOST_AUTO_TEST_CASE(VectorTfIdfRawCountEncodingTest) { keysCount[keyValue.second]++; - BOOST_REQUIRE_EQUAL(keysCount[keyValue.second], 1); + REQUIRE(keysCount[keyValue.second] == 1); } /* The expected values were obtained by almost the same script as in @@ -1069,7 +1068,7 @@ BOOST_AUTO_TEST_CASE(VectorTfIdfRawCountEncodingTest) * raw count term frequency type and the non-smooth inverse document frequency * type. */ -BOOST_AUTO_TEST_CASE(RawCountTfIdfEncodingIndividualCharactersTest) +TEST_CASE("RawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -1100,7 +1099,7 @@ BOOST_AUTO_TEST_CASE(RawCountTfIdfEncodingIndividualCharactersTest) * raw count term frequency type and the non-smooth inverse document frequency * type. The output type is vector>. */ -BOOST_AUTO_TEST_CASE(VectorRawCountTfIdfEncodingIndividualCharactersTest) +TEST_CASE("VectorRawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1130,7 +1129,7 @@ BOOST_AUTO_TEST_CASE(VectorRawCountTfIdfEncodingIndividualCharactersTest) * Test the Tf-Idf encoding algorithm for individual characters with the * binary term frequency type and the smooth inverse document frequency type. */ -BOOST_AUTO_TEST_CASE(BinarySmoothIdfEncodingIndividualCharactersTest) +TEST_CASE("BinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -1161,7 +1160,7 @@ BOOST_AUTO_TEST_CASE(BinarySmoothIdfEncodingIndividualCharactersTest) * binary term frequency type and the smooth inverse document frequency type. * The output type is vector>. */ -BOOST_AUTO_TEST_CASE(VectorBinarySmoothIdfEncodingIndividualCharactersTest) +TEST_CASE("VectorBinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1192,7 +1191,7 @@ BOOST_AUTO_TEST_CASE(VectorBinarySmoothIdfEncodingIndividualCharactersTest) * binary term frequency type and the non-smooth inverse document frequency * type. */ -BOOST_AUTO_TEST_CASE(BinaryTfIdfEncodingIndividualCharactersTest) +TEST_CASE("BinaryTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -1223,7 +1222,7 @@ BOOST_AUTO_TEST_CASE(BinaryTfIdfEncodingIndividualCharactersTest) * sublinear term frequency type and the smooth inverse document frequency * type. */ -BOOST_AUTO_TEST_CASE(SublinearSmoothIdfEncodingIndividualCharactersTest) +TEST_CASE("SublinearSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -1255,7 +1254,7 @@ BOOST_AUTO_TEST_CASE(SublinearSmoothIdfEncodingIndividualCharactersTest) * sublinear term frequency type and the non-smooth inverse document frequency * type. */ -BOOST_AUTO_TEST_CASE(SublinearTfIdfEncodingIndividualCharactersTest) +TEST_CASE("SublinearTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -1287,7 +1286,7 @@ BOOST_AUTO_TEST_CASE(SublinearTfIdfEncodingIndividualCharactersTest) * standard term frequency type and the smooth inverse document frequency * type. */ -BOOST_AUTO_TEST_CASE(TermFrequencySmoothIdfEncodingIndividualCharactersTest) +TEST_CASE("TermFrequencySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -1368,7 +1367,7 @@ BOOST_AUTO_TEST_CASE(TermFrequencySmoothIdfEncodingIndividualCharactersTest) * standard term frequency type and the non-smooth inverse document frequency * type. */ -BOOST_AUTO_TEST_CASE(TermFrequencyTfIdfEncodingIndividualCharactersTest) +TEST_CASE("TermFrequencyTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") { vector input = { "GACCA", @@ -1399,7 +1398,7 @@ BOOST_AUTO_TEST_CASE(TermFrequencyTfIdfEncodingIndividualCharactersTest) * Serialization test for the Tf-Idf encoding algorithm with * the SplitByAnyOf tokenizer. */ -BOOST_AUTO_TEST_CASE(SplitByAnyOfTfIdfEncodingSerialization) +TEST_CASE("SplitByAnyOfTfIdfEncodingSerialization", "[StringEncodingTest]") { using EncoderType = TfIdfEncoding; @@ -1424,6 +1423,3 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfTfIdfEncodingSerialization) CheckMatrices(output, xmlOutput, textOutput, binaryOutput); } - -BOOST_AUTO_TEST_SUITE_END(); - From f1928ee67959c238314dfc294e773958a14bdd19 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Sun, 4 Oct 2020 19:23:56 +0530 Subject: [PATCH 19/45] forward impl change: softmin, softmax --- src/mlpack/methods/ann/layer/softmax_impl.hpp | 10 +++++----- src/mlpack/methods/ann/layer/softmin_impl.hpp | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mlpack/methods/ann/layer/softmax_impl.hpp b/src/mlpack/methods/ann/layer/softmax_impl.hpp index 757431fa28..24fcec04b4 100644 --- a/src/mlpack/methods/ann/layer/softmax_impl.hpp +++ b/src/mlpack/methods/ann/layer/softmax_impl.hpp @@ -28,12 +28,12 @@ Softmax::Softmax() template template void Softmax::Forward( - const InputType& input, OutputType& output) + const InputType& input, + OutputType& output) { - InputType inputMax = arma::repmat(arma::max(input, 0), input.n_rows, 1); - output = inputMax + arma::log(arma::repmat( - arma::sum(arma::exp(input - inputMax), 0), input.n_rows, 1)); - output = arma::exp(input - output); + InputType softmaxInput = arma::exp(input.each_row() - + arma::max(input, 0)); + output = softmaxInput.each_row() / sum(softmaxInput, 0); } template diff --git a/src/mlpack/methods/ann/layer/softmin_impl.hpp b/src/mlpack/methods/ann/layer/softmin_impl.hpp index 7693ca11dd..686010a0e8 100644 --- a/src/mlpack/methods/ann/layer/softmin_impl.hpp +++ b/src/mlpack/methods/ann/layer/softmin_impl.hpp @@ -30,10 +30,9 @@ void Softmin::Forward( const InputType& input, OutputType& output) { - InputType inputMin = arma::repmat(arma::min(input,0), input.n_rows, 1); - output = arma::repmat(arma::log(arma::sum( - arma::exp(-(input - inputMin)),0)), input.n_rows, 1); - output = arma::exp(-(input - inputMin) - output); + InputType softminInput = arma::exp(-(input.each_row() - + arma::min(input, 0))); + output = softminInput.each_row() / sum(softminInput, 0); } template From d4c74c74ce4bd99748c99468339d3b742024a7d6 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Mon, 5 Oct 2020 00:24:05 +0530 Subject: [PATCH 20/45] fixed static code check --- src/mlpack/tests/range_search_test.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 2f40600405..41185f7a8a 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1104,7 +1104,8 @@ TEST_CASE("RangeTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1145,7 +1146,8 @@ TEST_CASE("TrainTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1199,7 +1201,8 @@ TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1241,7 +1244,8 @@ TEST_CASE("MoveTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1283,7 +1287,7 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j < 2; ++j) + for (size_t j = 0; j != 2; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); @@ -1325,8 +1329,8 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon - (1e-7)); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). + epsilon(1e-7)); } } } @@ -1369,7 +1373,7 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j < 2; ++j) + for (size_t j = 0; j != 2; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); @@ -1408,8 +1412,8 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon - (1e-7)); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). + epsilon(1e-7)); } } } From 9535efbb6e7ee61c4b1979b3b130c96f38fd3659 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Mon, 5 Oct 2020 19:59:39 +0530 Subject: [PATCH 21/45] Remove R-bindings from azure. --- .ci/ci.yaml | 9 --------- .ci/linux-steps.yaml | 9 --------- .ci/macos-steps.yaml | 8 -------- 3 files changed, 26 deletions(-) diff --git a/.ci/ci.yaml b/.ci/ci.yaml index 89adaec398..b3153479cc 100644 --- a/.ci/ci.yaml +++ b/.ci/ci.yaml @@ -27,10 +27,6 @@ jobs: binding: 'go' go.version: '1.11.0' CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=ON -DBUILD_R_BINDINGS=OFF' - R: - binding: 'R' - R.version: '4.0.0' - CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON' Markdown: CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_MARKDOWN_BINDINGS=ON -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_R_BINDINGS=OFF' @@ -59,11 +55,6 @@ jobs: python.version: '2.7' go.version: '1.11.0' CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=ON -DBUILD_R_BINDINGS=OFF' - R: - binding: 'R' - python.version: '2.7' - R.version: '4.0.0' - CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON' steps: - template: macos-steps.yaml diff --git a/.ci/linux-steps.yaml b/.ci/linux-steps.yaml index 84538f59b4..75cd4e2194 100644 --- a/.ci/linux-steps.yaml +++ b/.ci/linux-steps.yaml @@ -34,15 +34,6 @@ steps: sudo tar -C /opt/ -xvpf julia-1.3.0-linux-x86_64.tar.gz fi - if [ "$(binding)" == "R" ]; then - if [ "a$(R.version)" != "a" ]; then - sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/' - sudo apt-get -y update - sudo apt-get install -y r-base-core - fi - sudo Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" - fi - # Install armadillo. curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo* cmake . && make && sudo make install && cd .. diff --git a/.ci/macos-steps.yaml b/.ci/macos-steps.yaml index 09ee11f538..ac4441bb67 100644 --- a/.ci/macos-steps.yaml +++ b/.ci/macos-steps.yaml @@ -25,14 +25,6 @@ steps: brew cask install julia fi - if [ "$(binding)" == "R" ]; then - if [ "a$(R.version)" != "a" ]; then - brew cask install r - fi - brew cask install gfortran - Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'), repos = 'http://cran.us.r-project.org')" - fi - git clone --depth 1 https://github.com/mlpack/jenkins-conf.git conf displayName: 'Install Build Dependencies' From 74b9006631be037a7d1f7008c550d6f7c8b03e23 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Mon, 5 Oct 2020 20:00:25 +0530 Subject: [PATCH 22/45] run ctest with github-actions. --- .github/workflows/main.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8640c26471..fa8859710b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,11 +78,15 @@ jobs: - name: CMake run: | mkdir build - cd build && cmake -DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON .. + cd build && cmake -DDEBUG=OFF -DPROFILE=OFF -DBUILD_CLI_BINDINGS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON .. - name: Build run: | - cd build && make R -j2 + cd build && make -j2 + + - name: Run tests via ctest + run: | + cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test . - name: Upload R packages uses: actions/upload-artifact@v2 From fa2d45ead5a885bcc43929ae1df254ed0d48c749 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Mon, 5 Oct 2020 20:01:34 +0530 Subject: [PATCH 23/45] Upload only logs on failure. --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa8859710b..989b313bd0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -155,4 +155,5 @@ jobs: uses: actions/upload-artifact@master with: name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + path: check/mlpack.Rcheck/00check.log + path: check/mlpack.Rcheck/00install.out From 009b942a776d022687b066923bcb1b2e63093f21 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Mon, 5 Oct 2020 20:13:27 +0530 Subject: [PATCH 24/45] Oops multi paths. --- .github/workflows/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 989b313bd0..2d0f8a4ed1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -155,5 +155,6 @@ jobs: uses: actions/upload-artifact@master with: name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check/mlpack.Rcheck/00check.log - path: check/mlpack.Rcheck/00install.out + path: | + check/mlpack.Rcheck/00check.log + check/mlpack.Rcheck/00install.out From e73a7750fbc71ba2d1e269153f107c0865445e1c Mon Sep 17 00:00:00 2001 From: Yashwant Date: Mon, 5 Oct 2020 20:20:34 +0530 Subject: [PATCH 25/45] Oh, that was `BUILD_CLI_EXECUTABLES`. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2d0f8a4ed1..b5f99d96f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,7 +78,7 @@ jobs: - name: CMake run: | mkdir build - cd build && cmake -DDEBUG=OFF -DPROFILE=OFF -DBUILD_CLI_BINDINGS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON .. + cd build && cmake -DDEBUG=OFF -DPROFILE=OFF -DBUILD_CLI_EXECUTABLES=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON .. - name: Build run: | From 403b11ebbe8ccbdcc1c651296224bc2341e2b7b4 Mon Sep 17 00:00:00 2001 From: Aakash kaushik Date: Tue, 6 Oct 2020 00:41:50 +0530 Subject: [PATCH 26/45] updating range_search_test with mlpack/master (#7) * softmin activation function added * shift added * shift changed for inputmax to inputmin * Test added for softmin forward function * errors fixed * suggested changes * forward function fixed * added softmin to HISTORY.md * forward result calculation source changed * space added in comment * backward function added * backward test function added, values left * Added WeightSize() to linear.hpp atrous_convolution.hpp add.hpp. * tests made similar to softmax * conflict fix * fixed HISTORY.md conflict * tests made similar to softmax * Update activation_functions_test.cpp * Removed header iostream * Apply suggestions from code review Co-authored-by: Marcus Edel Co-authored-by: Ryan Curtin Include bias term in linear layer. * catch2 for mean_shift_test.cpp * fixed backward function * reverted changes to main/mean_shift_test.cpp * corrected the test cases * main/mean_shift_test.cpp from boost to catch2 * migrated mean_shift_test from boost to catch2 * tests changed * tests changed * Test for WeightSetVisitor and WeightSizeVisitor * Fix common failures by increasing threshold * Typo fix * Auto Cancel build on new push and enable cache for build. * Windows fix. * Install R-bindings dependencies separately. * rcmdcheck doesn't for building mlpack_r_tarball. * Install roxygen2. * Specify platform in windows build. * Stop github actions running on a forked repo. * softmin activation function added shift added shift changed for inputmax to inputmin Test added for softmin forward function errors fixed suggested changes forward function fixed added softmin to HISTORY.md forward result calculation source changed space added in comment backward function added backward test function added, values left tests made similar to softmax conflict fix fixed HISTORY.md conflict tests made similar to softmax Update activation_functions_test.cpp Removed header iostream fixed backward function reverted changes to main/mean_shift_test.cpp corrected the test cases tests changed tests changed * Fix static issues * All static issue fixed (hopefully) * Migrate det and distribution test to catch2 Co-authored-by: Utkarsh Rai Co-authored-by: kartikdutt18 Co-authored-by: Yashwant Co-authored-by: Ryan Curtin Co-authored-by: kartikdutt18 <39593019+kartikdutt18@users.noreply.github.com> Co-authored-by: Ryan Birmingham Co-authored-by: jeffin143 --- .ci/windows-steps.yaml | 1 + .github/workflows/main.yml | 66 +- HISTORY.md | 2 + src/mlpack/methods/ann/layer/CMakeLists.txt | 2 + src/mlpack/methods/ann/layer/add.hpp | 3 + .../methods/ann/layer/atrous_convolution.hpp | 6 + src/mlpack/methods/ann/layer/layer.hpp | 1 + src/mlpack/methods/ann/layer/linear.hpp | 6 + src/mlpack/methods/ann/layer/softmin.hpp | 97 +++ src/mlpack/methods/ann/layer/softmin_impl.hpp | 61 ++ src/mlpack/tests/CMakeLists.txt | 8 +- .../tests/activation_functions_test.cpp | 72 ++ src/mlpack/tests/ann_layer_test.cpp | 201 +++--- src/mlpack/tests/ann_visitor_test.cpp | 34 + src/mlpack/tests/det_test.cpp | 469 ++++++------- src/mlpack/tests/distribution_test.cpp | 618 +++++++++--------- src/mlpack/tests/feedforward_network_test.cpp | 10 +- .../tests/main_tests/mean_shift_test.cpp | 69 +- src/mlpack/tests/mean_shift_test.cpp | 26 +- src/mlpack/tests/random_forest_test.cpp | 3 +- 20 files changed, 1055 insertions(+), 700 deletions(-) create mode 100644 src/mlpack/methods/ann/layer/softmin.hpp create mode 100644 src/mlpack/methods/ann/layer/softmin_impl.hpp diff --git a/.ci/windows-steps.yaml b/.ci/windows-steps.yaml index 069c6c5b46..69a33520a3 100644 --- a/.ci/windows-steps.yaml +++ b/.ci/windows-steps.yaml @@ -78,6 +78,7 @@ steps: msbuildVersion: $(MSBuildVersion) configuration: 'Release' msbuildArchitecture: 'x64' + platform: 'x64' msbuildArguments: /m /p:BuildInParallel=true maximumCpuCount: false clean: false diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8a4790897d..8640c26471 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,13 +8,31 @@ on: - master release: types: [published, created, edited] +name: R CMD check mlpack jobs: + cancel: + name: 'Cancel Previous Builds' + if: ${{ github.event_name == 'pull_request' && github.repository == 'mlpack/mlpack' }} + runs-on: ubuntu-latest + timeout-minutes: 3 + steps: + - name: Get all workflow ids and set to env variable + run: echo ::set-env name=WORKFLOW_IDS_TO_CANCEL::$(curl https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows -s | jq -r '.workflows | map(.id|tostring) | join(",")') + + - uses: styfle/cancel-workflow-action@0.5.0 + with: + workflow_id: ${{ env.WORKFLOW_IDS_TO_CANCEL }} + access_token: ${{ secrets.GITHUB_TOKEN }} + jobR: - name: mlpack-R + name: Build mlpack_r_tarball + if: ${{ github.repository == 'mlpack/mlpack' }} runs-on: ubuntu-20.04 + outputs: r_bindings: ${{ steps.mlpack_version.outputs.mlpack_r_package }} + steps: - uses: actions/checkout@v2 @@ -27,16 +45,35 @@ jobs: MLPACK_VERSION_VALUE=${MLPACK_VERSION_MAJOR}.${MLPACK_VERSION_MINOR}.${MLPACK_VERSION_PATCH} echo ::set-output name=mlpack_r_package::$(echo mlpack_"$MLPACK_VERSION_VALUE".tar.gz) + - uses: r-lib/actions/setup-r@master + with: + r-version: release + + - name: Query dependencies + run: | + cp src/mlpack/bindings/R/mlpack/DESCRIPTION.in DESCRIPTION + Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps(dependencies = TRUE), 'depends.Rds')" + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-release-${{ hashFiles('depends.Rds') }} + restore-keys: ${{ runner.os }}-r-release- + - name: Install Build Dependencies run: | sudo apt-get update sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ libboost-all-dev curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo* cmake . && make && sudo make install && cd .. - sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/' - sudo apt-get -y update - sudo apt-get install -y r-base-core - sudo Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" + + - name: Install R-bindings dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("roxygen2") + shell: Rscript {0} - name: CMake run: | @@ -58,6 +95,7 @@ jobs: runs-on: ${{ matrix.config.os }} name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + if: ${{ github.repository == 'mlpack/mlpack' }} strategy: fail-fast: false @@ -74,6 +112,8 @@ jobs: R_CHECK_ARGS: "--no-build-vignettes" _R_CHECK_FORCE_SUGGESTS: 0 R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/download-artifact@v2 @@ -86,10 +126,22 @@ jobs: - uses: r-lib/actions/setup-pandoc@master + - name: Query dependencies + run: Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE), 'depends.Rds')" + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}- + - name: Install dependencies run: | - Rscript -e "install.packages('remotes')" -e "remotes::install_cran('rcmdcheck')" - Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" + remotes::install_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} - name: Check run: Rscript -e "rcmdcheck::rcmdcheck('${{ needs.jobR.outputs.r_bindings }}', args = c('--no-manual','--as-cran'), error_on = 'warning', check_dir = 'check')" diff --git a/HISTORY.md b/HISTORY.md index d7a2437e9e..5acdedcb4f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,8 @@ ###### ????-??-?? * Added Mean Absolute Percentage Error. + * Added Softmin activation function as layer in ann/layer. + ### mlpack 3.4.1 ###### 2020-09-07 * Fix incorrect parsing of required matrix/model parameters for command-line diff --git a/src/mlpack/methods/ann/layer/CMakeLists.txt b/src/mlpack/methods/ann/layer/CMakeLists.txt index 34ea03c6a7..b4726b0c6f 100644 --- a/src/mlpack/methods/ann/layer/CMakeLists.txt +++ b/src/mlpack/methods/ann/layer/CMakeLists.txt @@ -116,6 +116,8 @@ set(SOURCES celu_impl.hpp softshrink.hpp softshrink_impl.hpp + softmin.hpp + softmin_impl.hpp ) # Add directory name to sources. diff --git a/src/mlpack/methods/ann/layer/add.hpp b/src/mlpack/methods/ann/layer/add.hpp index b3f95dbbcc..42b27809b8 100644 --- a/src/mlpack/methods/ann/layer/add.hpp +++ b/src/mlpack/methods/ann/layer/add.hpp @@ -100,6 +100,9 @@ class Add //! Get the output size. size_t OutputSize() const { return outSize; } + //! Get the size of weights. + size_t WeightSize() const { return outSize; } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/atrous_convolution.hpp b/src/mlpack/methods/ann/layer/atrous_convolution.hpp index b2a8f497e6..b3dfd1ce85 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution.hpp @@ -257,6 +257,12 @@ class AtrousConvolution //! Modify the internal Padding layer. ann::Padding<>& Padding() { return padding; } + //! Get size of the weight matrix. + size_t WeightSize() const + { + return (outSize * inSize * kernelWidth * kernelHeight) + outSize; + } + /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/layer.hpp b/src/mlpack/methods/ann/layer/layer.hpp index d005d1eb42..947395fd6b 100644 --- a/src/mlpack/methods/ann/layer/layer.hpp +++ b/src/mlpack/methods/ann/layer/layer.hpp @@ -66,6 +66,7 @@ #include "sequential.hpp" #include "softshrink.hpp" #include "softmax.hpp" +#include "softmin.hpp" #include "spatial_dropout.hpp" #include "subview.hpp" #include "transposed_convolution.hpp" diff --git a/src/mlpack/methods/ann/layer/linear.hpp b/src/mlpack/methods/ann/layer/linear.hpp index 1930181654..6dfd719d5f 100644 --- a/src/mlpack/methods/ann/layer/linear.hpp +++ b/src/mlpack/methods/ann/layer/linear.hpp @@ -146,6 +146,12 @@ class Linear //! Modify the bias weights of the layer. OutputDataType& Bias() { return bias; } + //! Get the size of the weights. + size_t WeightSize() const + { + return (inSize * outSize) + outSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/softmin.hpp b/src/mlpack/methods/ann/layer/softmin.hpp new file mode 100644 index 0000000000..a7b882c942 --- /dev/null +++ b/src/mlpack/methods/ann/layer/softmin.hpp @@ -0,0 +1,97 @@ +/** + * @file methods/ann/layer/softmin.hpp + * @author Aakash Kaushik + * + * Definition of the Softmin class. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ + +#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP +#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP + +#include + +namespace mlpack { +namespace ann /** Artificial Neural Network. */ { + +/** + * Implementation of the Softmin layer. The Softmin function takes as a input + * a vector of K real numbers, rescaling them so that the elements of the + * K-dimensional output vector lie in the range [0, 1] and sum to 1. + * + * @tparam InputDataType Type of the input data (arma::colvec, arma::mat, + * arma::sp_mat or arma::cube). + * @tparam OutputDataType Type of the output data (arma::colvec, arma::mat, + * arma::sp_mat or arma::cube). + */ +template < + typename InputDataType = arma::mat, + typename OutputDataType = arma::mat +> +class Softmin +{ + public: + /** + * Create the Softmin object. + */ + Softmin(); + + /** + * Ordinary feed forward pass of a neural network, evaluating the function + * f(x) by propagating the activity forward through f. + * + * @param input Input data used for evaluating the specified function. + * @param output Resulting output activation. + */ + template + void Forward(const InputType& input, OutputType& output); + + /** + * Ordinary feed backward pass of a neural network, calculating the function + * f(x) by propagating x backwards through f. Using the results from the feed + * forward pass. + * + * @param input The propagated input activation. + * @param gy The backpropagated error. + * @param g The calculated gradient. + */ + template + void Backward(const arma::Mat& input, + const arma::Mat& gy, + arma::Mat& g); + + //! Get the output parameter. + OutputDataType& OutputParameter() const { return outputParameter; } + //! Modify the output parameter. + OutputDataType& OutputParameter() { return outputParameter; } + + //! Get the delta. + InputDataType& Delta() const { return delta; } + //! Modify the delta. + InputDataType& Delta() { return delta; } + + /** + * Serialize the layer. + */ + template + void serialize(Archive& /* ar */, const unsigned int /* version */); + + private: + //! Locally-stored delta object. + OutputDataType delta; + + //! Locally stored output parameter object. + OutputDataType outputParameter; +}; // class Softmin + +} // namespace ann +} // namespace mlpack + +// Include implementation. +#include "softmin_impl.hpp" + +#endif diff --git a/src/mlpack/methods/ann/layer/softmin_impl.hpp b/src/mlpack/methods/ann/layer/softmin_impl.hpp new file mode 100644 index 0000000000..7693ca11dd --- /dev/null +++ b/src/mlpack/methods/ann/layer/softmin_impl.hpp @@ -0,0 +1,61 @@ +/** + * @file methods/ann/layer/softmin_impl.hpp + * @author Aakash Kaushik + * + * Implementation of the Softmin class. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP +#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP + +// In case it hasn't yet been included. +#include "softmin.hpp" + +namespace mlpack { +namespace ann /** Artificial Neural Network. */ { + +template +Softmin::Softmin() +{ + // Nothing to do here. +} + +template +template +void Softmin::Forward( + const InputType& input, + OutputType& output) +{ + InputType inputMin = arma::repmat(arma::min(input,0), input.n_rows, 1); + output = arma::repmat(arma::log(arma::sum( + arma::exp(-(input - inputMin)),0)), input.n_rows, 1); + output = arma::exp(-(input - inputMin) - output); +} + +template +template +void Softmin::Backward( + const arma::Mat& input, + const arma::Mat& gy, + arma::Mat& g) +{ + g = input % (gy - arma::repmat(arma::sum(gy % input), input.n_rows, 1)); +} + +template +template +void Softmin::serialize( + Archive& /* ar */, + const unsigned int /* version */) +{ + // Nothing to do here. +} + +} // namespace ann +} // namespace mlpack + +#endif diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index fae84ae9a8..b273dd3e4e 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -8,8 +8,6 @@ add_executable(mlpack_test io_test.cpp cosine_tree_test.cpp dcgan_test.cpp - det_test.cpp - distribution_test.cpp drusilla_select_test.cpp emst_test.cpp fastmks_test.cpp @@ -36,7 +34,6 @@ add_executable(mlpack_test math_test.cpp matrix_completion_test.cpp maximal_inputs_test.cpp - mean_shift_test.cpp metric_test.cpp mlpack_test.cpp mock_categorical_data.hpp @@ -92,7 +89,6 @@ add_executable(mlpack_test main_tests/local_coordinate_coding_test.cpp main_tests/logistic_regression_test.cpp main_tests/lsh_test.cpp - main_tests/mean_shift_test.cpp main_tests/nbc_test.cpp main_tests/nmf_test.cpp main_tests/perceptron_test.cpp @@ -122,6 +118,8 @@ add_executable(mlpack_catch_test dbscan_test.cpp decision_stump_test.cpp decision_tree_test.cpp + det_test.cpp + distribution_test.cpp feedforward_network_test.cpp image_load_test.cpp imputation_test.cpp @@ -135,6 +133,7 @@ add_executable(mlpack_catch_test load_save_test.cpp loss_functions_test.cpp main.cpp + mean_shift_test.cpp nca_test.cpp one_hot_encoding_test.cpp pca_test.cpp @@ -168,6 +167,7 @@ add_executable(mlpack_catch_test main_tests/kmeans_test.cpp main_tests/knn_test.cpp main_tests/linear_regression_test.cpp + main_tests/mean_shift_test.cpp main_tests/nca_test.cpp main_tests/pca_test.cpp main_tests/preprocess_binarize_test.cpp diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 2c1fe63398..9ee1ebcaf9 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -558,6 +558,58 @@ void CheckCELUDerivativeCorrect(const arma::colvec input, } } +/** + * Implementation of the Softmin activation function test. The function is + * implemented as Softmin layer in the file softmin.hpp. + * + * @param input Input data used for evaluating the Softmin activation function. + * @param target Target data used to evaluate the Softmin activation. + */ +void CheckSoftminActivationCorrect(const arma::colvec input, + const arma::colvec target) +{ + // Initialize Softmin object. + Softmin<> softmin; + + // Test the activation function using the entire vector as input. + arma::colvec activations; + softmin.Forward(input,activations); + for (size_t i = 0; i < activations.n_elem; ++i) + { + REQUIRE(activations.at(i) == Approx(target.at(i)).epsilon(1e-5)); + } +} + +/** + * Implementation of the Softmin activation function derivative test. + * The function is implemented as Softmin layer in the file softmin.hpp. + * + * @param input Input data used for evaluating the Softmin activation function. + * @param target Target data used to evaluate the Softmin activation. + */ +void CheckSoftminDerivativeCorrect(const arma::colvec input, + const arma::colvec target) +{ + // Initialize Softmin object. + Softmin<> softmin; + + // Test the calculation of the derivatives using the entire vector as input. + arma::colvec derivatives, activations; + + // This error vector will be set to [[1.0],[0.0],[1.0],[0.0]] + // to get the derivatives. + arma::colvec error = arma::ones(input.n_elem); + error(1) = 0.0; + error(3) = 0.0; + softmin.Forward(input, activations); + softmin.Backward(activations, error, derivatives); + for (size_t i = 0; i < derivatives.n_elem; ++i) + { + REQUIRE(derivatives.at(i) == Approx(target.at(i)).epsilon(1e-5)); + } + +} + /** * Basic test of the tanh function. */ @@ -1063,3 +1115,23 @@ TEST_CASE("GaussianFunctionTest", "[ActivationFunctionsTest]") CheckDerivativeCorrect(desiredActivations, desiredDerivatives); } + +/** + * Basic test of the Softmin function. + */ +TEST_CASE("SoftminFunctionTest", "[ActivationFunctionsTest]") +{ + const arma::colvec activationData("4.2 2.4 7.0 6.4"); + + // Hand-calculated Values. + const arma::colvec desiredActivations("0.1384799751 0.8377550303 \ + 0.008420976 0.0153440186"); + + const arma::colvec desiredDerivatives("0.1181371351 -0.12306701070 \ + 0.0071839266 -0.0022540509"); + + CheckSoftminActivationCorrect(activationData, + desiredActivations); + CheckSoftminDerivativeCorrect(activationData, + desiredDerivatives); +} diff --git a/src/mlpack/tests/ann_layer_test.cpp b/src/mlpack/tests/ann_layer_test.cpp index dfd1ecf091..37a5a5b192 100644 --- a/src/mlpack/tests/ann_layer_test.cpp +++ b/src/mlpack/tests/ann_layer_test.cpp @@ -87,11 +87,10 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -416,11 +415,10 @@ TEST_CASE("GradientLinearLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -508,13 +506,12 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + inSize(4), + outSize(1), + nPoints(2), + batchSize(4) { - const size_t inSize = 4; - const size_t outSize = 1; - const size_t nPoints = 2; - const size_t batchSize = 4; - input = arma::randu(inSize * nPoints, batchSize); target = arma::zeros(outSize * nPoints, batchSize); target(0, 0) = 1; @@ -545,6 +542,10 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") FFN, RandomInitialization>* model; arma::mat input, target; + const size_t inSize; + const size_t outSize; + const size_t nPoints; + const size_t batchSize; } function; REQUIRE(CheckGradient(function) <= 1e-7); @@ -591,11 +592,10 @@ TEST_CASE("GradientNoisyLinearLayerTest", "[ANNLayerTest]") // Noisy linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -695,11 +695,10 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]") // LinearNoBias function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -797,11 +796,10 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(2, 1)), + target(arma::mat("1")) { - input = arma::randu(2, 1); - target = arma::mat("1"); - model = new FFN, RandomInitialization>( NegativeLogLikelihood<>(), RandomInitialization(0.1, 0.5)); @@ -1017,10 +1015,10 @@ TEST_CASE("GradientLSTMLayerTest", "[ANNLayerTest]") // LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(1, 1, 5)), + target(arma::ones(1, 1, 5)) { - input = arma::randu(1, 1, 5); - target.ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1122,10 +1120,10 @@ TEST_CASE("GradientFastLSTMLayerTest", "[ANNLayerTest]") // Fast LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(1, 1, 5)), + target(arma::ones(1, 1, 5)) { - input = arma::randu(1, 1, 5); - target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1391,10 +1389,10 @@ TEST_CASE("GradientGRULayerTest", "[ANNLayerTest]") // GRU function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(1, 1, 5)), + target(arma::ones(1, 1, 5)) { - input = arma::randu(1, 1, 5); - target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1631,11 +1629,10 @@ TEST_CASE("GradientConcatLayerTest", "[ANNLayerTest]") // Concat function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1700,11 +1697,10 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]") // Concatenate function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1905,11 +1901,10 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]") // Softmax function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1; 0")) { - input = arma::randu(10, 1); - target = arma::mat("1; 0"); - model = new FFN, RandomInitialization>; model->Predictors() = input; model->Responses() = target; @@ -2109,12 +2104,10 @@ TEST_CASE("GradientBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(32, 2048)), + target(arma::ones(1, 2048)) { - input = arma::randn(32, 2048); - arma::mat target; - target.ones(1, 2048); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2184,12 +2177,11 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(5, 256)), + target(arma::ones(1, 256)) { - input = arma::randn(5, 256); arma::mat referenceBatch = arma::mat(input.memptr(), input.n_rows, 16); - arma::mat target; - target.ones(1, 256); model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; @@ -2247,12 +2239,10 @@ TEST_CASE("MiniBatchDiscriminationTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(5, 4)), + target(arma::ones(1, 4)) { - input = arma::randn(5, 4); - arma::mat target; - target.ones(1, 4); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2427,11 +2417,10 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::linspace(0, 35, 36)), + target(arma::mat("1")) { - input = arma::linspace(0, 35, 36); - target = arma::mat("1"); - model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2544,11 +2533,10 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::linspace(0, 35, 36)), + target(arma::mat("1")) { - input = arma::linspace(0, 35, 36); - target = arma::mat("1"); - model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2575,7 +2563,7 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") arma::mat input, target; } function; - // TODO: this tolerance seems far higher than necessary. The implementation + // TODO: this tolerance seems far higher than necessary. The implementation // should be checked. REQUIRE(CheckGradient(function) <= 0.2); } @@ -2726,12 +2714,10 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(10, 256)), + target(arma::ones(1, 256)) { - input = arma::randn(10, 256); - arma::mat target; - target.ones(1, 256); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3048,11 +3034,10 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3092,11 +3077,10 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 2)), + target(arma::mat("1 1")) { - input = arma::randu(10, 2); - target = arma::mat("1 1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3248,11 +3232,10 @@ TEST_CASE("GradientHighwayLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(5, 1)), + target(arma::mat("1")) { - input = arma::randu(5, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3300,11 +3283,10 @@ TEST_CASE("GradientSequentialLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3351,11 +3333,10 @@ TEST_CASE("GradientWeightNormLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4185,12 +4166,10 @@ TEST_CASE("GradientBatchNormWithMiniBatchesTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(16, 1024)), + target(arma::ones(1, 1024)) { - input = arma::randn(16, 1024); - arma::mat target; - target.ones(1, 1024); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4683,7 +4662,13 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() + GradientFunction() : + tgtSeqLen(2), + srcSeqLen(2), + embedDim(4), + nHeads(2), + vocabSize(5), + batchSize(2) { input = arma::randu(embedDim * (tgtSeqLen + 2 * srcSeqLen), batchSize); target = arma::zeros(vocabSize, batchSize); @@ -4736,13 +4721,13 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") MultiheadAttention<>* attnModule; arma::mat input, target, attnMask, keyPaddingMask; - const size_t tgtSeqLen = 2; - const size_t srcSeqLen = 2; - const size_t embedDim = 4; - const size_t nHeads = 2; - const size_t vocabSize = 5; - const size_t batchSize = 2; + const size_t tgtSeqLen; + const size_t srcSeqLen; + const size_t embedDim; + const size_t nHeads; + const size_t vocabSize; + const size_t batchSize; } function; - REQUIRE(CheckGradient(function) <= 2e-06); + REQUIRE(CheckGradient(function) <= 3e-06); } diff --git a/src/mlpack/tests/ann_visitor_test.cpp b/src/mlpack/tests/ann_visitor_test.cpp index 1b01308ff3..ccf3cca35f 100644 --- a/src/mlpack/tests/ann_visitor_test.cpp +++ b/src/mlpack/tests/ann_visitor_test.cpp @@ -52,3 +52,37 @@ TEST_CASE("BiasSetVisitorTest", "[ANNVisitorTest]") boost::apply_visitor(DeleteVisitor(), linear); } + +/** + * Test that WeightSetVisitor works properly. + */ +TEST_CASE("WeightSetVisitorTest", "[ANNVisitorTest]") +{ + size_t randomSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> linear = new Linear<>(randomSize, randomSize); + + arma::mat layerWeights(randomSize * randomSize + randomSize, 1); + layerWeights.zeros(); + + size_t setWeights = boost::apply_visitor(WeightSetVisitor(layerWeights, 0), + linear); + + REQUIRE(setWeights == randomSize * randomSize + randomSize); +} + +/** + * Test that WeightSizeVisitor works properly. + */ +TEST_CASE("WeightSizeVisitorTest", "[ANNVisitorTest]") +{ + size_t randomSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> linear = new Linear<>(randomSize, randomSize); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), + linear); + + REQUIRE(weightSize == randomSize * randomSize + randomSize); +} + diff --git a/src/mlpack/tests/det_test.cpp b/src/mlpack/tests/det_test.cpp index 4a16bbd060..c0989768eb 100644 --- a/src/mlpack/tests/det_test.cpp +++ b/src/mlpack/tests/det_test.cpp @@ -11,8 +11,7 @@ * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" // This trick does not work on Windows. We will have to comment out the tests // that depend on it. @@ -33,13 +32,11 @@ using namespace mlpack; using namespace mlpack::det; using namespace std; -BOOST_AUTO_TEST_SUITE(DETTest); - // Tests for the private functions. We cannot perform these if we are on // Windows because we cannot make private functions accessible using the macro // trick above. #ifndef _WIN32 -BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) +TEST_CASE("TestGetMaxMinVals", "[DETTest]") { arma::mat testData(3, 5); @@ -49,15 +46,15 @@ BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) DTree tree(testData); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[0], 7); - BOOST_REQUIRE_EQUAL(tree.MinVals()[0], 3); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[1], 7); - BOOST_REQUIRE_EQUAL(tree.MinVals()[1], 0); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[2], 8); - BOOST_REQUIRE_EQUAL(tree.MinVals()[2], 1); + REQUIRE(tree.MaxVals()[0] == 7); + REQUIRE(tree.MinVals()[0] == 3); + REQUIRE(tree.MaxVals()[1] == 7); + REQUIRE(tree.MinVals()[1] == 0); + REQUIRE(tree.MaxVals()[2] == 8); + REQUIRE(tree.MinVals()[2] == 1); } -BOOST_AUTO_TEST_CASE(TestComputeNodeError) +TEST_CASE("TestComputeNodeError", "[DETTest]") { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -65,17 +62,18 @@ BOOST_AUTO_TEST_CASE(TestComputeNodeError) DTree testDTree(maxVals, minVals, 5); double trueNodeError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE((double) testDTree.logNegError, trueNodeError, 1e-10); + REQUIRE((double) testDTree.logNegError == + Approx(trueNodeError).epsilon(1e-12)); testDTree.start = 3; testDTree.end = 5; double nodeError = testDTree.LogNegativeError(5); trueNodeError = 2 * log(2.0 / 5.0) - log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(nodeError, trueNodeError, 1e-10); + REQUIRE(nodeError == Approx(trueNodeError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestWithinRange) +TEST_CASE("TestWithinRange", "[DETTest]") { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -85,14 +83,14 @@ BOOST_AUTO_TEST_CASE(TestWithinRange) arma::vec testQuery(3); testQuery << 4.5 << 2.5 << 2; - BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), true); + REQUIRE(testDTree.WithinRange(testQuery) == true); testQuery << 8.5 << 2.5 << 2; - BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), false); + REQUIRE(testDTree.WithinRange(testQuery) == false); } -BOOST_AUTO_TEST_CASE(TestFindSplit) +TEST_CASE("TestFindSplit", "[DETTest]") { arma::mat testData(3, 5); @@ -108,20 +106,21 @@ BOOST_AUTO_TEST_CASE(TestFindSplit) size_t trueDim = 2; double trueSplit = 5.5; double trueLeftError = 2 * log(2.0 / 5.0) - (log(7.0) + log(4.0) + log(4.5)); - double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + log(2.5)); + double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + + log(2.5)); testDTree.logVolume = log(7.0) + log(4.0) + log(7.0); - BOOST_REQUIRE(testDTree.FindSplit( + REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - BOOST_REQUIRE(trueDim == obDim); - BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); + REQUIRE(trueDim == obDim); + REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); - BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); - BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); + REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); + REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSplitData) +TEST_CASE("TestSplitData", "[DETTest]") { arma::mat testData(3, 5); @@ -140,16 +139,16 @@ BOOST_AUTO_TEST_CASE(TestSplitData) size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - BOOST_REQUIRE_EQUAL(splitInd, 2); // 2 points on left side. + REQUIRE(splitInd == 2); // 2 points on left side. - BOOST_REQUIRE_EQUAL(oTest[0], 1); - BOOST_REQUIRE_EQUAL(oTest[1], 4); - BOOST_REQUIRE_EQUAL(oTest[2], 3); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 5); + REQUIRE(oTest[0] == 1); + REQUIRE(oTest[1] == 4); + REQUIRE(oTest[2] == 3); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 5); } -BOOST_AUTO_TEST_CASE(TestSparseFindSplit) +TEST_CASE("TestSparseFindSplit", "[DETTest]") { arma::mat realData(4, 7); @@ -173,17 +172,17 @@ BOOST_AUTO_TEST_CASE(TestSparseFindSplit) (log(7.0) + log(6.5) + log(8.0) + log(6.0)); testDTree.logVolume = log(7.0) + log(7.0) + log(8.0) + log(6.0); - BOOST_REQUIRE(testDTree.FindSplit( + REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - BOOST_REQUIRE(trueDim == obDim); - BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); + REQUIRE(trueDim == obDim); + REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); - BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); - BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); + REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); + REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSparseSplitData) +TEST_CASE("TestSparseSplitData", "[DETTest]") { arma::mat realData(4, 7); @@ -205,22 +204,22 @@ BOOST_AUTO_TEST_CASE(TestSparseSplitData) size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - BOOST_REQUIRE_EQUAL(splitInd, 3); // 2 points on left side. + REQUIRE(splitInd == 3); // 2 points on left side. - BOOST_REQUIRE_EQUAL(oTest[0], 1); - BOOST_REQUIRE_EQUAL(oTest[1], 4); - BOOST_REQUIRE_EQUAL(oTest[2], 3); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 5); - BOOST_REQUIRE_EQUAL(oTest[5], 6); - BOOST_REQUIRE_EQUAL(oTest[6], 7); + REQUIRE(oTest[0] == 1); + REQUIRE(oTest[1] == 4); + REQUIRE(oTest[2] == 3); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 5); + REQUIRE(oTest[5] == 6); + REQUIRE(oTest[6] == 7); } #endif // Tests for the public functions. -BOOST_AUTO_TEST_CASE(TestGrow) +TEST_CASE("TestGrow", "[DETTest]") { arma::mat testData(3, 5); @@ -244,34 +243,36 @@ BOOST_AUTO_TEST_CASE(TestGrow) DTree testDTree(testData); double alpha = testDTree.Grow(testData, oTest, false, 2, 1); - BOOST_REQUIRE_EQUAL(oTest[0], 0); - BOOST_REQUIRE_EQUAL(oTest[1], 3); - BOOST_REQUIRE_EQUAL(oTest[2], 1); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 4); + REQUIRE(oTest[0] == 0); + REQUIRE(oTest[1] == 3); + REQUIRE(oTest[2] == 1); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 4); // Test the structure of the tree. - BOOST_REQUIRE(testDTree.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree.Right()->Right()->Right() == NULL); + REQUIRE(testDTree.Left()->Left() == NULL); + REQUIRE(testDTree.Left()->Right() == NULL); + REQUIRE(testDTree.Right()->Left()->Left() == NULL); + REQUIRE(testDTree.Right()->Left()->Right() == NULL); + REQUIRE(testDTree.Right()->Right()->Left() == NULL); + REQUIRE(testDTree.Right()->Right()->Right() == NULL); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 3); + REQUIRE(testDTree.SubtreeLeaves() == 3); - BOOST_REQUIRE(testDTree.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree.SplitDim() == 2); + REQUIRE(testDTree.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree.Right()->SplitDim() == 1); + REQUIRE(testDTree.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); // Test node errors for every node (these are private functions). #ifndef _WIN32 - BOOST_REQUIRE_CLOSE(testDTree.logNegError, rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Left()->logNegError, lError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->logNegError, rError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->Left()->logNegError, rlError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->Right()->logNegError, rrError, 1e-10); + REQUIRE(testDTree.logNegError == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left()->logNegError == Approx(lError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->logNegError == Approx(rError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->Left()->logNegError == + Approx(rlError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->Right()->logNegError == + Approx(rrError).epsilon(1e-12)); #endif // Test alpha. @@ -281,10 +282,10 @@ BOOST_AUTO_TEST_CASE(TestGrow) rAlpha = std::log(-(std::exp(rError) - (std::exp(rlError) + std::exp(rrError)))); - BOOST_REQUIRE_CLOSE(alpha, min(rootAlpha, rAlpha), 1e-10); + REQUIRE(alpha == Approx(min(rootAlpha, rAlpha)).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) +TEST_CASE("TestPruneAndUpdate", "[DETTest]") { arma::mat testData(3, 5); @@ -298,18 +299,19 @@ BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); + REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); - BOOST_REQUIRE(testDTree.Left() == NULL); - BOOST_REQUIRE(testDTree.Right() == NULL); + REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeavesLogNegError() == + Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left() == NULL); + REQUIRE(testDTree.Right() == NULL); } -BOOST_AUTO_TEST_CASE(TestComputeValue) +TEST_CASE("TestComputeValue", "[DETTest]") { arma::mat testData(3, 5); @@ -334,22 +336,22 @@ BOOST_AUTO_TEST_CASE(TestComputeValue) double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestVariableImportance) +TEST_CASE("TestVariableImportance", "[DETTest]") { arma::mat testData(3, 5); @@ -377,12 +379,14 @@ BOOST_AUTO_TEST_CASE(TestVariableImportance) testDTree.ComputeVariableImportance(imps); - BOOST_REQUIRE_CLOSE((double) 0.0, imps[0], 1e-10); - BOOST_REQUIRE_CLOSE((double) (rError - (rlError + rrError)), imps[1], 1e-10); - BOOST_REQUIRE_CLOSE((double) (rootError - (lError + rError)), imps[2], 1e-10); + REQUIRE((double) 0.0 == Approx(imps[0]).epsilon(1e-12)); + REQUIRE((double) (rError - (rlError + rrError)) == + Approx(imps[1]).epsilon(1e-12)); + REQUIRE((double) (rootError - (lError + rError)) == + Approx(imps[2]).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) +TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]") { arma::mat realData(3, 5); @@ -399,18 +403,19 @@ BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); + REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); - BOOST_REQUIRE(testDTree.Left() == NULL); - BOOST_REQUIRE(testDTree.Right() == NULL); + REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeavesLogNegError() == + Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left() == NULL); + REQUIRE(testDTree.Right() == NULL); } -BOOST_AUTO_TEST_CASE(TestSparseComputeValue) +TEST_CASE("TestSparseComputeValue", "[DETTest]") { arma::mat realData(3, 5); @@ -438,25 +443,25 @@ BOOST_AUTO_TEST_CASE(TestSparseComputeValue) double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); } /** * These are not yet implemented. * -BOOST_AUTO_TEST_CASE(TestTagTree) +TEST_CASE("TestTagTree", "[DETTest]") { MatType testData(3, 5); @@ -469,7 +474,7 @@ BOOST_AUTO_TEST_CASE(TestTagTree) delete testDTree; } -BOOST_AUTO_TEST_CASE(TestFindBucket) +TEST_CASE("TestFindBucket", "[DETTest]") { MatType testData(3, 5); @@ -484,24 +489,24 @@ BOOST_AUTO_TEST_CASE(TestFindBucket) // Test functions in dt_utils.hpp -BOOST_AUTO_TEST_CASE(TestTrainer) +TEST_CASE("TestTrainer", "[DETTest]") { } -BOOST_AUTO_TEST_CASE(TestPrintVariableImportance) +TEST_CASE("TestPrintVariableImportance", "[DETTest]") { } -BOOST_AUTO_TEST_CASE(TestPrintLeafMembership) +TEST_CASE("TestPrintLeafMembership", "[DETTest]") { } */ // Test the copy constructor and the copy operator. -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) +TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -544,76 +549,76 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) delete testDTree; // Test the data of copied tree (using copy constructor). - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the data of the copied tree (using the copy operator). - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[2], minVals2); + REQUIRE(testDTree3.MaxVals()[0] == maxVals0); + REQUIRE(testDTree3.MinVals()[0] == minVals0); + REQUIRE(testDTree3.MaxVals()[1] == maxVals1); + REQUIRE(testDTree3.MinVals()[1] == minVals1); + REQUIRE(testDTree3.MaxVals()[2] == maxVals2); + REQUIRE(testDTree3.MinVals()[2] == minVals2); // Test the structure of the tree copied using the copy constructor. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the structure of the tree copied using the copy operator. - BOOST_REQUIRE(testDTree3.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Right()->Right() == NULL); + REQUIRE(testDTree3.Left()->Left() == NULL); + REQUIRE(testDTree3.Left()->Right() == NULL); + REQUIRE(testDTree3.Right()->Left()->Left() == NULL); + REQUIRE(testDTree3.Right()->Left()->Right() == NULL); + REQUIRE(testDTree3.Right()->Right()->Left() == NULL); + REQUIRE(testDTree3.Right()->Right()->Right() == NULL); // Test the data of the tree copied using the copy constructor. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); // Test the data of the tree copied using the copy operator. - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree3.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree3.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree3.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree3.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree3.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree3.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree3.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree3.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree3.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree3.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree3.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree3.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree3.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree3.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree3.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree3.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree3.SplitDim() == 2); + REQUIRE(testDTree3.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree3.Right()->SplitDim() == 1); + REQUIRE(testDTree3.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } // Test the move constructor. -BOOST_AUTO_TEST_CASE(MoveConstructorTest) +TEST_CASE("MoveConstructorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -653,50 +658,50 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) DTree testDTree2(std::move(*testDTree)); // Check default values of the original tree. - BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); - BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); - BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); + REQUIRE(testDTree->LogNegError() == -DBL_MAX); + REQUIRE(testDTree->Left() == (DTree*) NULL); + REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the structure of the moved tree. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } // Test the move operator. -BOOST_AUTO_TEST_CASE(MoveOperatorTest) +TEST_CASE("MoveOperatorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -736,46 +741,44 @@ BOOST_AUTO_TEST_CASE(MoveOperatorTest) DTree testDTree2 = std::move(*testDTree); // Check default values of the original tree. - BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); - BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); - BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); + REQUIRE(testDTree->LogNegError() == -DBL_MAX); + REQUIRE(testDTree->Left() == (DTree*) NULL); + REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the structure of the moved tree. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 35103130b9..ab7d606a9f 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -19,17 +19,15 @@ #include #include -#include -#include "test_tools.hpp" -#include "serialization.hpp" +#include "catch.hpp" +#include "serialization_catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::distribution; using namespace mlpack::metric; using namespace mlpack::math; -BOOST_AUTO_TEST_SUITE(DistributionTest); - /*********************************/ /** Discrete Distribution Tests **/ /*********************************/ @@ -37,38 +35,38 @@ BOOST_AUTO_TEST_SUITE(DistributionTest); /** * Make sure we initialize correctly. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionConstructorTest) +TEST_CASE("DiscreteDistributionConstructorTest", "[DistributionTest]") { DiscreteDistribution d(5); - BOOST_REQUIRE_EQUAL(d.Probabilities().n_elem, 5); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); + REQUIRE(d.Probabilities().n_elem == 5); + REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); } /** * Make sure we get the probabilities of observations right. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionProbabilityTest) +TEST_CASE("DiscreteDistributionProbabilityTest", "[DistributionTest]") { DiscreteDistribution d(5); d.Probabilities() = "0.2 0.4 0.1 0.1 0.2"; - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.4, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.1, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.1, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.4).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.1).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.1).epsilon(1e-7)); + REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); } /** * Make sure we get random observations correct. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) +TEST_CASE("DiscreteDistributionRandomTest", "[DistributionTest]") { DiscreteDistribution d(arma::Col("3")); @@ -85,15 +83,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) actualProb /= accu(actualProb); // 8% tolerance, because this can be a noisy process. - BOOST_REQUIRE_CLOSE(actualProb(0), 0.3, 8.0); - BOOST_REQUIRE_CLOSE(actualProb(1), 0.6, 8.0); - BOOST_REQUIRE_CLOSE(actualProb(2), 0.1, 8.0); + REQUIRE(actualProb(0) == Approx(0.3).epsilon(0.08)); + REQUIRE(actualProb(1) == Approx(0.6).epsilon(0.08)); + REQUIRE(actualProb(2) == Approx(0.1).epsilon(0.08)); } /** * Make sure we can estimate from observations correctly. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) +TEST_CASE("DiscreteDistributionTrainTest", "[DistributionTest]") { DiscreteDistribution d(4); @@ -101,16 +99,16 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) d.Train(obs); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.375, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.125, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.375).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.125).epsilon(1e-7)); } /** * Estimate from observations with probabilities. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) +TEST_CASE("DiscreteDistributionTrainProbTest", "[DistributionTest]") { DiscreteDistribution d(3); @@ -120,15 +118,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) d.Train(obs, prob); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.5, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.5).epsilon(1e-7)); } /** * Achieve multidimensional probability distribution. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) +TEST_CASE("MultiDiscreteDistributionTrainProbTest", "[DistributionTest]") { DiscreteDistribution d("10 10 10"); @@ -137,29 +135,29 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) "0 0 0 1 1 2 2 2 2 2;"); d.Train(obs); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.009, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.015, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.054, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.009).epsilon(1e-7)); + REQUIRE(d.Probability("0 1 2") == Approx(0.015).epsilon(1e-7)); + REQUIRE(d.Probability("2 1 0") == Approx(0.054).epsilon(1e-7)); } /** * Make sure we initialize multidimensional probability distribution * correctly. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionConstructorTest) +TEST_CASE("MultiDiscreteDistributionConstructorTest", "[DistributionTest]") { DiscreteDistribution d("4 4 4 4"); - BOOST_REQUIRE_EQUAL(d.Probabilities(0).size(), 4); - BOOST_REQUIRE_EQUAL(d.Dimensionality(), 4); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0 0"), 0.00390625, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2 3"), 0.00390625, 1e-5); + REQUIRE(d.Probabilities(0).size() == 4); + REQUIRE(d.Dimensionality() == 4); + REQUIRE(d.Probability("0 0 0 0") == Approx(0.00390625).epsilon(1e-7)); + REQUIRE(d.Probability("0 1 2 3") == Approx(0.00390625).epsilon(1e-7)); } /** * Achieve multidimensional probability distribution. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) +TEST_CASE("MultiDiscreteDistributionTrainTest", "[DistributionTest]") { std::vector pro; pro.push_back(arma::vec("0.1, 0.3, 0.6")); @@ -168,16 +166,16 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) DiscreteDistribution d(pro); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.0083333, 1e-3); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.0166666, 1e-3); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.05, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.0083333).epsilon(1e-5)); + REQUIRE(d.Probability("0 1 2") == Approx(0.0166666).epsilon(1e-5)); + REQUIRE(d.Probability("2 1 0") == Approx(0.05).epsilon(1e-7)); } /** * Estimate multidimensional probability distribution from observations with * probabilities. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) +TEST_CASE("MultiDiscreteDistributionTrainProTest", "[DistributionTest]") { DiscreteDistribution d("5 5 5"); @@ -189,16 +187,16 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) d.Train(obs, prob); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.00390625, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1 0 1"), 0.0078125, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.015625, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.00390625).epsilon(1e-7)); + REQUIRE(d.Probability("1 0 1") == Approx(0.0078125).epsilon(1e-7)); + REQUIRE(d.Probability("2 1 0") == Approx(0.015625).epsilon(1e-7)); } /** * Test the LogProbability() function, for multiple points in the multivariate * Discrete case. */ -BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) +TEST_CASE("DiscreteLogProbabilityTest", "[DistributionTest]") { // Same case as before. DiscreteDistribution d("5 5"); @@ -210,17 +208,17 @@ BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) d.LogProbability(obs, logProb); - BOOST_REQUIRE_EQUAL(logProb.n_elem, 2); + REQUIRE(logProb.n_elem == 2); - BOOST_REQUIRE_CLOSE(logProb(0), -3.2188758248682, 1e-3); - BOOST_REQUIRE_CLOSE(logProb(1), -3.2188758248682, 1e-3); + REQUIRE(logProb(0) == Approx(-3.2188758248682).epsilon(1e-5)); + REQUIRE(logProb(1) == Approx(-3.2188758248682).epsilon(1e-5)); } /** * Test the Probability() function, for multiple points in the multivariate * Discrete case. */ -BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) +TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") { // Same case as before. DiscreteDistribution d("5 5"); @@ -232,10 +230,10 @@ BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) d.Probability(obs, prob); - BOOST_REQUIRE_EQUAL(prob.n_elem, 2); + REQUIRE(prob.n_elem == 2); - BOOST_REQUIRE_CLOSE(prob(0), 0.0400000000000, 1e-3); - BOOST_REQUIRE_CLOSE(prob(1), 0.0400000000000, 1e-3); + REQUIRE(prob(0) == Approx(0.0400000000000).epsilon(1e-5)); + REQUIRE(prob(1) == Approx(0.0400000000000).epsilon(1e-5)); } /*********************************/ @@ -245,32 +243,33 @@ BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) /** * Make sure Gaussian distributions are initialized correctly. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionEmptyConstructor) +TEST_CASE("GaussianDistributionEmptyConstructor", "[DistributionTest]") { GaussianDistribution d; - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); + REQUIRE(d.Mean().n_elem == 0); + REQUIRE(d.Covariance().n_elem == 0); } /** * Make sure Gaussian distributions are initialized to the correct * dimensionality. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionDimensionalityConstructor) +TEST_CASE("GaussianDistributionDimensionalityConstructor", + "[DistributionTest]") { GaussianDistribution d(4); - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_rows, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_cols, 4); + REQUIRE(d.Mean().n_elem == 4); + REQUIRE(d.Covariance().n_rows == 4); + REQUIRE(d.Covariance().n_cols == 4); } /** * Make sure Gaussian distributions are initialized correctly when we give a * mean and covariance. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) +TEST_CASE("GaussianDistributionDistributionConstructor", "[DistributionTest]") { arma::vec mean(3); arma::mat covariance(3, 3); @@ -283,17 +282,17 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) GaussianDistribution d(mean, covariance); for (size_t i = 0; i < 3; ++i) - BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); + REQUIRE(d.Mean()[i] == Approx(mean[i]).epsilon(1e-7)); for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) - BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); + REQUIRE(d.Covariance()(i, j) == Approx(covariance(i, j)).epsilon(1e-7)); } /** * Make sure the probability of observations is correct. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) +TEST_CASE("GaussianDistributionProbabilityTest", "[DistributionTest]") { arma::vec mean("5 6 3 3 2"); arma::mat cov("6 1 1 1 2;" @@ -304,52 +303,63 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) GaussianDistribution d(mean, cov); - BOOST_REQUIRE_CLOSE(d.LogProbability("0 1 2 3 4"), -13.432076798791542, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("3 2 3 7 8"), -15.814880322345738, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 2 0 8 1"), -13.754462857772776, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 1 5 0 1"), -13.283283233107898, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("3 0 5 1 0"), -13.800326511545279, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("4 0 6 1 0"), -14.900192463287908, 1e-5); + REQUIRE(d.LogProbability("0 1 2 3 4") == + Approx(-13.432076798791542).epsilon(1e-7)); + REQUIRE(d.LogProbability("3 2 3 7 8") == + Approx(-15.814880322345738).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 2 0 8 1") == + Approx(-13.754462857772776).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 1 5 0 1") == + Approx(-13.283283233107898).epsilon(1e-7)); + REQUIRE(d.LogProbability("3 0 5 1 0") == + Approx(-13.800326511545279).epsilon(1e-7)); + REQUIRE(d.LogProbability("4 0 6 1 0") == + Approx(-14.900192463287908).epsilon(1e-7)); } /** * Test GaussianDistribution::Probability() in the univariate case. */ -BOOST_AUTO_TEST_CASE(GaussianUnivariateProbabilityTest) +TEST_CASE("GaussianUnivariateProbabilityTest", "[DistributionTest]") { GaussianDistribution g(arma::vec("0.0"), arma::mat("1.0")); // Simple case. - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.398942280401433, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.241970724519143, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.241970724519143, - 1e-5); + REQUIRE(g.Probability(arma::vec("0.0")) == + Approx(0.398942280401433).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.241970724519143).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.241970724519143).epsilon(1e-7)); // A few more cases... arma::mat covariance; covariance = 2.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.282094791773878, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.219695644733861, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.219695644733861, - 1e-5); + REQUIRE(g.Probability(arma::vec("0.0")) == + Approx(0.282094791773878).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.219695644733861).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.219695644733861).epsilon(1e-7)); g.Mean().fill(1.0); covariance = 1.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.398942280401433, 1e-5); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.398942280401433).epsilon(1e-7)); covariance = 2.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.103776874355149, - 1e-5); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.103776874355149).epsilon(1e-7)); } /** * Test GaussianDistribution::Probability() in the multivariate case. */ -BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) +TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") { // Simple case. arma::vec mean = "0 0"; @@ -358,37 +368,37 @@ BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) GaussianDistribution g(mean, cov); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.159154943091895, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.159154943091895).epsilon(1e-7)); arma::mat covariance; covariance = "2 0; 0 2"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); x = "1 1"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0482661763150270, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0482661763150270, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0482661763150270).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(0.0482661763150270).epsilon(1e-7)); g.Mean() = "1 1"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(-x) == Approx(0.0795774715459477).epsilon(1e-7)); g.Mean() = "1 1"; covariance = "2 1.5; 1.5 4"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.066372199406187285, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.066372199406187285).epsilon(1e-7)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.066372199406187285, 1e-5); + REQUIRE(g.Probability(-x) == Approx(0.066372199406187285).epsilon(1e-7)); g.Mean() = "1 1"; x = "-1 4"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.00072147262356379415, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.00085851785428674523, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.00072147262356379415).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(0.00085851785428674523).epsilon(1e-7)); // Higher-dimensional case. x = "0 1 2 3 4"; @@ -401,19 +411,19 @@ BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) "2 0 1 0 6"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 1.4673143531128877e-06, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 7.7404143494891786e-09, 1e-8); + REQUIRE(g.Probability(x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 1.4673143531128877e-06, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(x), 7.7404143494891786e-09, 1e-8); + REQUIRE(g.Probability(-x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); + REQUIRE(g.Probability(x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. */ -BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) +TEST_CASE("GaussianMultipointMultivariateProbabilityTest", "[DistributionTest]") { // Same case as before. arma::vec mean = "5 6 3 3 2"; @@ -433,20 +443,20 @@ BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) GaussianDistribution g(mean, cov); g.LogProbability(points, phis); - BOOST_REQUIRE_EQUAL(phis.n_elem, 6); + REQUIRE(phis.n_elem == 6); - BOOST_REQUIRE_CLOSE(phis(0), -13.432076798791542, 1e-5); - BOOST_REQUIRE_CLOSE(phis(1), -15.814880322345738, 1e-5); - BOOST_REQUIRE_CLOSE(phis(2), -13.754462857772776, 1e-5); - BOOST_REQUIRE_CLOSE(phis(3), -13.283283233107898, 1e-5); - BOOST_REQUIRE_CLOSE(phis(4), -13.800326511545279, 1e-5); - BOOST_REQUIRE_CLOSE(phis(5), -14.900192463287908, 1e-5); + REQUIRE(phis(0) == Approx(-13.432076798791542).epsilon(1e-7)); + REQUIRE(phis(1) == Approx(-15.814880322345738).epsilon(1e-7)); + REQUIRE(phis(2) == Approx(-13.754462857772776).epsilon(1e-7)); + REQUIRE(phis(3) == Approx(-13.283283233107898).epsilon(1e-7)); + REQUIRE(phis(4) == Approx(-13.800326511545279).epsilon(1e-7)); + REQUIRE(phis(5) == Approx(-14.900192463287908).epsilon(1e-7)); } /** * Make sure random observations follow the probability distribution correctly. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) +TEST_CASE("GaussianDistributionRandomTest", "[DistributionTest]") { arma::vec mean("1.0 2.25"); arma::mat cov("0.85 0.60;" @@ -464,19 +474,19 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - BOOST_REQUIRE_CLOSE(obsMean[0], mean[0], 10.0); - BOOST_REQUIRE_CLOSE(obsMean[1], mean[1], 10.0); + REQUIRE(obsMean[0] == Approx(mean[0]).epsilon(0.1)); + REQUIRE(obsMean[1] == Approx(mean[1]).epsilon(0.1)); - BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0, 0), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(0, 1), cov(0, 1), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(1, 0), cov(1, 0), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1, 1), 10.0); + REQUIRE(obsCov(0, 0) == Approx(cov(0, 0)).epsilon(0.1)); + REQUIRE(obsCov(0, 1) == Approx(cov(0, 1)).epsilon(0.1)); + REQUIRE(obsCov(1, 0) == Approx(cov(1, 0)).epsilon(0.1)); + REQUIRE(obsCov(1, 1) == Approx(cov(1, 1)).epsilon(0.1)); } /** * Make sure that we can properly estimate from given observations. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) +TEST_CASE("GaussianDistributionTrainTest", "[DistributionTest]") { arma::vec mean("1.0 3.0 0.0 2.5"); arma::mat cov("3.0 0.0 1.0 4.0;" @@ -502,18 +512,22 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) // Check that everything is estimated right. for (size_t i = 0; i < 4; ++i) - BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); + REQUIRE(d.Mean()[i] - actualMean[i] == Approx(0.0).margin(1e-5)); for (size_t i = 0; i < 4; ++i) for (size_t j = 0; j < 4; ++j) - BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); + { + REQUIRE(d.Covariance()(i, j) - actualCov(i, j) == + Approx(0.0).margin(1e-5)); + } } /** * This test verifies the fitting of GaussianDistribution works properly when * probabilities for each sample is given. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) +TEST_CASE("GaussianDistributionTrainWithProbabilitiesTest", + "[DistributionTest]") { arma::vec mean = ("5.0"); arma::vec cov = ("2.0"); @@ -538,18 +552,19 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) GaussianDistribution guDist2; guDist2.Train(rdata); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 6); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 6); + REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(0.06)); + REQUIRE(guDist.Covariance()[0] == + Approx(guDist2.Covariance()[0]).epsilon(0.06)); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean[0], 6); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov[0], 6); + REQUIRE(guDist.Mean()[0] == Approx(mean[0]).epsilon(0.06)); + REQUIRE(guDist.Covariance()[0] == Approx(cov[0]).epsilon(0.06)); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) +TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") { arma::vec mean = ("5.0"); arma::vec cov = ("4.0"); @@ -573,8 +588,9 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) GaussianDistribution guDist2; guDist2.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 1e-15); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 1e-2); + REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(1e-17)); + REQUIRE(guDist.Covariance()[0] == + Approx(guDist2.Covariance()[0]).epsilon(1e-4)); } /** @@ -585,7 +601,8 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) * We expect that the distribution we recover after training to be the same as * the second normal distribution (the one with high probabilities). */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) +TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", + "[DistributionTest]") { arma::vec mean1 = ("5.0"); arma::vec cov1 = ("4.0"); @@ -626,8 +643,8 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) GaussianDistribution guDist; guDist.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean1[0], 5); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov1[0], 5); + REQUIRE(guDist.Mean()[0] == Approx(mean1[0]).epsilon(0.05)); + REQUIRE(guDist.Covariance()[0] == Approx(cov1[0]).epsilon(0.05)); } /******************************/ @@ -637,7 +654,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) * Make sure that using an object to fit one reference set and then asking * to fit another works properly. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) +TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") { // Create a gamma distribution random generator. double alphaReal = 5.3; @@ -659,8 +676,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) gDist.Train(rdata); // Training must estimate d pairs of alpha and beta parameters. - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); + REQUIRE(gDist.Dimensionality() == d); + REQUIRE(gDist.Dimensionality() == d); // Create a N' x d' gamma distribution, fit results without new object. size_t N2 = 350; @@ -676,15 +693,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) gDist.Train(rdata2); // Training must estimate d' pairs of alpha and beta parameters. - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); + REQUIRE(gDist.Dimensionality() == d2); + REQUIRE(gDist.Dimensionality() == d2); } /** * This test verifies that the fitting procedure for GammaDistribution works * properly when probabilities for each sample is given. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) +TEST_CASE("GammaDistributionTrainWithProbabilitiesTest", "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -711,24 +728,24 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) GammaDistribution gDist2; gDist2.Train(rdata); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1.5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1.5); + REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(0.015)); + REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(0.015)); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1.5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1.5); + REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(0.015)); + REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(0.015)); - BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(0), 3.0); - BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(0), 3.0); + REQUIRE(alphaReal == Approx(gDist.Alpha(0)).epsilon(0.03)); + REQUIRE(betaReal == Approx(gDist.Beta(0)).epsilon(0.03)); - BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(1), 3.0); - BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(1), 3.0); + REQUIRE(alphaReal == Approx(gDist.Alpha(1)).epsilon(0.03)); + REQUIRE(betaReal == Approx(gDist.Beta(1)).epsilon(0.03)); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) +TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -753,11 +770,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) arma::vec allProbabilities1(N, arma::fill::ones); gDist2.Train(rdata, allProbabilities1); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1e-5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1e-5); + REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(1e-7)); + REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1e-5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1e-5); + REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(1e-7)); + REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(1e-7)); } /** @@ -767,7 +784,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) * gamma distribution recovered has the same parameters as the second gamma * distribution with high probabilities. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) +TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", + "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -807,11 +825,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) GammaDistribution gDist; gDist.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(0), 5); - BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(0), 5); + REQUIRE(alphaReal2 == Approx(gDist.Alpha(0)).epsilon(0.05)); + REQUIRE(betaReal2 == Approx(gDist.Beta(0)).epsilon(0.05)); - BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(1), 5); - BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(1), 5); + REQUIRE(alphaReal2 == Approx(gDist.Alpha(1)).epsilon(0.05)); + REQUIRE(betaReal2 == Approx(gDist.Beta(1)).epsilon(0.05)); } /** @@ -820,7 +838,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) * with different alpha/beta parameters so we make sure we don't have some weird * bug that always converges to the same number. */ -BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) +TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") { // Offset from the actual alpha/beta. 10% is quite a relaxed tolerance since // the random points we generate are few (for test speed) and might be fitted @@ -848,8 +866,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) gDist.Train(rdata); // Estimated parameter must be close to real. - BOOST_REQUIRE_CLOSE(gDist.Alpha(0), alphaReal, errorTolerance); - BOOST_REQUIRE_CLOSE(gDist.Beta(0), betaReal, errorTolerance); + REQUIRE(gDist.Alpha(0) == Approx(alphaReal).epsilon(errorTolerance / 100)); + REQUIRE(gDist.Beta(0) == Approx(betaReal).epsilon(errorTolerance / 100)); /** Iteration 2 (different parameter set) **/ @@ -869,15 +887,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) gDist2.Train(rdata2); // Estimated parameter must be close to real. - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), alphaReal2, errorTolerance); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), betaReal2, errorTolerance); + REQUIRE(gDist2.Alpha(0) == Approx(alphaReal2).epsilon(errorTolerance / 100)); + REQUIRE(gDist2.Beta(0) == Approx(betaReal2).epsilon(errorTolerance / 100)); } /** * Test that Train() and the constructor that takes data give the same resulting * distribution. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) +TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") { const arma::mat data = arma::randu(10, 500); @@ -887,8 +905,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_CLOSE(d1.Alpha(i), d2.Alpha(i), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Beta(i), d2.Beta(i), 1e-5); + REQUIRE(d1.Alpha(i) == Approx(d2.Alpha(i)).epsilon(1e-7)); + REQUIRE(d1.Beta(i) == Approx(d2.Beta(i)).epsilon(1e-7)); } } @@ -896,7 +914,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) * Test that Train() with a dataset and Train() with dataset statistics return * the same results. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) +TEST_CASE("GammaDistributionTrainStatisticsTest", "[DistributionTest]") { const arma::mat data = arma::randu(1, 500); @@ -910,15 +928,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) const arma::vec logMeanx = arma::log(meanx); d2.Train(logMeanx, meanLogx, meanx); - BOOST_REQUIRE_CLOSE(d1.Alpha(0), d2.Alpha(0), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Beta(0), d2.Beta(0), 1e-5); + REQUIRE(d1.Alpha(0) == Approx(d2.Alpha(0)).epsilon(1e-7)); + REQUIRE(d1.Beta(0) == Approx(d2.Beta(0)).epsilon(1e-7)); } /** * Tests that Random() generates points that can be reasonably well fit by the * distribution that generated them. */ -BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) +TEST_CASE("GammaDistributionRandomTest", "[DistributionTest]") { const arma::vec a("2.0 2.5 3.0"), b("0.4 0.6 1.3"); const size_t numPoints = 2000; @@ -934,12 +952,12 @@ BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) GammaDistribution d2(data); for (size_t i = 0; i < 3; ++i) { - BOOST_REQUIRE_CLOSE(d2.Alpha(i), a(i), 10); // Within 10% - BOOST_REQUIRE_CLOSE(d2.Beta(i), b(i), 10); + REQUIRE(d2.Alpha(i) == Approx(a(i)).epsilon(0.1)); // Within 10% + REQUIRE(d2.Beta(i) == Approx(b(i)).epsilon(0.1)); } } -BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) +TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -949,16 +967,16 @@ BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.Probability(x1, prob1); - BOOST_REQUIRE_CLOSE(prob1(0), 0.267575, 1e-3); + REQUIRE(prob1(0) == Approx(0.267575).epsilon(1e-5)); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.Probability(x2, prob2); - BOOST_REQUIRE_CLOSE(prob2(0), 0.189043, 1e-3); + REQUIRE(prob2(0) == Approx(0.189043).epsilon(1e-5)); // Check that the overload that returns the probability for 1 dimension // agrees. - BOOST_REQUIRE_CLOSE(prob2(0), d2.Probability(2.94, 0), 1e-5); + REQUIRE(prob2(0) == Approx(d2.Probability(2.94, 0)).epsilon(1e-7)); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -971,11 +989,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.Probability(x3, prob3); - BOOST_REQUIRE_CLOSE(prob3(0), 0.04408, 1e-2); - BOOST_REQUIRE_CLOSE(prob3(1), 0.026165, 1e-2); + REQUIRE(prob3(0) == Approx(0.04408).epsilon(1e-4)); + REQUIRE(prob3(1) == Approx(0.026165).epsilon(1e-4)); } -BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) +TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -985,16 +1003,16 @@ BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.LogProbability(x1, logprob1); - BOOST_REQUIRE_CLOSE(logprob1(0), std::log(0.267575), 1e-3); + REQUIRE(logprob1(0) == Approx(std::log(0.267575)).epsilon(1e-5)); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.LogProbability(x2, logprob2); - BOOST_REQUIRE_CLOSE(logprob2(0), std::log(0.189043), 1e-3); + REQUIRE(logprob2(0) == Approx(std::log(0.189043)).epsilon(1e-5)); // Check that the overload that returns the log probability for // 1 dimension agrees. - BOOST_REQUIRE_CLOSE(logprob2(0), d2.LogProbability(2.94, 0), 1e-5); + REQUIRE(logprob2(0) == Approx(d2.LogProbability(2.94, 0)).epsilon(1e-7)); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -1008,14 +1026,14 @@ BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.LogProbability(x3, logprob3); - BOOST_REQUIRE_CLOSE(logprob3(0), std::log(0.04408), 1e-3); - BOOST_REQUIRE_CLOSE(logprob3(1), std::log(0.026165), 1e-3); + REQUIRE(logprob3(0) == Approx(std::log(0.04408)).epsilon(1e-5)); + REQUIRE(logprob3(1) == Approx(std::log(0.026165)).epsilon(1e-5)); } /** * Discrete Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) +TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") { // I assume that I am properly saving vectors, so, this should be // straightforward. @@ -1036,15 +1054,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) const double prob = t.Probability(obs); if (prob == 0.0) { - BOOST_REQUIRE_SMALL(xmlT.Probability(obs), 1e-8); - BOOST_REQUIRE_SMALL(textT.Probability(obs), 1e-8); - BOOST_REQUIRE_SMALL(binaryT.Probability(obs), 1e-8); + REQUIRE(xmlT.Probability(obs) == Approx(0.0).margin(1e-8)); + REQUIRE(textT.Probability(obs) == Approx(0.0).margin(1e-8)); + REQUIRE(binaryT.Probability(obs) == Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(prob, xmlT.Probability(obs), 1e-8); - BOOST_REQUIRE_CLOSE(prob, textT.Probability(obs), 1e-8); - BOOST_REQUIRE_CLOSE(prob, binaryT.Probability(obs), 1e-8); + REQUIRE(prob == Approx(xmlT.Probability(obs)).epsilon(1e-10)); + REQUIRE(prob == Approx(textT.Probability(obs)).epsilon(1e-10)); + REQUIRE(prob == Approx(binaryT.Probability(obs)).epsilon(1e-10)); } } } @@ -1052,7 +1070,7 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) /** * Gaussian Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTest) +TEST_CASE("GaussianDistributionTest", "[DistributionTest]") { arma::vec mean(10); mean.randu(); @@ -1066,9 +1084,9 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) SerializeObjectAll(g, xmlG, textG, binaryG); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), xmlG.Dimensionality()); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), textG.Dimensionality()); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), binaryG.Dimensionality()); + REQUIRE(g.Dimensionality() == xmlG.Dimensionality()); + REQUIRE(g.Dimensionality() == textG.Dimensionality()); + REQUIRE(g.Dimensionality() == binaryG.Dimensionality()); // First, check the means. CheckMatrices(g.Mean(), xmlG.Mean(), textG.Mean(), binaryG.Mean()); @@ -1088,18 +1106,21 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) if (prob == 0.0) { - BOOST_REQUIRE_SMALL(xmlG.Probability(randomObs.unsafe_col(i)), 1e-8); - BOOST_REQUIRE_SMALL(textG.Probability(randomObs.unsafe_col(i)), 1e-8); - BOOST_REQUIRE_SMALL(binaryG.Probability(randomObs.unsafe_col(i)), 1e-8); + REQUIRE(xmlG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); + REQUIRE(textG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); + REQUIRE(binaryG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(prob, xmlG.Probability(randomObs.unsafe_col(i)), - 1e-8); - BOOST_REQUIRE_CLOSE(prob, textG.Probability(randomObs.unsafe_col(i)), - 1e-8); - BOOST_REQUIRE_CLOSE(prob, binaryG.Probability(randomObs.unsafe_col(i)), - 1e-8); + REQUIRE(prob == + Approx(xmlG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + REQUIRE(prob == + Approx(textG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + REQUIRE(prob == + Approx(binaryG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); } } } @@ -1107,7 +1128,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) /** * Laplace Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) +TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") { arma::vec mean(20); mean.randu(); @@ -1117,9 +1138,9 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) SerializeObjectAll(l, xmlL, textL, binaryL); - BOOST_REQUIRE_CLOSE(l.Scale(), xmlL.Scale(), 1e-8); - BOOST_REQUIRE_CLOSE(l.Scale(), textL.Scale(), 1e-8); - BOOST_REQUIRE_CLOSE(l.Scale(), binaryL.Scale(), 1e-8); + REQUIRE(l.Scale() == Approx(xmlL.Scale()).epsilon(1e-10)); + REQUIRE(l.Scale() == Approx(textL.Scale()).epsilon(1e-10)); + REQUIRE(l.Scale() == Approx(binaryL.Scale()).epsilon(1e-10)); CheckMatrices(l.Mean(), xmlL.Mean(), textL.Mean(), binaryL.Mean()); } @@ -1127,15 +1148,15 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) /** * Laplace Distribution Probability Test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) +TEST_CASE("LaplaceDistributionProbabilityTest", "[DistributionTest]") { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("0.0")), - 0.500000000000000, 1e-5); - BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("1.0")), - 0.183939720585721, 1e-5); + REQUIRE(l.Probability(arma::vec("0.0")) == + Approx(0.500000000000000).epsilon(1e-7)); + REQUIRE(l.Probability(arma::vec("1.0")) == + Approx(0.183939720585721).epsilon(1e-7)); arma::mat points = "0.0 1.0;"; @@ -1143,24 +1164,24 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) l.Probability(points, probabilities); - BOOST_REQUIRE_EQUAL(probabilities.n_elem, 2); + REQUIRE(probabilities.n_elem == 2); - BOOST_REQUIRE_CLOSE(probabilities(0), 0.500000000000000, 1e-5); - BOOST_REQUIRE_CLOSE(probabilities(1), 0.183939720585721, 1e-5); + REQUIRE(probabilities(0) == Approx(0.500000000000000).epsilon(1e-7)); + REQUIRE(probabilities(1) == Approx(0.183939720585721).epsilon(1e-7)); } /** * Laplace Distribution Log Probability Test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) +TEST_CASE("LaplaceDistributionLogProbabilityTest", "[DistributionTest]") { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("0.0")), - -0.693147180559945, 1e-5); - BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("1.0")), - -1.693147180559946, 1e-5); + REQUIRE(l.LogProbability(arma::vec("0.0")) == + Approx(-0.693147180559945).epsilon(1e-7)); + REQUIRE(l.LogProbability(arma::vec("1.0")) == + Approx(-1.693147180559946).epsilon(1e-7)); arma::mat points = "0.0 1.0;"; @@ -1168,18 +1189,19 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) l.LogProbability(points, logProbabilities); - BOOST_REQUIRE_EQUAL(logProbabilities.n_elem, 2); + REQUIRE(logProbabilities.n_elem == 2); - BOOST_REQUIRE_CLOSE(logProbabilities(0), -0.693147180559945, - 1e-5); - BOOST_REQUIRE_CLOSE(logProbabilities(1), -1.693147180559946, - 1e-5); + REQUIRE(logProbabilities(0) == + Approx(-0.693147180559945).epsilon(1e-7)); + + REQUIRE(logProbabilities(1) == + Approx(-1.693147180559946).epsilon(1e-7)); } /** * Mahalanobis Distance serialization test. */ -BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) +TEST_CASE("MahalanobisDistanceTest", "[DistributionTest]") { MahalanobisDistance<> d; d.Covariance().randu(50, 50); @@ -1198,7 +1220,7 @@ BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) /** * Regression distribution serialization test. */ -BOOST_AUTO_TEST_CASE(RegressionDistributionTest) +TEST_CASE("RegressionDistributionTest", "[DistributionTest]") { // Generate some random data. arma::mat data; @@ -1225,15 +1247,15 @@ BOOST_AUTO_TEST_CASE(RegressionDistributionTest) // Check the regression function. if (rd.Rf().Lambda() == 0.0) { - BOOST_REQUIRE_SMALL(xmlRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_SMALL(textRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_SMALL(binaryRd.Rf().Lambda(), 1e-8); + REQUIRE(xmlRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + REQUIRE(textRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + REQUIRE(binaryRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), xmlRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), textRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), binaryRd.Rf().Lambda(), 1e-8); + REQUIRE(rd.Rf().Lambda() == Approx(xmlRd.Rf().Lambda()).epsilon(1e-10)); + REQUIRE(rd.Rf().Lambda() == Approx(textRd.Rf().Lambda()).epsilon(1e-10)); + REQUIRE(rd.Rf().Lambda() == Approx(binaryRd.Rf().Lambda()).epsilon(1e-10)); } CheckMatrices(rd.Rf().Parameters(), @@ -1250,31 +1272,32 @@ BOOST_AUTO_TEST_CASE(RegressionDistributionTest) * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionEmptyConstructor) +TEST_CASE("DiagonalGaussianDistributionEmptyConstructor", "[DistributionTest]") { DiagonalGaussianDistribution d; - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); + REQUIRE(d.Mean().n_elem == 0); + REQUIRE(d.Covariance().n_elem == 0); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized to * the correct dimensionality. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionDimensionalityConstructor) +TEST_CASE("DiagonalGaussianDistributionDimensionalityConstructor", + "[DistributionTest]") { DiagonalGaussianDistribution d(4); - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 4); + REQUIRE(d.Mean().n_elem == 4); + REQUIRE(d.Covariance().n_elem == 4); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly when we give a mean and covariance. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) +TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") { arma::vec mean = arma::randu(3); arma::vec covariance = arma::randu(3); @@ -1284,8 +1307,8 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) // Make sure the mean and covariance is correct. for (size_t i = 0; i < 3; ++i) { - BOOST_REQUIRE_CLOSE(d.Mean()(i), mean(i), 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(i), covariance(i), 1e-5); + REQUIRE(d.Mean()(i) == Approx(mean(i)).epsilon(1e-7)); + REQUIRE(d.Covariance()(i) == Approx(covariance(i)).epsilon(1e-7)); } } @@ -1293,7 +1316,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) * Make sure the probability of observations is correct. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) +TEST_CASE("DiagonalGaussianDistributionProbabilityTest", "[DistributionTest]") { arma::vec mean("2 5 3 4 1"); arma::vec cov("3 1 5 3 2"); @@ -1301,56 +1324,56 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) DiagonalGaussianDistribution d(mean, cov); // Observations lists randomly selected. - BOOST_REQUIRE_CLOSE(d.LogProbability("3 5 2 7 8"), -20.861264167855161, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("7 8 4 0 5"), -22.277930834521829, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("6 8 7 7 5"), -21.111264167855161, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 9 5 6 3"), -16.911264167855162, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("5 8 2 9 7"), -26.111264167855161, - 1e-5); + REQUIRE(d.LogProbability("3 5 2 7 8") == + Approx(-20.861264167855161).epsilon(1e-7)); + REQUIRE(d.LogProbability("7 8 4 0 5") == + Approx(-22.277930834521829).epsilon(1e-7)); + REQUIRE(d.LogProbability("6 8 7 7 5") == + Approx(-21.111264167855161).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 9 5 6 3") == + Approx(-16.9112641678551621).epsilon(1e-7)); + REQUIRE(d.LogProbability("5 8 2 9 7") == + Approx(-26.111264167855161).epsilon(1e-7)); } /** * Test DiagonalGaussianDistribution::Probability() in the univariate case. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianUnivariateProbabilityTest) +TEST_CASE("DiagonalGaussianUnivariateProbabilityTest", "[DistributionTest]") { DiagonalGaussianDistribution d(arma::vec("0.0"), arma::vec("1.0")); // Mean: 0.0, Covariance: 1.0 - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.3989422804014327, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.24197072451914337, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.24197072451914337, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.3989422804014327).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.24197072451914337).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.24197072451914337).epsilon(1e-7)); // Mean: 0.0, Covariance: 2.0 d.Covariance("2.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.28209479177387814, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.21969564473386122, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.21969564473386122, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.28209479177387814).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.21969564473386122).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.21969564473386122).epsilon(1e-7)); // Mean: 1.0, Covariance: 1.0 d.Mean() = "1.0"; d.Covariance("1.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.24197072451914337, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.3989422804014327, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.053990966513188056, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.24197072451914337).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.3989422804014327).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.053990966513188056).epsilon(1e-7)); // Mean: 1.0, Covariance: 2.0 d.Covariance("2.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.21969564473386122, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.28209479177387814, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.10377687435514872, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.21969564473386122).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.28209479177387814).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.10377687435514872).epsilon(1e-7)); } /** * Test DiagonalGaussianDistribution::Probability() in the multivariate case. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) +TEST_CASE("DiagonalGaussianMultivariateProbabilityTest", "[DistributionTest]") { arma::vec mean("0 0"); arma::vec cov("2 2"); @@ -1358,27 +1381,28 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) DiagonalGaussianDistribution d(mean, cov); - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.079577471545947673, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.079577471545947673).epsilon(1e-7)); obs = "1 1"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.048266176315026957, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.048266176315026957).epsilon(1e-7)); d.Mean() = "1 3"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.029274915762159581, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability(-obs), 0.00053618878559782773, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.029274915762159581).epsilon(1e-7)); + REQUIRE(d.Probability(-obs) == Approx(0.00053618878559782773).epsilon(1e-7)); // Higher dimensional case. d.Mean() = "1 3 6 2 7"; d.Covariance("3 1 5 3 2"); obs = "2 5 7 3 8"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 7.2790083003378082e-05, 1e-5); + REQUIRE(d.Probability(obs) == Approx(7.2790083003378082e-05).epsilon(1e-7)); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) +TEST_CASE("DiagonalGaussianMultipointMultivariateProbabilityTest", + "[DistributionTest]") { arma::vec mean = "2 5 3 7 2"; arma::vec cov("9 2 1 4 8"); @@ -1391,20 +1415,20 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) DiagonalGaussianDistribution d(mean, cov); d.LogProbability(points, phis); - BOOST_REQUIRE_EQUAL(phis.n_elem, 6); + REQUIRE(phis.n_elem == 6); - BOOST_REQUIRE_CLOSE(phis(0), -12.453302051926864, 1e-5); - BOOST_REQUIRE_CLOSE(phis(1), -10.147746496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(2), -13.210246496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(3), -19.724135385260197, 1e-5); - BOOST_REQUIRE_CLOSE(phis(4), -21.585246496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(5), -13.647746496371308, 1e-5); + REQUIRE(phis(0) == Approx(-12.453302051926864).epsilon(1e-7)); + REQUIRE(phis(1) == Approx(-10.147746496371308).epsilon(1e-7)); + REQUIRE(phis(2) == Approx(-13.210246496371308).epsilon(1e-7)); + REQUIRE(phis(3) == Approx(-19.724135385260197).epsilon(1e-7)); + REQUIRE(phis(4) == Approx(-21.585246496371308).epsilon(1e-7)); + REQUIRE(phis(5) == Approx(-13.647746496371308).epsilon(1e-7)); } /** * Make sure random observations follow the probability distribution correctly. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) +TEST_CASE("DiagonalGaussianDistributionRandomTest", "[DistributionTest]") { arma::vec mean("2.5 1.25"); arma::vec cov("0.50 0.25"); @@ -1421,17 +1445,17 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - BOOST_REQUIRE_CLOSE(obsMean(0), mean(0), 10.0); - BOOST_REQUIRE_CLOSE(obsMean(1), mean(1), 10.0); + REQUIRE(obsMean(0) == Approx(mean(0)).epsilon(0.1)); + REQUIRE(obsMean(1) == Approx(mean(1)).epsilon(0.1)); - BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0), 10); - BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1), 10); + REQUIRE(obsCov(0, 0) == Approx(cov(0)).epsilon(0.1)); + REQUIRE(obsCov(1, 1) == Approx(cov(1)).epsilon(0.1)); } /** * Make sure that we can properly estimate from given observations. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) +TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1454,8 +1478,8 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) // Check that the estimated parameters are right. for (size_t i = 0; i < 4; ++i) { - BOOST_REQUIRE_SMALL(d.Mean()(i) - actualMean(i), 1e-5); - BOOST_REQUIRE_SMALL(d.Covariance()(i) - actualCov(i, i), 1e-5); + REQUIRE(d.Mean()(i) - actualMean(i) == Approx(0.0).margin(1e-5)); + REQUIRE(d.Covariance()(i) - actualCov(i, i) == Approx(0.0).margin(1e-5)); } } @@ -1463,7 +1487,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) * Make sure the unbiased estimator of the weighted sample works correctly. * The values were calculated using 'cov.wt' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) +TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") { // Generate the observations. arma::mat observations("3 5 2 7;" @@ -1478,15 +1502,15 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) // Estimate the parameters. d.Train(observations, probs); - BOOST_REQUIRE_CLOSE(d.Mean()(0), 4.5, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(1), 4.4, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(2), 3.5, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(3), 6.8, 1e-5); + REQUIRE(d.Mean()(0) == Approx(4.5).epsilon(1e-7)); + REQUIRE(d.Mean()(1) == Approx(4.4).epsilon(1e-7)); + REQUIRE(d.Mean()(2) == Approx(3.5).epsilon(1e-7)); + REQUIRE(d.Mean()(3) == Approx(6.8).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(d.Covariance()(0), 3.78571428571428603, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(1), 6.34285714285714253, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(2), 6.64285714285714235, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(3), 2.22857142857142865, 1e-5); + REQUIRE(d.Covariance()(0) == Approx(3.78571428571428603).epsilon(1e-7)); + REQUIRE(d.Covariance()(1) == Approx(6.34285714285714253).epsilon(1e-7)); + REQUIRE(d.Covariance()(2) == Approx(6.64285714285714235).epsilon(1e-7)); + REQUIRE(d.Covariance()(3) == Approx(2.22857142857142865).epsilon(1e-7)); } /** @@ -1494,7 +1518,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) * the weighted mean and covariance reduce to the unweighted sample mean and * covariance. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) +TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1516,9 +1540,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) // Check if these are equal. for (size_t i = 0; i < 4; ++i) { - BOOST_REQUIRE_CLOSE(d1.Mean()(i), d2.Mean()(i), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Covariance()(i), d2.Covariance()(i), 1e-5); + REQUIRE(d1.Mean()(i) == Approx(d2.Mean()(i)).epsilon(1e-7)); + REQUIRE(d1.Covariance()(i) == Approx(d2.Covariance()(i)).epsilon(1e-7)); } } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index ba45afd29d..bcffa4c8a8 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -148,10 +148,10 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTest", "[FeedForwardNetworkTest]") model1->Add >(8, 3); model1->Add >(); - // Check whether copy cpnstructor is working or not. + // Check whether copy constructor is working or not. CheckCopyFunction<>(model, trainData, trainLabels, 1); - // Check whether move cpnstructor is working or not. + // Check whether move constructor is working or not. CheckMoveFunction<>(model1, trainData, trainLabels, 1); } @@ -489,7 +489,7 @@ TEST_CASE("FFNMiscTest", "[FeedForwardNetworkTest]") auto copiedModel(model); copiedModel = model; auto movedModel(std::move(model)); - movedModel = std::move(copiedModel); + auto moveOperator = std::move(copiedModel); } /** @@ -764,7 +764,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model.Add >(8, 3); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.1); + TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.2); arma::mat dataset; dataset.load("mnist_first250_training_4s_and_9s.arm"); @@ -796,5 +796,5 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model1.Add >(140, 2); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.1); + TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.2); } diff --git a/src/mlpack/tests/main_tests/mean_shift_test.cpp b/src/mlpack/tests/main_tests/mean_shift_test.cpp index eea3ceb3c7..5da1c28b95 100644 --- a/src/mlpack/tests/main_tests/mean_shift_test.cpp +++ b/src/mlpack/tests/main_tests/mean_shift_test.cpp @@ -12,15 +12,16 @@ #include #define BINDING_TYPE BINDING_TYPE_TEST -static const std::string testName = "MeanShift"; #include +static const std::string testName = "MeanShift"; + #include #include -#include "test_helper.hpp" -#include -#include "../test_tools.hpp" +#include "test_helper.hpp" +#include "../test_catch_tools.hpp" +#include "../catch.hpp" using namespace mlpack; @@ -48,13 +49,13 @@ static void ResetSettings() IO::RestoreSettings(testName); } -BOOST_FIXTURE_TEST_SUITE(MeanShiftMainTest, MeanShiftTestFixture); - /** * Ensure that the output has 1 extra row for the labels and * check the number of points for output remain the same. */ -BOOST_AUTO_TEST_CASE(MeanShiftOutputDimensionTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftOutputDimensionTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -65,16 +66,18 @@ BOOST_AUTO_TEST_CASE(MeanShiftOutputDimensionTest) mlpackMain(); // Now check that the output has 1 extra row for labels. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 3 + 1); + REQUIRE(IO::GetParam("output").n_rows == 3 + 1); // Check number of output points are the same. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); + REQUIRE(IO::GetParam("output").n_cols == 100); } /** * Ensure that if we ask for labels_only, output has 1 row and * same number of columns for each point's label. */ -BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftLabelOnlyOutputDimensionTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -86,9 +89,9 @@ BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) mlpackMain(); // Check that there is only 1 row containing all the labels. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 1); + REQUIRE(IO::GetParam("output").n_rows == 1); // Check number of output points are the same. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); + REQUIRE(IO::GetParam("output").n_cols == 100); } /** @@ -96,11 +99,13 @@ BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) * and check the number of points remain the same if the --in_place * flag is set. */ -BOOST_AUTO_TEST_CASE(MeanShiftInPlaceTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftInPlaceTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Get initial number of rows and columns in file. int numRows = x.n_rows; @@ -113,20 +118,22 @@ BOOST_AUTO_TEST_CASE(MeanShiftInPlaceTest) mlpackMain(); // Now check that the output has 1 extra row for labels. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, numRows + 1); + REQUIRE(IO::GetParam("output").n_rows == numRows + 1); // Check number of output points are the same. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, numCols); + REQUIRE(IO::GetParam("output").n_cols == numCols); } /** * Ensure that force_convergence is used by testing that the * force_convergence flag makes a difference in the program. */ -BOOST_AUTO_TEST_CASE(MeanShiftForceConvergenceTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftForceConvergenceTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -150,18 +157,20 @@ BOOST_AUTO_TEST_CASE(MeanShiftForceConvergenceTest) const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - BOOST_REQUIRE_NE(numCentroids1, numCentroids2); + REQUIRE(numCentroids1 != numCentroids2); } /** * Ensure that radius is used by testing that the radius * makes a difference in the program. */ -BOOST_AUTO_TEST_CASE(MeanShiftRadiusTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftRadiusTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -183,18 +192,20 @@ BOOST_AUTO_TEST_CASE(MeanShiftRadiusTest) const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - BOOST_REQUIRE_NE(numCentroids1, numCentroids2); + REQUIRE(numCentroids1 != numCentroids2); } /** * Ensure that max_iterations is used by testing that the * max_iteration makes a difference in the program. */ -BOOST_AUTO_TEST_CASE(MeanShiftMaxIterationsTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftMaxIterationsTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -216,13 +227,15 @@ BOOST_AUTO_TEST_CASE(MeanShiftMaxIterationsTest) const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - BOOST_REQUIRE_NE(numCentroids1, numCentroids2); + REQUIRE(numCentroids1 != numCentroids2); } /** * Ensure that we can't specify an invalid max number of iterations. */ -BOOST_AUTO_TEST_CASE(MeanShiftInvalidMaxIterationsTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftInvalidMaxIterationsTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -233,8 +246,6 @@ BOOST_AUTO_TEST_CASE(MeanShiftInvalidMaxIterationsTest) SetInputParam("max_iterations", (int) -1); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp index 818602f632..9f6c229639 100644 --- a/src/mlpack/tests/mean_shift_test.cpp +++ b/src/mlpack/tests/mean_shift_test.cpp @@ -12,15 +12,13 @@ #include -#include -#include "test_tools.hpp" +#include "test_catch_tools.hpp" +#include "catch.hpp" using namespace mlpack; using namespace mlpack::meanshift; using namespace mlpack::distribution; -BOOST_AUTO_TEST_SUITE(MeanShiftTest); - // Generate dataset; written transposed because it's easier to read. arma::mat meanShiftData(" 0.0 0.0;" // Class 1. " 0.3 0.4;" @@ -57,7 +55,7 @@ arma::mat meanShiftData(" 0.0 0.0;" // Class 1. /** * 30-point 3-class test case for Mean Shift. */ -BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) +TEST_CASE("MeanShiftSimpleTest", "[MeanShiftTest]") { MeanShift<> meanShift; @@ -70,29 +68,29 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) size_t firstClass = assignments(0); for (size_t i = 1; i < 13; ++i) - BOOST_REQUIRE_EQUAL(assignments(i), firstClass); + REQUIRE(assignments(i) == firstClass); size_t secondClass = assignments(13); // To ensure that class 1 != class 2. - BOOST_REQUIRE_NE(firstClass, secondClass); + REQUIRE(firstClass != secondClass); for (size_t i = 13; i < 20; ++i) - BOOST_REQUIRE_EQUAL(assignments(i), secondClass); + REQUIRE(assignments(i) == secondClass); size_t thirdClass = assignments(20); // To ensure that this is the third class which we haven't seen yet. - BOOST_REQUIRE_NE(firstClass, thirdClass); - BOOST_REQUIRE_NE(secondClass, thirdClass); + REQUIRE(firstClass != thirdClass); + REQUIRE(secondClass != thirdClass); for (size_t i = 20; i < 30; ++i) - BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); + REQUIRE(assignments(i) == thirdClass); } // Generate samples from four Gaussians, and make sure mean shift nearly // recovers those four centers. -BOOST_AUTO_TEST_CASE(GaussianClustering) +TEST_CASE("GaussianClustering", "[MeanShiftTest]") { GaussianDistribution g1("0.0 0.0 0.0", arma::eye(3, 3)); GaussianDistribution g2("5.0 5.0 5.0", 2 * arma::eye(3, 3)); @@ -162,7 +160,5 @@ BOOST_AUTO_TEST_CASE(GaussianClustering) break; } - BOOST_REQUIRE_EQUAL(success, true); + REQUIRE(success == true); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/random_forest_test.cpp b/src/mlpack/tests/random_forest_test.cpp index edc6bb2b60..3db62942c3 100644 --- a/src/mlpack/tests/random_forest_test.cpp +++ b/src/mlpack/tests/random_forest_test.cpp @@ -13,8 +13,9 @@ #include #include +#include "serialization_catch.hpp" +#include "test_catch_tools.hpp" #include "catch.hpp" -#include "serialization.hpp" #include "mock_categorical_data.hpp" using namespace mlpack; From 785def258acaa4c79c547cae934a50d31b7b419b Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 00:44:53 +0530 Subject: [PATCH 27/45] reverted changed test names --- src/mlpack/tests/range_search_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 41185f7a8a..464f827f64 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1074,7 +1074,7 @@ TEST_CASE("EmptySearchTest", "[RangeSearchTest]") /** * Make sure things work right after Train() is called. */ -TEST_CASE("RangeTrainTest", "[RangeSearchTest]") +TEST_CASE("TrainTest", "[RangeSearchTest]") { RangeSearch<> empty; From f326b6e86ba1517a4c0237effdd5065a72f03486 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 01:14:13 +0530 Subject: [PATCH 28/45] tests with same name changed --- src/mlpack/tests/range_search_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 464f827f64..af01a26ccc 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1074,7 +1074,7 @@ TEST_CASE("EmptySearchTest", "[RangeSearchTest]") /** * Make sure things work right after Train() is called. */ -TEST_CASE("TrainTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchTrainTest", "[RangeSearchTest]") { RangeSearch<> empty; @@ -1448,7 +1448,7 @@ TEST_CASE("NeighborPtrDeleteTest", "[RangeSearchTest]") /** * Test copy constructor and copy operator. */ -TEST_CASE("CopyConstructorAndOperatorTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchCopyConstructorAndOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<> rs(std::move(dataset)); @@ -1493,7 +1493,7 @@ TEST_CASE("CopyConstructorAndOperatorTest", "[RangeSearchTest]") /** * Test move constructor. */ -TEST_CASE("MoveConstructorTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchMoveConstructorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); @@ -1532,7 +1532,7 @@ TEST_CASE("MoveConstructorTest", "[RangeSearchTest]") /** * Test move operator. */ -TEST_CASE("MoveOperatorTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchMoveOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); From 0b83c2add01763480ec9fc26bc02a1ccb00f1a98 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 01:21:24 +0530 Subject: [PATCH 29/45] Revert "updating range_search_test with mlpack/master (#7)" This reverts commit 403b11ebbe8ccbdcc1c651296224bc2341e2b7b4. --- .ci/windows-steps.yaml | 1 - .github/workflows/main.yml | 66 +- HISTORY.md | 2 - src/mlpack/methods/ann/layer/CMakeLists.txt | 2 - src/mlpack/methods/ann/layer/add.hpp | 3 - .../methods/ann/layer/atrous_convolution.hpp | 6 - src/mlpack/methods/ann/layer/layer.hpp | 1 - src/mlpack/methods/ann/layer/linear.hpp | 6 - src/mlpack/methods/ann/layer/softmin.hpp | 97 --- src/mlpack/methods/ann/layer/softmin_impl.hpp | 61 -- src/mlpack/tests/CMakeLists.txt | 8 +- .../tests/activation_functions_test.cpp | 72 -- src/mlpack/tests/ann_layer_test.cpp | 201 +++--- src/mlpack/tests/ann_visitor_test.cpp | 34 - src/mlpack/tests/det_test.cpp | 469 +++++++------ src/mlpack/tests/distribution_test.cpp | 618 +++++++++--------- src/mlpack/tests/feedforward_network_test.cpp | 10 +- .../tests/main_tests/mean_shift_test.cpp | 69 +- src/mlpack/tests/mean_shift_test.cpp | 26 +- src/mlpack/tests/random_forest_test.cpp | 3 +- 20 files changed, 700 insertions(+), 1055 deletions(-) delete mode 100644 src/mlpack/methods/ann/layer/softmin.hpp delete mode 100644 src/mlpack/methods/ann/layer/softmin_impl.hpp diff --git a/.ci/windows-steps.yaml b/.ci/windows-steps.yaml index 69a33520a3..069c6c5b46 100644 --- a/.ci/windows-steps.yaml +++ b/.ci/windows-steps.yaml @@ -78,7 +78,6 @@ steps: msbuildVersion: $(MSBuildVersion) configuration: 'Release' msbuildArchitecture: 'x64' - platform: 'x64' msbuildArguments: /m /p:BuildInParallel=true maximumCpuCount: false clean: false diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8640c26471..8a4790897d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,31 +8,13 @@ on: - master release: types: [published, created, edited] -name: R CMD check mlpack jobs: - cancel: - name: 'Cancel Previous Builds' - if: ${{ github.event_name == 'pull_request' && github.repository == 'mlpack/mlpack' }} - runs-on: ubuntu-latest - timeout-minutes: 3 - steps: - - name: Get all workflow ids and set to env variable - run: echo ::set-env name=WORKFLOW_IDS_TO_CANCEL::$(curl https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows -s | jq -r '.workflows | map(.id|tostring) | join(",")') - - - uses: styfle/cancel-workflow-action@0.5.0 - with: - workflow_id: ${{ env.WORKFLOW_IDS_TO_CANCEL }} - access_token: ${{ secrets.GITHUB_TOKEN }} - jobR: - name: Build mlpack_r_tarball - if: ${{ github.repository == 'mlpack/mlpack' }} + name: mlpack-R runs-on: ubuntu-20.04 - outputs: r_bindings: ${{ steps.mlpack_version.outputs.mlpack_r_package }} - steps: - uses: actions/checkout@v2 @@ -45,35 +27,16 @@ jobs: MLPACK_VERSION_VALUE=${MLPACK_VERSION_MAJOR}.${MLPACK_VERSION_MINOR}.${MLPACK_VERSION_PATCH} echo ::set-output name=mlpack_r_package::$(echo mlpack_"$MLPACK_VERSION_VALUE".tar.gz) - - uses: r-lib/actions/setup-r@master - with: - r-version: release - - - name: Query dependencies - run: | - cp src/mlpack/bindings/R/mlpack/DESCRIPTION.in DESCRIPTION - Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps(dependencies = TRUE), 'depends.Rds')" - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v1 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-r-release-${{ hashFiles('depends.Rds') }} - restore-keys: ${{ runner.os }}-r-release- - - name: Install Build Dependencies run: | sudo apt-get update sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ libboost-all-dev curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo* cmake . && make && sudo make install && cd .. - - - name: Install R-bindings dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("roxygen2") - shell: Rscript {0} + sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/' + sudo apt-get -y update + sudo apt-get install -y r-base-core + sudo Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" - name: CMake run: | @@ -95,7 +58,6 @@ jobs: runs-on: ${{ matrix.config.os }} name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - if: ${{ github.repository == 'mlpack/mlpack' }} strategy: fail-fast: false @@ -112,8 +74,6 @@ jobs: R_CHECK_ARGS: "--no-build-vignettes" _R_CHECK_FORCE_SUGGESTS: 0 R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/download-artifact@v2 @@ -126,22 +86,10 @@ jobs: - uses: r-lib/actions/setup-pandoc@master - - name: Query dependencies - run: Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE), 'depends.Rds')" - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v1 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }} - restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}- - - name: Install dependencies run: | - remotes::install_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} + Rscript -e "install.packages('remotes')" -e "remotes::install_cran('rcmdcheck')" + Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" - name: Check run: Rscript -e "rcmdcheck::rcmdcheck('${{ needs.jobR.outputs.r_bindings }}', args = c('--no-manual','--as-cran'), error_on = 'warning', check_dir = 'check')" diff --git a/HISTORY.md b/HISTORY.md index 5acdedcb4f..d7a2437e9e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,8 +2,6 @@ ###### ????-??-?? * Added Mean Absolute Percentage Error. - * Added Softmin activation function as layer in ann/layer. - ### mlpack 3.4.1 ###### 2020-09-07 * Fix incorrect parsing of required matrix/model parameters for command-line diff --git a/src/mlpack/methods/ann/layer/CMakeLists.txt b/src/mlpack/methods/ann/layer/CMakeLists.txt index b4726b0c6f..34ea03c6a7 100644 --- a/src/mlpack/methods/ann/layer/CMakeLists.txt +++ b/src/mlpack/methods/ann/layer/CMakeLists.txt @@ -116,8 +116,6 @@ set(SOURCES celu_impl.hpp softshrink.hpp softshrink_impl.hpp - softmin.hpp - softmin_impl.hpp ) # Add directory name to sources. diff --git a/src/mlpack/methods/ann/layer/add.hpp b/src/mlpack/methods/ann/layer/add.hpp index 42b27809b8..b3f95dbbcc 100644 --- a/src/mlpack/methods/ann/layer/add.hpp +++ b/src/mlpack/methods/ann/layer/add.hpp @@ -100,9 +100,6 @@ class Add //! Get the output size. size_t OutputSize() const { return outSize; } - //! Get the size of weights. - size_t WeightSize() const { return outSize; } - /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/atrous_convolution.hpp b/src/mlpack/methods/ann/layer/atrous_convolution.hpp index b3dfd1ce85..b2a8f497e6 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution.hpp @@ -257,12 +257,6 @@ class AtrousConvolution //! Modify the internal Padding layer. ann::Padding<>& Padding() { return padding; } - //! Get size of the weight matrix. - size_t WeightSize() const - { - return (outSize * inSize * kernelWidth * kernelHeight) + outSize; - } - /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/layer.hpp b/src/mlpack/methods/ann/layer/layer.hpp index 947395fd6b..d005d1eb42 100644 --- a/src/mlpack/methods/ann/layer/layer.hpp +++ b/src/mlpack/methods/ann/layer/layer.hpp @@ -66,7 +66,6 @@ #include "sequential.hpp" #include "softshrink.hpp" #include "softmax.hpp" -#include "softmin.hpp" #include "spatial_dropout.hpp" #include "subview.hpp" #include "transposed_convolution.hpp" diff --git a/src/mlpack/methods/ann/layer/linear.hpp b/src/mlpack/methods/ann/layer/linear.hpp index 6dfd719d5f..1930181654 100644 --- a/src/mlpack/methods/ann/layer/linear.hpp +++ b/src/mlpack/methods/ann/layer/linear.hpp @@ -146,12 +146,6 @@ class Linear //! Modify the bias weights of the layer. OutputDataType& Bias() { return bias; } - //! Get the size of the weights. - size_t WeightSize() const - { - return (inSize * outSize) + outSize; - } - /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/softmin.hpp b/src/mlpack/methods/ann/layer/softmin.hpp deleted file mode 100644 index a7b882c942..0000000000 --- a/src/mlpack/methods/ann/layer/softmin.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @file methods/ann/layer/softmin.hpp - * @author Aakash Kaushik - * - * Definition of the Softmin class. - * - * mlpack is free software; you may redistribute it and/or modify it under the - * terms of the 3-clause BSD license. You should have received a copy of the - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP -#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP - -#include - -namespace mlpack { -namespace ann /** Artificial Neural Network. */ { - -/** - * Implementation of the Softmin layer. The Softmin function takes as a input - * a vector of K real numbers, rescaling them so that the elements of the - * K-dimensional output vector lie in the range [0, 1] and sum to 1. - * - * @tparam InputDataType Type of the input data (arma::colvec, arma::mat, - * arma::sp_mat or arma::cube). - * @tparam OutputDataType Type of the output data (arma::colvec, arma::mat, - * arma::sp_mat or arma::cube). - */ -template < - typename InputDataType = arma::mat, - typename OutputDataType = arma::mat -> -class Softmin -{ - public: - /** - * Create the Softmin object. - */ - Softmin(); - - /** - * Ordinary feed forward pass of a neural network, evaluating the function - * f(x) by propagating the activity forward through f. - * - * @param input Input data used for evaluating the specified function. - * @param output Resulting output activation. - */ - template - void Forward(const InputType& input, OutputType& output); - - /** - * Ordinary feed backward pass of a neural network, calculating the function - * f(x) by propagating x backwards through f. Using the results from the feed - * forward pass. - * - * @param input The propagated input activation. - * @param gy The backpropagated error. - * @param g The calculated gradient. - */ - template - void Backward(const arma::Mat& input, - const arma::Mat& gy, - arma::Mat& g); - - //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } - //! Modify the output parameter. - OutputDataType& OutputParameter() { return outputParameter; } - - //! Get the delta. - InputDataType& Delta() const { return delta; } - //! Modify the delta. - InputDataType& Delta() { return delta; } - - /** - * Serialize the layer. - */ - template - void serialize(Archive& /* ar */, const unsigned int /* version */); - - private: - //! Locally-stored delta object. - OutputDataType delta; - - //! Locally stored output parameter object. - OutputDataType outputParameter; -}; // class Softmin - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "softmin_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/layer/softmin_impl.hpp b/src/mlpack/methods/ann/layer/softmin_impl.hpp deleted file mode 100644 index 7693ca11dd..0000000000 --- a/src/mlpack/methods/ann/layer/softmin_impl.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file methods/ann/layer/softmin_impl.hpp - * @author Aakash Kaushik - * - * Implementation of the Softmin class. - * - * mlpack is free software; you may redistribute it and/or modify it under the - * terms of the 3-clause BSD license. You should have received a copy of the - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP -#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP - -// In case it hasn't yet been included. -#include "softmin.hpp" - -namespace mlpack { -namespace ann /** Artificial Neural Network. */ { - -template -Softmin::Softmin() -{ - // Nothing to do here. -} - -template -template -void Softmin::Forward( - const InputType& input, - OutputType& output) -{ - InputType inputMin = arma::repmat(arma::min(input,0), input.n_rows, 1); - output = arma::repmat(arma::log(arma::sum( - arma::exp(-(input - inputMin)),0)), input.n_rows, 1); - output = arma::exp(-(input - inputMin) - output); -} - -template -template -void Softmin::Backward( - const arma::Mat& input, - const arma::Mat& gy, - arma::Mat& g) -{ - g = input % (gy - arma::repmat(arma::sum(gy % input), input.n_rows, 1)); -} - -template -template -void Softmin::serialize( - Archive& /* ar */, - const unsigned int /* version */) -{ - // Nothing to do here. -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index b273dd3e4e..fae84ae9a8 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -8,6 +8,8 @@ add_executable(mlpack_test io_test.cpp cosine_tree_test.cpp dcgan_test.cpp + det_test.cpp + distribution_test.cpp drusilla_select_test.cpp emst_test.cpp fastmks_test.cpp @@ -34,6 +36,7 @@ add_executable(mlpack_test math_test.cpp matrix_completion_test.cpp maximal_inputs_test.cpp + mean_shift_test.cpp metric_test.cpp mlpack_test.cpp mock_categorical_data.hpp @@ -89,6 +92,7 @@ add_executable(mlpack_test main_tests/local_coordinate_coding_test.cpp main_tests/logistic_regression_test.cpp main_tests/lsh_test.cpp + main_tests/mean_shift_test.cpp main_tests/nbc_test.cpp main_tests/nmf_test.cpp main_tests/perceptron_test.cpp @@ -118,8 +122,6 @@ add_executable(mlpack_catch_test dbscan_test.cpp decision_stump_test.cpp decision_tree_test.cpp - det_test.cpp - distribution_test.cpp feedforward_network_test.cpp image_load_test.cpp imputation_test.cpp @@ -133,7 +135,6 @@ add_executable(mlpack_catch_test load_save_test.cpp loss_functions_test.cpp main.cpp - mean_shift_test.cpp nca_test.cpp one_hot_encoding_test.cpp pca_test.cpp @@ -167,7 +168,6 @@ add_executable(mlpack_catch_test main_tests/kmeans_test.cpp main_tests/knn_test.cpp main_tests/linear_regression_test.cpp - main_tests/mean_shift_test.cpp main_tests/nca_test.cpp main_tests/pca_test.cpp main_tests/preprocess_binarize_test.cpp diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 9ee1ebcaf9..2c1fe63398 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -558,58 +558,6 @@ void CheckCELUDerivativeCorrect(const arma::colvec input, } } -/** - * Implementation of the Softmin activation function test. The function is - * implemented as Softmin layer in the file softmin.hpp. - * - * @param input Input data used for evaluating the Softmin activation function. - * @param target Target data used to evaluate the Softmin activation. - */ -void CheckSoftminActivationCorrect(const arma::colvec input, - const arma::colvec target) -{ - // Initialize Softmin object. - Softmin<> softmin; - - // Test the activation function using the entire vector as input. - arma::colvec activations; - softmin.Forward(input,activations); - for (size_t i = 0; i < activations.n_elem; ++i) - { - REQUIRE(activations.at(i) == Approx(target.at(i)).epsilon(1e-5)); - } -} - -/** - * Implementation of the Softmin activation function derivative test. - * The function is implemented as Softmin layer in the file softmin.hpp. - * - * @param input Input data used for evaluating the Softmin activation function. - * @param target Target data used to evaluate the Softmin activation. - */ -void CheckSoftminDerivativeCorrect(const arma::colvec input, - const arma::colvec target) -{ - // Initialize Softmin object. - Softmin<> softmin; - - // Test the calculation of the derivatives using the entire vector as input. - arma::colvec derivatives, activations; - - // This error vector will be set to [[1.0],[0.0],[1.0],[0.0]] - // to get the derivatives. - arma::colvec error = arma::ones(input.n_elem); - error(1) = 0.0; - error(3) = 0.0; - softmin.Forward(input, activations); - softmin.Backward(activations, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; ++i) - { - REQUIRE(derivatives.at(i) == Approx(target.at(i)).epsilon(1e-5)); - } - -} - /** * Basic test of the tanh function. */ @@ -1115,23 +1063,3 @@ TEST_CASE("GaussianFunctionTest", "[ActivationFunctionsTest]") CheckDerivativeCorrect(desiredActivations, desiredDerivatives); } - -/** - * Basic test of the Softmin function. - */ -TEST_CASE("SoftminFunctionTest", "[ActivationFunctionsTest]") -{ - const arma::colvec activationData("4.2 2.4 7.0 6.4"); - - // Hand-calculated Values. - const arma::colvec desiredActivations("0.1384799751 0.8377550303 \ - 0.008420976 0.0153440186"); - - const arma::colvec desiredDerivatives("0.1181371351 -0.12306701070 \ - 0.0071839266 -0.0022540509"); - - CheckSoftminActivationCorrect(activationData, - desiredActivations); - CheckSoftminDerivativeCorrect(activationData, - desiredDerivatives); -} diff --git a/src/mlpack/tests/ann_layer_test.cpp b/src/mlpack/tests/ann_layer_test.cpp index 37a5a5b192..dfd1ecf091 100644 --- a/src/mlpack/tests/ann_layer_test.cpp +++ b/src/mlpack/tests/ann_layer_test.cpp @@ -87,10 +87,11 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -415,10 +416,11 @@ TEST_CASE("GradientLinearLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -506,12 +508,13 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - inSize(4), - outSize(1), - nPoints(2), - batchSize(4) + GradientFunction() { + const size_t inSize = 4; + const size_t outSize = 1; + const size_t nPoints = 2; + const size_t batchSize = 4; + input = arma::randu(inSize * nPoints, batchSize); target = arma::zeros(outSize * nPoints, batchSize); target(0, 0) = 1; @@ -542,10 +545,6 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") FFN, RandomInitialization>* model; arma::mat input, target; - const size_t inSize; - const size_t outSize; - const size_t nPoints; - const size_t batchSize; } function; REQUIRE(CheckGradient(function) <= 1e-7); @@ -592,10 +591,11 @@ TEST_CASE("GradientNoisyLinearLayerTest", "[ANNLayerTest]") // Noisy linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -695,10 +695,11 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]") // LinearNoBias function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -796,10 +797,11 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(2, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(2, 1); + target = arma::mat("1"); + model = new FFN, RandomInitialization>( NegativeLogLikelihood<>(), RandomInitialization(0.1, 0.5)); @@ -1015,10 +1017,10 @@ TEST_CASE("GradientLSTMLayerTest", "[ANNLayerTest]") // LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(1, 1, 5)), - target(arma::ones(1, 1, 5)) + GradientFunction() { + input = arma::randu(1, 1, 5); + target.ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1120,10 +1122,10 @@ TEST_CASE("GradientFastLSTMLayerTest", "[ANNLayerTest]") // Fast LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(1, 1, 5)), - target(arma::ones(1, 1, 5)) + GradientFunction() { + input = arma::randu(1, 1, 5); + target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1389,10 +1391,10 @@ TEST_CASE("GradientGRULayerTest", "[ANNLayerTest]") // GRU function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(1, 1, 5)), - target(arma::ones(1, 1, 5)) + GradientFunction() { + input = arma::randu(1, 1, 5); + target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1629,10 +1631,11 @@ TEST_CASE("GradientConcatLayerTest", "[ANNLayerTest]") // Concat function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1697,10 +1700,11 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]") // Concatenate function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1901,10 +1905,11 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]") // Softmax function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1; 0")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1; 0"); + model = new FFN, RandomInitialization>; model->Predictors() = input; model->Responses() = target; @@ -2104,10 +2109,12 @@ TEST_CASE("GradientBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(32, 2048)), - target(arma::ones(1, 2048)) + GradientFunction() { + input = arma::randn(32, 2048); + arma::mat target; + target.ones(1, 2048); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2177,11 +2184,12 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(5, 256)), - target(arma::ones(1, 256)) + GradientFunction() { + input = arma::randn(5, 256); arma::mat referenceBatch = arma::mat(input.memptr(), input.n_rows, 16); + arma::mat target; + target.ones(1, 256); model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; @@ -2239,10 +2247,12 @@ TEST_CASE("MiniBatchDiscriminationTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(5, 4)), - target(arma::ones(1, 4)) + GradientFunction() { + input = arma::randn(5, 4); + arma::mat target; + target.ones(1, 4); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2417,10 +2427,11 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() : - input(arma::linspace(0, 35, 36)), - target(arma::mat("1")) + GradientFunction() { + input = arma::linspace(0, 35, 36); + target = arma::mat("1"); + model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2533,10 +2544,11 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::linspace(0, 35, 36)), - target(arma::mat("1")) + GradientFunction() { + input = arma::linspace(0, 35, 36); + target = arma::mat("1"); + model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2563,7 +2575,7 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") arma::mat input, target; } function; - // TODO: this tolerance seems far higher than necessary. The implementation + // TODO: this tolerance seems far higher than necessary. The implementation // should be checked. REQUIRE(CheckGradient(function) <= 0.2); } @@ -2714,10 +2726,12 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(10, 256)), - target(arma::ones(1, 256)) + GradientFunction() { + input = arma::randn(10, 256); + arma::mat target; + target.ones(1, 256); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3034,10 +3048,11 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3077,10 +3092,11 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 2)), - target(arma::mat("1 1")) + GradientFunction() { + input = arma::randu(10, 2); + target = arma::mat("1 1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3232,10 +3248,11 @@ TEST_CASE("GradientHighwayLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(5, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(5, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3283,10 +3300,11 @@ TEST_CASE("GradientSequentialLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3333,10 +3351,11 @@ TEST_CASE("GradientWeightNormLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4166,10 +4185,12 @@ TEST_CASE("GradientBatchNormWithMiniBatchesTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() : - input(arma::randn(16, 1024)), - target(arma::ones(1, 1024)) + GradientFunction() { + input = arma::randn(16, 1024); + arma::mat target; + target.ones(1, 1024); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4662,13 +4683,7 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() : - tgtSeqLen(2), - srcSeqLen(2), - embedDim(4), - nHeads(2), - vocabSize(5), - batchSize(2) + GradientFunction() { input = arma::randu(embedDim * (tgtSeqLen + 2 * srcSeqLen), batchSize); target = arma::zeros(vocabSize, batchSize); @@ -4721,13 +4736,13 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") MultiheadAttention<>* attnModule; arma::mat input, target, attnMask, keyPaddingMask; - const size_t tgtSeqLen; - const size_t srcSeqLen; - const size_t embedDim; - const size_t nHeads; - const size_t vocabSize; - const size_t batchSize; + const size_t tgtSeqLen = 2; + const size_t srcSeqLen = 2; + const size_t embedDim = 4; + const size_t nHeads = 2; + const size_t vocabSize = 5; + const size_t batchSize = 2; } function; - REQUIRE(CheckGradient(function) <= 3e-06); + REQUIRE(CheckGradient(function) <= 2e-06); } diff --git a/src/mlpack/tests/ann_visitor_test.cpp b/src/mlpack/tests/ann_visitor_test.cpp index ccf3cca35f..1b01308ff3 100644 --- a/src/mlpack/tests/ann_visitor_test.cpp +++ b/src/mlpack/tests/ann_visitor_test.cpp @@ -52,37 +52,3 @@ TEST_CASE("BiasSetVisitorTest", "[ANNVisitorTest]") boost::apply_visitor(DeleteVisitor(), linear); } - -/** - * Test that WeightSetVisitor works properly. - */ -TEST_CASE("WeightSetVisitorTest", "[ANNVisitorTest]") -{ - size_t randomSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> linear = new Linear<>(randomSize, randomSize); - - arma::mat layerWeights(randomSize * randomSize + randomSize, 1); - layerWeights.zeros(); - - size_t setWeights = boost::apply_visitor(WeightSetVisitor(layerWeights, 0), - linear); - - REQUIRE(setWeights == randomSize * randomSize + randomSize); -} - -/** - * Test that WeightSizeVisitor works properly. - */ -TEST_CASE("WeightSizeVisitorTest", "[ANNVisitorTest]") -{ - size_t randomSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> linear = new Linear<>(randomSize, randomSize); - - size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), - linear); - - REQUIRE(weightSize == randomSize * randomSize + randomSize); -} - diff --git a/src/mlpack/tests/det_test.cpp b/src/mlpack/tests/det_test.cpp index c0989768eb..4a16bbd060 100644 --- a/src/mlpack/tests/det_test.cpp +++ b/src/mlpack/tests/det_test.cpp @@ -11,7 +11,8 @@ * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #include -#include "catch.hpp" +#include +#include "test_tools.hpp" // This trick does not work on Windows. We will have to comment out the tests // that depend on it. @@ -32,11 +33,13 @@ using namespace mlpack; using namespace mlpack::det; using namespace std; +BOOST_AUTO_TEST_SUITE(DETTest); + // Tests for the private functions. We cannot perform these if we are on // Windows because we cannot make private functions accessible using the macro // trick above. #ifndef _WIN32 -TEST_CASE("TestGetMaxMinVals", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) { arma::mat testData(3, 5); @@ -46,15 +49,15 @@ TEST_CASE("TestGetMaxMinVals", "[DETTest]") DTree tree(testData); - REQUIRE(tree.MaxVals()[0] == 7); - REQUIRE(tree.MinVals()[0] == 3); - REQUIRE(tree.MaxVals()[1] == 7); - REQUIRE(tree.MinVals()[1] == 0); - REQUIRE(tree.MaxVals()[2] == 8); - REQUIRE(tree.MinVals()[2] == 1); + BOOST_REQUIRE_EQUAL(tree.MaxVals()[0], 7); + BOOST_REQUIRE_EQUAL(tree.MinVals()[0], 3); + BOOST_REQUIRE_EQUAL(tree.MaxVals()[1], 7); + BOOST_REQUIRE_EQUAL(tree.MinVals()[1], 0); + BOOST_REQUIRE_EQUAL(tree.MaxVals()[2], 8); + BOOST_REQUIRE_EQUAL(tree.MinVals()[2], 1); } -TEST_CASE("TestComputeNodeError", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestComputeNodeError) { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -62,18 +65,17 @@ TEST_CASE("TestComputeNodeError", "[DETTest]") DTree testDTree(maxVals, minVals, 5); double trueNodeError = -log(4.0) - log(7.0) - log(7.0); - REQUIRE((double) testDTree.logNegError == - Approx(trueNodeError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE((double) testDTree.logNegError, trueNodeError, 1e-10); testDTree.start = 3; testDTree.end = 5; double nodeError = testDTree.LogNegativeError(5); trueNodeError = 2 * log(2.0 / 5.0) - log(4.0) - log(7.0) - log(7.0); - REQUIRE(nodeError == Approx(trueNodeError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(nodeError, trueNodeError, 1e-10); } -TEST_CASE("TestWithinRange", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestWithinRange) { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -83,14 +85,14 @@ TEST_CASE("TestWithinRange", "[DETTest]") arma::vec testQuery(3); testQuery << 4.5 << 2.5 << 2; - REQUIRE(testDTree.WithinRange(testQuery) == true); + BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), true); testQuery << 8.5 << 2.5 << 2; - REQUIRE(testDTree.WithinRange(testQuery) == false); + BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), false); } -TEST_CASE("TestFindSplit", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestFindSplit) { arma::mat testData(3, 5); @@ -106,21 +108,20 @@ TEST_CASE("TestFindSplit", "[DETTest]") size_t trueDim = 2; double trueSplit = 5.5; double trueLeftError = 2 * log(2.0 / 5.0) - (log(7.0) + log(4.0) + log(4.5)); - double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + - log(2.5)); + double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + log(2.5)); testDTree.logVolume = log(7.0) + log(4.0) + log(7.0); - REQUIRE(testDTree.FindSplit( + BOOST_REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - REQUIRE(trueDim == obDim); - REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); + BOOST_REQUIRE(trueDim == obDim); + BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); - REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); - REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); + BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); } -TEST_CASE("TestSplitData", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSplitData) { arma::mat testData(3, 5); @@ -139,16 +140,16 @@ TEST_CASE("TestSplitData", "[DETTest]") size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - REQUIRE(splitInd == 2); // 2 points on left side. + BOOST_REQUIRE_EQUAL(splitInd, 2); // 2 points on left side. - REQUIRE(oTest[0] == 1); - REQUIRE(oTest[1] == 4); - REQUIRE(oTest[2] == 3); - REQUIRE(oTest[3] == 2); - REQUIRE(oTest[4] == 5); + BOOST_REQUIRE_EQUAL(oTest[0], 1); + BOOST_REQUIRE_EQUAL(oTest[1], 4); + BOOST_REQUIRE_EQUAL(oTest[2], 3); + BOOST_REQUIRE_EQUAL(oTest[3], 2); + BOOST_REQUIRE_EQUAL(oTest[4], 5); } -TEST_CASE("TestSparseFindSplit", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparseFindSplit) { arma::mat realData(4, 7); @@ -172,17 +173,17 @@ TEST_CASE("TestSparseFindSplit", "[DETTest]") (log(7.0) + log(6.5) + log(8.0) + log(6.0)); testDTree.logVolume = log(7.0) + log(7.0) + log(8.0) + log(6.0); - REQUIRE(testDTree.FindSplit( + BOOST_REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - REQUIRE(trueDim == obDim); - REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); + BOOST_REQUIRE(trueDim == obDim); + BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); - REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); - REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); + BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); } -TEST_CASE("TestSparseSplitData", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparseSplitData) { arma::mat realData(4, 7); @@ -204,22 +205,22 @@ TEST_CASE("TestSparseSplitData", "[DETTest]") size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - REQUIRE(splitInd == 3); // 2 points on left side. + BOOST_REQUIRE_EQUAL(splitInd, 3); // 2 points on left side. - REQUIRE(oTest[0] == 1); - REQUIRE(oTest[1] == 4); - REQUIRE(oTest[2] == 3); - REQUIRE(oTest[3] == 2); - REQUIRE(oTest[4] == 5); - REQUIRE(oTest[5] == 6); - REQUIRE(oTest[6] == 7); + BOOST_REQUIRE_EQUAL(oTest[0], 1); + BOOST_REQUIRE_EQUAL(oTest[1], 4); + BOOST_REQUIRE_EQUAL(oTest[2], 3); + BOOST_REQUIRE_EQUAL(oTest[3], 2); + BOOST_REQUIRE_EQUAL(oTest[4], 5); + BOOST_REQUIRE_EQUAL(oTest[5], 6); + BOOST_REQUIRE_EQUAL(oTest[6], 7); } #endif // Tests for the public functions. -TEST_CASE("TestGrow", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestGrow) { arma::mat testData(3, 5); @@ -243,36 +244,34 @@ TEST_CASE("TestGrow", "[DETTest]") DTree testDTree(testData); double alpha = testDTree.Grow(testData, oTest, false, 2, 1); - REQUIRE(oTest[0] == 0); - REQUIRE(oTest[1] == 3); - REQUIRE(oTest[2] == 1); - REQUIRE(oTest[3] == 2); - REQUIRE(oTest[4] == 4); + BOOST_REQUIRE_EQUAL(oTest[0], 0); + BOOST_REQUIRE_EQUAL(oTest[1], 3); + BOOST_REQUIRE_EQUAL(oTest[2], 1); + BOOST_REQUIRE_EQUAL(oTest[3], 2); + BOOST_REQUIRE_EQUAL(oTest[4], 4); // Test the structure of the tree. - REQUIRE(testDTree.Left()->Left() == NULL); - REQUIRE(testDTree.Left()->Right() == NULL); - REQUIRE(testDTree.Right()->Left()->Left() == NULL); - REQUIRE(testDTree.Right()->Left()->Right() == NULL); - REQUIRE(testDTree.Right()->Right()->Left() == NULL); - REQUIRE(testDTree.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree.Right()->Right()->Right() == NULL); - REQUIRE(testDTree.SubtreeLeaves() == 3); + BOOST_REQUIRE(testDTree.SubtreeLeaves() == 3); - REQUIRE(testDTree.SplitDim() == 2); - REQUIRE(testDTree.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree.Right()->SplitDim() == 1); - REQUIRE(testDTree.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE(testDTree.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree.Right()->SplitValue(), 0.5, 1e-5); // Test node errors for every node (these are private functions). #ifndef _WIN32 - REQUIRE(testDTree.logNegError == Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.Left()->logNegError == Approx(lError).epsilon(1e-12)); - REQUIRE(testDTree.Right()->logNegError == Approx(rError).epsilon(1e-12)); - REQUIRE(testDTree.Right()->Left()->logNegError == - Approx(rlError).epsilon(1e-12)); - REQUIRE(testDTree.Right()->Right()->logNegError == - Approx(rrError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(testDTree.logNegError, rootError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Left()->logNegError, lError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Right()->logNegError, rError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Right()->Left()->logNegError, rlError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Right()->Right()->logNegError, rrError, 1e-10); #endif // Test alpha. @@ -282,10 +281,10 @@ TEST_CASE("TestGrow", "[DETTest]") rAlpha = std::log(-(std::exp(rError) - (std::exp(rlError) + std::exp(rrError)))); - REQUIRE(alpha == Approx(min(rootAlpha, rAlpha)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(alpha, min(rootAlpha, rAlpha), 1e-10); } -TEST_CASE("TestPruneAndUpdate", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) { arma::mat testData(3, 5); @@ -299,19 +298,18 @@ TEST_CASE("TestPruneAndUpdate", "[DETTest]") double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeaves() == 1); + BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); + BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeavesLogNegError() == - Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.Left() == NULL); - REQUIRE(testDTree.Right() == NULL); + BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); + BOOST_REQUIRE(testDTree.Left() == NULL); + BOOST_REQUIRE(testDTree.Right() == NULL); } -TEST_CASE("TestComputeValue", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestComputeValue) { arma::mat testData(3, 5); @@ -336,22 +334,22 @@ TEST_CASE("TestComputeValue", "[DETTest]") double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); } -TEST_CASE("TestVariableImportance", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestVariableImportance) { arma::mat testData(3, 5); @@ -379,14 +377,12 @@ TEST_CASE("TestVariableImportance", "[DETTest]") testDTree.ComputeVariableImportance(imps); - REQUIRE((double) 0.0 == Approx(imps[0]).epsilon(1e-12)); - REQUIRE((double) (rError - (rlError + rrError)) == - Approx(imps[1]).epsilon(1e-12)); - REQUIRE((double) (rootError - (lError + rError)) == - Approx(imps[2]).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE((double) 0.0, imps[0], 1e-10); + BOOST_REQUIRE_CLOSE((double) (rError - (rlError + rrError)), imps[1], 1e-10); + BOOST_REQUIRE_CLOSE((double) (rootError - (lError + rError)), imps[2], 1e-10); } -TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) { arma::mat realData(3, 5); @@ -403,19 +399,18 @@ TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]") double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeaves() == 1); + BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); + BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeavesLogNegError() == - Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.Left() == NULL); - REQUIRE(testDTree.Right() == NULL); + BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); + BOOST_REQUIRE(testDTree.Left() == NULL); + BOOST_REQUIRE(testDTree.Right() == NULL); } -TEST_CASE("TestSparseComputeValue", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparseComputeValue) { arma::mat realData(3, 5); @@ -443,25 +438,25 @@ TEST_CASE("TestSparseComputeValue", "[DETTest]") double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); } /** * These are not yet implemented. * -TEST_CASE("TestTagTree", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestTagTree) { MatType testData(3, 5); @@ -474,7 +469,7 @@ TEST_CASE("TestTagTree", "[DETTest]") delete testDTree; } -TEST_CASE("TestFindBucket", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestFindBucket) { MatType testData(3, 5); @@ -489,24 +484,24 @@ TEST_CASE("TestFindBucket", "[DETTest]") // Test functions in dt_utils.hpp -TEST_CASE("TestTrainer", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestTrainer) { } -TEST_CASE("TestPrintVariableImportance", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestPrintVariableImportance) { } -TEST_CASE("TestPrintLeafMembership", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestPrintLeafMembership) { } */ // Test the copy constructor and the copy operator. -TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]") +BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) { arma::mat testData(3, 5); @@ -549,76 +544,76 @@ TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]") delete testDTree; // Test the data of copied tree (using copy constructor). - REQUIRE(testDTree2.MaxVals()[0] == maxVals0); - REQUIRE(testDTree2.MinVals()[0] == minVals0); - REQUIRE(testDTree2.MaxVals()[1] == maxVals1); - REQUIRE(testDTree2.MinVals()[1] == minVals1); - REQUIRE(testDTree2.MaxVals()[2] == maxVals2); - REQUIRE(testDTree2.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); // Test the data of the copied tree (using the copy operator). - REQUIRE(testDTree3.MaxVals()[0] == maxVals0); - REQUIRE(testDTree3.MinVals()[0] == minVals0); - REQUIRE(testDTree3.MaxVals()[1] == maxVals1); - REQUIRE(testDTree3.MinVals()[1] == minVals1); - REQUIRE(testDTree3.MaxVals()[2] == maxVals2); - REQUIRE(testDTree3.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[2], minVals2); // Test the structure of the tree copied using the copy constructor. - REQUIRE(testDTree2.Left()->Left() == NULL); - REQUIRE(testDTree2.Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the structure of the tree copied using the copy operator. - REQUIRE(testDTree3.Left()->Left() == NULL); - REQUIRE(testDTree3.Left()->Right() == NULL); - REQUIRE(testDTree3.Right()->Left()->Left() == NULL); - REQUIRE(testDTree3.Right()->Left()->Right() == NULL); - REQUIRE(testDTree3.Right()->Right()->Left() == NULL); - REQUIRE(testDTree3.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree3.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree3.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Right()->Right() == NULL); // Test the data of the tree copied using the copy constructor. - REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree2.SplitDim() == 2); - REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree2.Right()->SplitDim() == 1); - REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree2.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); // Test the data of the tree copied using the copy operator. - REQUIRE(testDTree3.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree3.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree3.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree3.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree3.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree3.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree3.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree3.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree3.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree3.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree3.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree3.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree3.SplitDim() == 2); - REQUIRE(testDTree3.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree3.Right()->SplitDim() == 1); - REQUIRE(testDTree3.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree3.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree3.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree3.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree3.Right()->SplitValue(), 0.5, 1e-5); } // Test the move constructor. -TEST_CASE("MoveConstructorTest", "[DETTest]") +BOOST_AUTO_TEST_CASE(MoveConstructorTest) { arma::mat testData(3, 5); @@ -658,50 +653,50 @@ TEST_CASE("MoveConstructorTest", "[DETTest]") DTree testDTree2(std::move(*testDTree)); // Check default values of the original tree. - REQUIRE(testDTree->LogNegError() == -DBL_MAX); - REQUIRE(testDTree->Left() == (DTree*) NULL); - REQUIRE(testDTree->Right() == (DTree*) NULL); + BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); + BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); + BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - REQUIRE(testDTree2.MaxVals()[0] == maxVals0); - REQUIRE(testDTree2.MinVals()[0] == minVals0); - REQUIRE(testDTree2.MaxVals()[1] == maxVals1); - REQUIRE(testDTree2.MinVals()[1] == minVals1); - REQUIRE(testDTree2.MaxVals()[2] == maxVals2); - REQUIRE(testDTree2.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); // Test the structure of the moved tree. - REQUIRE(testDTree2.Left()->Left() == NULL); - REQUIRE(testDTree2.Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of the moved tree. - REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree2.SplitDim() == 2); - REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree2.Right()->SplitDim() == 1); - REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree2.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); } // Test the move operator. -TEST_CASE("MoveOperatorTest", "[DETTest]") +BOOST_AUTO_TEST_CASE(MoveOperatorTest) { arma::mat testData(3, 5); @@ -741,44 +736,46 @@ TEST_CASE("MoveOperatorTest", "[DETTest]") DTree testDTree2 = std::move(*testDTree); // Check default values of the original tree. - REQUIRE(testDTree->LogNegError() == -DBL_MAX); - REQUIRE(testDTree->Left() == (DTree*) NULL); - REQUIRE(testDTree->Right() == (DTree*) NULL); + BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); + BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); + BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - REQUIRE(testDTree2.MaxVals()[0] == maxVals0); - REQUIRE(testDTree2.MinVals()[0] == minVals0); - REQUIRE(testDTree2.MaxVals()[1] == maxVals1); - REQUIRE(testDTree2.MinVals()[1] == minVals1); - REQUIRE(testDTree2.MaxVals()[2] == maxVals2); - REQUIRE(testDTree2.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); // Test the structure of the moved tree. - REQUIRE(testDTree2.Left()->Left() == NULL); - REQUIRE(testDTree2.Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of moved tree. - REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree2.SplitDim() == 2); - REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree2.Right()->SplitDim() == 1); - REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree2.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index ab7d606a9f..35103130b9 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -19,15 +19,17 @@ #include #include -#include "catch.hpp" -#include "serialization_catch.hpp" -#include "test_catch_tools.hpp" +#include +#include "test_tools.hpp" +#include "serialization.hpp" using namespace mlpack; using namespace mlpack::distribution; using namespace mlpack::metric; using namespace mlpack::math; +BOOST_AUTO_TEST_SUITE(DistributionTest); + /*********************************/ /** Discrete Distribution Tests **/ /*********************************/ @@ -35,38 +37,38 @@ using namespace mlpack::math; /** * Make sure we initialize correctly. */ -TEST_CASE("DiscreteDistributionConstructorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionConstructorTest) { DiscreteDistribution d(5); - REQUIRE(d.Probabilities().n_elem == 5); - REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("3") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(d.Probabilities().n_elem, 5); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); } /** * Make sure we get the probabilities of observations right. */ -TEST_CASE("DiscreteDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionProbabilityTest) { DiscreteDistribution d(5); d.Probabilities() = "0.2 0.4 0.1 0.1 0.2"; - REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.4).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.1).epsilon(1e-7)); - REQUIRE(d.Probability("3") == Approx(0.1).epsilon(1e-7)); - REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.4, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.1, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.1, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); } /** * Make sure we get random observations correct. */ -TEST_CASE("DiscreteDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) { DiscreteDistribution d(arma::Col("3")); @@ -83,15 +85,15 @@ TEST_CASE("DiscreteDistributionRandomTest", "[DistributionTest]") actualProb /= accu(actualProb); // 8% tolerance, because this can be a noisy process. - REQUIRE(actualProb(0) == Approx(0.3).epsilon(0.08)); - REQUIRE(actualProb(1) == Approx(0.6).epsilon(0.08)); - REQUIRE(actualProb(2) == Approx(0.1).epsilon(0.08)); + BOOST_REQUIRE_CLOSE(actualProb(0), 0.3, 8.0); + BOOST_REQUIRE_CLOSE(actualProb(1), 0.6, 8.0); + BOOST_REQUIRE_CLOSE(actualProb(2), 0.1, 8.0); } /** * Make sure we can estimate from observations correctly. */ -TEST_CASE("DiscreteDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) { DiscreteDistribution d(4); @@ -99,16 +101,16 @@ TEST_CASE("DiscreteDistributionTrainTest", "[DistributionTest]") d.Train(obs); - REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.375).epsilon(1e-7)); - REQUIRE(d.Probability("3") == Approx(0.125).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.375, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.125, 1e-5); } /** * Estimate from observations with probabilities. */ -TEST_CASE("DiscreteDistributionTrainProbTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) { DiscreteDistribution d(3); @@ -118,15 +120,15 @@ TEST_CASE("DiscreteDistributionTrainProbTest", "[DistributionTest]") d.Train(obs, prob); - REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.5, 1e-5); } /** * Achieve multidimensional probability distribution. */ -TEST_CASE("MultiDiscreteDistributionTrainProbTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) { DiscreteDistribution d("10 10 10"); @@ -135,29 +137,29 @@ TEST_CASE("MultiDiscreteDistributionTrainProbTest", "[DistributionTest]") "0 0 0 1 1 2 2 2 2 2;"); d.Train(obs); - REQUIRE(d.Probability("0 0 0") == Approx(0.009).epsilon(1e-7)); - REQUIRE(d.Probability("0 1 2") == Approx(0.015).epsilon(1e-7)); - REQUIRE(d.Probability("2 1 0") == Approx(0.054).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.009, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.015, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.054, 1e-5); } /** * Make sure we initialize multidimensional probability distribution * correctly. */ -TEST_CASE("MultiDiscreteDistributionConstructorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionConstructorTest) { DiscreteDistribution d("4 4 4 4"); - REQUIRE(d.Probabilities(0).size() == 4); - REQUIRE(d.Dimensionality() == 4); - REQUIRE(d.Probability("0 0 0 0") == Approx(0.00390625).epsilon(1e-7)); - REQUIRE(d.Probability("0 1 2 3") == Approx(0.00390625).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(d.Probabilities(0).size(), 4); + BOOST_REQUIRE_EQUAL(d.Dimensionality(), 4); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0 0"), 0.00390625, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("0 1 2 3"), 0.00390625, 1e-5); } /** * Achieve multidimensional probability distribution. */ -TEST_CASE("MultiDiscreteDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) { std::vector pro; pro.push_back(arma::vec("0.1, 0.3, 0.6")); @@ -166,16 +168,16 @@ TEST_CASE("MultiDiscreteDistributionTrainTest", "[DistributionTest]") DiscreteDistribution d(pro); - REQUIRE(d.Probability("0 0 0") == Approx(0.0083333).epsilon(1e-5)); - REQUIRE(d.Probability("0 1 2") == Approx(0.0166666).epsilon(1e-5)); - REQUIRE(d.Probability("2 1 0") == Approx(0.05).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.0083333, 1e-3); + BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.0166666, 1e-3); + BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.05, 1e-5); } /** * Estimate multidimensional probability distribution from observations with * probabilities. */ -TEST_CASE("MultiDiscreteDistributionTrainProTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) { DiscreteDistribution d("5 5 5"); @@ -187,16 +189,16 @@ TEST_CASE("MultiDiscreteDistributionTrainProTest", "[DistributionTest]") d.Train(obs, prob); - REQUIRE(d.Probability("0 0 0") == Approx(0.00390625).epsilon(1e-7)); - REQUIRE(d.Probability("1 0 1") == Approx(0.0078125).epsilon(1e-7)); - REQUIRE(d.Probability("2 1 0") == Approx(0.015625).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.00390625, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1 0 1"), 0.0078125, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.015625, 1e-5); } /** * Test the LogProbability() function, for multiple points in the multivariate * Discrete case. */ -TEST_CASE("DiscreteLogProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) { // Same case as before. DiscreteDistribution d("5 5"); @@ -208,17 +210,17 @@ TEST_CASE("DiscreteLogProbabilityTest", "[DistributionTest]") d.LogProbability(obs, logProb); - REQUIRE(logProb.n_elem == 2); + BOOST_REQUIRE_EQUAL(logProb.n_elem, 2); - REQUIRE(logProb(0) == Approx(-3.2188758248682).epsilon(1e-5)); - REQUIRE(logProb(1) == Approx(-3.2188758248682).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logProb(0), -3.2188758248682, 1e-3); + BOOST_REQUIRE_CLOSE(logProb(1), -3.2188758248682, 1e-3); } /** * Test the Probability() function, for multiple points in the multivariate * Discrete case. */ -TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) { // Same case as before. DiscreteDistribution d("5 5"); @@ -230,10 +232,10 @@ TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") d.Probability(obs, prob); - REQUIRE(prob.n_elem == 2); + BOOST_REQUIRE_EQUAL(prob.n_elem, 2); - REQUIRE(prob(0) == Approx(0.0400000000000).epsilon(1e-5)); - REQUIRE(prob(1) == Approx(0.0400000000000).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(prob(0), 0.0400000000000, 1e-3); + BOOST_REQUIRE_CLOSE(prob(1), 0.0400000000000, 1e-3); } /*********************************/ @@ -243,33 +245,32 @@ TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") /** * Make sure Gaussian distributions are initialized correctly. */ -TEST_CASE("GaussianDistributionEmptyConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionEmptyConstructor) { GaussianDistribution d; - REQUIRE(d.Mean().n_elem == 0); - REQUIRE(d.Covariance().n_elem == 0); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); + BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); } /** * Make sure Gaussian distributions are initialized to the correct * dimensionality. */ -TEST_CASE("GaussianDistributionDimensionalityConstructor", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionDimensionalityConstructor) { GaussianDistribution d(4); - REQUIRE(d.Mean().n_elem == 4); - REQUIRE(d.Covariance().n_rows == 4); - REQUIRE(d.Covariance().n_cols == 4); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); + BOOST_REQUIRE_EQUAL(d.Covariance().n_rows, 4); + BOOST_REQUIRE_EQUAL(d.Covariance().n_cols, 4); } /** * Make sure Gaussian distributions are initialized correctly when we give a * mean and covariance. */ -TEST_CASE("GaussianDistributionDistributionConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) { arma::vec mean(3); arma::mat covariance(3, 3); @@ -282,17 +283,17 @@ TEST_CASE("GaussianDistributionDistributionConstructor", "[DistributionTest]") GaussianDistribution d(mean, covariance); for (size_t i = 0; i < 3; ++i) - REQUIRE(d.Mean()[i] == Approx(mean[i]).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) - REQUIRE(d.Covariance()(i, j) == Approx(covariance(i, j)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); } /** * Make sure the probability of observations is correct. */ -TEST_CASE("GaussianDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) { arma::vec mean("5 6 3 3 2"); arma::mat cov("6 1 1 1 2;" @@ -303,63 +304,52 @@ TEST_CASE("GaussianDistributionProbabilityTest", "[DistributionTest]") GaussianDistribution d(mean, cov); - REQUIRE(d.LogProbability("0 1 2 3 4") == - Approx(-13.432076798791542).epsilon(1e-7)); - REQUIRE(d.LogProbability("3 2 3 7 8") == - Approx(-15.814880322345738).epsilon(1e-7)); - REQUIRE(d.LogProbability("2 2 0 8 1") == - Approx(-13.754462857772776).epsilon(1e-7)); - REQUIRE(d.LogProbability("2 1 5 0 1") == - Approx(-13.283283233107898).epsilon(1e-7)); - REQUIRE(d.LogProbability("3 0 5 1 0") == - Approx(-13.800326511545279).epsilon(1e-7)); - REQUIRE(d.LogProbability("4 0 6 1 0") == - Approx(-14.900192463287908).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.LogProbability("0 1 2 3 4"), -13.432076798791542, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("3 2 3 7 8"), -15.814880322345738, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("2 2 0 8 1"), -13.754462857772776, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("2 1 5 0 1"), -13.283283233107898, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("3 0 5 1 0"), -13.800326511545279, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("4 0 6 1 0"), -14.900192463287908, 1e-5); } /** * Test GaussianDistribution::Probability() in the univariate case. */ -TEST_CASE("GaussianUnivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianUnivariateProbabilityTest) { GaussianDistribution g(arma::vec("0.0"), arma::mat("1.0")); // Simple case. - REQUIRE(g.Probability(arma::vec("0.0")) == - Approx(0.398942280401433).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("1.0")) == - Approx(0.241970724519143).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("-1.0")) == - Approx(0.241970724519143).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.398942280401433, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.241970724519143, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.241970724519143, + 1e-5); // A few more cases... arma::mat covariance; covariance = 2.0; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(arma::vec("0.0")) == - Approx(0.282094791773878).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("1.0")) == - Approx(0.219695644733861).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("-1.0")) == - Approx(0.219695644733861).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.282094791773878, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.219695644733861, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.219695644733861, + 1e-5); g.Mean().fill(1.0); covariance = 1.0; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(arma::vec("1.0")) == - Approx(0.398942280401433).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.398942280401433, 1e-5); covariance = 2.0; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(arma::vec("-1.0")) == - Approx(0.103776874355149).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.103776874355149, + 1e-5); } /** * Test GaussianDistribution::Probability() in the multivariate case. */ -TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) { // Simple case. arma::vec mean = "0 0"; @@ -368,37 +358,37 @@ TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") GaussianDistribution g(mean, cov); - REQUIRE(g.Probability(x) == Approx(0.159154943091895).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.159154943091895, 1e-5); arma::mat covariance; covariance = "2 0; 0 2"; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); x = "1 1"; - REQUIRE(g.Probability(x) == Approx(0.0482661763150270).epsilon(1e-7)); - REQUIRE(g.Probability(-x) == Approx(0.0482661763150270).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0482661763150270, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0482661763150270, 1e-5); g.Mean() = "1 1"; - REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); g.Mean() *= -1; - REQUIRE(g.Probability(-x) == Approx(0.0795774715459477).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0795774715459477, 1e-5); g.Mean() = "1 1"; covariance = "2 1.5; 1.5 4"; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(x) == Approx(0.066372199406187285).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.066372199406187285, 1e-5); g.Mean() *= -1; - REQUIRE(g.Probability(-x) == Approx(0.066372199406187285).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.066372199406187285, 1e-5); g.Mean() = "1 1"; x = "-1 4"; - REQUIRE(g.Probability(x) == Approx(0.00072147262356379415).epsilon(1e-7)); - REQUIRE(g.Probability(-x) == Approx(0.00085851785428674523).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.00072147262356379415, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.00085851785428674523, 1e-5); // Higher-dimensional case. x = "0 1 2 3 4"; @@ -411,19 +401,19 @@ TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") "2 0 1 0 6"; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); - REQUIRE(g.Probability(-x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 1.4673143531128877e-06, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 7.7404143494891786e-09, 1e-8); g.Mean() *= -1; - REQUIRE(g.Probability(-x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); - REQUIRE(g.Probability(x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 1.4673143531128877e-06, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(x), 7.7404143494891786e-09, 1e-8); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. */ -TEST_CASE("GaussianMultipointMultivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) { // Same case as before. arma::vec mean = "5 6 3 3 2"; @@ -443,20 +433,20 @@ TEST_CASE("GaussianMultipointMultivariateProbabilityTest", "[DistributionTest]") GaussianDistribution g(mean, cov); g.LogProbability(points, phis); - REQUIRE(phis.n_elem == 6); + BOOST_REQUIRE_EQUAL(phis.n_elem, 6); - REQUIRE(phis(0) == Approx(-13.432076798791542).epsilon(1e-7)); - REQUIRE(phis(1) == Approx(-15.814880322345738).epsilon(1e-7)); - REQUIRE(phis(2) == Approx(-13.754462857772776).epsilon(1e-7)); - REQUIRE(phis(3) == Approx(-13.283283233107898).epsilon(1e-7)); - REQUIRE(phis(4) == Approx(-13.800326511545279).epsilon(1e-7)); - REQUIRE(phis(5) == Approx(-14.900192463287908).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(phis(0), -13.432076798791542, 1e-5); + BOOST_REQUIRE_CLOSE(phis(1), -15.814880322345738, 1e-5); + BOOST_REQUIRE_CLOSE(phis(2), -13.754462857772776, 1e-5); + BOOST_REQUIRE_CLOSE(phis(3), -13.283283233107898, 1e-5); + BOOST_REQUIRE_CLOSE(phis(4), -13.800326511545279, 1e-5); + BOOST_REQUIRE_CLOSE(phis(5), -14.900192463287908, 1e-5); } /** * Make sure random observations follow the probability distribution correctly. */ -TEST_CASE("GaussianDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) { arma::vec mean("1.0 2.25"); arma::mat cov("0.85 0.60;" @@ -474,19 +464,19 @@ TEST_CASE("GaussianDistributionRandomTest", "[DistributionTest]") arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - REQUIRE(obsMean[0] == Approx(mean[0]).epsilon(0.1)); - REQUIRE(obsMean[1] == Approx(mean[1]).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsMean[0], mean[0], 10.0); + BOOST_REQUIRE_CLOSE(obsMean[1], mean[1], 10.0); - REQUIRE(obsCov(0, 0) == Approx(cov(0, 0)).epsilon(0.1)); - REQUIRE(obsCov(0, 1) == Approx(cov(0, 1)).epsilon(0.1)); - REQUIRE(obsCov(1, 0) == Approx(cov(1, 0)).epsilon(0.1)); - REQUIRE(obsCov(1, 1) == Approx(cov(1, 1)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0, 0), 10.0); + BOOST_REQUIRE_CLOSE(obsCov(0, 1), cov(0, 1), 10.0); + BOOST_REQUIRE_CLOSE(obsCov(1, 0), cov(1, 0), 10.0); + BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1, 1), 10.0); } /** * Make sure that we can properly estimate from given observations. */ -TEST_CASE("GaussianDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) { arma::vec mean("1.0 3.0 0.0 2.5"); arma::mat cov("3.0 0.0 1.0 4.0;" @@ -512,22 +502,18 @@ TEST_CASE("GaussianDistributionTrainTest", "[DistributionTest]") // Check that everything is estimated right. for (size_t i = 0; i < 4; ++i) - REQUIRE(d.Mean()[i] - actualMean[i] == Approx(0.0).margin(1e-5)); + BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); for (size_t i = 0; i < 4; ++i) for (size_t j = 0; j < 4; ++j) - { - REQUIRE(d.Covariance()(i, j) - actualCov(i, j) == - Approx(0.0).margin(1e-5)); - } + BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); } /** * This test verifies the fitting of GaussianDistribution works properly when * probabilities for each sample is given. */ -TEST_CASE("GaussianDistributionTrainWithProbabilitiesTest", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) { arma::vec mean = ("5.0"); arma::vec cov = ("2.0"); @@ -552,19 +538,18 @@ TEST_CASE("GaussianDistributionTrainWithProbabilitiesTest", GaussianDistribution guDist2; guDist2.Train(rdata); - REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(0.06)); - REQUIRE(guDist.Covariance()[0] == - Approx(guDist2.Covariance()[0]).epsilon(0.06)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 6); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 6); - REQUIRE(guDist.Mean()[0] == Approx(mean[0]).epsilon(0.06)); - REQUIRE(guDist.Covariance()[0] == Approx(cov[0]).epsilon(0.06)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean[0], 6); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov[0], 6); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) { arma::vec mean = ("5.0"); arma::vec cov = ("4.0"); @@ -588,9 +573,8 @@ TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") GaussianDistribution guDist2; guDist2.Train(rdata, probabilities); - REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(1e-17)); - REQUIRE(guDist.Covariance()[0] == - Approx(guDist2.Covariance()[0]).epsilon(1e-4)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 1e-15); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 1e-2); } /** @@ -601,8 +585,7 @@ TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") * We expect that the distribution we recover after training to be the same as * the second normal distribution (the one with high probabilities). */ -TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) { arma::vec mean1 = ("5.0"); arma::vec cov1 = ("4.0"); @@ -643,8 +626,8 @@ TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", GaussianDistribution guDist; guDist.Train(rdata, probabilities); - REQUIRE(guDist.Mean()[0] == Approx(mean1[0]).epsilon(0.05)); - REQUIRE(guDist.Covariance()[0] == Approx(cov1[0]).epsilon(0.05)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean1[0], 5); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov1[0], 5); } /******************************/ @@ -654,7 +637,7 @@ TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", * Make sure that using an object to fit one reference set and then asking * to fit another works properly. */ -TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) { // Create a gamma distribution random generator. double alphaReal = 5.3; @@ -676,8 +659,8 @@ TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") gDist.Train(rdata); // Training must estimate d pairs of alpha and beta parameters. - REQUIRE(gDist.Dimensionality() == d); - REQUIRE(gDist.Dimensionality() == d); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); // Create a N' x d' gamma distribution, fit results without new object. size_t N2 = 350; @@ -693,15 +676,15 @@ TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") gDist.Train(rdata2); // Training must estimate d' pairs of alpha and beta parameters. - REQUIRE(gDist.Dimensionality() == d2); - REQUIRE(gDist.Dimensionality() == d2); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); } /** * This test verifies that the fitting procedure for GammaDistribution works * properly when probabilities for each sample is given. */ -TEST_CASE("GammaDistributionTrainWithProbabilitiesTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) { double alphaReal = 5.4; double betaReal = 6.7; @@ -728,24 +711,24 @@ TEST_CASE("GammaDistributionTrainWithProbabilitiesTest", "[DistributionTest]") GammaDistribution gDist2; gDist2.Train(rdata); - REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(0.015)); - REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(0.015)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1.5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1.5); - REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(0.015)); - REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(0.015)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1.5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1.5); - REQUIRE(alphaReal == Approx(gDist.Alpha(0)).epsilon(0.03)); - REQUIRE(betaReal == Approx(gDist.Beta(0)).epsilon(0.03)); + BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(0), 3.0); + BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(0), 3.0); - REQUIRE(alphaReal == Approx(gDist.Alpha(1)).epsilon(0.03)); - REQUIRE(betaReal == Approx(gDist.Beta(1)).epsilon(0.03)); + BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(1), 3.0); + BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(1), 3.0); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) { double alphaReal = 5.4; double betaReal = 6.7; @@ -770,11 +753,11 @@ TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") arma::vec allProbabilities1(N, arma::fill::ones); gDist2.Train(rdata, allProbabilities1); - REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(1e-7)); - REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1e-5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1e-5); - REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(1e-7)); - REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1e-5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1e-5); } /** @@ -784,8 +767,7 @@ TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") * gamma distribution recovered has the same parameters as the second gamma * distribution with high probabilities. */ -TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) { double alphaReal = 5.4; double betaReal = 6.7; @@ -825,11 +807,11 @@ TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", GammaDistribution gDist; gDist.Train(rdata, probabilities); - REQUIRE(alphaReal2 == Approx(gDist.Alpha(0)).epsilon(0.05)); - REQUIRE(betaReal2 == Approx(gDist.Beta(0)).epsilon(0.05)); + BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(0), 5); + BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(0), 5); - REQUIRE(alphaReal2 == Approx(gDist.Alpha(1)).epsilon(0.05)); - REQUIRE(betaReal2 == Approx(gDist.Beta(1)).epsilon(0.05)); + BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(1), 5); + BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(1), 5); } /** @@ -838,7 +820,7 @@ TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", * with different alpha/beta parameters so we make sure we don't have some weird * bug that always converges to the same number. */ -TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) { // Offset from the actual alpha/beta. 10% is quite a relaxed tolerance since // the random points we generate are few (for test speed) and might be fitted @@ -866,8 +848,8 @@ TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") gDist.Train(rdata); // Estimated parameter must be close to real. - REQUIRE(gDist.Alpha(0) == Approx(alphaReal).epsilon(errorTolerance / 100)); - REQUIRE(gDist.Beta(0) == Approx(betaReal).epsilon(errorTolerance / 100)); + BOOST_REQUIRE_CLOSE(gDist.Alpha(0), alphaReal, errorTolerance); + BOOST_REQUIRE_CLOSE(gDist.Beta(0), betaReal, errorTolerance); /** Iteration 2 (different parameter set) **/ @@ -887,15 +869,15 @@ TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") gDist2.Train(rdata2); // Estimated parameter must be close to real. - REQUIRE(gDist2.Alpha(0) == Approx(alphaReal2).epsilon(errorTolerance / 100)); - REQUIRE(gDist2.Beta(0) == Approx(betaReal2).epsilon(errorTolerance / 100)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), alphaReal2, errorTolerance); + BOOST_REQUIRE_CLOSE(gDist2.Beta(0), betaReal2, errorTolerance); } /** * Test that Train() and the constructor that takes data give the same resulting * distribution. */ -TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) { const arma::mat data = arma::randu(10, 500); @@ -905,8 +887,8 @@ TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") for (size_t i = 0; i < 10; ++i) { - REQUIRE(d1.Alpha(i) == Approx(d2.Alpha(i)).epsilon(1e-7)); - REQUIRE(d1.Beta(i) == Approx(d2.Beta(i)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d1.Alpha(i), d2.Alpha(i), 1e-5); + BOOST_REQUIRE_CLOSE(d1.Beta(i), d2.Beta(i), 1e-5); } } @@ -914,7 +896,7 @@ TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") * Test that Train() with a dataset and Train() with dataset statistics return * the same results. */ -TEST_CASE("GammaDistributionTrainStatisticsTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) { const arma::mat data = arma::randu(1, 500); @@ -928,15 +910,15 @@ TEST_CASE("GammaDistributionTrainStatisticsTest", "[DistributionTest]") const arma::vec logMeanx = arma::log(meanx); d2.Train(logMeanx, meanLogx, meanx); - REQUIRE(d1.Alpha(0) == Approx(d2.Alpha(0)).epsilon(1e-7)); - REQUIRE(d1.Beta(0) == Approx(d2.Beta(0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d1.Alpha(0), d2.Alpha(0), 1e-5); + BOOST_REQUIRE_CLOSE(d1.Beta(0), d2.Beta(0), 1e-5); } /** * Tests that Random() generates points that can be reasonably well fit by the * distribution that generated them. */ -TEST_CASE("GammaDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) { const arma::vec a("2.0 2.5 3.0"), b("0.4 0.6 1.3"); const size_t numPoints = 2000; @@ -952,12 +934,12 @@ TEST_CASE("GammaDistributionRandomTest", "[DistributionTest]") GammaDistribution d2(data); for (size_t i = 0; i < 3; ++i) { - REQUIRE(d2.Alpha(i) == Approx(a(i)).epsilon(0.1)); // Within 10% - REQUIRE(d2.Beta(i) == Approx(b(i)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(d2.Alpha(i), a(i), 10); // Within 10% + BOOST_REQUIRE_CLOSE(d2.Beta(i), b(i), 10); } } -TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -967,16 +949,16 @@ TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.Probability(x1, prob1); - REQUIRE(prob1(0) == Approx(0.267575).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(prob1(0), 0.267575, 1e-3); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.Probability(x2, prob2); - REQUIRE(prob2(0) == Approx(0.189043).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(prob2(0), 0.189043, 1e-3); // Check that the overload that returns the probability for 1 dimension // agrees. - REQUIRE(prob2(0) == Approx(d2.Probability(2.94, 0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(prob2(0), d2.Probability(2.94, 0), 1e-5); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -989,11 +971,11 @@ TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.Probability(x3, prob3); - REQUIRE(prob3(0) == Approx(0.04408).epsilon(1e-4)); - REQUIRE(prob3(1) == Approx(0.026165).epsilon(1e-4)); + BOOST_REQUIRE_CLOSE(prob3(0), 0.04408, 1e-2); + BOOST_REQUIRE_CLOSE(prob3(1), 0.026165, 1e-2); } -TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -1003,16 +985,16 @@ TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.LogProbability(x1, logprob1); - REQUIRE(logprob1(0) == Approx(std::log(0.267575)).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logprob1(0), std::log(0.267575), 1e-3); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.LogProbability(x2, logprob2); - REQUIRE(logprob2(0) == Approx(std::log(0.189043)).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logprob2(0), std::log(0.189043), 1e-3); // Check that the overload that returns the log probability for // 1 dimension agrees. - REQUIRE(logprob2(0) == Approx(d2.LogProbability(2.94, 0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(logprob2(0), d2.LogProbability(2.94, 0), 1e-5); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -1026,14 +1008,14 @@ TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.LogProbability(x3, logprob3); - REQUIRE(logprob3(0) == Approx(std::log(0.04408)).epsilon(1e-5)); - REQUIRE(logprob3(1) == Approx(std::log(0.026165)).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logprob3(0), std::log(0.04408), 1e-3); + BOOST_REQUIRE_CLOSE(logprob3(1), std::log(0.026165), 1e-3); } /** * Discrete Distribution serialization test. */ -TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) { // I assume that I am properly saving vectors, so, this should be // straightforward. @@ -1054,15 +1036,15 @@ TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") const double prob = t.Probability(obs); if (prob == 0.0) { - REQUIRE(xmlT.Probability(obs) == Approx(0.0).margin(1e-8)); - REQUIRE(textT.Probability(obs) == Approx(0.0).margin(1e-8)); - REQUIRE(binaryT.Probability(obs) == Approx(0.0).margin(1e-8)); + BOOST_REQUIRE_SMALL(xmlT.Probability(obs), 1e-8); + BOOST_REQUIRE_SMALL(textT.Probability(obs), 1e-8); + BOOST_REQUIRE_SMALL(binaryT.Probability(obs), 1e-8); } else { - REQUIRE(prob == Approx(xmlT.Probability(obs)).epsilon(1e-10)); - REQUIRE(prob == Approx(textT.Probability(obs)).epsilon(1e-10)); - REQUIRE(prob == Approx(binaryT.Probability(obs)).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(prob, xmlT.Probability(obs), 1e-8); + BOOST_REQUIRE_CLOSE(prob, textT.Probability(obs), 1e-8); + BOOST_REQUIRE_CLOSE(prob, binaryT.Probability(obs), 1e-8); } } } @@ -1070,7 +1052,7 @@ TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") /** * Gaussian Distribution serialization test. */ -TEST_CASE("GaussianDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTest) { arma::vec mean(10); mean.randu(); @@ -1084,9 +1066,9 @@ TEST_CASE("GaussianDistributionTest", "[DistributionTest]") SerializeObjectAll(g, xmlG, textG, binaryG); - REQUIRE(g.Dimensionality() == xmlG.Dimensionality()); - REQUIRE(g.Dimensionality() == textG.Dimensionality()); - REQUIRE(g.Dimensionality() == binaryG.Dimensionality()); + BOOST_REQUIRE_EQUAL(g.Dimensionality(), xmlG.Dimensionality()); + BOOST_REQUIRE_EQUAL(g.Dimensionality(), textG.Dimensionality()); + BOOST_REQUIRE_EQUAL(g.Dimensionality(), binaryG.Dimensionality()); // First, check the means. CheckMatrices(g.Mean(), xmlG.Mean(), textG.Mean(), binaryG.Mean()); @@ -1106,21 +1088,18 @@ TEST_CASE("GaussianDistributionTest", "[DistributionTest]") if (prob == 0.0) { - REQUIRE(xmlG.Probability(randomObs.unsafe_col(i)) == - Approx(0.0).margin(1e-8)); - REQUIRE(textG.Probability(randomObs.unsafe_col(i)) == - Approx(0.0).margin(1e-8)); - REQUIRE(binaryG.Probability(randomObs.unsafe_col(i)) == - Approx(0.0).margin(1e-8)); + BOOST_REQUIRE_SMALL(xmlG.Probability(randomObs.unsafe_col(i)), 1e-8); + BOOST_REQUIRE_SMALL(textG.Probability(randomObs.unsafe_col(i)), 1e-8); + BOOST_REQUIRE_SMALL(binaryG.Probability(randomObs.unsafe_col(i)), 1e-8); } else { - REQUIRE(prob == - Approx(xmlG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); - REQUIRE(prob == - Approx(textG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); - REQUIRE(prob == - Approx(binaryG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(prob, xmlG.Probability(randomObs.unsafe_col(i)), + 1e-8); + BOOST_REQUIRE_CLOSE(prob, textG.Probability(randomObs.unsafe_col(i)), + 1e-8); + BOOST_REQUIRE_CLOSE(prob, binaryG.Probability(randomObs.unsafe_col(i)), + 1e-8); } } } @@ -1128,7 +1107,7 @@ TEST_CASE("GaussianDistributionTest", "[DistributionTest]") /** * Laplace Distribution serialization test. */ -TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) { arma::vec mean(20); mean.randu(); @@ -1138,9 +1117,9 @@ TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") SerializeObjectAll(l, xmlL, textL, binaryL); - REQUIRE(l.Scale() == Approx(xmlL.Scale()).epsilon(1e-10)); - REQUIRE(l.Scale() == Approx(textL.Scale()).epsilon(1e-10)); - REQUIRE(l.Scale() == Approx(binaryL.Scale()).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(l.Scale(), xmlL.Scale(), 1e-8); + BOOST_REQUIRE_CLOSE(l.Scale(), textL.Scale(), 1e-8); + BOOST_REQUIRE_CLOSE(l.Scale(), binaryL.Scale(), 1e-8); CheckMatrices(l.Mean(), xmlL.Mean(), textL.Mean(), binaryL.Mean()); } @@ -1148,15 +1127,15 @@ TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") /** * Laplace Distribution Probability Test. */ -TEST_CASE("LaplaceDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - REQUIRE(l.Probability(arma::vec("0.0")) == - Approx(0.500000000000000).epsilon(1e-7)); - REQUIRE(l.Probability(arma::vec("1.0")) == - Approx(0.183939720585721).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("0.0")), + 0.500000000000000, 1e-5); + BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("1.0")), + 0.183939720585721, 1e-5); arma::mat points = "0.0 1.0;"; @@ -1164,24 +1143,24 @@ TEST_CASE("LaplaceDistributionProbabilityTest", "[DistributionTest]") l.Probability(points, probabilities); - REQUIRE(probabilities.n_elem == 2); + BOOST_REQUIRE_EQUAL(probabilities.n_elem, 2); - REQUIRE(probabilities(0) == Approx(0.500000000000000).epsilon(1e-7)); - REQUIRE(probabilities(1) == Approx(0.183939720585721).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(probabilities(0), 0.500000000000000, 1e-5); + BOOST_REQUIRE_CLOSE(probabilities(1), 0.183939720585721, 1e-5); } /** * Laplace Distribution Log Probability Test. */ -TEST_CASE("LaplaceDistributionLogProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - REQUIRE(l.LogProbability(arma::vec("0.0")) == - Approx(-0.693147180559945).epsilon(1e-7)); - REQUIRE(l.LogProbability(arma::vec("1.0")) == - Approx(-1.693147180559946).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("0.0")), + -0.693147180559945, 1e-5); + BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("1.0")), + -1.693147180559946, 1e-5); arma::mat points = "0.0 1.0;"; @@ -1189,19 +1168,18 @@ TEST_CASE("LaplaceDistributionLogProbabilityTest", "[DistributionTest]") l.LogProbability(points, logProbabilities); - REQUIRE(logProbabilities.n_elem == 2); + BOOST_REQUIRE_EQUAL(logProbabilities.n_elem, 2); - REQUIRE(logProbabilities(0) == - Approx(-0.693147180559945).epsilon(1e-7)); - - REQUIRE(logProbabilities(1) == - Approx(-1.693147180559946).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(logProbabilities(0), -0.693147180559945, + 1e-5); + BOOST_REQUIRE_CLOSE(logProbabilities(1), -1.693147180559946, + 1e-5); } /** * Mahalanobis Distance serialization test. */ -TEST_CASE("MahalanobisDistanceTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) { MahalanobisDistance<> d; d.Covariance().randu(50, 50); @@ -1220,7 +1198,7 @@ TEST_CASE("MahalanobisDistanceTest", "[DistributionTest]") /** * Regression distribution serialization test. */ -TEST_CASE("RegressionDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(RegressionDistributionTest) { // Generate some random data. arma::mat data; @@ -1247,15 +1225,15 @@ TEST_CASE("RegressionDistributionTest", "[DistributionTest]") // Check the regression function. if (rd.Rf().Lambda() == 0.0) { - REQUIRE(xmlRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); - REQUIRE(textRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); - REQUIRE(binaryRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + BOOST_REQUIRE_SMALL(xmlRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_SMALL(textRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_SMALL(binaryRd.Rf().Lambda(), 1e-8); } else { - REQUIRE(rd.Rf().Lambda() == Approx(xmlRd.Rf().Lambda()).epsilon(1e-10)); - REQUIRE(rd.Rf().Lambda() == Approx(textRd.Rf().Lambda()).epsilon(1e-10)); - REQUIRE(rd.Rf().Lambda() == Approx(binaryRd.Rf().Lambda()).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), xmlRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), textRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), binaryRd.Rf().Lambda(), 1e-8); } CheckMatrices(rd.Rf().Parameters(), @@ -1272,32 +1250,31 @@ TEST_CASE("RegressionDistributionTest", "[DistributionTest]") * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly. */ -TEST_CASE("DiagonalGaussianDistributionEmptyConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionEmptyConstructor) { DiagonalGaussianDistribution d; - REQUIRE(d.Mean().n_elem == 0); - REQUIRE(d.Covariance().n_elem == 0); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); + BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized to * the correct dimensionality. */ -TEST_CASE("DiagonalGaussianDistributionDimensionalityConstructor", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionDimensionalityConstructor) { DiagonalGaussianDistribution d(4); - REQUIRE(d.Mean().n_elem == 4); - REQUIRE(d.Covariance().n_elem == 4); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); + BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 4); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly when we give a mean and covariance. */ -TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) { arma::vec mean = arma::randu(3); arma::vec covariance = arma::randu(3); @@ -1307,8 +1284,8 @@ TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") // Make sure the mean and covariance is correct. for (size_t i = 0; i < 3; ++i) { - REQUIRE(d.Mean()(i) == Approx(mean(i)).epsilon(1e-7)); - REQUIRE(d.Covariance()(i) == Approx(covariance(i)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Mean()(i), mean(i), 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(i), covariance(i), 1e-5); } } @@ -1316,7 +1293,7 @@ TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") * Make sure the probability of observations is correct. * The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) { arma::vec mean("2 5 3 4 1"); arma::vec cov("3 1 5 3 2"); @@ -1324,56 +1301,56 @@ TEST_CASE("DiagonalGaussianDistributionProbabilityTest", "[DistributionTest]") DiagonalGaussianDistribution d(mean, cov); // Observations lists randomly selected. - REQUIRE(d.LogProbability("3 5 2 7 8") == - Approx(-20.861264167855161).epsilon(1e-7)); - REQUIRE(d.LogProbability("7 8 4 0 5") == - Approx(-22.277930834521829).epsilon(1e-7)); - REQUIRE(d.LogProbability("6 8 7 7 5") == - Approx(-21.111264167855161).epsilon(1e-7)); - REQUIRE(d.LogProbability("2 9 5 6 3") == - Approx(-16.9112641678551621).epsilon(1e-7)); - REQUIRE(d.LogProbability("5 8 2 9 7") == - Approx(-26.111264167855161).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.LogProbability("3 5 2 7 8"), -20.861264167855161, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("7 8 4 0 5"), -22.277930834521829, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("6 8 7 7 5"), -21.111264167855161, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("2 9 5 6 3"), -16.911264167855162, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("5 8 2 9 7"), -26.111264167855161, + 1e-5); } /** * Test DiagonalGaussianDistribution::Probability() in the univariate case. * The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianUnivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianUnivariateProbabilityTest) { DiagonalGaussianDistribution d(arma::vec("0.0"), arma::vec("1.0")); // Mean: 0.0, Covariance: 1.0 - REQUIRE(d.Probability("0.0") == Approx(0.3989422804014327).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.24197072451914337).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.24197072451914337).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.3989422804014327, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.24197072451914337, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.24197072451914337, 1e-5); // Mean: 0.0, Covariance: 2.0 d.Covariance("2.0"); - REQUIRE(d.Probability("0.0") == Approx(0.28209479177387814).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.21969564473386122).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.21969564473386122).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.28209479177387814, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.21969564473386122, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.21969564473386122, 1e-5); // Mean: 1.0, Covariance: 1.0 d.Mean() = "1.0"; d.Covariance("1.0"); - REQUIRE(d.Probability("0.0") == Approx(0.24197072451914337).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.3989422804014327).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.053990966513188056).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.24197072451914337, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.3989422804014327, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.053990966513188056, 1e-5); // Mean: 1.0, Covariance: 2.0 d.Covariance("2.0"); - REQUIRE(d.Probability("0.0") == Approx(0.21969564473386122).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.28209479177387814).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.10377687435514872).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.21969564473386122, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.28209479177387814, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.10377687435514872, 1e-5); } /** * Test DiagonalGaussianDistribution::Probability() in the multivariate case. * The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianMultivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) { arma::vec mean("0 0"); arma::vec cov("2 2"); @@ -1381,28 +1358,27 @@ TEST_CASE("DiagonalGaussianMultivariateProbabilityTest", "[DistributionTest]") DiagonalGaussianDistribution d(mean, cov); - REQUIRE(d.Probability(obs) == Approx(0.079577471545947673).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.079577471545947673, 1e-5); obs = "1 1"; - REQUIRE(d.Probability(obs) == Approx(0.048266176315026957).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.048266176315026957, 1e-5); d.Mean() = "1 3"; - REQUIRE(d.Probability(obs) == Approx(0.029274915762159581).epsilon(1e-7)); - REQUIRE(d.Probability(-obs) == Approx(0.00053618878559782773).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.029274915762159581, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability(-obs), 0.00053618878559782773, 1e-5); // Higher dimensional case. d.Mean() = "1 3 6 2 7"; d.Covariance("3 1 5 3 2"); obs = "2 5 7 3 8"; - REQUIRE(d.Probability(obs) == Approx(7.2790083003378082e-05).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 7.2790083003378082e-05, 1e-5); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianMultipointMultivariateProbabilityTest", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) { arma::vec mean = "2 5 3 7 2"; arma::vec cov("9 2 1 4 8"); @@ -1415,20 +1391,20 @@ TEST_CASE("DiagonalGaussianMultipointMultivariateProbabilityTest", DiagonalGaussianDistribution d(mean, cov); d.LogProbability(points, phis); - REQUIRE(phis.n_elem == 6); + BOOST_REQUIRE_EQUAL(phis.n_elem, 6); - REQUIRE(phis(0) == Approx(-12.453302051926864).epsilon(1e-7)); - REQUIRE(phis(1) == Approx(-10.147746496371308).epsilon(1e-7)); - REQUIRE(phis(2) == Approx(-13.210246496371308).epsilon(1e-7)); - REQUIRE(phis(3) == Approx(-19.724135385260197).epsilon(1e-7)); - REQUIRE(phis(4) == Approx(-21.585246496371308).epsilon(1e-7)); - REQUIRE(phis(5) == Approx(-13.647746496371308).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(phis(0), -12.453302051926864, 1e-5); + BOOST_REQUIRE_CLOSE(phis(1), -10.147746496371308, 1e-5); + BOOST_REQUIRE_CLOSE(phis(2), -13.210246496371308, 1e-5); + BOOST_REQUIRE_CLOSE(phis(3), -19.724135385260197, 1e-5); + BOOST_REQUIRE_CLOSE(phis(4), -21.585246496371308, 1e-5); + BOOST_REQUIRE_CLOSE(phis(5), -13.647746496371308, 1e-5); } /** * Make sure random observations follow the probability distribution correctly. */ -TEST_CASE("DiagonalGaussianDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) { arma::vec mean("2.5 1.25"); arma::vec cov("0.50 0.25"); @@ -1445,17 +1421,17 @@ TEST_CASE("DiagonalGaussianDistributionRandomTest", "[DistributionTest]") arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - REQUIRE(obsMean(0) == Approx(mean(0)).epsilon(0.1)); - REQUIRE(obsMean(1) == Approx(mean(1)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsMean(0), mean(0), 10.0); + BOOST_REQUIRE_CLOSE(obsMean(1), mean(1), 10.0); - REQUIRE(obsCov(0, 0) == Approx(cov(0)).epsilon(0.1)); - REQUIRE(obsCov(1, 1) == Approx(cov(1)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0), 10); + BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1), 10); } /** * Make sure that we can properly estimate from given observations. */ -TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1478,8 +1454,8 @@ TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") // Check that the estimated parameters are right. for (size_t i = 0; i < 4; ++i) { - REQUIRE(d.Mean()(i) - actualMean(i) == Approx(0.0).margin(1e-5)); - REQUIRE(d.Covariance()(i) - actualCov(i, i) == Approx(0.0).margin(1e-5)); + BOOST_REQUIRE_SMALL(d.Mean()(i) - actualMean(i), 1e-5); + BOOST_REQUIRE_SMALL(d.Covariance()(i) - actualCov(i, i), 1e-5); } } @@ -1487,7 +1463,7 @@ TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") * Make sure the unbiased estimator of the weighted sample works correctly. * The values were calculated using 'cov.wt' in R. */ -TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) { // Generate the observations. arma::mat observations("3 5 2 7;" @@ -1502,15 +1478,15 @@ TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") // Estimate the parameters. d.Train(observations, probs); - REQUIRE(d.Mean()(0) == Approx(4.5).epsilon(1e-7)); - REQUIRE(d.Mean()(1) == Approx(4.4).epsilon(1e-7)); - REQUIRE(d.Mean()(2) == Approx(3.5).epsilon(1e-7)); - REQUIRE(d.Mean()(3) == Approx(6.8).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Mean()(0), 4.5, 1e-5); + BOOST_REQUIRE_CLOSE(d.Mean()(1), 4.4, 1e-5); + BOOST_REQUIRE_CLOSE(d.Mean()(2), 3.5, 1e-5); + BOOST_REQUIRE_CLOSE(d.Mean()(3), 6.8, 1e-5); - REQUIRE(d.Covariance()(0) == Approx(3.78571428571428603).epsilon(1e-7)); - REQUIRE(d.Covariance()(1) == Approx(6.34285714285714253).epsilon(1e-7)); - REQUIRE(d.Covariance()(2) == Approx(6.64285714285714235).epsilon(1e-7)); - REQUIRE(d.Covariance()(3) == Approx(2.22857142857142865).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Covariance()(0), 3.78571428571428603, 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(1), 6.34285714285714253, 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(2), 6.64285714285714235, 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(3), 2.22857142857142865, 1e-5); } /** @@ -1518,7 +1494,7 @@ TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") * the weighted mean and covariance reduce to the unweighted sample mean and * covariance. */ -TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1540,7 +1516,9 @@ TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest] // Check if these are equal. for (size_t i = 0; i < 4; ++i) { - REQUIRE(d1.Mean()(i) == Approx(d2.Mean()(i)).epsilon(1e-7)); - REQUIRE(d1.Covariance()(i) == Approx(d2.Covariance()(i)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d1.Mean()(i), d2.Mean()(i), 1e-5); + BOOST_REQUIRE_CLOSE(d1.Covariance()(i), d2.Covariance()(i), 1e-5); } } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index bcffa4c8a8..ba45afd29d 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -148,10 +148,10 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTest", "[FeedForwardNetworkTest]") model1->Add >(8, 3); model1->Add >(); - // Check whether copy constructor is working or not. + // Check whether copy cpnstructor is working or not. CheckCopyFunction<>(model, trainData, trainLabels, 1); - // Check whether move constructor is working or not. + // Check whether move cpnstructor is working or not. CheckMoveFunction<>(model1, trainData, trainLabels, 1); } @@ -489,7 +489,7 @@ TEST_CASE("FFNMiscTest", "[FeedForwardNetworkTest]") auto copiedModel(model); copiedModel = model; auto movedModel(std::move(model)); - auto moveOperator = std::move(copiedModel); + movedModel = std::move(copiedModel); } /** @@ -764,7 +764,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model.Add >(8, 3); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.2); + TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.1); arma::mat dataset; dataset.load("mnist_first250_training_4s_and_9s.arm"); @@ -796,5 +796,5 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model1.Add >(140, 2); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.2); + TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.1); } diff --git a/src/mlpack/tests/main_tests/mean_shift_test.cpp b/src/mlpack/tests/main_tests/mean_shift_test.cpp index 5da1c28b95..eea3ceb3c7 100644 --- a/src/mlpack/tests/main_tests/mean_shift_test.cpp +++ b/src/mlpack/tests/main_tests/mean_shift_test.cpp @@ -12,16 +12,15 @@ #include #define BINDING_TYPE BINDING_TYPE_TEST - -#include static const std::string testName = "MeanShift"; +#include #include #include - #include "test_helper.hpp" -#include "../test_catch_tools.hpp" -#include "../catch.hpp" + +#include +#include "../test_tools.hpp" using namespace mlpack; @@ -49,13 +48,13 @@ static void ResetSettings() IO::RestoreSettings(testName); } +BOOST_FIXTURE_TEST_SUITE(MeanShiftMainTest, MeanShiftTestFixture); + /** * Ensure that the output has 1 extra row for the labels and * check the number of points for output remain the same. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftOutputDimensionTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftOutputDimensionTest) { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -66,18 +65,16 @@ TEST_CASE_METHOD( mlpackMain(); // Now check that the output has 1 extra row for labels. - REQUIRE(IO::GetParam("output").n_rows == 3 + 1); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 3 + 1); // Check number of output points are the same. - REQUIRE(IO::GetParam("output").n_cols == 100); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); } /** * Ensure that if we ask for labels_only, output has 1 row and * same number of columns for each point's label. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftLabelOnlyOutputDimensionTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -89,9 +86,9 @@ TEST_CASE_METHOD( mlpackMain(); // Check that there is only 1 row containing all the labels. - REQUIRE(IO::GetParam("output").n_rows == 1); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 1); // Check number of output points are the same. - REQUIRE(IO::GetParam("output").n_cols == 100); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); } /** @@ -99,13 +96,11 @@ TEST_CASE_METHOD( * and check the number of points remain the same if the --in_place * flag is set. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftInPlaceTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftInPlaceTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Get initial number of rows and columns in file. int numRows = x.n_rows; @@ -118,22 +113,20 @@ TEST_CASE_METHOD( mlpackMain(); // Now check that the output has 1 extra row for labels. - REQUIRE(IO::GetParam("output").n_rows == numRows + 1); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, numRows + 1); // Check number of output points are the same. - REQUIRE(IO::GetParam("output").n_cols == numCols); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, numCols); } /** * Ensure that force_convergence is used by testing that the * force_convergence flag makes a difference in the program. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftForceConvergenceTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftForceConvergenceTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -157,20 +150,18 @@ TEST_CASE_METHOD( const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - REQUIRE(numCentroids1 != numCentroids2); + BOOST_REQUIRE_NE(numCentroids1, numCentroids2); } /** * Ensure that radius is used by testing that the radius * makes a difference in the program. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftRadiusTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftRadiusTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -192,20 +183,18 @@ TEST_CASE_METHOD( const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - REQUIRE(numCentroids1 != numCentroids2); + BOOST_REQUIRE_NE(numCentroids1, numCentroids2); } /** * Ensure that max_iterations is used by testing that the * max_iteration makes a difference in the program. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftMaxIterationsTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftMaxIterationsTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -227,15 +216,13 @@ TEST_CASE_METHOD( const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - REQUIRE(numCentroids1 != numCentroids2); + BOOST_REQUIRE_NE(numCentroids1, numCentroids2); } /** * Ensure that we can't specify an invalid max number of iterations. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftInvalidMaxIterationsTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftInvalidMaxIterationsTest) { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -246,6 +233,8 @@ TEST_CASE_METHOD( SetInputParam("max_iterations", (int) -1); Log::Fatal.ignoreInput = true; - REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp index 9f6c229639..818602f632 100644 --- a/src/mlpack/tests/mean_shift_test.cpp +++ b/src/mlpack/tests/mean_shift_test.cpp @@ -12,13 +12,15 @@ #include -#include "test_catch_tools.hpp" -#include "catch.hpp" +#include +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::meanshift; using namespace mlpack::distribution; +BOOST_AUTO_TEST_SUITE(MeanShiftTest); + // Generate dataset; written transposed because it's easier to read. arma::mat meanShiftData(" 0.0 0.0;" // Class 1. " 0.3 0.4;" @@ -55,7 +57,7 @@ arma::mat meanShiftData(" 0.0 0.0;" // Class 1. /** * 30-point 3-class test case for Mean Shift. */ -TEST_CASE("MeanShiftSimpleTest", "[MeanShiftTest]") +BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) { MeanShift<> meanShift; @@ -68,29 +70,29 @@ TEST_CASE("MeanShiftSimpleTest", "[MeanShiftTest]") size_t firstClass = assignments(0); for (size_t i = 1; i < 13; ++i) - REQUIRE(assignments(i) == firstClass); + BOOST_REQUIRE_EQUAL(assignments(i), firstClass); size_t secondClass = assignments(13); // To ensure that class 1 != class 2. - REQUIRE(firstClass != secondClass); + BOOST_REQUIRE_NE(firstClass, secondClass); for (size_t i = 13; i < 20; ++i) - REQUIRE(assignments(i) == secondClass); + BOOST_REQUIRE_EQUAL(assignments(i), secondClass); size_t thirdClass = assignments(20); // To ensure that this is the third class which we haven't seen yet. - REQUIRE(firstClass != thirdClass); - REQUIRE(secondClass != thirdClass); + BOOST_REQUIRE_NE(firstClass, thirdClass); + BOOST_REQUIRE_NE(secondClass, thirdClass); for (size_t i = 20; i < 30; ++i) - REQUIRE(assignments(i) == thirdClass); + BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); } // Generate samples from four Gaussians, and make sure mean shift nearly // recovers those four centers. -TEST_CASE("GaussianClustering", "[MeanShiftTest]") +BOOST_AUTO_TEST_CASE(GaussianClustering) { GaussianDistribution g1("0.0 0.0 0.0", arma::eye(3, 3)); GaussianDistribution g2("5.0 5.0 5.0", 2 * arma::eye(3, 3)); @@ -160,5 +162,7 @@ TEST_CASE("GaussianClustering", "[MeanShiftTest]") break; } - REQUIRE(success == true); + BOOST_REQUIRE_EQUAL(success, true); } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/random_forest_test.cpp b/src/mlpack/tests/random_forest_test.cpp index 3db62942c3..edc6bb2b60 100644 --- a/src/mlpack/tests/random_forest_test.cpp +++ b/src/mlpack/tests/random_forest_test.cpp @@ -13,9 +13,8 @@ #include #include -#include "serialization_catch.hpp" -#include "test_catch_tools.hpp" #include "catch.hpp" +#include "serialization.hpp" #include "mock_categorical_data.hpp" using namespace mlpack; From 4fb41ec70268000dc924130abe4afe502ef402f7 Mon Sep 17 00:00:00 2001 From: Anush V Kini Date: Tue, 6 Oct 2020 09:09:12 +0530 Subject: [PATCH 30/45] Style fixes --- src/mlpack/tests/metric_test.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mlpack/tests/metric_test.cpp b/src/mlpack/tests/metric_test.cpp index 0ffc36d5ba..db3f164650 100644 --- a/src/mlpack/tests/metric_test.cpp +++ b/src/mlpack/tests/metric_test.cpp @@ -39,10 +39,10 @@ TEST_CASE("L1MetricTest", "[MetricTest]") ManhattanDistance lMetric; REQUIRE((double) arma::accu(arma::abs(a1 - b1)) == - Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); + Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); REQUIRE((double) arma::accu(arma::abs(a2 - b2)) == - Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); + Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); } /** @@ -65,10 +65,10 @@ TEST_CASE("L2MetricTest", "[MetricTest]") EuclideanDistance lMetric; REQUIRE((double) sqrt(arma::accu(arma::square(a1 - b1))) == - Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); + Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); REQUIRE((double) sqrt(arma::accu(arma::square(a2 - b2))) == - Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); + Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); } /** @@ -91,10 +91,10 @@ TEST_CASE("LINFMetricTest", "[MetricTest]") ChebyshevDistance lMetric; REQUIRE((double) arma::as_scalar(arma::max(arma::abs(a1 - b1))) == - Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); + Approx(lMetric.Evaluate(a1, b1)).epsilon(1e-7)); REQUIRE((double) arma::as_scalar(arma::max(arma::abs(a2 - b2))) == - Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); + Approx(lMetric.Evaluate(a2, b2)).epsilon(1e-7)); } /** @@ -114,13 +114,13 @@ TEST_CASE("IoUMetricTest", "[MetricTest]") bbox2 << 54 << 66 << 198 << 114; // Value calculated using Python interpreter. REQUIRE(IoU::Evaluate(bbox1, bbox2) == - Approx(0.7980093).epsilon(1e-6)); + Approx(0.7980093).epsilon(1e-6)); bbox1 << 31 << 69 << 201 << 125; bbox2 << 18 << 63 << 235 << 135; // Value calculated using Python interpreter. REQUIRE(IoU::Evaluate(bbox1, bbox2) == - Approx(0.612479577).epsilon(1e-6)); + Approx(0.612479577).epsilon(1e-6)); // Use hieght - width representation of bounding boxes. // Bounding boxes represent {x0, y0, h, w}. @@ -341,7 +341,7 @@ TEST_CASE("BLEUScoreTest", "[MetricTest]") for (size_t i = 0; i < bleu.Precisions().size(); ++i) { REQUIRE(bleu.Precisions()[i] == - Approx((double)expectedPrecision[i]).epsilon(1e-4)); + Approx((double)expectedPrecision[i]).epsilon(1e-4)); } //! We will use smoothing function here by setting smooth to true. @@ -356,6 +356,6 @@ TEST_CASE("BLEUScoreTest", "[MetricTest]") for (size_t i = 0; i < bleu.Precisions().size(); ++i) { REQUIRE(bleu.Precisions()[i] == - Approx(expectedPrecision[i]).epsilon(1e-4)); + Approx(expectedPrecision[i]).epsilon(1e-4)); } } From 6e0484dcace31ce41e60497128a0bf26ad07b0b9 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 10:49:43 +0530 Subject: [PATCH 31/45] static code fix try --- src/mlpack/tests/range_search_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index af01a26ccc..f8c8d23151 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1287,7 +1287,7 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j != 2; ++j) + for (size_t j = 0; j < 3; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); @@ -1373,7 +1373,7 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j != 2; ++j) + for (size_t j = 0; j < 3; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); From b4c1a40645507b744dd2c584bd0937a88d0bb451 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 14:35:08 +0530 Subject: [PATCH 32/45] indentation fixed --- .../tests/main_tests/range_search_test.cpp | 12 ++-- src/mlpack/tests/range_search_test.cpp | 60 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/mlpack/tests/main_tests/range_search_test.cpp b/src/mlpack/tests/main_tests/range_search_test.cpp index b32478da23..3d9fd08bb5 100644 --- a/src/mlpack/tests/main_tests/range_search_test.cpp +++ b/src/mlpack/tests/main_tests/range_search_test.cpp @@ -299,7 +299,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", CheckMatrices(distances, distancetemp); REQUIRE(ModelToString(outputModel) == - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); remove(neighborsFile.c_str()); remove(distanceFile.c_str()); @@ -357,7 +357,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel1) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); if (i != leafSizes.size() - 1) delete IO::GetParam("output_model"); @@ -431,7 +431,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel1) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); if (i != trees.size() - 1) delete IO::GetParam("output_model"); @@ -480,7 +480,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", mlpackMain(); REQUIRE(ModelToString(outputModel) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -535,7 +535,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -589,7 +589,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "SingleModeTest", CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); delete outputModel; diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index f8c8d23151..ccf839a018 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -491,8 +491,8 @@ TEST_CASE("DualTreeVsNaive1", "[RangeSearchTest]") for (size_t j = 0; j < sortedTree[i].size(); ++j) { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon - (1e-5)); + REQUIRE(sortedTree[i][j].first == + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -540,8 +540,8 @@ TEST_CASE("DualTreeVsNaive2", "[RangeSearchTest]") for (size_t j = 0; j < sortedTree[i].size(); ++j) { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon - (1e-5)); + REQUIRE(sortedTree[i][j].first == + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -589,8 +589,8 @@ TEST_CASE("SingleTreeVsNaive", "[RangeSearchTest]") for (size_t j = 0; j < sortedTree[i].size(); ++j) { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon - (1e-5)); + REQUIRE(sortedTree[i][j].first == + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -662,8 +662,8 @@ TEST_CASE("CoverTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -740,8 +740,8 @@ TEST_CASE("CoverTreeTwoDatasetsTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -814,8 +814,8 @@ TEST_CASE("CoverTreeSingleTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -888,8 +888,8 @@ TEST_CASE("SingleBallTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -962,8 +962,8 @@ TEST_CASE("DualBallTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -1041,8 +1041,8 @@ TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(ballSorted[i][j].first).epsilon (1e-7)); } } } @@ -1104,8 +1104,8 @@ TEST_CASE("RangeSearchTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1146,8 +1146,8 @@ TEST_CASE("TrainTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1201,8 +1201,8 @@ TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1244,8 +1244,8 @@ TEST_CASE("MoveTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1329,8 +1329,8 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). - epsilon(1e-7)); + REQUIRE(sorted[k][l].first == + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } } @@ -1412,8 +1412,8 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). - epsilon(1e-7)); + REQUIRE(sorted[k][l].first == + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } } From ea39cd3c8c4e7aa70dd9cb3d902a3bdf87737472 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Tue, 6 Oct 2020 21:08:37 +0530 Subject: [PATCH 33/45] Fix R documentation. --- src/mlpack/bindings/R/print_R.cpp | 3 ++- .../bindings/R/print_doc_functions_impl.hpp | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/mlpack/bindings/R/print_R.cpp b/src/mlpack/bindings/R/print_R.cpp index bf047c2769..5b089cbd28 100644 --- a/src/mlpack/bindings/R/print_R.cpp +++ b/src/mlpack/bindings/R/print_R.cpp @@ -92,7 +92,8 @@ void PrintR(const util::BindingDetails& doc, cout << "#'" << endl; // Next, print information on the output options. - cout << "#' @return A list with several components:" << endl; + if (outputOptions.size() > 0) + cout << "#' @return A list with several components:" << endl; for (size_t i = 0; i < outputOptions.size(); ++i) { diff --git a/src/mlpack/bindings/R/print_doc_functions_impl.hpp b/src/mlpack/bindings/R/print_doc_functions_impl.hpp index 2273f83197..dcdfd5d15d 100644 --- a/src/mlpack/bindings/R/print_doc_functions_impl.hpp +++ b/src/mlpack/bindings/R/print_doc_functions_impl.hpp @@ -61,10 +61,10 @@ inline std::string PrintValue(const T& value, bool quotes) { std::ostringstream oss; if (quotes) - oss << "\""; + oss << "`"; oss << value; if (quotes) - oss << "\""; + oss << "`"; return oss.str(); } @@ -76,7 +76,7 @@ inline std::string PrintValue(const std::vector& value, bool quotes) { std::ostringstream oss; if (quotes) - oss << "\""; + oss << "`"; oss << "c("; if (value.size() > 0) { @@ -86,7 +86,7 @@ inline std::string PrintValue(const std::vector& value, bool quotes) } oss << ")"; if (quotes) - oss << "\""; + oss << "`"; return oss.str(); } @@ -229,7 +229,9 @@ std::string ProgramCall(const bool markdown, // Find out if we have any output options first. std::ostringstream ossOutput; - oss << "output <- "; + ossOutput << PrintOutputOptions(markdown, args...); + if (ossOutput.str() != "") + oss << "output <- "; oss << programName << "("; // Now process each input option. @@ -330,7 +332,7 @@ inline std::string ProgramCall(const std::string& programName) */ inline std::string PrintModel(const std::string& modelName) { - return "\"" + modelName + "\""; + return "`" + modelName + "`"; } /** @@ -339,7 +341,7 @@ inline std::string PrintModel(const std::string& modelName) */ inline std::string PrintDataset(const std::string& datasetName) { - return "\"" + datasetName + "\""; + return "`" + datasetName + "`"; } /** @@ -357,7 +359,7 @@ inline std::string ProgramCallClose() inline std::string ParamString(const std::string& paramName) { // For a R binding we don't need to know the type. - return "\"" + paramName + "\""; + return "`" + paramName + "`"; } /** From f9052df41fd9bfeb509741c683c82f9623a342d3 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Wed, 7 Oct 2020 07:34:23 +0530 Subject: [PATCH 34/45] Renaming job names. --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5f99d96f1..e40ceb91ca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ on: - master release: types: [published, created, edited] -name: R CMD check mlpack +name: mlpack.mlpack jobs: cancel: @@ -26,7 +26,7 @@ jobs: access_token: ${{ secrets.GITHUB_TOKEN }} jobR: - name: Build mlpack_r_tarball + name: mlpack R tarball if: ${{ github.repository == 'mlpack/mlpack' }} runs-on: ubuntu-20.04 @@ -98,16 +98,16 @@ jobs: needs: jobR runs-on: ${{ matrix.config.os }} - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + name: ${{ matrix.config.name }} if: ${{ github.repository == 'mlpack/mlpack' }} strategy: fail-fast: false matrix: config: - - {os: windows-latest, r: '4.0'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: windows-latest, r: '4.0', name: 'Windows R'} + - {os: macOS-latest, r: 'release', name: 'macOS R'} + - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", name: 'Linux R'} env: From 4757d67a9bb7cd30b3d6ee2d64d916a999f44957 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Wed, 7 Oct 2020 10:57:34 +0530 Subject: [PATCH 35/45] replace r to r-binding --- .../bindings/markdown/default_param.hpp | 2 +- .../bindings/markdown/get_binding_name.cpp | 2 +- .../bindings/markdown/get_printable_type.hpp | 2 +- .../markdown/print_doc_functions_impl.hpp | 26 +++++++++---------- .../bindings/markdown/print_type_doc.hpp | 2 +- src/mlpack/methods/adaboost/CMakeLists.txt | 2 +- src/mlpack/methods/approx_kfn/CMakeLists.txt | 2 +- .../bayesian_linear_regression/CMakeLists.txt | 2 +- src/mlpack/methods/cf/CMakeLists.txt | 2 +- src/mlpack/methods/dbscan/CMakeLists.txt | 2 +- .../methods/decision_tree/CMakeLists.txt | 2 +- src/mlpack/methods/det/CMakeLists.txt | 2 +- src/mlpack/methods/emst/CMakeLists.txt | 2 +- src/mlpack/methods/fastmks/CMakeLists.txt | 2 +- src/mlpack/methods/gmm/CMakeLists.txt | 6 ++--- src/mlpack/methods/hmm/CMakeLists.txt | 8 +++--- .../methods/hoeffding_trees/CMakeLists.txt | 2 +- src/mlpack/methods/kde/CMakeLists.txt | 2 +- src/mlpack/methods/kernel_pca/CMakeLists.txt | 2 +- src/mlpack/methods/kmeans/CMakeLists.txt | 2 +- src/mlpack/methods/lars/CMakeLists.txt | 2 +- .../methods/linear_regression/CMakeLists.txt | 2 +- src/mlpack/methods/linear_svm/CMakeLists.txt | 2 +- src/mlpack/methods/lmnn/CMakeLists.txt | 2 +- .../local_coordinate_coding/CMakeLists.txt | 2 +- .../logistic_regression/CMakeLists.txt | 2 +- src/mlpack/methods/lsh/CMakeLists.txt | 2 +- src/mlpack/methods/mean_shift/CMakeLists.txt | 2 +- src/mlpack/methods/naive_bayes/CMakeLists.txt | 2 +- src/mlpack/methods/nca/CMakeLists.txt | 2 +- .../methods/neighbor_search/CMakeLists.txt | 4 +-- src/mlpack/methods/nmf/CMakeLists.txt | 2 +- src/mlpack/methods/pca/CMakeLists.txt | 2 +- src/mlpack/methods/perceptron/CMakeLists.txt | 2 +- src/mlpack/methods/preprocess/CMakeLists.txt | 12 ++++----- src/mlpack/methods/radical/CMakeLists.txt | 2 +- .../methods/random_forest/CMakeLists.txt | 2 +- src/mlpack/methods/rann/CMakeLists.txt | 2 +- .../methods/softmax_regression/CMakeLists.txt | 2 +- .../methods/sparse_coding/CMakeLists.txt | 2 +- 40 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/mlpack/bindings/markdown/default_param.hpp b/src/mlpack/bindings/markdown/default_param.hpp index cf4a175a29..973758255b 100644 --- a/src/mlpack/bindings/markdown/default_param.hpp +++ b/src/mlpack/bindings/markdown/default_param.hpp @@ -55,7 +55,7 @@ void DefaultParam(util::ParamData& data, *((std::string*) output) = go::DefaultParamImpl::type>(data); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { *((std::string*) output) = r::DefaultParamImpl::type>(data); diff --git a/src/mlpack/bindings/markdown/get_binding_name.cpp b/src/mlpack/bindings/markdown/get_binding_name.cpp index b3cf4e51e8..5524664ed7 100644 --- a/src/mlpack/bindings/markdown/get_binding_name.cpp +++ b/src/mlpack/bindings/markdown/get_binding_name.cpp @@ -42,7 +42,7 @@ std::string GetBindingName(const std::string& language, // For Go bindings, the name is unchanged. return name; } - else if (language == "r") + else if (language == "r-binding") { // For R bindings, the name is unchanged. return name; diff --git a/src/mlpack/bindings/markdown/get_printable_type.hpp b/src/mlpack/bindings/markdown/get_printable_type.hpp index 2848947b54..afe9e2cb9e 100644 --- a/src/mlpack/bindings/markdown/get_printable_type.hpp +++ b/src/mlpack/bindings/markdown/get_printable_type.hpp @@ -54,7 +54,7 @@ void GetPrintableType(util::ParamData& data, *((std::string*) output) = go::GetPrintableType::type>(data); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { *((std::string*) output) = r::GetPrintableType::type>(data); diff --git a/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp b/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp index 06ebaab813..6fec1b918b 100644 --- a/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp +++ b/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp @@ -50,7 +50,7 @@ inline std::string GetBindingName(const std::string& bindingName) { return go::GetBindingName(bindingName); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { return r::GetBindingName(bindingName); } @@ -82,7 +82,7 @@ inline std::string PrintLanguage(const std::string& language) { return "Go"; } - else if (language == "r") + else if (language == "r-binding") { return "R"; } @@ -114,7 +114,7 @@ inline std::string PrintImport(const std::string& bindingName) { return go::PrintImport(); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { return r::PrintImport(); } @@ -146,7 +146,7 @@ inline std::string PrintInputOptionInfo() { return go::PrintInputOptionInfo(); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { return r::PrintInputOptionInfo(); } @@ -178,7 +178,7 @@ inline std::string PrintOutputOptionInfo() { return go::PrintOutputOptionInfo(); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { return r::PrintOutputOptionInfo(); } @@ -411,7 +411,7 @@ inline std::string PrintValue(const T& value, bool quotes) { result = go::PrintValue(value, quotes); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { result = r::PrintValue(value, quotes); } @@ -458,7 +458,7 @@ inline std::string PrintDefault(const std::string& paramName) { oss << go::PrintDefault(paramName); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { oss << r::PrintDefault(paramName); } @@ -494,7 +494,7 @@ inline std::string PrintDataset(const std::string& dataset) { result = go::PrintDataset(dataset); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { result = r::PrintDataset(dataset); } @@ -529,7 +529,7 @@ inline std::string PrintModel(const std::string& model) { result = go::PrintModel(model); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { result = r::PrintModel(model); } @@ -571,7 +571,7 @@ std::string ProgramCall(const std::string& programName, Args... args) s += "```go\n"; s += go::ProgramCall(programName, args...); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { s += "```R\n"; s += r::ProgramCall(true, programName, args...); @@ -626,7 +626,7 @@ inline std::string ProgramCall(const std::string& programName) s += import + "\n"; s += go::ProgramCall(programName); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { s += "R\n"; std::string import = PrintImport(programName); @@ -672,7 +672,7 @@ inline std::string ParamString(const std::string& paramName) { s = go::ParamString(paramName); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { s = r::ParamString(paramName); } @@ -723,7 +723,7 @@ inline bool IgnoreCheck(const T& t) { return go::IgnoreCheck(t); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { return r::IgnoreCheck(t); } diff --git a/src/mlpack/bindings/markdown/print_type_doc.hpp b/src/mlpack/bindings/markdown/print_type_doc.hpp index 34a1906fa0..30a6b3298e 100644 --- a/src/mlpack/bindings/markdown/print_type_doc.hpp +++ b/src/mlpack/bindings/markdown/print_type_doc.hpp @@ -48,7 +48,7 @@ std::string PrintTypeDoc(util::ParamData& data) { return go::PrintTypeDoc::type>(data); } - else if (BindingInfo::Language() == "r") + else if (BindingInfo::Language() == "r-binding") { return r::PrintTypeDoc::type>(data); } diff --git a/src/mlpack/methods/adaboost/CMakeLists.txt b/src/mlpack/methods/adaboost/CMakeLists.txt index 102c41c488..79910a3bb7 100644 --- a/src/mlpack/methods/adaboost/CMakeLists.txt +++ b/src/mlpack/methods/adaboost/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(adaboost) add_julia_binding(adaboost) add_go_binding(adaboost) add_r_binding(adaboost) -add_markdown_docs(adaboost "cli;python;julia;go;r" "classification") +add_markdown_docs(adaboost "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/approx_kfn/CMakeLists.txt b/src/mlpack/methods/approx_kfn/CMakeLists.txt index f769425127..b005f22e0d 100644 --- a/src/mlpack/methods/approx_kfn/CMakeLists.txt +++ b/src/mlpack/methods/approx_kfn/CMakeLists.txt @@ -24,4 +24,4 @@ add_python_binding(approx_kfn) add_julia_binding(approx_kfn) add_go_binding(approx_kfn) add_r_binding(approx_kfn) -add_markdown_docs(approx_kfn "cli;python;julia;go;r" "geometry") +add_markdown_docs(approx_kfn "cli;python;julia;go;r-binding" "geometry") diff --git a/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt b/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt index 7ded67c3fa..172e02e75f 100644 --- a/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt +++ b/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(bayesian_linear_regression) add_julia_binding(bayesian_linear_regression) add_go_binding(bayesian_linear_regression) add_r_binding(bayesian_linear_regression) -add_markdown_docs(bayesian_linear_regression "cli;python;julia;go;r" "regression") +add_markdown_docs(bayesian_linear_regression "cli;python;julia;go;r-binding" "regression") diff --git a/src/mlpack/methods/cf/CMakeLists.txt b/src/mlpack/methods/cf/CMakeLists.txt index a7c552ae28..51722b8970 100644 --- a/src/mlpack/methods/cf/CMakeLists.txt +++ b/src/mlpack/methods/cf/CMakeLists.txt @@ -28,4 +28,4 @@ add_python_binding(cf) add_julia_binding(cf) add_go_binding(cf) add_r_binding(cf) -add_markdown_docs(cf "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(cf "cli;python;julia;go;r-binding" "misc. / other") diff --git a/src/mlpack/methods/dbscan/CMakeLists.txt b/src/mlpack/methods/dbscan/CMakeLists.txt index 7c0a883504..6be902c1fa 100644 --- a/src/mlpack/methods/dbscan/CMakeLists.txt +++ b/src/mlpack/methods/dbscan/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(dbscan) add_julia_binding(dbscan) add_go_binding(dbscan) add_r_binding(dbscan) -add_markdown_docs(dbscan "cli;python;julia;go;r" "clustering") +add_markdown_docs(dbscan "cli;python;julia;go;r-binding" "clustering") diff --git a/src/mlpack/methods/decision_tree/CMakeLists.txt b/src/mlpack/methods/decision_tree/CMakeLists.txt index 68f5a2ef41..6e084a6bfe 100644 --- a/src/mlpack/methods/decision_tree/CMakeLists.txt +++ b/src/mlpack/methods/decision_tree/CMakeLists.txt @@ -28,4 +28,4 @@ add_python_binding(decision_tree) add_julia_binding(decision_tree) add_go_binding(decision_tree) add_r_binding(decision_tree) -add_markdown_docs(decision_tree "cli;python;julia;go;r" "classification") +add_markdown_docs(decision_tree "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/det/CMakeLists.txt b/src/mlpack/methods/det/CMakeLists.txt index 2d35bd9fb8..79f7e108c2 100644 --- a/src/mlpack/methods/det/CMakeLists.txt +++ b/src/mlpack/methods/det/CMakeLists.txt @@ -24,4 +24,4 @@ add_python_binding(det) add_julia_binding(det) add_go_binding(det) add_r_binding(det) -add_markdown_docs(det "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(det "cli;python;julia;go;r-binding" "misc. / other") diff --git a/src/mlpack/methods/emst/CMakeLists.txt b/src/mlpack/methods/emst/CMakeLists.txt index 4d7fd2cd4c..9f91988a9c 100644 --- a/src/mlpack/methods/emst/CMakeLists.txt +++ b/src/mlpack/methods/emst/CMakeLists.txt @@ -26,4 +26,4 @@ add_python_binding(emst) add_julia_binding(emst) add_go_binding(emst) add_r_binding(emst) -add_markdown_docs(emst "cli;python;julia;go;r" "geometry") +add_markdown_docs(emst "cli;python;julia;go;r-binding" "geometry") diff --git a/src/mlpack/methods/fastmks/CMakeLists.txt b/src/mlpack/methods/fastmks/CMakeLists.txt index 78a11b535c..280b9708bd 100644 --- a/src/mlpack/methods/fastmks/CMakeLists.txt +++ b/src/mlpack/methods/fastmks/CMakeLists.txt @@ -25,4 +25,4 @@ add_python_binding(fastmks) add_julia_binding(fastmks) add_go_binding(fastmks) add_r_binding(fastmks) -add_markdown_docs(fastmks "cli;python;julia;go;r" "geometry") +add_markdown_docs(fastmks "cli;python;julia;go;r-binding" "geometry") diff --git a/src/mlpack/methods/gmm/CMakeLists.txt b/src/mlpack/methods/gmm/CMakeLists.txt index 52d98b7c1e..e85002c541 100644 --- a/src/mlpack/methods/gmm/CMakeLists.txt +++ b/src/mlpack/methods/gmm/CMakeLists.txt @@ -29,18 +29,18 @@ add_python_binding(gmm_train) add_julia_binding(gmm_train) add_go_binding(gmm_train) add_r_binding(gmm_train) -add_markdown_docs(gmm_train "cli;python;julia;go;r" "clustering") +add_markdown_docs(gmm_train "cli;python;julia;go;r-binding" "clustering") add_cli_executable(gmm_generate) add_python_binding(gmm_generate) add_julia_binding(gmm_generate) add_go_binding(gmm_generate) add_r_binding(gmm_generate) -add_markdown_docs(gmm_generate "cli;python;julia;go;r" "clustering") +add_markdown_docs(gmm_generate "cli;python;julia;go;r-binding" "clustering") add_cli_executable(gmm_probability) add_python_binding(gmm_probability) add_julia_binding(gmm_probability) add_go_binding(gmm_probability) add_r_binding(gmm_probability) -add_markdown_docs(gmm_probability "cli;python;julia;go;r" "clustering") +add_markdown_docs(gmm_probability "cli;python;julia;go;r-binding" "clustering") diff --git a/src/mlpack/methods/hmm/CMakeLists.txt b/src/mlpack/methods/hmm/CMakeLists.txt index bfe2cedc58..1c2992e59d 100644 --- a/src/mlpack/methods/hmm/CMakeLists.txt +++ b/src/mlpack/methods/hmm/CMakeLists.txt @@ -24,25 +24,25 @@ add_python_binding(hmm_train) add_julia_binding(hmm_train) add_go_binding(hmm_train) add_r_binding(hmm_train) -add_markdown_docs(hmm_train "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(hmm_train "cli;python;julia;go;r-binding" "misc. / other") add_cli_executable(hmm_loglik) add_python_binding(hmm_loglik) add_julia_binding(hmm_loglik) add_go_binding(hmm_loglik) add_r_binding(hmm_loglik) -add_markdown_docs(hmm_loglik "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(hmm_loglik "cli;python;julia;go;r-binding" "misc. / other") add_cli_executable(hmm_viterbi) add_python_binding(hmm_viterbi) add_julia_binding(hmm_viterbi) add_go_binding(hmm_viterbi) add_r_binding(hmm_viterbi) -add_markdown_docs(hmm_viterbi "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(hmm_viterbi "cli;python;julia;go;r-binding" "misc. / other") add_cli_executable(hmm_generate) add_python_binding(hmm_generate) add_julia_binding(hmm_generate) add_go_binding(hmm_generate) add_r_binding(hmm_generate) -add_markdown_docs(hmm_generate "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(hmm_generate "cli;python;julia;go;r-binding" "misc. / other") diff --git a/src/mlpack/methods/hoeffding_trees/CMakeLists.txt b/src/mlpack/methods/hoeffding_trees/CMakeLists.txt index cd679cc55e..72eae04729 100644 --- a/src/mlpack/methods/hoeffding_trees/CMakeLists.txt +++ b/src/mlpack/methods/hoeffding_trees/CMakeLists.txt @@ -33,4 +33,4 @@ add_python_binding(hoeffding_tree) add_julia_binding(hoeffding_tree) add_go_binding(hoeffding_tree) add_r_binding(hoeffding_tree) -add_markdown_docs(hoeffding_tree "cli;python;julia;go;r" "classification") +add_markdown_docs(hoeffding_tree "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/kde/CMakeLists.txt b/src/mlpack/methods/kde/CMakeLists.txt index 31dacaee43..70ea42284e 100644 --- a/src/mlpack/methods/kde/CMakeLists.txt +++ b/src/mlpack/methods/kde/CMakeLists.txt @@ -24,4 +24,4 @@ add_python_binding(kde) add_julia_binding(kde) add_go_binding(kde) add_r_binding(kde) -add_markdown_docs(kde "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(kde "cli;python;julia;go;r-binding" "misc. / other") diff --git a/src/mlpack/methods/kernel_pca/CMakeLists.txt b/src/mlpack/methods/kernel_pca/CMakeLists.txt index 61d49b5a26..89d69f28c8 100644 --- a/src/mlpack/methods/kernel_pca/CMakeLists.txt +++ b/src/mlpack/methods/kernel_pca/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(kernel_pca) add_julia_binding(kernel_pca) add_go_binding(kernel_pca) add_r_binding(kernel_pca) -add_markdown_docs(kernel_pca "cli;python;julia;go;r" "transformations") +add_markdown_docs(kernel_pca "cli;python;julia;go;r-binding" "transformations") diff --git a/src/mlpack/methods/kmeans/CMakeLists.txt b/src/mlpack/methods/kmeans/CMakeLists.txt index 1dbbbba626..7aa94b7b69 100644 --- a/src/mlpack/methods/kmeans/CMakeLists.txt +++ b/src/mlpack/methods/kmeans/CMakeLists.txt @@ -43,4 +43,4 @@ add_python_binding(kmeans) add_julia_binding(kmeans) add_go_binding(kmeans) add_r_binding(kmeans) -add_markdown_docs(kmeans "cli;python;julia;go;r" "clustering") +add_markdown_docs(kmeans "cli;python;julia;go;r-binding" "clustering") diff --git a/src/mlpack/methods/lars/CMakeLists.txt b/src/mlpack/methods/lars/CMakeLists.txt index df7d973cde..aa8a19c605 100644 --- a/src/mlpack/methods/lars/CMakeLists.txt +++ b/src/mlpack/methods/lars/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(lars) add_julia_binding(lars) add_go_binding(lars) add_r_binding(lars) -add_markdown_docs(lars "cli;python;julia;go;r" "regression") +add_markdown_docs(lars "cli;python;julia;go;r-binding" "regression") diff --git a/src/mlpack/methods/linear_regression/CMakeLists.txt b/src/mlpack/methods/linear_regression/CMakeLists.txt index bfb2bdb25b..2f4ce7035a 100644 --- a/src/mlpack/methods/linear_regression/CMakeLists.txt +++ b/src/mlpack/methods/linear_regression/CMakeLists.txt @@ -20,4 +20,4 @@ add_python_binding(linear_regression) add_julia_binding(linear_regression) add_go_binding(linear_regression) add_r_binding(linear_regression) -add_markdown_docs(linear_regression "cli;python;julia;go;r" "regression") +add_markdown_docs(linear_regression "cli;python;julia;go;r-binding" "regression") diff --git a/src/mlpack/methods/linear_svm/CMakeLists.txt b/src/mlpack/methods/linear_svm/CMakeLists.txt index 937cad9c5f..c5347000ca 100644 --- a/src/mlpack/methods/linear_svm/CMakeLists.txt +++ b/src/mlpack/methods/linear_svm/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(linear_svm) add_go_binding(linear_svm) add_julia_binding(linear_svm) add_r_binding(linear_svm) -add_markdown_docs(linear_svm "cli;python;julia;go;r" "classification") +add_markdown_docs(linear_svm "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/lmnn/CMakeLists.txt b/src/mlpack/methods/lmnn/CMakeLists.txt index f383a49657..f314f6fd01 100644 --- a/src/mlpack/methods/lmnn/CMakeLists.txt +++ b/src/mlpack/methods/lmnn/CMakeLists.txt @@ -23,4 +23,4 @@ add_python_binding(lmnn) add_julia_binding(lmnn) add_go_binding(lmnn) add_r_binding(lmnn) -add_markdown_docs(lmnn "cli;python;julia;go;r" "transformations") +add_markdown_docs(lmnn "cli;python;julia;go;r-binding" "transformations") diff --git a/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt b/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt index dd5124bb37..b9e0759f46 100644 --- a/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt +++ b/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt @@ -23,4 +23,4 @@ add_python_binding(local_coordinate_coding) add_julia_binding(local_coordinate_coding) add_go_binding(local_coordinate_coding) add_r_binding(local_coordinate_coding) -add_markdown_docs(local_coordinate_coding "cli;python;julia;go;r" "transformations") +add_markdown_docs(local_coordinate_coding "cli;python;julia;go;r-binding" "transformations") diff --git a/src/mlpack/methods/logistic_regression/CMakeLists.txt b/src/mlpack/methods/logistic_regression/CMakeLists.txt index f5a00bccc6..c33029aaba 100644 --- a/src/mlpack/methods/logistic_regression/CMakeLists.txt +++ b/src/mlpack/methods/logistic_regression/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(logistic_regression) add_julia_binding(logistic_regression) add_go_binding(logistic_regression) add_r_binding(logistic_regression) -add_markdown_docs(logistic_regression "cli;python;julia;go;r" "classification") +add_markdown_docs(logistic_regression "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/lsh/CMakeLists.txt b/src/mlpack/methods/lsh/CMakeLists.txt index 79fa17b44e..55201564e9 100644 --- a/src/mlpack/methods/lsh/CMakeLists.txt +++ b/src/mlpack/methods/lsh/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(lsh) add_julia_binding(lsh) add_go_binding(lsh) add_r_binding(lsh) -add_markdown_docs(lsh "cli;python;julia;go;r" "geometry") +add_markdown_docs(lsh "cli;python;julia;go;r-binding" "geometry") diff --git a/src/mlpack/methods/mean_shift/CMakeLists.txt b/src/mlpack/methods/mean_shift/CMakeLists.txt index 2ad5033520..b0b6918065 100644 --- a/src/mlpack/methods/mean_shift/CMakeLists.txt +++ b/src/mlpack/methods/mean_shift/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(mean_shift) add_julia_binding(mean_shift) add_go_binding(mean_shift) add_r_binding(mean_shift) -add_markdown_docs(mean_shift "cli;python;julia;go;r" "clustering") +add_markdown_docs(mean_shift "cli;python;julia;go;r-binding" "clustering") diff --git a/src/mlpack/methods/naive_bayes/CMakeLists.txt b/src/mlpack/methods/naive_bayes/CMakeLists.txt index 85ab2beb5e..2fb0f94f46 100644 --- a/src/mlpack/methods/naive_bayes/CMakeLists.txt +++ b/src/mlpack/methods/naive_bayes/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(nbc) add_julia_binding(nbc) add_go_binding(nbc) add_r_binding(nbc) -add_markdown_docs(nbc "cli;python;julia;go;r" "classification") +add_markdown_docs(nbc "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/nca/CMakeLists.txt b/src/mlpack/methods/nca/CMakeLists.txt index e956d76a6a..dec0d5a8a4 100644 --- a/src/mlpack/methods/nca/CMakeLists.txt +++ b/src/mlpack/methods/nca/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(nca) add_julia_binding(nca) add_go_binding(nca) add_r_binding(nca) -add_markdown_docs(nca "cli;python;julia;go;r" "transformations") +add_markdown_docs(nca "cli;python;julia;go;r-binding" "transformations") diff --git a/src/mlpack/methods/neighbor_search/CMakeLists.txt b/src/mlpack/methods/neighbor_search/CMakeLists.txt index ce24ba085f..46c64ef231 100644 --- a/src/mlpack/methods/neighbor_search/CMakeLists.txt +++ b/src/mlpack/methods/neighbor_search/CMakeLists.txt @@ -32,11 +32,11 @@ add_python_binding(knn) add_julia_binding(knn) add_go_binding(knn) add_r_binding(knn) -add_markdown_docs(knn "cli;python;julia;go;r" "geometry") +add_markdown_docs(knn "cli;python;julia;go;r-binding" "geometry") add_cli_executable(kfn) add_python_binding(kfn) add_julia_binding(kfn) add_go_binding(kfn) add_r_binding(kfn) -add_markdown_docs(kfn "cli;python;julia;go;r" "geometry") +add_markdown_docs(kfn "cli;python;julia;go;r-binding" "geometry") diff --git a/src/mlpack/methods/nmf/CMakeLists.txt b/src/mlpack/methods/nmf/CMakeLists.txt index 7f93ae3502..b4cc17340b 100644 --- a/src/mlpack/methods/nmf/CMakeLists.txt +++ b/src/mlpack/methods/nmf/CMakeLists.txt @@ -3,4 +3,4 @@ add_python_binding(nmf) add_julia_binding(nmf) add_go_binding(nmf) add_r_binding(nmf) -add_markdown_docs(nmf "cli;python;julia;go;r" "misc. / other") +add_markdown_docs(nmf "cli;python;julia;go;r-binding" "misc. / other") diff --git a/src/mlpack/methods/pca/CMakeLists.txt b/src/mlpack/methods/pca/CMakeLists.txt index 6ed7d726d8..9d17936ac9 100644 --- a/src/mlpack/methods/pca/CMakeLists.txt +++ b/src/mlpack/methods/pca/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(pca) add_julia_binding(pca) add_go_binding(pca) add_r_binding(pca) -add_markdown_docs(pca "cli;python;julia;go;r" "transformations") +add_markdown_docs(pca "cli;python;julia;go;r-binding" "transformations") diff --git a/src/mlpack/methods/perceptron/CMakeLists.txt b/src/mlpack/methods/perceptron/CMakeLists.txt index 1315d08608..2124b9c77c 100644 --- a/src/mlpack/methods/perceptron/CMakeLists.txt +++ b/src/mlpack/methods/perceptron/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(perceptron) add_julia_binding(perceptron) add_go_binding(perceptron) add_r_binding(perceptron) -add_markdown_docs(perceptron "cli;python;julia;go;r" "classification") +add_markdown_docs(perceptron "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/preprocess/CMakeLists.txt b/src/mlpack/methods/preprocess/CMakeLists.txt index 4dfdc06810..83ebd72d83 100644 --- a/src/mlpack/methods/preprocess/CMakeLists.txt +++ b/src/mlpack/methods/preprocess/CMakeLists.txt @@ -21,21 +21,21 @@ add_python_binding(preprocess_split) add_julia_binding(preprocess_split) add_go_binding(preprocess_split) add_r_binding(preprocess_split) -add_markdown_docs(preprocess_split "cli;python;julia;go;r" "preprocessing") +add_markdown_docs(preprocess_split "cli;python;julia;go;r-binding" "preprocessing") add_cli_executable(preprocess_binarize) add_python_binding(preprocess_binarize) add_julia_binding(preprocess_binarize) add_go_binding(preprocess_binarize) add_r_binding(preprocess_binarize) -add_markdown_docs(preprocess_binarize "cli;python;julia;go;r" "preprocessing") +add_markdown_docs(preprocess_binarize "cli;python;julia;go;r-binding" "preprocessing") add_cli_executable(preprocess_describe) add_python_binding(preprocess_describe) add_julia_binding(preprocess_describe) add_go_binding(preprocess_describe) add_r_binding(preprocess_describe) -add_markdown_docs(preprocess_describe "cli;python;julia;go;r" "preprocessing") +add_markdown_docs(preprocess_describe "cli;python;julia;go;r-binding" "preprocessing") #add_cli_executable(preprocess_scan) @@ -51,14 +51,14 @@ add_python_binding(preprocess_scale) add_go_binding(preprocess_scale) add_julia_binding(preprocess_scale) add_r_binding(preprocess_scale) -add_markdown_docs(preprocess_scale "cli;python;julia;go;r" "preprocessing") +add_markdown_docs(preprocess_scale "cli;python;julia;go;r-binding" "preprocessing") add_cli_executable(preprocess_one_hot_encoding) add_python_binding(preprocess_one_hot_encoding) add_go_binding(preprocess_one_hot_encoding) add_julia_binding(preprocess_one_hot_encoding) add_r_binding(preprocess_one_hot_encoding) -add_markdown_docs(preprocess_one_hot_encoding "cli;python;julia;go;r" +add_markdown_docs(preprocess_one_hot_encoding "cli;python;julia;go;r-binding" "preprocessing") if (STB_AVAILABLE) @@ -67,5 +67,5 @@ if (STB_AVAILABLE) add_julia_binding(image_converter) add_go_binding(image_converter) add_r_binding(image_converter) - add_markdown_docs(image_converter "cli;python;julia;go;r" "preprocessing") + add_markdown_docs(image_converter "cli;python;julia;go;r-binding" "preprocessing") endif () diff --git a/src/mlpack/methods/radical/CMakeLists.txt b/src/mlpack/methods/radical/CMakeLists.txt index 723f61e158..3458fce5f0 100644 --- a/src/mlpack/methods/radical/CMakeLists.txt +++ b/src/mlpack/methods/radical/CMakeLists.txt @@ -18,4 +18,4 @@ add_python_binding(radical) add_julia_binding(radical) add_go_binding(radical) add_r_binding(radical) -add_markdown_docs(radical "cli;python;julia;go;r" "transformations") +add_markdown_docs(radical "cli;python;julia;go;r-binding" "transformations") diff --git a/src/mlpack/methods/random_forest/CMakeLists.txt b/src/mlpack/methods/random_forest/CMakeLists.txt index 4be75d3761..19cc6bb05f 100644 --- a/src/mlpack/methods/random_forest/CMakeLists.txt +++ b/src/mlpack/methods/random_forest/CMakeLists.txt @@ -20,4 +20,4 @@ add_python_binding(random_forest) add_julia_binding(random_forest) add_go_binding(random_forest) add_r_binding(random_forest) -add_markdown_docs(random_forest "cli;python;julia;go;r" "classification") +add_markdown_docs(random_forest "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/rann/CMakeLists.txt b/src/mlpack/methods/rann/CMakeLists.txt index 99e838b459..8678e10052 100644 --- a/src/mlpack/methods/rann/CMakeLists.txt +++ b/src/mlpack/methods/rann/CMakeLists.txt @@ -40,4 +40,4 @@ add_python_binding(krann) add_julia_binding(krann) add_go_binding(krann) add_r_binding(krann) -add_markdown_docs(krann "cli;python;julia;go;r" "geometry") +add_markdown_docs(krann "cli;python;julia;go;r-binding" "geometry") diff --git a/src/mlpack/methods/softmax_regression/CMakeLists.txt b/src/mlpack/methods/softmax_regression/CMakeLists.txt index d245fa4547..3be5b25724 100644 --- a/src/mlpack/methods/softmax_regression/CMakeLists.txt +++ b/src/mlpack/methods/softmax_regression/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(softmax_regression) add_julia_binding(softmax_regression) add_go_binding(softmax_regression) add_r_binding(softmax_regression) -add_markdown_docs(softmax_regression "cli;python;julia;go;r" "classification") +add_markdown_docs(softmax_regression "cli;python;julia;go;r-binding" "classification") diff --git a/src/mlpack/methods/sparse_coding/CMakeLists.txt b/src/mlpack/methods/sparse_coding/CMakeLists.txt index 45b627bcc0..3d5ee4f61f 100644 --- a/src/mlpack/methods/sparse_coding/CMakeLists.txt +++ b/src/mlpack/methods/sparse_coding/CMakeLists.txt @@ -23,4 +23,4 @@ add_python_binding(sparse_coding) add_julia_binding(sparse_coding) add_go_binding(sparse_coding) add_r_binding(sparse_coding) -add_markdown_docs(sparse_coding "cli;python;julia;go;r" "transformations") +add_markdown_docs(sparse_coding "cli;python;julia;go;r-binding" "transformations") From b59619c16399d39c68b34604094833be23d8a4f6 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Wed, 7 Oct 2020 11:04:57 +0530 Subject: [PATCH 36/45] Revert previous changes. --- src/mlpack/bindings/R/print_doc_functions_impl.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mlpack/bindings/R/print_doc_functions_impl.hpp b/src/mlpack/bindings/R/print_doc_functions_impl.hpp index dcdfd5d15d..76b956812e 100644 --- a/src/mlpack/bindings/R/print_doc_functions_impl.hpp +++ b/src/mlpack/bindings/R/print_doc_functions_impl.hpp @@ -61,10 +61,10 @@ inline std::string PrintValue(const T& value, bool quotes) { std::ostringstream oss; if (quotes) - oss << "`"; + oss << "\""; oss << value; if (quotes) - oss << "`"; + oss << "\""; return oss.str(); } @@ -76,7 +76,7 @@ inline std::string PrintValue(const std::vector& value, bool quotes) { std::ostringstream oss; if (quotes) - oss << "`"; + oss << "\""; oss << "c("; if (value.size() > 0) { @@ -86,7 +86,7 @@ inline std::string PrintValue(const std::vector& value, bool quotes) } oss << ")"; if (quotes) - oss << "`"; + oss << "\""; return oss.str(); } @@ -332,7 +332,7 @@ inline std::string ProgramCall(const std::string& programName) */ inline std::string PrintModel(const std::string& modelName) { - return "`" + modelName + "`"; + return "\"" + modelName + "\""; } /** @@ -341,7 +341,7 @@ inline std::string PrintModel(const std::string& modelName) */ inline std::string PrintDataset(const std::string& datasetName) { - return "`" + datasetName + "`"; + return "\"" + datasetName + "\""; } /** @@ -359,7 +359,7 @@ inline std::string ProgramCallClose() inline std::string ParamString(const std::string& paramName) { // For a R binding we don't need to know the type. - return "`" + paramName + "`"; + return "\"" + paramName + "\""; } /** From d86dba09320be248725bd315c9851e08b6a1a643 Mon Sep 17 00:00:00 2001 From: jeffin sam Date: Wed, 7 Oct 2020 15:34:00 +0530 Subject: [PATCH 37/45] Apply suggestions from code review Co-authored-by: Ryan Curtin --- src/mlpack/tests/lars_test.cpp | 10 +++++----- src/mlpack/tests/layer_names_test.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mlpack/tests/lars_test.cpp b/src/mlpack/tests/lars_test.cpp index 4a525fad4b..c18cf76f50 100644 --- a/src/mlpack/tests/lars_test.cpp +++ b/src/mlpack/tests/lars_test.cpp @@ -187,7 +187,7 @@ TEST_CASE("PredictTest", "[LARSTest]") if (std::abs(betaOptPred[i]) < 1e-5) REQUIRE(adjPred[i] == Approx(0.0).margin(1e-5)); else - REQUIRE(adjPred[i] == Approx( betaOptPred[i]).epsilon(1e-7)); + REQUIRE(adjPred[i] == Approx(betaOptPred[i]).epsilon(1e-7)); } } } @@ -219,7 +219,7 @@ TEST_CASE("PredictRowMajorTest", "[LARSTest]") if (std::abs(colMajorPred[i]) < 1e-5) REQUIRE(rowMajorPred[i] == Approx(0.0).margin(1e-5)); else - REQUIRE(colMajorPred[i] == Approx( rowMajorPred[i]).epsilon(1e-7)); + REQUIRE(colMajorPred[i] == Approx(rowMajorPred[i]).epsilon(1e-7)); } } @@ -296,7 +296,7 @@ TEST_CASE("TrainingAndAccessingBetaTest", "[LARSTest]") REQUIRE(beta.n_elem == lars2.Beta().n_elem); for (size_t i = 0; i < beta.n_elem; ++i) - REQUIRE(beta[i] == Approx( lars2.Beta()[i]).epsilon(1e-7)); + REQUIRE(beta[i] == Approx(lars2.Beta()[i]).epsilon(1e-7)); } /** @@ -318,7 +318,7 @@ TEST_CASE("TrainingConstructorWithDefaultsTest", "[LARSTest]") REQUIRE(beta.n_elem == lars2.Beta().n_elem); for (size_t i = 0; i < beta.n_elem; ++i) - REQUIRE(beta[i] == Approx( lars2.Beta()[i]).epsilon(1e-7)); + REQUIRE(beta[i] == Approx(lars2.Beta()[i]).epsilon(1e-7)); } /** @@ -345,7 +345,7 @@ TEST_CASE("TrainingConstructorWithNonDefaultsTest", "[LARSTest]") REQUIRE(beta.n_elem == lars2.Beta().n_elem); for (size_t i = 0; i < beta.n_elem; ++i) - REQUIRE(beta[i] == Approx( lars2.Beta()[i]).epsilon(1e-7)); + REQUIRE(beta[i] == Approx(lars2.Beta()[i]).epsilon(1e-7)); } /** diff --git a/src/mlpack/tests/layer_names_test.cpp b/src/mlpack/tests/layer_names_test.cpp index 7cec416479..8bd6f5f00a 100644 --- a/src/mlpack/tests/layer_names_test.cpp +++ b/src/mlpack/tests/layer_names_test.cpp @@ -61,7 +61,7 @@ TEST_CASE("LayerNameVisitorTest", "[LayerNamesTest]") LayerTypes<> unsupportedLayer = new BilinearInterpolation<>(); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - atrousConvolution) == "atrousconvolution"); + atrousConvolution) == "atrousconvolution"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), alphaDropout) == "alphadropout"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), From 8714426393bc156b97ba6e06df557558f69713e6 Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Wed, 7 Oct 2020 15:39:38 +0530 Subject: [PATCH 38/45] fix style issues --- src/mlpack/tests/lars_test.cpp | 3 +- src/mlpack/tests/layer_names_test.cpp | 62 +++++++++++++-------------- src/mlpack/tests/lin_alg_test.cpp | 4 ++ 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/mlpack/tests/lars_test.cpp b/src/mlpack/tests/lars_test.cpp index c18cf76f50..68f89db8fc 100644 --- a/src/mlpack/tests/lars_test.cpp +++ b/src/mlpack/tests/lars_test.cpp @@ -36,7 +36,8 @@ void LARSVerifyCorrectness(arma::vec beta, arma::vec errCorr, double lambda) if (beta(j) == 0) { // Make sure that |errCorr(j)| <= lambda. - REQUIRE(std::max(fabs(errCorr(j)) - lambda, 0.0) == Approx(0.0).margin(tol)); + REQUIRE(std::max(fabs(errCorr(j)) - lambda, 0.0) == + Approx(0.0).margin(tol)); } else if (beta(j) < 0) { diff --git a/src/mlpack/tests/layer_names_test.cpp b/src/mlpack/tests/layer_names_test.cpp index 8bd6f5f00a..9d94f0ff67 100644 --- a/src/mlpack/tests/layer_names_test.cpp +++ b/src/mlpack/tests/layer_names_test.cpp @@ -63,67 +63,67 @@ TEST_CASE("LayerNameVisitorTest", "[LayerNamesTest]") REQUIRE(boost::apply_visitor(LayerNameVisitor(), atrousConvolution) == "atrousconvolution"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - alphaDropout) == "alphadropout"); + alphaDropout) == "alphadropout"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - batchNorm) == "batchnorm"); + batchNorm) == "batchnorm"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - constant) == "constant"); + constant) == "constant"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - convolution) == "convolution"); + convolution) == "convolution"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - dropConnect) == "dropconnect"); + dropConnect) == "dropconnect"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - dropout) == "dropout"); + dropout) == "dropout"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - flexibleReLU) == "flexiblerelu"); + flexibleReLU) == "flexiblerelu"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - layerNorm) == "layernorm"); + layerNorm) == "layernorm"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - linear) == "linear"); + linear) == "linear"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - linearNoBias) == "linearnobias"); + linearNoBias) == "linearnobias"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - maxPooling) == "maxpooling"); + maxPooling) == "maxpooling"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - meanPooling) == "meanpooling"); + meanPooling) == "meanpooling"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - multiplyConstant) == "multiplyconstant"); + multiplyConstant) == "multiplyconstant"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - reLULayer) == "relu"); + reLULayer) == "relu"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - transposedConvolution) == "transposedconvolution"); + transposedConvolution) == "transposedconvolution"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - identityLayer) == "identity"); + identityLayer) == "identity"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - tanHLayer) == "tanh"); + tanHLayer) == "tanh"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - eLU) == "elu"); + eLU) == "elu"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - hardTanH) == "hardtanh"); + hardTanH) == "hardtanh"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - leakyReLU) == "leakyrelu"); + leakyReLU) == "leakyrelu"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - pReLU) == "prelu"); + pReLU) == "prelu"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - sigmoidLayer) == "sigmoid"); + sigmoidLayer) == "sigmoid"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - logSoftMax) == "logsoftmax"); + logSoftMax) == "logsoftmax"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - unsupportedLayer) == "unsupported"); + unsupportedLayer) == "unsupported"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - lstmLayer) == "lstm"); + lstmLayer) == "lstm"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - creluLayer) == "crelu"); + creluLayer) == "crelu"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - highwayLayer) == "highway"); + highwayLayer) == "highway"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - gruLayer) == "gru"); + gruLayer) == "gru"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - glimpseLayer) == "glimpse"); + glimpseLayer) == "glimpse"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - fastlstmLayer) == "fastlstm"); + fastlstmLayer) == "fastlstm"); REQUIRE(boost::apply_visitor(LayerNameVisitor(), - weightnormLayer) == "weightnorm"); + weightnormLayer) == "weightnorm"); // Delete all instances. boost::apply_visitor(DeleteVisitor(), atrousConvolution); boost::apply_visitor(DeleteVisitor(), alphaDropout); diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index 1ed30a60f0..7454564c20 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -49,11 +49,13 @@ TEST_CASE("TestCenterA", "[LinAlgTest]") // [-6 -3 0 3 6 ] // [-8 -4 0 4 8]] for (int row = 0; row < 5; row++) + { for (int col = 0; col < 5; col++) { REQUIRE(tmp_out(row, col) == Approx((double) (col - 2) * row).epsilon(1e-7)); } + } } TEST_CASE("TestCenterB", "[LinAlgTest]") @@ -75,11 +77,13 @@ TEST_CASE("TestCenterB", "[LinAlgTest]") // [-7.5 -4.5 -1.5 1.5 1.5 4.5] // [-10 -6 -2 2 6 10 ]] for (int row = 0; row < 5; row++) + { for (int col = 0; col < 6; col++) { REQUIRE(tmp_out(row, col) == Approx((double) (col - 2.5) * row).epsilon(1e-7)); } + } } TEST_CASE("TestOrthogonalize", "[LinAlgTest]") From ef28802329de1f0e46d2f5deb6b685d639b159a5 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Wed, 7 Oct 2020 16:06:51 +0530 Subject: [PATCH 39/45] Add @rcurtin's suggestion. --- src/mlpack/bindings/markdown/print_docs.cpp | 34 +++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/mlpack/bindings/markdown/print_docs.cpp b/src/mlpack/bindings/markdown/print_docs.cpp index 5d8a55e140..10805e8209 100644 --- a/src/mlpack/bindings/markdown/print_docs.cpp +++ b/src/mlpack/bindings/markdown/print_docs.cpp @@ -166,15 +166,31 @@ void PrintDocs(const std::string& bindingName, } cout << endl; - // Next, iterate through the list of output options. - cout << "### Output options" << endl; - cout << endl; - string outputInfo = PrintOutputOptionInfo(); - if (outputInfo.size() > 0) - cout << outputInfo << endl; - cout << endl; - cout << "| ***name*** | ***type*** | ***description*** |" << endl; - cout << "|------------|------------|-------------------|" << endl; + // Determine if there are any output options, to see if we need + // to print the header of the output options table. + bool hasOutputOptions = false; + for (map::iterator it = parameters.begin(); + it != parameters.end(); ++it) + { + if (!it->second.input) + { + hasOutputOptions = true; + break; + } + } + + if (hasOutputOptions) + { + // Next, iterate through the list of output options. + cout << "### Output options" << endl; + cout << endl; + string outputInfo = PrintOutputOptionInfo(); + if (outputInfo.size() > 0) + cout << outputInfo << endl; + cout << endl; + cout << "| ***name*** | ***type*** | ***description*** |" << endl; + cout << "|------------|------------|-------------------|" << endl; + } for (map::iterator it = parameters.begin(); it != parameters.end(); ++it) { From b6e978e249d020cbda87752b55e4f2d947d6e7f4 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Thu, 8 Oct 2020 20:43:38 -0400 Subject: [PATCH 40/45] Pass CMAKE_SIZEOF_VOID_P directly to CreateArmaConfig.cmake script. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f041e321e6..8235d8fc29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -568,6 +568,7 @@ add_custom_target(mlpack_arma_config ALL COMMAND ${CMAKE_COMMAND} -D ARMADILLO_INCLUDE_DIR="${ARMADILLO_INCLUDE_DIR}" -D OPENMP_FOUND="${OPENMP_FOUND}" + -D CMAKE_SIZEOF_VOID_P="${CMAKE_SIZEOF_VOID_P}" -P CMake/CreateArmaConfigInfo.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Updating arma_config.hpp (if necessary)") From e10e77e8ef71dfaaefe8bbafdd18f2c73eab8823 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Thu, 8 Oct 2020 20:44:32 -0400 Subject: [PATCH 41/45] Update HISTORY.md. --- HISTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 5acdedcb4f..a250c1ec98 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,8 @@ * Added Softmin activation function as layer in ann/layer. + * Fix spurious ARMA_64BIT_WORD compilation warnings on 32-bit systems. + ### mlpack 3.4.1 ###### 2020-09-07 * Fix incorrect parsing of required matrix/model parameters for command-line From 6a503266d8b3f76979cd6235dd955cb2c3a23136 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Thu, 8 Oct 2020 20:51:19 -0400 Subject: [PATCH 42/45] Update HISTORY with correct issue number. --- HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index a250c1ec98..b839c8dc9e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,7 @@ * Added Softmin activation function as layer in ann/layer. - * Fix spurious ARMA_64BIT_WORD compilation warnings on 32-bit systems. + * Fix spurious ARMA_64BIT_WORD compilation warnings on 32-bit systems (#2665). ### mlpack 3.4.1 ###### 2020-09-07 From 76133b4f3f150f88a1d418f376411d35eba1fcf5 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Fri, 9 Oct 2020 09:24:24 +0530 Subject: [PATCH 43/45] style guide changes --- src/mlpack/tests/range_search_test.cpp | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index ccf839a018..7bd714beaf 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -492,7 +492,7 @@ TEST_CASE("DualTreeVsNaive1", "[RangeSearchTest]") { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); REQUIRE(sortedTree[i][j].first == - Approx(sortedNaive[i][j].first).epsilon(1e-7)); + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -541,7 +541,7 @@ TEST_CASE("DualTreeVsNaive2", "[RangeSearchTest]") { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); REQUIRE(sortedTree[i][j].first == - Approx(sortedNaive[i][j].first).epsilon(1e-7)); + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -590,7 +590,7 @@ TEST_CASE("SingleTreeVsNaive", "[RangeSearchTest]") { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); REQUIRE(sortedTree[i][j].first == - Approx(sortedNaive[i][j].first).epsilon(1e-7)); + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -663,7 +663,7 @@ TEST_CASE("CoverTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(coverSorted[i][j].first).epsilon(1e-7)); + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -741,7 +741,7 @@ TEST_CASE("CoverTreeTwoDatasetsTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(coverSorted[i][j].first).epsilon(1e-7)); + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -815,7 +815,7 @@ TEST_CASE("CoverTreeSingleTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(coverSorted[i][j].first).epsilon(1e-7)); + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -889,7 +889,7 @@ TEST_CASE("SingleBallTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon(1e-7)); + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -963,7 +963,7 @@ TEST_CASE("DualBallTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon(1e-7)); + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -1042,7 +1042,7 @@ TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon (1e-7)); + Approx(ballSorted[i][j].first).epsilon (1e-7)); } } } @@ -1105,7 +1105,7 @@ TEST_CASE("RangeSearchTrainTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(baselineSorted[i][j].first).epsilon(1e-7)); + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1147,7 +1147,7 @@ TEST_CASE("TrainTreeTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(baselineSorted[i][j].first).epsilon(1e-7)); + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1202,7 +1202,7 @@ TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(moveSorted[i][j].first).epsilon(1e-7)); + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1245,7 +1245,7 @@ TEST_CASE("MoveTrainTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(moveSorted[i][j].first).epsilon(1e-7)); + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1330,7 +1330,7 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); REQUIRE(sorted[k][l].first == - Approx(baselineSorted[k][l].first).epsilon(1e-7)); + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } } @@ -1413,7 +1413,7 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); REQUIRE(sorted[k][l].first == - Approx(baselineSorted[k][l].first).epsilon(1e-7)); + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } } From 99ef23fdf0351351f0997d385071929293998f5d Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Sat, 10 Oct 2020 19:40:27 +0530 Subject: [PATCH 44/45] fix static analysis job --- src/mlpack/tests/augmented_rnns_tasks_test.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mlpack/tests/augmented_rnns_tasks_test.cpp b/src/mlpack/tests/augmented_rnns_tasks_test.cpp index 1dca6d10b2..17fd801394 100644 --- a/src/mlpack/tests/augmented_rnns_tasks_test.cpp +++ b/src/mlpack/tests/augmented_rnns_tasks_test.cpp @@ -50,8 +50,10 @@ class HardCodedCopyModel size_t zeroCnt = 0, oneCnt = 0; for (size_t i = 1; i < input.n_rows; i += 2) { - size_t& addVar = (input.at(i, 0) == 0) ? zeroCnt : oneCnt; - ++addVar; + if (input.at(i, 0) == 0) + ++zeroCnt; + else + ++oneCnt; } assert(oneCnt % zeroCnt == 0); nRepeats = oneCnt / zeroCnt; @@ -157,7 +159,7 @@ class HardCodedAddModel predictors = predictors.t(); predictors.reshape(3, predictors.n_elem / 3); assert(predictors.n_rows == 3); - int num_A = 0, num_B = 0; + size_t num_A = 0, num_B = 0; bool num = false; // True iff we have already seen the separating symbol. size_t cnt = 0; for (size_t i = 0; i < predictors.n_cols; ++i) From a11e21c0d70b8bb2a87704537aa3b8d4096f50bf Mon Sep 17 00:00:00 2001 From: Yashwant Date: Sat, 10 Oct 2020 20:36:01 +0530 Subject: [PATCH 45/45] Revert r-binding to r. --- .../bindings/markdown/default_param.hpp | 2 +- .../bindings/markdown/get_binding_name.cpp | 2 +- .../bindings/markdown/get_printable_type.hpp | 2 +- .../markdown/print_doc_functions_impl.hpp | 26 +++++++++---------- .../bindings/markdown/print_type_doc.hpp | 2 +- src/mlpack/methods/adaboost/CMakeLists.txt | 2 +- src/mlpack/methods/approx_kfn/CMakeLists.txt | 2 +- .../bayesian_linear_regression/CMakeLists.txt | 2 +- src/mlpack/methods/cf/CMakeLists.txt | 2 +- src/mlpack/methods/dbscan/CMakeLists.txt | 2 +- .../methods/decision_tree/CMakeLists.txt | 2 +- src/mlpack/methods/det/CMakeLists.txt | 2 +- src/mlpack/methods/emst/CMakeLists.txt | 2 +- src/mlpack/methods/fastmks/CMakeLists.txt | 2 +- src/mlpack/methods/gmm/CMakeLists.txt | 6 ++--- src/mlpack/methods/hmm/CMakeLists.txt | 8 +++--- .../methods/hoeffding_trees/CMakeLists.txt | 2 +- src/mlpack/methods/kde/CMakeLists.txt | 2 +- src/mlpack/methods/kernel_pca/CMakeLists.txt | 2 +- src/mlpack/methods/kmeans/CMakeLists.txt | 2 +- src/mlpack/methods/lars/CMakeLists.txt | 2 +- .../methods/linear_regression/CMakeLists.txt | 2 +- src/mlpack/methods/linear_svm/CMakeLists.txt | 2 +- src/mlpack/methods/lmnn/CMakeLists.txt | 2 +- .../local_coordinate_coding/CMakeLists.txt | 2 +- .../logistic_regression/CMakeLists.txt | 2 +- src/mlpack/methods/lsh/CMakeLists.txt | 2 +- src/mlpack/methods/mean_shift/CMakeLists.txt | 2 +- src/mlpack/methods/naive_bayes/CMakeLists.txt | 2 +- src/mlpack/methods/nca/CMakeLists.txt | 2 +- .../methods/neighbor_search/CMakeLists.txt | 4 +-- src/mlpack/methods/nmf/CMakeLists.txt | 2 +- src/mlpack/methods/pca/CMakeLists.txt | 2 +- src/mlpack/methods/perceptron/CMakeLists.txt | 2 +- src/mlpack/methods/preprocess/CMakeLists.txt | 12 ++++----- src/mlpack/methods/radical/CMakeLists.txt | 2 +- .../methods/random_forest/CMakeLists.txt | 2 +- src/mlpack/methods/rann/CMakeLists.txt | 2 +- .../methods/softmax_regression/CMakeLists.txt | 2 +- .../methods/sparse_coding/CMakeLists.txt | 2 +- 40 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/mlpack/bindings/markdown/default_param.hpp b/src/mlpack/bindings/markdown/default_param.hpp index 973758255b..cf4a175a29 100644 --- a/src/mlpack/bindings/markdown/default_param.hpp +++ b/src/mlpack/bindings/markdown/default_param.hpp @@ -55,7 +55,7 @@ void DefaultParam(util::ParamData& data, *((std::string*) output) = go::DefaultParamImpl::type>(data); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { *((std::string*) output) = r::DefaultParamImpl::type>(data); diff --git a/src/mlpack/bindings/markdown/get_binding_name.cpp b/src/mlpack/bindings/markdown/get_binding_name.cpp index 5524664ed7..b3cf4e51e8 100644 --- a/src/mlpack/bindings/markdown/get_binding_name.cpp +++ b/src/mlpack/bindings/markdown/get_binding_name.cpp @@ -42,7 +42,7 @@ std::string GetBindingName(const std::string& language, // For Go bindings, the name is unchanged. return name; } - else if (language == "r-binding") + else if (language == "r") { // For R bindings, the name is unchanged. return name; diff --git a/src/mlpack/bindings/markdown/get_printable_type.hpp b/src/mlpack/bindings/markdown/get_printable_type.hpp index afe9e2cb9e..2848947b54 100644 --- a/src/mlpack/bindings/markdown/get_printable_type.hpp +++ b/src/mlpack/bindings/markdown/get_printable_type.hpp @@ -54,7 +54,7 @@ void GetPrintableType(util::ParamData& data, *((std::string*) output) = go::GetPrintableType::type>(data); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { *((std::string*) output) = r::GetPrintableType::type>(data); diff --git a/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp b/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp index 6fec1b918b..06ebaab813 100644 --- a/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp +++ b/src/mlpack/bindings/markdown/print_doc_functions_impl.hpp @@ -50,7 +50,7 @@ inline std::string GetBindingName(const std::string& bindingName) { return go::GetBindingName(bindingName); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { return r::GetBindingName(bindingName); } @@ -82,7 +82,7 @@ inline std::string PrintLanguage(const std::string& language) { return "Go"; } - else if (language == "r-binding") + else if (language == "r") { return "R"; } @@ -114,7 +114,7 @@ inline std::string PrintImport(const std::string& bindingName) { return go::PrintImport(); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { return r::PrintImport(); } @@ -146,7 +146,7 @@ inline std::string PrintInputOptionInfo() { return go::PrintInputOptionInfo(); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { return r::PrintInputOptionInfo(); } @@ -178,7 +178,7 @@ inline std::string PrintOutputOptionInfo() { return go::PrintOutputOptionInfo(); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { return r::PrintOutputOptionInfo(); } @@ -411,7 +411,7 @@ inline std::string PrintValue(const T& value, bool quotes) { result = go::PrintValue(value, quotes); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { result = r::PrintValue(value, quotes); } @@ -458,7 +458,7 @@ inline std::string PrintDefault(const std::string& paramName) { oss << go::PrintDefault(paramName); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { oss << r::PrintDefault(paramName); } @@ -494,7 +494,7 @@ inline std::string PrintDataset(const std::string& dataset) { result = go::PrintDataset(dataset); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { result = r::PrintDataset(dataset); } @@ -529,7 +529,7 @@ inline std::string PrintModel(const std::string& model) { result = go::PrintModel(model); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { result = r::PrintModel(model); } @@ -571,7 +571,7 @@ std::string ProgramCall(const std::string& programName, Args... args) s += "```go\n"; s += go::ProgramCall(programName, args...); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { s += "```R\n"; s += r::ProgramCall(true, programName, args...); @@ -626,7 +626,7 @@ inline std::string ProgramCall(const std::string& programName) s += import + "\n"; s += go::ProgramCall(programName); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { s += "R\n"; std::string import = PrintImport(programName); @@ -672,7 +672,7 @@ inline std::string ParamString(const std::string& paramName) { s = go::ParamString(paramName); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { s = r::ParamString(paramName); } @@ -723,7 +723,7 @@ inline bool IgnoreCheck(const T& t) { return go::IgnoreCheck(t); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { return r::IgnoreCheck(t); } diff --git a/src/mlpack/bindings/markdown/print_type_doc.hpp b/src/mlpack/bindings/markdown/print_type_doc.hpp index 30a6b3298e..34a1906fa0 100644 --- a/src/mlpack/bindings/markdown/print_type_doc.hpp +++ b/src/mlpack/bindings/markdown/print_type_doc.hpp @@ -48,7 +48,7 @@ std::string PrintTypeDoc(util::ParamData& data) { return go::PrintTypeDoc::type>(data); } - else if (BindingInfo::Language() == "r-binding") + else if (BindingInfo::Language() == "r") { return r::PrintTypeDoc::type>(data); } diff --git a/src/mlpack/methods/adaboost/CMakeLists.txt b/src/mlpack/methods/adaboost/CMakeLists.txt index 79910a3bb7..102c41c488 100644 --- a/src/mlpack/methods/adaboost/CMakeLists.txt +++ b/src/mlpack/methods/adaboost/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(adaboost) add_julia_binding(adaboost) add_go_binding(adaboost) add_r_binding(adaboost) -add_markdown_docs(adaboost "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(adaboost "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/approx_kfn/CMakeLists.txt b/src/mlpack/methods/approx_kfn/CMakeLists.txt index b005f22e0d..f769425127 100644 --- a/src/mlpack/methods/approx_kfn/CMakeLists.txt +++ b/src/mlpack/methods/approx_kfn/CMakeLists.txt @@ -24,4 +24,4 @@ add_python_binding(approx_kfn) add_julia_binding(approx_kfn) add_go_binding(approx_kfn) add_r_binding(approx_kfn) -add_markdown_docs(approx_kfn "cli;python;julia;go;r-binding" "geometry") +add_markdown_docs(approx_kfn "cli;python;julia;go;r" "geometry") diff --git a/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt b/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt index 172e02e75f..7ded67c3fa 100644 --- a/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt +++ b/src/mlpack/methods/bayesian_linear_regression/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(bayesian_linear_regression) add_julia_binding(bayesian_linear_regression) add_go_binding(bayesian_linear_regression) add_r_binding(bayesian_linear_regression) -add_markdown_docs(bayesian_linear_regression "cli;python;julia;go;r-binding" "regression") +add_markdown_docs(bayesian_linear_regression "cli;python;julia;go;r" "regression") diff --git a/src/mlpack/methods/cf/CMakeLists.txt b/src/mlpack/methods/cf/CMakeLists.txt index 51722b8970..a7c552ae28 100644 --- a/src/mlpack/methods/cf/CMakeLists.txt +++ b/src/mlpack/methods/cf/CMakeLists.txt @@ -28,4 +28,4 @@ add_python_binding(cf) add_julia_binding(cf) add_go_binding(cf) add_r_binding(cf) -add_markdown_docs(cf "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(cf "cli;python;julia;go;r" "misc. / other") diff --git a/src/mlpack/methods/dbscan/CMakeLists.txt b/src/mlpack/methods/dbscan/CMakeLists.txt index 6be902c1fa..7c0a883504 100644 --- a/src/mlpack/methods/dbscan/CMakeLists.txt +++ b/src/mlpack/methods/dbscan/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(dbscan) add_julia_binding(dbscan) add_go_binding(dbscan) add_r_binding(dbscan) -add_markdown_docs(dbscan "cli;python;julia;go;r-binding" "clustering") +add_markdown_docs(dbscan "cli;python;julia;go;r" "clustering") diff --git a/src/mlpack/methods/decision_tree/CMakeLists.txt b/src/mlpack/methods/decision_tree/CMakeLists.txt index 6e084a6bfe..68f5a2ef41 100644 --- a/src/mlpack/methods/decision_tree/CMakeLists.txt +++ b/src/mlpack/methods/decision_tree/CMakeLists.txt @@ -28,4 +28,4 @@ add_python_binding(decision_tree) add_julia_binding(decision_tree) add_go_binding(decision_tree) add_r_binding(decision_tree) -add_markdown_docs(decision_tree "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(decision_tree "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/det/CMakeLists.txt b/src/mlpack/methods/det/CMakeLists.txt index 79f7e108c2..2d35bd9fb8 100644 --- a/src/mlpack/methods/det/CMakeLists.txt +++ b/src/mlpack/methods/det/CMakeLists.txt @@ -24,4 +24,4 @@ add_python_binding(det) add_julia_binding(det) add_go_binding(det) add_r_binding(det) -add_markdown_docs(det "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(det "cli;python;julia;go;r" "misc. / other") diff --git a/src/mlpack/methods/emst/CMakeLists.txt b/src/mlpack/methods/emst/CMakeLists.txt index 9f91988a9c..4d7fd2cd4c 100644 --- a/src/mlpack/methods/emst/CMakeLists.txt +++ b/src/mlpack/methods/emst/CMakeLists.txt @@ -26,4 +26,4 @@ add_python_binding(emst) add_julia_binding(emst) add_go_binding(emst) add_r_binding(emst) -add_markdown_docs(emst "cli;python;julia;go;r-binding" "geometry") +add_markdown_docs(emst "cli;python;julia;go;r" "geometry") diff --git a/src/mlpack/methods/fastmks/CMakeLists.txt b/src/mlpack/methods/fastmks/CMakeLists.txt index 280b9708bd..78a11b535c 100644 --- a/src/mlpack/methods/fastmks/CMakeLists.txt +++ b/src/mlpack/methods/fastmks/CMakeLists.txt @@ -25,4 +25,4 @@ add_python_binding(fastmks) add_julia_binding(fastmks) add_go_binding(fastmks) add_r_binding(fastmks) -add_markdown_docs(fastmks "cli;python;julia;go;r-binding" "geometry") +add_markdown_docs(fastmks "cli;python;julia;go;r" "geometry") diff --git a/src/mlpack/methods/gmm/CMakeLists.txt b/src/mlpack/methods/gmm/CMakeLists.txt index e85002c541..52d98b7c1e 100644 --- a/src/mlpack/methods/gmm/CMakeLists.txt +++ b/src/mlpack/methods/gmm/CMakeLists.txt @@ -29,18 +29,18 @@ add_python_binding(gmm_train) add_julia_binding(gmm_train) add_go_binding(gmm_train) add_r_binding(gmm_train) -add_markdown_docs(gmm_train "cli;python;julia;go;r-binding" "clustering") +add_markdown_docs(gmm_train "cli;python;julia;go;r" "clustering") add_cli_executable(gmm_generate) add_python_binding(gmm_generate) add_julia_binding(gmm_generate) add_go_binding(gmm_generate) add_r_binding(gmm_generate) -add_markdown_docs(gmm_generate "cli;python;julia;go;r-binding" "clustering") +add_markdown_docs(gmm_generate "cli;python;julia;go;r" "clustering") add_cli_executable(gmm_probability) add_python_binding(gmm_probability) add_julia_binding(gmm_probability) add_go_binding(gmm_probability) add_r_binding(gmm_probability) -add_markdown_docs(gmm_probability "cli;python;julia;go;r-binding" "clustering") +add_markdown_docs(gmm_probability "cli;python;julia;go;r" "clustering") diff --git a/src/mlpack/methods/hmm/CMakeLists.txt b/src/mlpack/methods/hmm/CMakeLists.txt index 1c2992e59d..bfe2cedc58 100644 --- a/src/mlpack/methods/hmm/CMakeLists.txt +++ b/src/mlpack/methods/hmm/CMakeLists.txt @@ -24,25 +24,25 @@ add_python_binding(hmm_train) add_julia_binding(hmm_train) add_go_binding(hmm_train) add_r_binding(hmm_train) -add_markdown_docs(hmm_train "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(hmm_train "cli;python;julia;go;r" "misc. / other") add_cli_executable(hmm_loglik) add_python_binding(hmm_loglik) add_julia_binding(hmm_loglik) add_go_binding(hmm_loglik) add_r_binding(hmm_loglik) -add_markdown_docs(hmm_loglik "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(hmm_loglik "cli;python;julia;go;r" "misc. / other") add_cli_executable(hmm_viterbi) add_python_binding(hmm_viterbi) add_julia_binding(hmm_viterbi) add_go_binding(hmm_viterbi) add_r_binding(hmm_viterbi) -add_markdown_docs(hmm_viterbi "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(hmm_viterbi "cli;python;julia;go;r" "misc. / other") add_cli_executable(hmm_generate) add_python_binding(hmm_generate) add_julia_binding(hmm_generate) add_go_binding(hmm_generate) add_r_binding(hmm_generate) -add_markdown_docs(hmm_generate "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(hmm_generate "cli;python;julia;go;r" "misc. / other") diff --git a/src/mlpack/methods/hoeffding_trees/CMakeLists.txt b/src/mlpack/methods/hoeffding_trees/CMakeLists.txt index 72eae04729..cd679cc55e 100644 --- a/src/mlpack/methods/hoeffding_trees/CMakeLists.txt +++ b/src/mlpack/methods/hoeffding_trees/CMakeLists.txt @@ -33,4 +33,4 @@ add_python_binding(hoeffding_tree) add_julia_binding(hoeffding_tree) add_go_binding(hoeffding_tree) add_r_binding(hoeffding_tree) -add_markdown_docs(hoeffding_tree "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(hoeffding_tree "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/kde/CMakeLists.txt b/src/mlpack/methods/kde/CMakeLists.txt index 70ea42284e..31dacaee43 100644 --- a/src/mlpack/methods/kde/CMakeLists.txt +++ b/src/mlpack/methods/kde/CMakeLists.txt @@ -24,4 +24,4 @@ add_python_binding(kde) add_julia_binding(kde) add_go_binding(kde) add_r_binding(kde) -add_markdown_docs(kde "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(kde "cli;python;julia;go;r" "misc. / other") diff --git a/src/mlpack/methods/kernel_pca/CMakeLists.txt b/src/mlpack/methods/kernel_pca/CMakeLists.txt index 89d69f28c8..61d49b5a26 100644 --- a/src/mlpack/methods/kernel_pca/CMakeLists.txt +++ b/src/mlpack/methods/kernel_pca/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(kernel_pca) add_julia_binding(kernel_pca) add_go_binding(kernel_pca) add_r_binding(kernel_pca) -add_markdown_docs(kernel_pca "cli;python;julia;go;r-binding" "transformations") +add_markdown_docs(kernel_pca "cli;python;julia;go;r" "transformations") diff --git a/src/mlpack/methods/kmeans/CMakeLists.txt b/src/mlpack/methods/kmeans/CMakeLists.txt index 7aa94b7b69..1dbbbba626 100644 --- a/src/mlpack/methods/kmeans/CMakeLists.txt +++ b/src/mlpack/methods/kmeans/CMakeLists.txt @@ -43,4 +43,4 @@ add_python_binding(kmeans) add_julia_binding(kmeans) add_go_binding(kmeans) add_r_binding(kmeans) -add_markdown_docs(kmeans "cli;python;julia;go;r-binding" "clustering") +add_markdown_docs(kmeans "cli;python;julia;go;r" "clustering") diff --git a/src/mlpack/methods/lars/CMakeLists.txt b/src/mlpack/methods/lars/CMakeLists.txt index aa8a19c605..df7d973cde 100644 --- a/src/mlpack/methods/lars/CMakeLists.txt +++ b/src/mlpack/methods/lars/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(lars) add_julia_binding(lars) add_go_binding(lars) add_r_binding(lars) -add_markdown_docs(lars "cli;python;julia;go;r-binding" "regression") +add_markdown_docs(lars "cli;python;julia;go;r" "regression") diff --git a/src/mlpack/methods/linear_regression/CMakeLists.txt b/src/mlpack/methods/linear_regression/CMakeLists.txt index 2f4ce7035a..bfb2bdb25b 100644 --- a/src/mlpack/methods/linear_regression/CMakeLists.txt +++ b/src/mlpack/methods/linear_regression/CMakeLists.txt @@ -20,4 +20,4 @@ add_python_binding(linear_regression) add_julia_binding(linear_regression) add_go_binding(linear_regression) add_r_binding(linear_regression) -add_markdown_docs(linear_regression "cli;python;julia;go;r-binding" "regression") +add_markdown_docs(linear_regression "cli;python;julia;go;r" "regression") diff --git a/src/mlpack/methods/linear_svm/CMakeLists.txt b/src/mlpack/methods/linear_svm/CMakeLists.txt index c5347000ca..937cad9c5f 100644 --- a/src/mlpack/methods/linear_svm/CMakeLists.txt +++ b/src/mlpack/methods/linear_svm/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(linear_svm) add_go_binding(linear_svm) add_julia_binding(linear_svm) add_r_binding(linear_svm) -add_markdown_docs(linear_svm "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(linear_svm "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/lmnn/CMakeLists.txt b/src/mlpack/methods/lmnn/CMakeLists.txt index f314f6fd01..f383a49657 100644 --- a/src/mlpack/methods/lmnn/CMakeLists.txt +++ b/src/mlpack/methods/lmnn/CMakeLists.txt @@ -23,4 +23,4 @@ add_python_binding(lmnn) add_julia_binding(lmnn) add_go_binding(lmnn) add_r_binding(lmnn) -add_markdown_docs(lmnn "cli;python;julia;go;r-binding" "transformations") +add_markdown_docs(lmnn "cli;python;julia;go;r" "transformations") diff --git a/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt b/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt index b9e0759f46..dd5124bb37 100644 --- a/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt +++ b/src/mlpack/methods/local_coordinate_coding/CMakeLists.txt @@ -23,4 +23,4 @@ add_python_binding(local_coordinate_coding) add_julia_binding(local_coordinate_coding) add_go_binding(local_coordinate_coding) add_r_binding(local_coordinate_coding) -add_markdown_docs(local_coordinate_coding "cli;python;julia;go;r-binding" "transformations") +add_markdown_docs(local_coordinate_coding "cli;python;julia;go;r" "transformations") diff --git a/src/mlpack/methods/logistic_regression/CMakeLists.txt b/src/mlpack/methods/logistic_regression/CMakeLists.txt index c33029aaba..f5a00bccc6 100644 --- a/src/mlpack/methods/logistic_regression/CMakeLists.txt +++ b/src/mlpack/methods/logistic_regression/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(logistic_regression) add_julia_binding(logistic_regression) add_go_binding(logistic_regression) add_r_binding(logistic_regression) -add_markdown_docs(logistic_regression "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(logistic_regression "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/lsh/CMakeLists.txt b/src/mlpack/methods/lsh/CMakeLists.txt index 55201564e9..79fa17b44e 100644 --- a/src/mlpack/methods/lsh/CMakeLists.txt +++ b/src/mlpack/methods/lsh/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(lsh) add_julia_binding(lsh) add_go_binding(lsh) add_r_binding(lsh) -add_markdown_docs(lsh "cli;python;julia;go;r-binding" "geometry") +add_markdown_docs(lsh "cli;python;julia;go;r" "geometry") diff --git a/src/mlpack/methods/mean_shift/CMakeLists.txt b/src/mlpack/methods/mean_shift/CMakeLists.txt index b0b6918065..2ad5033520 100644 --- a/src/mlpack/methods/mean_shift/CMakeLists.txt +++ b/src/mlpack/methods/mean_shift/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(mean_shift) add_julia_binding(mean_shift) add_go_binding(mean_shift) add_r_binding(mean_shift) -add_markdown_docs(mean_shift "cli;python;julia;go;r-binding" "clustering") +add_markdown_docs(mean_shift "cli;python;julia;go;r" "clustering") diff --git a/src/mlpack/methods/naive_bayes/CMakeLists.txt b/src/mlpack/methods/naive_bayes/CMakeLists.txt index 2fb0f94f46..85ab2beb5e 100644 --- a/src/mlpack/methods/naive_bayes/CMakeLists.txt +++ b/src/mlpack/methods/naive_bayes/CMakeLists.txt @@ -19,4 +19,4 @@ add_python_binding(nbc) add_julia_binding(nbc) add_go_binding(nbc) add_r_binding(nbc) -add_markdown_docs(nbc "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(nbc "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/nca/CMakeLists.txt b/src/mlpack/methods/nca/CMakeLists.txt index dec0d5a8a4..e956d76a6a 100644 --- a/src/mlpack/methods/nca/CMakeLists.txt +++ b/src/mlpack/methods/nca/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(nca) add_julia_binding(nca) add_go_binding(nca) add_r_binding(nca) -add_markdown_docs(nca "cli;python;julia;go;r-binding" "transformations") +add_markdown_docs(nca "cli;python;julia;go;r" "transformations") diff --git a/src/mlpack/methods/neighbor_search/CMakeLists.txt b/src/mlpack/methods/neighbor_search/CMakeLists.txt index 46c64ef231..ce24ba085f 100644 --- a/src/mlpack/methods/neighbor_search/CMakeLists.txt +++ b/src/mlpack/methods/neighbor_search/CMakeLists.txt @@ -32,11 +32,11 @@ add_python_binding(knn) add_julia_binding(knn) add_go_binding(knn) add_r_binding(knn) -add_markdown_docs(knn "cli;python;julia;go;r-binding" "geometry") +add_markdown_docs(knn "cli;python;julia;go;r" "geometry") add_cli_executable(kfn) add_python_binding(kfn) add_julia_binding(kfn) add_go_binding(kfn) add_r_binding(kfn) -add_markdown_docs(kfn "cli;python;julia;go;r-binding" "geometry") +add_markdown_docs(kfn "cli;python;julia;go;r" "geometry") diff --git a/src/mlpack/methods/nmf/CMakeLists.txt b/src/mlpack/methods/nmf/CMakeLists.txt index b4cc17340b..7f93ae3502 100644 --- a/src/mlpack/methods/nmf/CMakeLists.txt +++ b/src/mlpack/methods/nmf/CMakeLists.txt @@ -3,4 +3,4 @@ add_python_binding(nmf) add_julia_binding(nmf) add_go_binding(nmf) add_r_binding(nmf) -add_markdown_docs(nmf "cli;python;julia;go;r-binding" "misc. / other") +add_markdown_docs(nmf "cli;python;julia;go;r" "misc. / other") diff --git a/src/mlpack/methods/pca/CMakeLists.txt b/src/mlpack/methods/pca/CMakeLists.txt index 9d17936ac9..6ed7d726d8 100644 --- a/src/mlpack/methods/pca/CMakeLists.txt +++ b/src/mlpack/methods/pca/CMakeLists.txt @@ -21,4 +21,4 @@ add_python_binding(pca) add_julia_binding(pca) add_go_binding(pca) add_r_binding(pca) -add_markdown_docs(pca "cli;python;julia;go;r-binding" "transformations") +add_markdown_docs(pca "cli;python;julia;go;r" "transformations") diff --git a/src/mlpack/methods/perceptron/CMakeLists.txt b/src/mlpack/methods/perceptron/CMakeLists.txt index 2124b9c77c..1315d08608 100644 --- a/src/mlpack/methods/perceptron/CMakeLists.txt +++ b/src/mlpack/methods/perceptron/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(perceptron) add_julia_binding(perceptron) add_go_binding(perceptron) add_r_binding(perceptron) -add_markdown_docs(perceptron "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(perceptron "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/preprocess/CMakeLists.txt b/src/mlpack/methods/preprocess/CMakeLists.txt index 83ebd72d83..4dfdc06810 100644 --- a/src/mlpack/methods/preprocess/CMakeLists.txt +++ b/src/mlpack/methods/preprocess/CMakeLists.txt @@ -21,21 +21,21 @@ add_python_binding(preprocess_split) add_julia_binding(preprocess_split) add_go_binding(preprocess_split) add_r_binding(preprocess_split) -add_markdown_docs(preprocess_split "cli;python;julia;go;r-binding" "preprocessing") +add_markdown_docs(preprocess_split "cli;python;julia;go;r" "preprocessing") add_cli_executable(preprocess_binarize) add_python_binding(preprocess_binarize) add_julia_binding(preprocess_binarize) add_go_binding(preprocess_binarize) add_r_binding(preprocess_binarize) -add_markdown_docs(preprocess_binarize "cli;python;julia;go;r-binding" "preprocessing") +add_markdown_docs(preprocess_binarize "cli;python;julia;go;r" "preprocessing") add_cli_executable(preprocess_describe) add_python_binding(preprocess_describe) add_julia_binding(preprocess_describe) add_go_binding(preprocess_describe) add_r_binding(preprocess_describe) -add_markdown_docs(preprocess_describe "cli;python;julia;go;r-binding" "preprocessing") +add_markdown_docs(preprocess_describe "cli;python;julia;go;r" "preprocessing") #add_cli_executable(preprocess_scan) @@ -51,14 +51,14 @@ add_python_binding(preprocess_scale) add_go_binding(preprocess_scale) add_julia_binding(preprocess_scale) add_r_binding(preprocess_scale) -add_markdown_docs(preprocess_scale "cli;python;julia;go;r-binding" "preprocessing") +add_markdown_docs(preprocess_scale "cli;python;julia;go;r" "preprocessing") add_cli_executable(preprocess_one_hot_encoding) add_python_binding(preprocess_one_hot_encoding) add_go_binding(preprocess_one_hot_encoding) add_julia_binding(preprocess_one_hot_encoding) add_r_binding(preprocess_one_hot_encoding) -add_markdown_docs(preprocess_one_hot_encoding "cli;python;julia;go;r-binding" +add_markdown_docs(preprocess_one_hot_encoding "cli;python;julia;go;r" "preprocessing") if (STB_AVAILABLE) @@ -67,5 +67,5 @@ if (STB_AVAILABLE) add_julia_binding(image_converter) add_go_binding(image_converter) add_r_binding(image_converter) - add_markdown_docs(image_converter "cli;python;julia;go;r-binding" "preprocessing") + add_markdown_docs(image_converter "cli;python;julia;go;r" "preprocessing") endif () diff --git a/src/mlpack/methods/radical/CMakeLists.txt b/src/mlpack/methods/radical/CMakeLists.txt index 3458fce5f0..723f61e158 100644 --- a/src/mlpack/methods/radical/CMakeLists.txt +++ b/src/mlpack/methods/radical/CMakeLists.txt @@ -18,4 +18,4 @@ add_python_binding(radical) add_julia_binding(radical) add_go_binding(radical) add_r_binding(radical) -add_markdown_docs(radical "cli;python;julia;go;r-binding" "transformations") +add_markdown_docs(radical "cli;python;julia;go;r" "transformations") diff --git a/src/mlpack/methods/random_forest/CMakeLists.txt b/src/mlpack/methods/random_forest/CMakeLists.txt index 19cc6bb05f..4be75d3761 100644 --- a/src/mlpack/methods/random_forest/CMakeLists.txt +++ b/src/mlpack/methods/random_forest/CMakeLists.txt @@ -20,4 +20,4 @@ add_python_binding(random_forest) add_julia_binding(random_forest) add_go_binding(random_forest) add_r_binding(random_forest) -add_markdown_docs(random_forest "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(random_forest "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/rann/CMakeLists.txt b/src/mlpack/methods/rann/CMakeLists.txt index 8678e10052..99e838b459 100644 --- a/src/mlpack/methods/rann/CMakeLists.txt +++ b/src/mlpack/methods/rann/CMakeLists.txt @@ -40,4 +40,4 @@ add_python_binding(krann) add_julia_binding(krann) add_go_binding(krann) add_r_binding(krann) -add_markdown_docs(krann "cli;python;julia;go;r-binding" "geometry") +add_markdown_docs(krann "cli;python;julia;go;r" "geometry") diff --git a/src/mlpack/methods/softmax_regression/CMakeLists.txt b/src/mlpack/methods/softmax_regression/CMakeLists.txt index 3be5b25724..d245fa4547 100644 --- a/src/mlpack/methods/softmax_regression/CMakeLists.txt +++ b/src/mlpack/methods/softmax_regression/CMakeLists.txt @@ -22,4 +22,4 @@ add_python_binding(softmax_regression) add_julia_binding(softmax_regression) add_go_binding(softmax_regression) add_r_binding(softmax_regression) -add_markdown_docs(softmax_regression "cli;python;julia;go;r-binding" "classification") +add_markdown_docs(softmax_regression "cli;python;julia;go;r" "classification") diff --git a/src/mlpack/methods/sparse_coding/CMakeLists.txt b/src/mlpack/methods/sparse_coding/CMakeLists.txt index 3d5ee4f61f..45b627bcc0 100644 --- a/src/mlpack/methods/sparse_coding/CMakeLists.txt +++ b/src/mlpack/methods/sparse_coding/CMakeLists.txt @@ -23,4 +23,4 @@ add_python_binding(sparse_coding) add_julia_binding(sparse_coding) add_go_binding(sparse_coding) add_r_binding(sparse_coding) -add_markdown_docs(sparse_coding "cli;python;julia;go;r-binding" "transformations") +add_markdown_docs(sparse_coding "cli;python;julia;go;r" "transformations")