From fd87a3633ea2ec881c9afa5a1db1e9df6a079004 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 31 Aug 2023 11:26:37 +0200 Subject: [PATCH] Add tests for BTInvert --- tests/test_invert.h | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/test_invert.h diff --git a/tests/test_invert.h b/tests/test_invert.h new file mode 100644 index 0000000..ee38e66 --- /dev/null +++ b/tests/test_invert.h @@ -0,0 +1,63 @@ +/** + * test_invert.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_INVERT_H +#define TEST_INVERT_H + +#include "limbo_test.h" + +#include "modules/limboai/bt/tasks/bt_task.h" +#include "modules/limboai/bt/tasks/decorators/bt_invert.h" + +namespace TestInvert { + +TEST_CASE("[Modules][LimboAI] BTInvert") { + Ref inv = memnew(BTInvert); + + SUBCASE("When empty") { + ERR_PRINT_OFF; + CHECK(inv->execute(0.01666) == BTTask::FAILURE); + ERR_PRINT_ON; + } + + Ref task = memnew(BTTestAction); + inv->add_child(task); + + SUBCASE("With SUCCESS") { + task->ret_status = BTTask::SUCCESS; + CHECK(inv->execute(0.01666) == BTTask::FAILURE); + CHECK(task->get_status() == BTTask::SUCCESS); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 1); + } + + SUBCASE("With FAILURE") { + task->ret_status = BTTask::FAILURE; + CHECK(inv->execute(0.01666) == BTTask::SUCCESS); + CHECK(task->get_status() == BTTask::FAILURE); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 1); + } + + SUBCASE("With RUNNING followed by SUCCESS") { + task->ret_status = BTTask::RUNNING; + CHECK(inv->execute(0.01666) == BTTask::RUNNING); + CHECK(task->get_status() == BTTask::RUNNING); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 1, 0); + + task->ret_status = BTTask::SUCCESS; + CHECK(inv->execute(0.01666) == BTTask::FAILURE); + CHECK(task->get_status() == BTTask::SUCCESS); + CHECK_ENTRIES_TICKS_EXITS(task, 1, 2, 1); + } +} + +} //namespace TestInvert + +#endif // TEST_INVERT_H