diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index 54fee13a21..88f79f477e 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -5,12 +5,10 @@ add_executable(mlpack_test callback_test.cpp cf_test.cpp cosine_tree_test.cpp - dcgan_test.cpp drusilla_select_test.cpp emst_test.cpp fastmks_test.cpp facilities_test.cpp - gan_test.cpp gmm_test.cpp hmm_test.cpp hoeffding_tree_test.cpp @@ -26,7 +24,6 @@ add_executable(mlpack_test log_test.cpp logistic_regression_test.cpp lsh_test.cpp - math_test.cpp matrix_completion_test.cpp maximal_inputs_test.cpp mlpack_test.cpp @@ -59,7 +56,6 @@ add_executable(mlpack_test ub_tree_test.cpp union_find_test.cpp vantage_point_tree_test.cpp - wgan_test.cpp main_tests/cf_test.cpp main_tests/det_test.cpp main_tests/emst_test.cpp @@ -108,11 +104,13 @@ add_executable(mlpack_catch_test convolution_test.cpp cv_test.cpp dbscan_test.cpp + dcgan_test.cpp decision_stump_test.cpp decision_tree_test.cpp det_test.cpp distribution_test.cpp feedforward_network_test.cpp + gan_test.cpp image_load_test.cpp imputation_test.cpp io_test.cpp @@ -129,6 +127,7 @@ add_executable(mlpack_catch_test load_save_test.cpp loss_functions_test.cpp main.cpp + math_test.cpp metric_test.cpp mean_shift_test.cpp nca_test.cpp @@ -155,6 +154,7 @@ add_executable(mlpack_catch_test svd_incremental_test.cpp svdplusplus_test.cpp test_catch_tools.hpp + wgan_test.cpp main_tests/adaboost_test.cpp main_tests/approx_kfn_test.cpp main_tests/bayesian_linear_regression_test.cpp diff --git a/src/mlpack/tests/dcgan_test.cpp b/src/mlpack/tests/dcgan_test.cpp index 0f6e016600..0cab7d9654 100644 --- a/src/mlpack/tests/dcgan_test.cpp +++ b/src/mlpack/tests/dcgan_test.cpp @@ -20,8 +20,7 @@ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" #include "serialization.hpp" using namespace mlpack; @@ -30,14 +29,12 @@ using namespace mlpack::math; using namespace mlpack::regression; using namespace std::placeholders; -BOOST_AUTO_TEST_SUITE(DCGANNetworkTest); - /* * Tests the DCGAN implementation on the MNIST dataset. * It's not viable to train on bigger parameters due to time constraints. * Please refer mlpack/models repository for the tutorial. */ -BOOST_AUTO_TEST_CASE(DCGANMNISTTest) +TEST_CASE("DCGANMNISTTest", "[DCGANNetworkTest]") { size_t dNumKernels = 32; size_t discriminatorPreTrain = 5; @@ -129,7 +126,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) double objVal = dcgan.Train(trainData, optimizer); // Test that objective value returned by GAN::Train() is finite. - BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); + REQUIRE(std::isfinite(objVal) == true); // Generate samples. Log::Info << "Sampling..." << std::endl; @@ -196,7 +193,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) * Tests the DCGAN implementation with minibatch layer on the MNIST dataset. * It's not viable to train on bigger parameters due to time constraints. -BOOST_AUTO_TEST_CASE(DCGANMNISTTest) +TEST_CASE("DCGANMNISTTest", "[DCGANNetworkTest]") { size_t dNumKernels = 32; size_t discriminatorPreTrain = 5; @@ -284,7 +281,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) double objVal = dcgan.Train(optimizer); // Test that objective value returned by GAN::Train() is finite. - BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); + REQUIRE(std::isfinite(objVal) == true); // Generate samples Log::Info << "Sampling..." << std::endl; @@ -350,7 +347,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) * It's currently not possible to run this every time due to time constraints. * Please refer mlpack/models repository for the tutorial. -BOOST_AUTO_TEST_CASE(DCGANCelebATest) +TEST_CASE("DCGANCelebATest", "[DCGANNetworkTest]") { size_t dNumKernels = 64; size_t discriminatorPreTrain = 300; @@ -470,5 +467,3 @@ BOOST_AUTO_TEST_CASE(DCGANCelebATest) Log::Info << "Output generated!" << std::endl; } */ - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/gan_test.cpp b/src/mlpack/tests/gan_test.cpp index c5ed9f7dff..53a74ae4d2 100644 --- a/src/mlpack/tests/gan_test.cpp +++ b/src/mlpack/tests/gan_test.cpp @@ -20,8 +20,7 @@ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" #include "serialization.hpp" using namespace mlpack; @@ -30,14 +29,12 @@ using namespace mlpack::math; using namespace mlpack::regression; using namespace std::placeholders; -BOOST_AUTO_TEST_SUITE(GANNetworkTest); - /* * Load pre trained network values * for generating distribution that * is close to N(4, 0.5) */ -BOOST_AUTO_TEST_CASE(GANTest) +TEST_CASE("GANTest", "[GANNetworkTest]") { size_t generatorHiddenLayerSize = 8; size_t discriminatorHiddenLayerSize = 8; @@ -125,8 +122,8 @@ BOOST_AUTO_TEST_CASE(GANTest) double originalStd = arma::as_scalar(arma::stddev( generatedData.rows(dim, 2 * dim - 1), 0, 1)); - BOOST_REQUIRE_LE(generatedMean - originalMean, 0.2); - BOOST_REQUIRE_LE(generatedStd - originalStd, 0.2); + REQUIRE(generatedMean - originalMean <= 0.2); + REQUIRE(generatedStd - originalStd <= 0.2); } /* @@ -134,7 +131,7 @@ BOOST_AUTO_TEST_CASE(GANTest) * It's not viable to train on bigger parameters due to time constraints. * Please refer mlpack/models repository for the tutorial. */ -BOOST_AUTO_TEST_CASE(GANMNISTTest) +TEST_CASE("GANMNISTTest", "[GANNetworkTest]") { size_t dNumKernels = 32; size_t discriminatorPreTrain = 5; @@ -217,8 +214,8 @@ BOOST_AUTO_TEST_CASE(GANMNISTTest) Log::Info << "Training..." << std::endl; std::stringstream stream; double objVal = gan.Train(trainData, optimizer, ens::ProgressBar(70, stream)); - BOOST_REQUIRE_GT(stream.str().length(), 0); - BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); + REQUIRE(stream.str().length() > 0); + REQUIRE(std::isfinite(objVal) == true); // Generate samples. Log::Info << "Sampling..." << std::endl; @@ -284,7 +281,7 @@ BOOST_AUTO_TEST_CASE(GANMNISTTest) * Create GAN network and test for memory sharing * between discriminator and gan predictors. */ -BOOST_AUTO_TEST_CASE(GANMemorySharingTest) +TEST_CASE("GANMemorySharingTest", "[GANNetworkTest]") { size_t generatorHiddenLayerSize = 8; size_t discriminatorHiddenLayerSize = 8; @@ -347,5 +344,3 @@ BOOST_AUTO_TEST_CASE(GANMemorySharingTest) CheckMatricesNotEqual(gan.Predictors().head_cols(trainData.n_cols), trainData); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/math_test.cpp b/src/mlpack/tests/math_test.cpp index 93375572ce..e5681a8f03 100644 --- a/src/mlpack/tests/math_test.cpp +++ b/src/mlpack/tests/math_test.cpp @@ -12,94 +12,91 @@ #include #include #include -#include -#include "test_tools.hpp" +#include "catch.hpp" using namespace mlpack; using namespace math; -BOOST_AUTO_TEST_SUITE(MathTest); - /** * Verify that the empty constructor creates an empty range. */ -BOOST_AUTO_TEST_CASE(RangeEmptyConstructor) +TEST_CASE("RangeEmptyConstructor", "[MathTest]") { Range x = Range(); // Just verify that it is empty. - BOOST_REQUIRE_GT(x.Lo(), x.Hi()); + REQUIRE(x.Lo() > x.Hi()); } /** * Verify that the point constructor correctly creates a range that is just a * point. */ -BOOST_AUTO_TEST_CASE(RangePointConstructor) +TEST_CASE("RangePointConstructor", "[MathTest]") { Range x(10.0); - BOOST_REQUIRE_CLOSE(x.Lo(), x.Hi(), 1e-25); - BOOST_REQUIRE_SMALL(x.Width(), 1e-5); - BOOST_REQUIRE_CLOSE(x.Lo(), 10.0, 1e-25); - BOOST_REQUIRE_CLOSE(x.Hi(), 10.0, 1e-25); + REQUIRE(x.Lo() == Approx(x.Hi()).epsilon(1e-27)); + REQUIRE(x.Width() == Approx(0.0).margin(1e-5)); + REQUIRE(x.Lo() == Approx(10.0).epsilon(1e-27)); + REQUIRE(x.Hi() == Approx(10.0).epsilon(1e-27)); } /** * Verify that the range constructor correctly creates the range. */ -BOOST_AUTO_TEST_CASE(RangeConstructor) +TEST_CASE("RangeConstructor", "[MathTest]") { Range x(0.5, 5.5); - BOOST_REQUIRE_CLOSE(x.Lo(), 0.5, 1e-25); - BOOST_REQUIRE_CLOSE(x.Hi(), 5.5, 1e-25); + REQUIRE(x.Lo() == Approx(0.5).epsilon(1e-27)); + REQUIRE(x.Hi() == Approx(5.5).epsilon(1e-27)); } /** * Test that we get the width correct. */ -BOOST_AUTO_TEST_CASE(RangeWidth) +TEST_CASE("RangeWidth", "[MathTest]") { Range x(0.0, 10.0); - BOOST_REQUIRE_CLOSE(x.Width(), 10.0, 1e-20); + REQUIRE(x.Width() == Approx(10.0).epsilon(1e-22)); // Make it empty. x.Hi() = 0.0; - BOOST_REQUIRE_SMALL(x.Width(), 1e-5); + REQUIRE(x.Width() == Approx(0.0).margin(1e-5)); // Make it negative. x.Hi() = -2.0; - BOOST_REQUIRE_SMALL(x.Width(), 1e-5); + REQUIRE(x.Width() == Approx(0.0).margin(1e-5)); // Just one more test. x.Lo() = -5.2; x.Hi() = 5.2; - BOOST_REQUIRE_CLOSE(x.Width(), 10.4, 1e-5); + REQUIRE(x.Width() == Approx(10.4).epsilon(1e-7)); } /** * Test that we get the midpoint correct. */ -BOOST_AUTO_TEST_CASE(RangeMidpoint) +TEST_CASE("RangeMidpoint", "[MathTest]") { Range x(0.0, 10.0); - BOOST_REQUIRE_CLOSE(x.Mid(), 5.0, 1e-5); + REQUIRE(x.Mid() == Approx(5.0).epsilon(1e-7)); x.Lo() = -5.0; - BOOST_REQUIRE_CLOSE(x.Mid(), 2.5, 1e-5); + REQUIRE(x.Mid() == Approx(2.5).epsilon(1e-7)); } /** * Test that we can expand to include other ranges correctly. */ -BOOST_AUTO_TEST_CASE(RangeIncludeOther) +TEST_CASE("RangeIncludeOther", "[MathTest]") { // We need to test both |= and |. // We have three cases: non-overlapping; overlapping; equivalent, and then a @@ -112,20 +109,20 @@ BOOST_AUTO_TEST_CASE(RangeIncludeOther) z |= y; w = x | y; - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 5.0, 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 5.0, 1e-5); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(5.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(5.0).epsilon(1e-7)); // Switch operator precedence. z = y; z |= x; w = y | x; - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 5.0, 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 5.0, 1e-5); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(5.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(5.0).epsilon(1e-7)); // Now make them overlapping. x = Range(0.0, 3.5); @@ -135,20 +132,20 @@ BOOST_AUTO_TEST_CASE(RangeIncludeOther) z |= y; w = x | y; - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 4.0, 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 4.0, 1e-5); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(4.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(4.0).epsilon(1e-7)); // Switch operator precedence. z = y; z |= x; w = y | x; - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 4.0, 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 4.0, 1e-5); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(4.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(4.0).epsilon(1e-7)); // Now the equivalent case. x = Range(0.0, 2.0); @@ -158,25 +155,25 @@ BOOST_AUTO_TEST_CASE(RangeIncludeOther) z |= y; w = x | y; - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 2.0, 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 2.0, 1e-5); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(2.0).epsilon(1e-7)); z = y; z |= x; w = y | x; - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 2.0, 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 2.0, 1e-5); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(2.0).epsilon(1e-7)); } /** * Test that we can 'and' ranges correctly. */ -BOOST_AUTO_TEST_CASE(RangeIntersectOther) +TEST_CASE("RangeIntersectOther", "[MathTest]") { // We need to test both &= and &. // We have three cases: non-overlapping, overlapping; equivalent, and then a @@ -189,16 +186,16 @@ BOOST_AUTO_TEST_CASE(RangeIntersectOther) z &= y; w = x & y; - BOOST_REQUIRE_SMALL(z.Width(), 1e-5); - BOOST_REQUIRE_SMALL(w.Width(), 1e-5); + REQUIRE(z.Width() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Width() == Approx(0.0).margin(1e-5)); // Reverse operator precedence. z = y; z &= x; w = y & x; - BOOST_REQUIRE_SMALL(z.Width(), 1e-5); - BOOST_REQUIRE_SMALL(w.Width(), 1e-5); + REQUIRE(z.Width() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Width() == Approx(0.0).margin(1e-5)); // Now make them overlapping. x = Range(0.0, 3.5); @@ -208,20 +205,20 @@ BOOST_AUTO_TEST_CASE(RangeIntersectOther) z &= y; w = x & y; - BOOST_REQUIRE_CLOSE(z.Lo(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 3.5, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 3.5, 1e-5); + REQUIRE(z.Lo() == Approx(3.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(3.5).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(3.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(3.5).epsilon(1e-7)); // Reverse operator precedence. z = y; z &= x; w = y & x; - BOOST_REQUIRE_CLOSE(z.Lo(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 3.5, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 3.5, 1e-5); + REQUIRE(z.Lo() == Approx(3.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(3.5).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(3.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(3.5).epsilon(1e-7)); // Now make them equivalent. x = Range(2.0, 4.0); @@ -231,16 +228,16 @@ BOOST_AUTO_TEST_CASE(RangeIntersectOther) z &= y; w = x & y; - BOOST_REQUIRE_CLOSE(z.Lo(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 4.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 4.0, 1e-5); + REQUIRE(z.Lo() == Approx(2.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(4.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(2.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(4.0).epsilon(1e-7)); } /** * Test multiplication of a range with a double. */ -BOOST_AUTO_TEST_CASE(RangeMultiply) +TEST_CASE("RangeMultiply", "[MathTest]") { // We need to test both * and *=, as well as both cases of *. // We'll try with a couple of numbers: -1, 0, 2. @@ -257,36 +254,36 @@ BOOST_AUTO_TEST_CASE(RangeMultiply) z = x * -1.0; w = -1.0 * x; - BOOST_REQUIRE_CLOSE(y.Lo(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(y.Hi(), 5.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Lo(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 5.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), 3.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 5.0, 1e-5); + REQUIRE(y.Lo() == Approx(3.0).epsilon(1e-7)); + REQUIRE(y.Hi() == Approx(5.0).epsilon(1e-7)); + REQUIRE(z.Lo() == Approx(3.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(5.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(3.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(5.0).epsilon(1e-7)); y = x; y *= 0.0; z = x * 0.0; w = 0.0 * x; - BOOST_REQUIRE_SMALL(y.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(y.Hi(), 1e-5); - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(z.Hi(), 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(w.Hi(), 1e-5); + REQUIRE(y.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(y.Hi() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(0.0).margin(1e-5)); y = x; y *= 2.0; z = x * 2.0; w = 2.0 * x; - BOOST_REQUIRE_CLOSE(y.Lo(), -10.0, 1e-5); - BOOST_REQUIRE_CLOSE(y.Hi(), -6.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Lo(), -10.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), -6.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), -10.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), -6.0, 1e-5); + REQUIRE(y.Lo() == Approx(-10.0).epsilon(1e-7)); + REQUIRE(y.Hi() == Approx(-6.0).epsilon(1e-7)); + REQUIRE(z.Lo() == Approx(-10.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(-6.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(-10.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(-6.0).epsilon(1e-7)); x = Range(-2.0, 2.0); y = x; @@ -295,36 +292,36 @@ BOOST_AUTO_TEST_CASE(RangeMultiply) z = x * -1.0; w = -1.0 * x; - BOOST_REQUIRE_CLOSE(y.Lo(), -2.0, 1e-5); - BOOST_REQUIRE_CLOSE(y.Hi(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Lo(), -2.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 2.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), -2.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 2.0, 1e-5); + REQUIRE(y.Lo() == Approx(-2.0).epsilon(1e-7)); + REQUIRE(y.Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(z.Lo() == Approx(-2.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(2.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(-2.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(2.0).epsilon(1e-7)); y = x; y *= 0.0; z = x * 0.0; w = 0.0 * x; - BOOST_REQUIRE_SMALL(y.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(y.Hi(), 1e-5); - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(z.Hi(), 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(w.Hi(), 1e-5); + REQUIRE(y.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(y.Hi() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(0.0).margin(1e-5)); y = x; y *= 2.0; z = x * 2.0; w = 2.0 * x; - BOOST_REQUIRE_CLOSE(y.Lo(), -4.0, 1e-5); - BOOST_REQUIRE_CLOSE(y.Hi(), 4.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Lo(), -4.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 4.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), -4.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 4.0, 1e-5); + REQUIRE(y.Lo() == Approx(-4.0).epsilon(1e-7)); + REQUIRE(y.Hi() == Approx(4.0).epsilon(1e-7)); + REQUIRE(z.Lo() == Approx(-4.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(4.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(-4.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(4.0).epsilon(1e-7)); x = Range(3.0, 5.0); @@ -333,42 +330,42 @@ BOOST_AUTO_TEST_CASE(RangeMultiply) z = x * -1.0; w = -1.0 * x; - BOOST_REQUIRE_CLOSE(y.Lo(), -5.0, 1e-5); - BOOST_REQUIRE_CLOSE(y.Hi(), -3.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Lo(), -5.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), -3.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), -5.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), -3.0, 1e-5); + REQUIRE(y.Lo() == Approx(-5.0).epsilon(1e-7)); + REQUIRE(y.Hi() == Approx(-3.0).epsilon(1e-7)); + REQUIRE(z.Lo() == Approx(-5.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(-3.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(-5.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(-3.0).epsilon(1e-7)); y = x; y *= 0.0; z = x * 0.0; w = 0.0 * x; - BOOST_REQUIRE_SMALL(y.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(y.Hi(), 1e-5); - BOOST_REQUIRE_SMALL(z.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(z.Hi(), 1e-5); - BOOST_REQUIRE_SMALL(w.Lo(), 1e-5); - BOOST_REQUIRE_SMALL(w.Hi(), 1e-5); + REQUIRE(y.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(y.Hi() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(z.Hi() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Lo() == Approx(0.0).margin(1e-5)); + REQUIRE(w.Hi() == Approx(0.0).margin(1e-5)); y = x; y *= 2.0; z = x * 2.0; w = 2.0 * x; - BOOST_REQUIRE_CLOSE(y.Lo(), 6.0, 1e-5); - BOOST_REQUIRE_CLOSE(y.Hi(), 10.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Lo(), 6.0, 1e-5); - BOOST_REQUIRE_CLOSE(z.Hi(), 10.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Lo(), 6.0, 1e-5); - BOOST_REQUIRE_CLOSE(w.Hi(), 10.0, 1e-5); + REQUIRE(y.Lo() == Approx(6.0).epsilon(1e-7)); + REQUIRE(y.Hi() == Approx(10.0).epsilon(1e-7)); + REQUIRE(z.Lo() == Approx(6.0).epsilon(1e-7)); + REQUIRE(z.Hi() == Approx(10.0).epsilon(1e-7)); + REQUIRE(w.Lo() == Approx(6.0).epsilon(1e-7)); + REQUIRE(w.Hi() == Approx(10.0).epsilon(1e-7)); } /** * Test equality operator. */ -BOOST_AUTO_TEST_CASE(RangeEquality) +TEST_CASE("RangeEquality", "[MathTest]") { // Three cases: non-overlapping, overlapping, equivalent. We should also // consider empty ranges, which are not necessarily equal... @@ -376,24 +373,24 @@ BOOST_AUTO_TEST_CASE(RangeEquality) Range y(3.0, 5.0); // These are odd calls, but we don't want to use operator!= here. - BOOST_REQUIRE_EQUAL((x == y), false); - BOOST_REQUIRE_EQUAL((y == x), false); + REQUIRE((x == y) == false); + REQUIRE((y == x) == false); y = Range(1.0, 3.0); - BOOST_REQUIRE_EQUAL((x == y), false); - BOOST_REQUIRE_EQUAL((y == x), false); + REQUIRE((x == y) == false); + REQUIRE((y == x) == false); y = Range(0.0, 2.0); - BOOST_REQUIRE_EQUAL((x == y), true); - BOOST_REQUIRE_EQUAL((y == x), true); + REQUIRE((x == y) == true); + REQUIRE((y == x) == true); x = Range(1.0, -1.0); // Empty. y = Range(1.0, -1.0); // Also empty. - BOOST_REQUIRE_EQUAL((x == y), true); - BOOST_REQUIRE_EQUAL((y == x), true); + REQUIRE((x == y) == true); + REQUIRE((y == x) == true); // No need to test what it does if the empty ranges are different "ranges" // because we are not forcing behavior for that. @@ -402,83 +399,83 @@ BOOST_AUTO_TEST_CASE(RangeEquality) /** * Test inequality operator. */ -BOOST_AUTO_TEST_CASE(RangeInequality) +TEST_CASE("RangeInequality", "[MathTest]") { // We will use the same three cases as the RangeEquality test. Range x(0.0, 2.0); Range y(3.0, 5.0); // Again, odd calls, but we want to force use of operator!=. - BOOST_REQUIRE_EQUAL((x != y), true); - BOOST_REQUIRE_EQUAL((y != x), true); + REQUIRE((x != y) == true); + REQUIRE((y != x) == true); y = Range(1.0, 3.0); - BOOST_REQUIRE_EQUAL((x != y), true); - BOOST_REQUIRE_EQUAL((y != x), true); + REQUIRE((x != y) == true); + REQUIRE((y != x) == true); y = Range(0.0, 2.0); - BOOST_REQUIRE_EQUAL((x != y), false); - BOOST_REQUIRE_EQUAL((y != x), false); + REQUIRE((x != y) == false); + REQUIRE((y != x) == false); x = Range(1.0, -1.0); // Empty. y = Range(1.0, -1.0); // Also empty. - BOOST_REQUIRE_EQUAL((x != y), false); - BOOST_REQUIRE_EQUAL((y != x), false); + REQUIRE((x != y) == false); + REQUIRE((y != x) == false); } /** * Test strict less-than operator. */ -BOOST_AUTO_TEST_CASE(RangeStrictLessThan) +TEST_CASE("RangeStrictLessThan", "[MathTest]") { // Three cases: non-overlapping, overlapping, and equivalent. Range x(0.0, 2.0); Range y(3.0, 5.0); - BOOST_REQUIRE_EQUAL((x < y), true); - BOOST_REQUIRE_EQUAL((y < x), false); + REQUIRE((x < y) == true); + REQUIRE((y < x) == false); y = Range(1.0, 3.0); - BOOST_REQUIRE_EQUAL((x < y), false); - BOOST_REQUIRE_EQUAL((y < x), false); + REQUIRE((x < y) == false); + REQUIRE((y < x) == false); y = Range(0.0, 2.0); - BOOST_REQUIRE_EQUAL((x < y), false); - BOOST_REQUIRE_EQUAL((y < x), false); + REQUIRE((x < y) == false); + REQUIRE((y < x) == false); } /** * Test strict greater-than operator. */ -BOOST_AUTO_TEST_CASE(RangeStrictGreaterThan) +TEST_CASE("RangeStrictGreaterThan", "[MathTest]") { // Three cases: non-overlapping, overlapping, and equivalent. Range x(0.0, 2.0); Range y(3.0, 5.0); - BOOST_REQUIRE_EQUAL((x > y), false); - BOOST_REQUIRE_EQUAL((y > x), true); + REQUIRE((x > y) == false); + REQUIRE((y > x) == true); y = Range(1.0, 3.0); - BOOST_REQUIRE_EQUAL((x > y), false); - BOOST_REQUIRE_EQUAL((y > x), false); + REQUIRE((x > y) == false); + REQUIRE((y > x) == false); y = Range(0.0, 2.0); - BOOST_REQUIRE_EQUAL((x > y), false); - BOOST_REQUIRE_EQUAL((y > x), false); + REQUIRE((x > y) == false); + REQUIRE((y > x) == false); } /** * Test the Contains() operator. */ -BOOST_AUTO_TEST_CASE(RangeContains) +TEST_CASE("RangeContains", "[MathTest]") { // We have three Range cases: strictly less than 0; overlapping 0; and // strictly greater than 0. Then the numbers we check can be the same three @@ -486,107 +483,107 @@ BOOST_AUTO_TEST_CASE(RangeContains) // be about 15 total cases. Range x(-2.0, -1.0); - BOOST_REQUIRE(!x.Contains(-3.0)); - BOOST_REQUIRE(x.Contains(-2.0)); - BOOST_REQUIRE(x.Contains(-1.5)); - BOOST_REQUIRE(x.Contains(-1.0)); - BOOST_REQUIRE(!x.Contains(-0.5)); - BOOST_REQUIRE(!x.Contains(0.0)); - BOOST_REQUIRE(!x.Contains(1.0)); + REQUIRE(!x.Contains(-3.0)); + REQUIRE(x.Contains(-2.0)); + REQUIRE(x.Contains(-1.5)); + REQUIRE(x.Contains(-1.0)); + REQUIRE(!x.Contains(-0.5)); + REQUIRE(!x.Contains(0.0)); + REQUIRE(!x.Contains(1.0)); x = Range(-1.0, 1.0); - BOOST_REQUIRE(!x.Contains(-2.0)); - BOOST_REQUIRE(x.Contains(-1.0)); - BOOST_REQUIRE(x.Contains(0.0)); - BOOST_REQUIRE(x.Contains(1.0)); - BOOST_REQUIRE(!x.Contains(2.0)); + REQUIRE(!x.Contains(-2.0)); + REQUIRE(x.Contains(-1.0)); + REQUIRE(x.Contains(0.0)); + REQUIRE(x.Contains(1.0)); + REQUIRE(!x.Contains(2.0)); x = Range(1.0, 2.0); - BOOST_REQUIRE(!x.Contains(-1.0)); - BOOST_REQUIRE(!x.Contains(0.0)); - BOOST_REQUIRE(!x.Contains(0.5)); - BOOST_REQUIRE(x.Contains(1.0)); - BOOST_REQUIRE(x.Contains(1.5)); - BOOST_REQUIRE(x.Contains(2.0)); - BOOST_REQUIRE(!x.Contains(2.5)); + REQUIRE(!x.Contains(-1.0)); + REQUIRE(!x.Contains(0.0)); + REQUIRE(!x.Contains(0.5)); + REQUIRE(x.Contains(1.0)); + REQUIRE(x.Contains(1.5)); + REQUIRE(x.Contains(2.0)); + REQUIRE(!x.Contains(2.5)); // Now let's try it on an empty range. x = Range(); - BOOST_REQUIRE(!x.Contains(-10.0)); - BOOST_REQUIRE(!x.Contains(0.0)); - BOOST_REQUIRE(!x.Contains(10.0)); + REQUIRE(!x.Contains(-10.0)); + REQUIRE(!x.Contains(0.0)); + REQUIRE(!x.Contains(10.0)); // And an infinite range. x = Range(-DBL_MAX, DBL_MAX); - BOOST_REQUIRE(x.Contains(-10.0)); - BOOST_REQUIRE(x.Contains(0.0)); - BOOST_REQUIRE(x.Contains(10.0)); + REQUIRE(x.Contains(-10.0)); + REQUIRE(x.Contains(0.0)); + REQUIRE(x.Contains(10.0)); } /** * Test that Range::Contains() works on other Ranges. It should return false * unless the ranges overlap at all. */ -BOOST_AUTO_TEST_CASE(RangeContainsRange) +TEST_CASE("RangeContainsRange", "[MathTest]") { // Empty ranges should not contain each other. Range a; Range b; - BOOST_REQUIRE_EQUAL(a.Contains(b), false); - BOOST_REQUIRE_EQUAL(b.Contains(a), false); + REQUIRE(a.Contains(b) == false); + REQUIRE(b.Contains(a) == false); // Completely disparate ranges. a = Range(-5.0, -3.0); b = Range(3.0, 5.0); - BOOST_REQUIRE_EQUAL(a.Contains(b), false); - BOOST_REQUIRE_EQUAL(b.Contains(a), false); + REQUIRE(a.Contains(b) == false); + REQUIRE(b.Contains(a) == false); // Overlapping at the end-point; this is containment of the end point. a = Range(-5.0, 0.0); b = Range(0.0, 5.0); - BOOST_REQUIRE_EQUAL(a.Contains(b), true); - BOOST_REQUIRE_EQUAL(b.Contains(a), true); + REQUIRE(a.Contains(b) == true); + REQUIRE(b.Contains(a) == true); // Partially overlapping. a = Range(-5.0, 2.0); b = Range(-2.0, 5.0); - BOOST_REQUIRE_EQUAL(a.Contains(b), true); - BOOST_REQUIRE_EQUAL(b.Contains(a), true); + REQUIRE(a.Contains(b) == true); + REQUIRE(b.Contains(a) == true); // One range encloses the other. a = Range(-5.0, 5.0); b = Range(-3.0, 3.0); - BOOST_REQUIRE_EQUAL(a.Contains(b), true); - BOOST_REQUIRE_EQUAL(b.Contains(a), true); + REQUIRE(a.Contains(b) == true); + REQUIRE(b.Contains(a) == true); // Identical ranges. a = Range(-3.0, 3.0); b = Range(-3.0, 3.0); - BOOST_REQUIRE_EQUAL(a.Contains(b), true); - BOOST_REQUIRE_EQUAL(b.Contains(a), true); + REQUIRE(a.Contains(b) == true); + REQUIRE(b.Contains(a) == true); // Single-point ranges. a = Range(0.0, 0.0); b = Range(0.0, 0.0); - BOOST_REQUIRE_EQUAL(a.Contains(b), true); - BOOST_REQUIRE_EQUAL(b.Contains(a), true); + REQUIRE(a.Contains(b) == true); + REQUIRE(b.Contains(a) == true); } /** * Make sure shuffling data works. */ -BOOST_AUTO_TEST_CASE(ShuffleTest) +TEST_CASE("ShuffleTest", "[MathTest]") { arma::mat data(3, 10, arma::fill::zeros); arma::Row labels(10); @@ -601,28 +598,28 @@ BOOST_AUTO_TEST_CASE(ShuffleTest) ShuffleData(data, labels, outputData, outputLabels); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_SMALL(outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL(outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE(outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE(outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; } for (size_t i = 0; i < 10; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); } /** * Make sure shuffling sparse data works. */ -BOOST_AUTO_TEST_CASE(SparseShuffleTest) +TEST_CASE("SparseShuffleTest", "[MathTest]") { arma::sp_mat data(3, 10); arma::Row labels(10); @@ -639,28 +636,28 @@ BOOST_AUTO_TEST_CASE(SparseShuffleTest) ShuffleData(data, labels, outputData, outputLabels); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_SMALL((double) outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL((double) outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE((double) outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE((double) outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; } for (size_t i = 0; i < 10; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); } /** * Make sure shuffling cubes works. */ -BOOST_AUTO_TEST_CASE(CubeShuffleTest) +TEST_CASE("CubeShuffleTest", "[MathTest]") { arma::cube data(3, 10, 5, arma::fill::zeros); arma::cube labels(1, 10, 5); @@ -678,12 +675,12 @@ BOOST_AUTO_TEST_CASE(CubeShuffleTest) ShuffleData(data, labels, outputData, outputLabels); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputData.n_slices, data.n_slices); - BOOST_REQUIRE_EQUAL(outputLabels.n_rows, labels.n_rows); - BOOST_REQUIRE_EQUAL(outputLabels.n_cols, labels.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_slices, labels.n_slices); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputData.n_slices == data.n_slices); + REQUIRE(outputLabels.n_rows == labels.n_rows); + REQUIRE(outputLabels.n_cols == labels.n_cols); + REQUIRE(outputLabels.n_slices == labels.n_slices); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); @@ -691,20 +688,20 @@ BOOST_AUTO_TEST_CASE(CubeShuffleTest) { for (size_t s = 0; s < data.n_slices; ++s) { - BOOST_REQUIRE_EQUAL(data(0, i, s) + data(1, i, s), labels(0, i, s)); - BOOST_REQUIRE_SMALL(data(2, i, s), 1e-5); + REQUIRE(data(0, i, s) + data(1, i, s) == labels(0, i, s)); + REQUIRE(data(2, i, s) == Approx(0.0).margin(1e-5)); counts[data(1, i, s)]++; } } for (size_t i = 0; i < 10; ++i) - BOOST_REQUIRE_EQUAL(counts[i], data.n_slices); + REQUIRE(counts[i] == data.n_slices); } /** * Make sure shuffling data with weights works. */ -BOOST_AUTO_TEST_CASE(ShuffleWeightsTest) +TEST_CASE("ShuffleWeightsTest", "[MathTest]") { arma::mat data(3, 10, arma::fill::zeros); arma::Row labels(10); @@ -722,35 +719,35 @@ BOOST_AUTO_TEST_CASE(ShuffleWeightsTest) ShuffleData(data, labels, weights, outputData, outputLabels, outputWeights); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); - BOOST_REQUIRE_EQUAL(outputWeights.n_elem, weights.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); + REQUIRE(outputWeights.n_elem == weights.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); arma::Row weightCounts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), (size_t) outputWeights[i]); - BOOST_REQUIRE_SMALL(outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL(outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE((size_t) outputData(0, i) == (size_t) outputWeights[i]); + REQUIRE(outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE(outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; weightCounts[(size_t) outputWeights[i]]++; } for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL(counts[i], 1); - BOOST_REQUIRE_EQUAL(weightCounts[i], 1); + REQUIRE(counts[i] == 1); + REQUIRE(weightCounts[i] == 1); } } /** * Make sure shuffling sparse data with weights works. */ -BOOST_AUTO_TEST_CASE(SparseShuffleWeightsTest) +TEST_CASE("SparseShuffleWeightsTest", "[MathTest]") { arma::sp_mat data(3, 10); arma::Row labels(10); @@ -770,28 +767,28 @@ BOOST_AUTO_TEST_CASE(SparseShuffleWeightsTest) ShuffleData(data, labels, weights, outputData, outputLabels, outputWeights); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); - BOOST_REQUIRE_EQUAL(outputWeights.n_elem, weights.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); + REQUIRE(outputWeights.n_elem == weights.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); arma::Row weightCounts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), (size_t) outputWeights[i]); - BOOST_REQUIRE_SMALL((double) outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL((double) outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE((size_t) outputData(0, i) == (size_t) outputWeights[i]); + REQUIRE((double) outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE((double) outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; weightCounts[(size_t) outputWeights[i]]++; } for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL(counts[i], 1); - BOOST_REQUIRE_EQUAL(weightCounts[i], 1); + REQUIRE(counts[i] == 1); + REQUIRE(weightCounts[i] == 1); } } @@ -799,7 +796,7 @@ BOOST_AUTO_TEST_CASE(SparseShuffleWeightsTest) * Make sure shuffling data works when the same matrices are given as input and * output. */ -BOOST_AUTO_TEST_CASE(InplaceShuffleTest) +TEST_CASE("InplaceShuffleTest", "[MathTest]") { arma::mat data(3, 10, arma::fill::zeros); arma::Row labels(10); @@ -814,29 +811,29 @@ BOOST_AUTO_TEST_CASE(InplaceShuffleTest) ShuffleData(outputData, outputLabels, outputData, outputLabels); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_SMALL(outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL(outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE(outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE(outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; } for (size_t i = 0; i < 10; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); } /** * Make sure shuffling sparse data works when the input and output matrices are * the same. */ -BOOST_AUTO_TEST_CASE(InplaceSparseShuffleTest) +TEST_CASE("InplaceSparseShuffleTest", "[MathTest]") { arma::sp_mat data(3, 10); arma::Row labels(10); @@ -851,28 +848,28 @@ BOOST_AUTO_TEST_CASE(InplaceSparseShuffleTest) ShuffleData(outputData, outputLabels, outputData, outputLabels); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_SMALL((double) outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL((double) outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE((double) outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE((double) outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; } for (size_t i = 0; i < 10; ++i) - BOOST_REQUIRE_EQUAL(counts[i], 1); + REQUIRE(counts[i] == 1); } /** * Make sure shuffling cubes works when the input and output cubes are the same. */ -BOOST_AUTO_TEST_CASE(InplaceCubeShuffleTest) +TEST_CASE("InplaceCubeShuffleTest", "[MathTest]") { arma::cube data(3, 10, 5, arma::fill::zeros); arma::cube labels(1, 10, 5); @@ -890,12 +887,12 @@ BOOST_AUTO_TEST_CASE(InplaceCubeShuffleTest) ShuffleData(outputData, outputLabels, outputData, outputLabels); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputData.n_slices, data.n_slices); - BOOST_REQUIRE_EQUAL(outputLabels.n_rows, labels.n_rows); - BOOST_REQUIRE_EQUAL(outputLabels.n_cols, labels.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_slices, labels.n_slices); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputData.n_slices == data.n_slices); + REQUIRE(outputLabels.n_rows == labels.n_rows); + REQUIRE(outputLabels.n_cols == labels.n_cols); + REQUIRE(outputLabels.n_slices == labels.n_slices); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); @@ -903,21 +900,21 @@ BOOST_AUTO_TEST_CASE(InplaceCubeShuffleTest) { for (size_t s = 0; s < data.n_slices; ++s) { - BOOST_REQUIRE_EQUAL(data(0, i, s) + data(1, i, s), labels(0, i, s)); - BOOST_REQUIRE_SMALL(data(2, i, s), 1e-5); + REQUIRE(data(0, i, s) + data(1, i, s) == labels(0, i, s)); + REQUIRE(data(2, i, s) == Approx(0.0).margin(1e-5)); counts[data(1, i, s)]++; } } for (size_t i = 0; i < 10; ++i) - BOOST_REQUIRE_EQUAL(counts[i], data.n_slices); + REQUIRE(counts[i] == data.n_slices); } /** * Make sure shuffling data with weights works when the same matrices are given * as input and output. */ -BOOST_AUTO_TEST_CASE(InplaceShuffleWeightsTest) +TEST_CASE("InplaceShuffleWeightsTest", "[MathTest]") { arma::mat data(3, 10, arma::fill::zeros); arma::Row labels(10); @@ -936,28 +933,28 @@ BOOST_AUTO_TEST_CASE(InplaceShuffleWeightsTest) ShuffleData(outputData, outputLabels, outputWeights, outputData, outputLabels, outputWeights); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); - BOOST_REQUIRE_EQUAL(outputWeights.n_elem, weights.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); + REQUIRE(outputWeights.n_elem == weights.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); arma::Row weightCounts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), (size_t) outputWeights[i]); - BOOST_REQUIRE_SMALL(outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL(outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE((size_t) outputData(0, i) == (size_t) outputWeights[i]); + REQUIRE(outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE(outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; weightCounts[(size_t) outputWeights[i]]++; } for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL(counts[i], 1); - BOOST_REQUIRE_EQUAL(weightCounts[i], 1); + REQUIRE(counts[i] == 1); + REQUIRE(weightCounts[i] == 1); } } @@ -965,7 +962,7 @@ BOOST_AUTO_TEST_CASE(InplaceShuffleWeightsTest) * Make sure shuffling sparse data with weights works when the input and output * matrices are the same. */ -BOOST_AUTO_TEST_CASE(InplaceSparseShuffleWeightsTest) +TEST_CASE("InplaceSparseShuffleWeightsTest", "[MathTest]") { arma::sp_mat data(3, 10); arma::Row labels(10); @@ -984,29 +981,27 @@ BOOST_AUTO_TEST_CASE(InplaceSparseShuffleWeightsTest) ShuffleData(outputData, outputLabels, outputWeights, outputData, outputLabels, outputWeights); - BOOST_REQUIRE_EQUAL(outputData.n_rows, data.n_rows); - BOOST_REQUIRE_EQUAL(outputData.n_cols, data.n_cols); - BOOST_REQUIRE_EQUAL(outputLabels.n_elem, labels.n_elem); - BOOST_REQUIRE_EQUAL(outputWeights.n_elem, weights.n_elem); + REQUIRE(outputData.n_rows == data.n_rows); + REQUIRE(outputData.n_cols == data.n_cols); + REQUIRE(outputLabels.n_elem == labels.n_elem); + REQUIRE(outputWeights.n_elem == weights.n_elem); // Make sure we only have each point once. arma::Row counts(10, arma::fill::zeros); arma::Row weightCounts(10, arma::fill::zeros); for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), outputLabels[i]); - BOOST_REQUIRE_EQUAL((size_t) outputData(0, i), (size_t) outputWeights[i]); - BOOST_REQUIRE_SMALL((double) outputData(1, i), 1e-5); - BOOST_REQUIRE_SMALL((double) outputData(2, i), 1e-5); + REQUIRE((size_t) outputData(0, i) == outputLabels[i]); + REQUIRE((size_t) outputData(0, i) == (size_t) outputWeights[i]); + REQUIRE((double) outputData(1, i) == Approx(0.0).margin(1e-5)); + REQUIRE((double) outputData(2, i) == Approx(0.0).margin(1e-5)); counts[outputLabels[i]]++; weightCounts[(size_t) outputWeights[i]]++; } for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_EQUAL(counts[i], 1); - BOOST_REQUIRE_EQUAL(weightCounts[i], 1); + REQUIRE(counts[i] == 1); + REQUIRE(weightCounts[i] == 1); } } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/wgan_test.cpp b/src/mlpack/tests/wgan_test.cpp index a590746ed0..d2954b4218 100644 --- a/src/mlpack/tests/wgan_test.cpp +++ b/src/mlpack/tests/wgan_test.cpp @@ -20,8 +20,7 @@ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" #include "serialization.hpp" using namespace mlpack; @@ -30,14 +29,12 @@ using namespace mlpack::math; using namespace mlpack::regression; using namespace std::placeholders; -BOOST_AUTO_TEST_SUITE(WGANNetworkTest); - /* * Tests the standard WGAN implementation on the MNIST dataset. * It's not viable to train on bigger parameters due to time constraints. * Please refer mlpack/models repository for the tutorial. */ -BOOST_AUTO_TEST_CASE(WGANMNISTTest) +TEST_CASE("WGANMNISTTest", "[WGANNetworkTest]") { size_t dNumKernels = 32; size_t discriminatorPreTrain = 5; @@ -131,7 +128,7 @@ BOOST_AUTO_TEST_CASE(WGANMNISTTest) double objVal = wgan.Train(trainData, optimizer); // Test that objective value returned by GAN::Train() is finite. - BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); + REQUIRE(std::isfinite(objVal) == true); // Generate samples. Log::Info << "Sampling..." << std::endl; @@ -198,7 +195,7 @@ BOOST_AUTO_TEST_CASE(WGANMNISTTest) * It's not viable to train on bigger parameters due to time constraints. * Please refer mlpack/models repository for the tutorial. */ -BOOST_AUTO_TEST_CASE(WGANGPMNISTTest) +TEST_CASE("WGANGPMNISTTest","[WGANNetworkTest]") { size_t dNumKernels = 32; size_t discriminatorPreTrain = 5; @@ -293,7 +290,7 @@ BOOST_AUTO_TEST_CASE(WGANGPMNISTTest) double objVal = wganGP.Train(trainData, optimizer); // Test that objective value returned by GAN::Train() is finite. - BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); + REQUIRE(std::isfinite(objVal) == true); // Generate samples. Log::Info << "Sampling..." << std::endl; @@ -354,5 +351,3 @@ BOOST_AUTO_TEST_CASE(WGANGPMNISTTest) CheckMatrices(orgPredictions, textPredictions); CheckMatrices(orgPredictions, binaryPredictions); } - -BOOST_AUTO_TEST_SUITE_END();