From f7159123c6f5d611630e469357a042f21445bc45 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Wed, 30 Aug 2023 12:20:18 +0200 Subject: [PATCH] Improve test for BTRandomSequence --- tests/limbo_test.h | 2 ++ tests/test_random_sequence.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/limbo_test.h b/tests/limbo_test.h index 8d59fd4..4e85b24 100644 --- a/tests/limbo_test.h +++ b/tests/limbo_test.h @@ -35,6 +35,8 @@ protected: } public: + bool is_status_either(int p_status1, int p_status2) { return (get_status() == p_status1 || get_status() == p_status2); } + BTTestAction(int p_return_status) { ret_status = p_return_status; } BTTestAction() {} }; diff --git a/tests/test_random_sequence.h b/tests/test_random_sequence.h index c03d1af..ee66d96 100644 --- a/tests/test_random_sequence.h +++ b/tests/test_random_sequence.h @@ -37,13 +37,24 @@ TEST_CASE("[Modules][LimboAI] BTRandomSequence") { task3->ret_status = BTTask::SUCCESS; CHECK(seq->execute(0.01666) == BTTask::RUNNING); + + CHECK(task1->is_status_either(BTTask::SUCCESS, BTTask::FRESH)); + CHECK(task2->get_status() == BTTask::RUNNING); + CHECK(task3->is_status_either(BTTask::SUCCESS, BTTask::FRESH)); + CHECK_ENTRIES_TICKS_EXITS_UP_TO(task1, 1, 1, 1); // * ran no more than once CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 0); // * running - enters and ticks CHECK_ENTRIES_TICKS_EXITS_UP_TO(task3, 1, 1, 1); // * ran no more than once SUBCASE("Resuming and succeeding when all tasks succeed") { task2->ret_status = BTTask::SUCCESS; + CHECK(seq->execute(0.01666) == BTTask::SUCCESS); + + CHECK(task1->get_status() == BTTask::SUCCESS); + CHECK(task2->get_status() == BTTask::SUCCESS); + CHECK(task3->get_status() == BTTask::SUCCESS); + CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1); // * ran once CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 1); // * finishes - ticks and exits with SUCCESS CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 1); // * ran once @@ -51,7 +62,13 @@ TEST_CASE("[Modules][LimboAI] BTRandomSequence") { SUBCASE("Resuming and failing when a child task fails") { task2->ret_status = BTTask::FAILURE; + CHECK(seq->execute(0.01666) == BTTask::FAILURE); + + CHECK(task1->is_status_either(BTTask::SUCCESS, BTTask::FRESH)); + CHECK(task2->get_status() == BTTask::FAILURE); + CHECK(task3->is_status_either(BTTask::SUCCESS, BTTask::FRESH)); + CHECK_ENTRIES_TICKS_EXITS_UP_TO(task1, 1, 1, 1); // * ran no more than once CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 1); // * finishes - ticks and exits with FAILURE CHECK_ENTRIES_TICKS_EXITS_UP_TO(task3, 1, 1, 1); // * ran no more than once