From 9604b272d0fbb081b4c10d30dba51d83cc038c2e Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Sat, 3 Oct 2020 11:01:54 +0530 Subject: [PATCH 1/2] 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 99ef23fdf0351351f0997d385071929293998f5d Mon Sep 17 00:00:00 2001 From: jeffin143 Date: Sat, 10 Oct 2020 19:40:27 +0530 Subject: [PATCH 2/2] 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)