From 5fe64c5aae59051f023480523316f3d96aa03f1a Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Wed, 30 Aug 2023 17:06:27 +0200 Subject: [PATCH] Add tests for BTAlways{Fail,Succeed} --- tests/test_always_fail.h | 63 +++++++++++++++++++++++++++++++++++++ tests/test_always_succeed.h | 63 +++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 tests/test_always_fail.h create mode 100644 tests/test_always_succeed.h diff --git a/tests/test_always_fail.h b/tests/test_always_fail.h new file mode 100644 index 0000000..55fe97e --- /dev/null +++ b/tests/test_always_fail.h @@ -0,0 +1,63 @@ +/** + * test_always_fail.h + * ============================================================================= + * Copyright 2021-2023 Serhii Snitsaruk + * + * Use of this source code is governed by an MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT. + * ============================================================================= + */ + +#ifndef TEST_ALWAYS_FAIL_H +#define TEST_ALWAYS_FAIL_H + +#include "limbo_test.h" + +#include "modules/limboai/bt/tasks/bt_task.h" +#include "modules/limboai/bt/tasks/decorators/bt_always_fail.h" + +namespace TestAlwaysFail { + +TEST_CASE("[Modules][LimboAI] BTAlwaysFail") { + Ref af = memnew(BTAlwaysFail); + + SUBCASE("When empty") { + CHECK(af->execute(0.01666) == BTTask::FAILURE); + } + + Ref task = memnew(BTTestAction); + + af->add_child(task); + + SUBCASE("When child returns FAILURE") { + task->ret_status = BTTask::FAILURE; + + CHECK(af->execute(0.01666) == BTTask::FAILURE); + + CHECK(task->get_status() == BTTask::FAILURE); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 1); + } + + SUBCASE("When child returns SUCCESS") { + task->ret_status = BTTask::SUCCESS; + + CHECK(af->execute(0.01666) == BTTask::FAILURE); + + CHECK(task->get_status() == BTTask::SUCCESS); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 1); + } + + SUBCASE("When child returns RUNNING") { + task->ret_status = BTTask::RUNNING; + + CHECK(af->execute(0.01666) == BTTask::RUNNING); + + CHECK(task->get_status() == BTTask::RUNNING); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 0); + } +} + +} //namespace TestAlwaysFail + +#endif // TEST_ALWAYS_FAIL_H diff --git a/tests/test_always_succeed.h b/tests/test_always_succeed.h new file mode 100644 index 0000000..92a7494 --- /dev/null +++ b/tests/test_always_succeed.h @@ -0,0 +1,63 @@ +/** + * test_always_succeed.h + * ============================================================================= + * Copyright 2021-2023 Serhii Snitsaruk + * + * Use of this source code is governed by an MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT. + * ============================================================================= + */ + +#ifndef TEST_ALWAYS_SUCCEED_H +#define TEST_ALWAYS_SUCCEED_H + +#include "limbo_test.h" + +#include "modules/limboai/bt/tasks/bt_task.h" +#include "modules/limboai/bt/tasks/decorators/bt_always_succeed.h" + +namespace TestAlwaysSucceed { + +TEST_CASE("[Modules][LimboAI] BTAlwaysSucceed") { + Ref as = memnew(BTAlwaysSucceed); + + SUBCASE("When empty") { + CHECK(as->execute(0.01666) == BTTask::SUCCESS); + } + + Ref task = memnew(BTTestAction); + + as->add_child(task); + + SUBCASE("When child returns FAILURE") { + task->ret_status = BTTask::FAILURE; + + CHECK(as->execute(0.01666) == BTTask::SUCCESS); + + CHECK(task->get_status() == BTTask::FAILURE); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 1); + } + + SUBCASE("When child returns SUCCESS") { + task->ret_status = BTTask::SUCCESS; + + CHECK(as->execute(0.01666) == BTTask::SUCCESS); + + CHECK(task->get_status() == BTTask::SUCCESS); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 1); + } + + SUBCASE("When child returns RUNNING") { + task->ret_status = BTTask::RUNNING; + + CHECK(as->execute(0.01666) == BTTask::RUNNING); + + CHECK(task->get_status() == BTTask::RUNNING); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 0); + } +} + +} //namespace TestAlwaysSucceed + +#endif // TEST_ALWAYS_SUCCEED_H