Add tests for BTDynamicSelector
This commit is contained in:
parent
e3e65994ec
commit
9600e94ee6
|
@ -0,0 +1,121 @@
|
||||||
|
/**
|
||||||
|
* test_dynamic_selector.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_DYNAMIC_SELECTOR_H
|
||||||
|
#define TEST_DYNAMIC_SELECTOR_H
|
||||||
|
|
||||||
|
#include "limbo_test.h"
|
||||||
|
|
||||||
|
#include "modules/limboai/bt/tasks/bt_task.h"
|
||||||
|
#include "modules/limboai/bt/tasks/composites/bt_dynamic_selector.h"
|
||||||
|
|
||||||
|
namespace TestDynamicSelector {
|
||||||
|
|
||||||
|
TEST_CASE("[Modules][LimboAI] BTDynamicSelector") {
|
||||||
|
Ref<BTDynamicSelector> sel = memnew(BTDynamicSelector);
|
||||||
|
Ref<BTTestAction> task1 = memnew(BTTestAction(BTTask::SUCCESS));
|
||||||
|
Ref<BTTestAction> task2 = memnew(BTTestAction(BTTask::SUCCESS));
|
||||||
|
Ref<BTTestAction> task3 = memnew(BTTestAction(BTTask::SUCCESS));
|
||||||
|
|
||||||
|
sel->add_child(task1);
|
||||||
|
sel->add_child(task2);
|
||||||
|
sel->add_child(task3);
|
||||||
|
|
||||||
|
REQUIRE(sel->get_child_count() == 3);
|
||||||
|
|
||||||
|
SUBCASE("Subcase #1: Dynamic selector processes tasks sequentially until first SUCCESS, while re-evaluating its child tasks in every execution tick.") {
|
||||||
|
task1->ret_status = BTTask::FAILURE;
|
||||||
|
task2->ret_status = BTTask::RUNNING;
|
||||||
|
task3->ret_status = BTTask::SUCCESS;
|
||||||
|
|
||||||
|
CHECK(sel->execute(0.1666) == BTTask::RUNNING);
|
||||||
|
|
||||||
|
CHECK(task1->get_status() == BTTask::FAILURE);
|
||||||
|
CHECK(task2->get_status() == BTTask::RUNNING);
|
||||||
|
CHECK(task3->get_status() == BTTask::FRESH);
|
||||||
|
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1); // * finished with FAILURE
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 0); // * enetered and running
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
||||||
|
|
||||||
|
SUBCASE("Subcase 1A: With no changes, first task is re-evaluated.") {
|
||||||
|
CHECK(sel->execute(0.1666) == BTTask::RUNNING);
|
||||||
|
|
||||||
|
CHECK(task1->get_status() == BTTask::FAILURE);
|
||||||
|
CHECK(task2->get_status() == BTTask::RUNNING);
|
||||||
|
CHECK(task3->get_status() == BTTask::FRESH);
|
||||||
|
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * re-evaluated with FAILURE
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 0); // * continued
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("Subcase 1B: When second task succeeds, we finish with SUCCESS.") {
|
||||||
|
task2->ret_status = BTTask::SUCCESS;
|
||||||
|
CHECK(sel->execute(0.1666) == BTTask::SUCCESS);
|
||||||
|
|
||||||
|
CHECK(task1->get_status() == BTTask::FAILURE);
|
||||||
|
CHECK(task2->get_status() == BTTask::SUCCESS);
|
||||||
|
CHECK(task3->get_status() == BTTask::FRESH);
|
||||||
|
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * re-evaluated with FAILURE
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 1); // * ticked and exited with SUCCESS
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("Subcase 1C: When first task re-evaluates to SUCCESS, second task should be cancelled and exited.") {
|
||||||
|
task1->ret_status = BTTask::SUCCESS;
|
||||||
|
CHECK(sel->execute(0.1666) == BTTask::SUCCESS);
|
||||||
|
|
||||||
|
CHECK(task1->get_status() == BTTask::SUCCESS);
|
||||||
|
CHECK(task2->get_status() == BTTask::FRESH); // * cancelled - status changed to FRESH
|
||||||
|
CHECK(task3->get_status() == BTTask::FRESH);
|
||||||
|
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * re-evaluated with SUCCESS
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 1); // * cancelled - not ticked and exited
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
||||||
|
}
|
||||||
|
|
||||||
|
SUBCASE("Subcase 1D: When first two fail, third one is executed.") {
|
||||||
|
task1->ret_status = BTTask::FAILURE;
|
||||||
|
task2->ret_status = BTTask::FAILURE;
|
||||||
|
task3->ret_status = BTTask::RUNNING;
|
||||||
|
CHECK(sel->execute(0.1666) == BTTask::RUNNING);
|
||||||
|
|
||||||
|
CHECK(task1->get_status() == BTTask::FAILURE);
|
||||||
|
CHECK(task2->get_status() == BTTask::FAILURE);
|
||||||
|
CHECK(task3->get_status() == BTTask::RUNNING);
|
||||||
|
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * re-evaluated with FAILURE
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 1); // * ticked and exited with FAILURE
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 0); // * entered and running
|
||||||
|
|
||||||
|
SUBCASE("Subcase 1D1: First two are re-evaluated, and when all finish with FAILURE, we expect FAILURE.") {
|
||||||
|
task1->ret_status = BTTask::FAILURE;
|
||||||
|
task2->ret_status = BTTask::FAILURE;
|
||||||
|
task3->ret_status = BTTask::FAILURE;
|
||||||
|
CHECK(sel->execute(0.1666) == BTTask::FAILURE);
|
||||||
|
|
||||||
|
CHECK(task1->get_status() == BTTask::FAILURE);
|
||||||
|
CHECK(task2->get_status() == BTTask::FAILURE);
|
||||||
|
CHECK(task3->get_status() == BTTask::FAILURE);
|
||||||
|
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task1, 3, 3, 3); // * re-evaluated with SUCCESS
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task2, 2, 3, 2); // * re-evaluated with SUCCESS
|
||||||
|
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 2, 1); // * ticked and exited with SUCCESS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace TestDynamicSelector
|
||||||
|
|
||||||
|
#endif // TEST_DYNAMIC_SELECTOR_H
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
namespace TestDynamicSequence {
|
namespace TestDynamicSequence {
|
||||||
|
|
||||||
TEST_CASE("[Modules][LimboAI] BTDynamicSequence #1") {
|
TEST_CASE("[Modules][LimboAI] BTDynamicSequence") {
|
||||||
Ref<BTDynamicSequence> seq = memnew(BTDynamicSequence);
|
Ref<BTDynamicSequence> seq = memnew(BTDynamicSequence);
|
||||||
Ref<BTTestAction> task1 = memnew(BTTestAction(BTTask::SUCCESS));
|
Ref<BTTestAction> task1 = memnew(BTTestAction(BTTask::SUCCESS));
|
||||||
Ref<BTTestAction> task2 = memnew(BTTestAction(BTTask::SUCCESS));
|
Ref<BTTestAction> task2 = memnew(BTTestAction(BTTask::SUCCESS));
|
||||||
|
@ -53,7 +53,7 @@ TEST_CASE("[Modules][LimboAI] BTDynamicSequence #1") {
|
||||||
CHECK(task2->get_status() == BTTask::RUNNING);
|
CHECK(task2->get_status() == BTTask::RUNNING);
|
||||||
CHECK(task3->get_status() == BTTask::FRESH);
|
CHECK(task3->get_status() == BTTask::FRESH);
|
||||||
|
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * reevaluated with SUCCESS
|
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * re-evaluated with SUCCESS
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 0); // * continued
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 0); // * continued
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ TEST_CASE("[Modules][LimboAI] BTDynamicSequence #1") {
|
||||||
CHECK(task2->get_status() == BTTask::FRESH); // * cancelled - status changed to FRESH
|
CHECK(task2->get_status() == BTTask::FRESH); // * cancelled - status changed to FRESH
|
||||||
CHECK(task3->get_status() == BTTask::FRESH);
|
CHECK(task3->get_status() == BTTask::FRESH);
|
||||||
|
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * reevaluated with FAILURE
|
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * re-evaluated with FAILURE
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 1); // * cancelled - not ticked and exited
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 1); // * cancelled - not ticked and exited
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0); // * still fresh
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ TEST_CASE("[Modules][LimboAI] BTDynamicSequence #1") {
|
||||||
CHECK(task2->get_status() == BTTask::SUCCESS);
|
CHECK(task2->get_status() == BTTask::SUCCESS);
|
||||||
CHECK(task3->get_status() == BTTask::RUNNING);
|
CHECK(task3->get_status() == BTTask::RUNNING);
|
||||||
|
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * reevaluated with SUCCESS
|
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2); // * re-evaluated with SUCCESS
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 1); // * ticked and exited with SUCCESS
|
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 1); // * ticked and exited with SUCCESS
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 0); // * entered and running
|
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 0); // * entered and running
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ TEST_CASE("[Modules][LimboAI] BTDynamicSequence #1") {
|
||||||
CHECK(task2->get_status() == BTTask::SUCCESS);
|
CHECK(task2->get_status() == BTTask::SUCCESS);
|
||||||
CHECK(task3->get_status() == BTTask::SUCCESS);
|
CHECK(task3->get_status() == BTTask::SUCCESS);
|
||||||
|
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task1, 3, 3, 3); // * reevaluated with SUCCESS
|
CHECK_ENTRIES_TICKS_EXITS(task1, 3, 3, 3); // * re-evaluated with SUCCESS
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task2, 2, 3, 2); // * reevaluated with SUCCESS
|
CHECK_ENTRIES_TICKS_EXITS(task2, 2, 3, 2); // * re-evaluated with SUCCESS
|
||||||
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 2, 1); // * tiched and exited with SUCCESS
|
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 2, 1); // * ticked and exited with SUCCESS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue