Refactor unit tests
This commit is contained in:
parent
dad8d5297f
commit
7252a37b2c
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* bt_test_action.h
|
||||
* limbo_test.h
|
||||
* =============================================================================
|
||||
* Copyright 2021-2023 Serhii Snitsaruk
|
||||
*
|
||||
|
@ -9,8 +9,10 @@
|
|||
* =============================================================================
|
||||
*/
|
||||
|
||||
#ifndef BT_TEST_ACTION_H
|
||||
#define BT_TEST_ACTION_H
|
||||
#ifndef LIMBO_TEST_H
|
||||
#define LIMBO_TEST_H
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
|
||||
#include "modules/limboai/bt/tasks/bt_action.h"
|
||||
|
||||
|
@ -36,4 +38,9 @@ public:
|
|||
BTTestAction(int p_return_status) { ret_status = p_return_status; }
|
||||
};
|
||||
|
||||
#endif // BT_TEST_ACTION_H
|
||||
#define CHECK_ENTRIES_TICKS_EXITS(m_task, m_entries, m_ticks, m_exits) \
|
||||
CHECK(m_task->num_entries == m_entries); \
|
||||
CHECK(m_task->num_ticks == m_ticks); \
|
||||
CHECK(m_task->num_exits == m_exits);
|
||||
|
||||
#endif // LIMBO_TEST_H
|
|
@ -12,11 +12,10 @@
|
|||
#ifndef TEST_SELECTOR_H
|
||||
#define TEST_SELECTOR_H
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
#include "limbo_test.h"
|
||||
|
||||
#include "modules/limboai/bt/tasks/bt_task.h"
|
||||
#include "modules/limboai/bt/tasks/composites/bt_selector.h"
|
||||
#include "modules/limboai/tests/tasks/bt_test_action.h"
|
||||
|
||||
namespace TestSelector {
|
||||
|
||||
|
@ -39,17 +38,9 @@ TEST_CASE("[Modules][LimboAI] BTSelector when all return FAILURE") {
|
|||
CHECK(task2->get_status() == BTTask::FAILURE);
|
||||
CHECK(task3->get_status() == BTTask::FAILURE);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 1);
|
||||
CHECK(task2->num_exits == 1);
|
||||
|
||||
CHECK(task3->num_entries == 1);
|
||||
CHECK(task3->num_ticks == 1);
|
||||
CHECK(task3->num_exits == 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 1);
|
||||
|
||||
// * Second execution.
|
||||
CHECK(sel->execute(0.1666) == BTTask::FAILURE);
|
||||
|
@ -58,17 +49,9 @@ TEST_CASE("[Modules][LimboAI] BTSelector when all return FAILURE") {
|
|||
CHECK(task2->get_status() == BTTask::FAILURE);
|
||||
CHECK(task3->get_status() == BTTask::FAILURE);
|
||||
|
||||
CHECK(task1->num_entries == 2);
|
||||
CHECK(task1->num_ticks == 2);
|
||||
CHECK(task1->num_exits == 2);
|
||||
|
||||
CHECK(task2->num_entries == 2);
|
||||
CHECK(task2->num_ticks == 2);
|
||||
CHECK(task2->num_exits == 2);
|
||||
|
||||
CHECK(task3->num_entries == 2);
|
||||
CHECK(task3->num_ticks == 2);
|
||||
CHECK(task3->num_exits == 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 2, 2, 2);
|
||||
}
|
||||
|
||||
TEST_CASE("[Modules][LimboAI] BTSelector when second returns SUCCESS") {
|
||||
|
@ -90,17 +73,9 @@ TEST_CASE("[Modules][LimboAI] BTSelector when second returns SUCCESS") {
|
|||
CHECK(task2->get_status() == BTTask::SUCCESS);
|
||||
CHECK(task3->get_status() == BTTask::FRESH);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 1);
|
||||
CHECK(task2->num_exits == 1);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
|
||||
// * Second execution.
|
||||
CHECK(sel->execute(0.1666) == BTTask::SUCCESS);
|
||||
|
@ -109,17 +84,9 @@ TEST_CASE("[Modules][LimboAI] BTSelector when second returns SUCCESS") {
|
|||
CHECK(task2->get_status() == BTTask::SUCCESS);
|
||||
CHECK(task3->get_status() == BTTask::FRESH);
|
||||
|
||||
CHECK(task1->num_entries == 2);
|
||||
CHECK(task1->num_ticks == 2);
|
||||
CHECK(task1->num_exits == 2);
|
||||
|
||||
CHECK(task2->num_entries == 2);
|
||||
CHECK(task2->num_ticks == 2);
|
||||
CHECK(task2->num_exits == 2);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("[Modules][LimboAI] BTSelector when second returns RUNNING") {
|
||||
|
@ -141,17 +108,9 @@ TEST_CASE("[Modules][LimboAI] BTSelector when second returns RUNNING") {
|
|||
CHECK(task2->get_status() == BTTask::RUNNING);
|
||||
CHECK(task3->get_status() == BTTask::FRESH);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 1);
|
||||
CHECK(task2->num_exits == 0);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
|
||||
// * Second execution.
|
||||
CHECK(sel->execute(0.1666) == BTTask::RUNNING);
|
||||
|
@ -160,17 +119,9 @@ TEST_CASE("[Modules][LimboAI] BTSelector when second returns RUNNING") {
|
|||
CHECK(task2->get_status() == BTTask::RUNNING);
|
||||
CHECK(task3->get_status() == BTTask::FRESH);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 2);
|
||||
CHECK(task2->num_exits == 0);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
|
||||
// * Third execution with second task returning FAILURE.
|
||||
task2->ret_status = BTTask::FAILURE;
|
||||
|
@ -180,17 +131,9 @@ TEST_CASE("[Modules][LimboAI] BTSelector when second returns RUNNING") {
|
|||
CHECK(task2->get_status() == BTTask::FAILURE);
|
||||
CHECK(task3->get_status() == BTTask::FAILURE);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 3);
|
||||
CHECK(task2->num_exits == 1);
|
||||
|
||||
CHECK(task3->num_entries == 1);
|
||||
CHECK(task3->num_ticks == 1);
|
||||
CHECK(task3->num_exits == 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 3, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 1);
|
||||
}
|
||||
|
||||
} //namespace TestSelector
|
||||
|
|
|
@ -12,11 +12,10 @@
|
|||
#ifndef TEST_SEQUENCE_H
|
||||
#define TEST_SEQUENCE_H
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
#include "limbo_test.h"
|
||||
|
||||
#include "modules/limboai/bt/tasks/bt_task.h"
|
||||
#include "modules/limboai/bt/tasks/composites/bt_sequence.h"
|
||||
#include "modules/limboai/tests/tasks/bt_test_action.h"
|
||||
|
||||
namespace TestSequence {
|
||||
|
||||
|
@ -39,17 +38,9 @@ TEST_CASE("[Modules][LimboAI] BTSequence when all return SUCCESS") {
|
|||
CHECK(task2->get_status() == BTTask::SUCCESS);
|
||||
CHECK(task3->get_status() == BTTask::SUCCESS);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 1);
|
||||
CHECK(task2->num_exits == 1);
|
||||
|
||||
CHECK(task3->num_entries == 1);
|
||||
CHECK(task3->num_ticks == 1);
|
||||
CHECK(task3->num_exits == 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 1);
|
||||
|
||||
// * Second execution.
|
||||
CHECK(seq->execute(0.1666) == BTTask::SUCCESS);
|
||||
|
@ -58,17 +49,9 @@ TEST_CASE("[Modules][LimboAI] BTSequence when all return SUCCESS") {
|
|||
CHECK(task2->get_status() == BTTask::SUCCESS);
|
||||
CHECK(task3->get_status() == BTTask::SUCCESS);
|
||||
|
||||
CHECK(task1->num_entries == 2);
|
||||
CHECK(task1->num_ticks == 2);
|
||||
CHECK(task1->num_exits == 2);
|
||||
|
||||
CHECK(task2->num_entries == 2);
|
||||
CHECK(task2->num_ticks == 2);
|
||||
CHECK(task2->num_exits == 2);
|
||||
|
||||
CHECK(task3->num_entries == 2);
|
||||
CHECK(task3->num_ticks == 2);
|
||||
CHECK(task3->num_exits == 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 2, 2, 2);
|
||||
}
|
||||
|
||||
TEST_CASE("[Modules][LimboAI] BTSequence when second returns FAILURE") {
|
||||
|
@ -90,17 +73,9 @@ TEST_CASE("[Modules][LimboAI] BTSequence when second returns FAILURE") {
|
|||
CHECK(task2->get_status() == BTTask::FAILURE);
|
||||
CHECK(task3->get_status() == BTTask::FRESH);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 1);
|
||||
CHECK(task2->num_exits == 1);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
|
||||
// * Second execution.
|
||||
CHECK(seq->execute(0.1666) == BTTask::FAILURE);
|
||||
|
@ -109,17 +84,9 @@ TEST_CASE("[Modules][LimboAI] BTSequence when second returns FAILURE") {
|
|||
CHECK(task2->get_status() == BTTask::FAILURE);
|
||||
CHECK(task3->get_status() == BTTask::FRESH);
|
||||
|
||||
CHECK(task1->num_entries == 2);
|
||||
CHECK(task1->num_ticks == 2);
|
||||
CHECK(task1->num_exits == 2);
|
||||
|
||||
CHECK(task2->num_entries == 2);
|
||||
CHECK(task2->num_ticks == 2);
|
||||
CHECK(task2->num_exits == 2);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 2, 2, 2);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("[Modules][LimboAI] BTSequence when second returns RUNNING") {
|
||||
|
@ -141,32 +108,28 @@ TEST_CASE("[Modules][LimboAI] BTSequence when second returns RUNNING") {
|
|||
CHECK(task2->get_status() == BTTask::RUNNING);
|
||||
CHECK(task3->get_status() == BTTask::FRESH);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 1);
|
||||
CHECK(task2->num_exits == 0);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 1, 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
|
||||
// * Second execution.
|
||||
CHECK(seq->execute(0.1666) == BTTask::RUNNING);
|
||||
|
||||
CHECK(task1->num_entries == 1);
|
||||
CHECK(task1->num_exits == 1);
|
||||
CHECK(task1->num_ticks == 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task1, 1, 1, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 2, 0);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 0, 0, 0);
|
||||
|
||||
CHECK(task2->num_entries == 1);
|
||||
CHECK(task2->num_ticks == 2);
|
||||
CHECK(task2->num_exits == 0);
|
||||
// * Third execution with second task returning SUCCESS.
|
||||
task2->ret_status = BTTask::SUCCESS;
|
||||
CHECK(seq->execute(0.1666) == BTTask::SUCCESS);
|
||||
|
||||
CHECK(task3->num_entries == 0);
|
||||
CHECK(task3->num_ticks == 0);
|
||||
CHECK(task3->num_exits == 0);
|
||||
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);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task2, 1, 3, 1);
|
||||
CHECK_ENTRIES_TICKS_EXITS(task3, 1, 1, 1);
|
||||
}
|
||||
|
||||
TEST_CASE("[Modules][LimboAI] BTSequence with no child tasks") {
|
||||
|
|
Loading…
Reference in New Issue