From d5111dbbf1cab5120ee874da023bf7922dfaec7e Mon Sep 17 00:00:00 2001 From: nishantkr18 Date: Sun, 12 Apr 2020 20:40:49 +0530 Subject: [PATCH] motified test for Pendulum --- src/mlpack/tests/rl_components_test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mlpack/tests/rl_components_test.cpp b/src/mlpack/tests/rl_components_test.cpp index 8161e7637f..a4990955d0 100644 --- a/src/mlpack/tests/rl_components_test.cpp +++ b/src/mlpack/tests/rl_components_test.cpp @@ -38,25 +38,25 @@ BOOST_AUTO_TEST_SUITE(RLComponentsTest) BOOST_AUTO_TEST_CASE(SimplePendulumTest) { Pendulum task = Pendulum(); - task.MaxSteps() = 5; + task.MaxSteps() = 20; Pendulum::State state = task.InitialSample(); Pendulum::Action action; action.action[0] = math::Random(-2.0, 2.0); - double reward = task.Sample(state, action); - - // The reward is always negative. Check if not lower than lowest possible. - BOOST_REQUIRE(reward >= -(pow(M_PI, 2) + 6.404)); + double reward; BOOST_REQUIRE(!task.IsTerminal(state)); while (!task.IsTerminal(state)) - task.Sample(state, action, state); + reward = task.Sample(state, action, state); + + // The reward is always negative. Check if not lower than lowest possible. + BOOST_REQUIRE(reward >= -(pow(M_PI, 2) + 6.404)); // Check if the number of steps performed is less or equal as the maximum // allowed, since we use a random action there is no guarantee that we will // reach the maximum number of steps. - BOOST_REQUIRE_LE(task.StepsPerformed(), 5); + BOOST_REQUIRE_LE(task.StepsPerformed(), 20); // The action is simply the torque. Check if dimension is 1. BOOST_REQUIRE_EQUAL(1, action.size);