Tests for per-transition guards

This commit is contained in:
Serhii Snitsaruk 2024-11-01 14:59:10 +01:00
parent bbe71bb378
commit 85eda3c804
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
1 changed files with 20 additions and 1 deletions

View File

@ -215,7 +215,7 @@ TEST_CASE("[Modules][LimboAI] HSM") {
CHECK(beta_updates->num_callbacks == 0); CHECK(beta_updates->num_callbacks == 0);
CHECK(beta_exits->num_callbacks == 1); // * exited CHECK(beta_exits->num_callbacks == 1); // * exited
} }
SUBCASE("Test transition with guard") { SUBCASE("Test transition with state-wide guard") {
Ref<TestGuard> guard = memnew(TestGuard); Ref<TestGuard> guard = memnew(TestGuard);
state_beta->set_guard(callable_mp(guard.ptr(), &TestGuard::can_enter)); state_beta->set_guard(callable_mp(guard.ptr(), &TestGuard::can_enter));
@ -234,6 +234,25 @@ TEST_CASE("[Modules][LimboAI] HSM") {
CHECK(beta_entries->num_callbacks == 0); CHECK(beta_entries->num_callbacks == 0);
} }
} }
SUBCASE("Test transition with transition-scoped guard") {
Ref<TestGuard> guard = memnew(TestGuard);
hsm->add_transition(state_alpha, state_beta, "guarded_transition", callable_mp(guard.ptr(), &TestGuard::can_enter));
SUBCASE("When entry is permitted") {
guard->permitted_to_enter = true;
hsm->dispatch("guarded_transition");
CHECK(hsm->get_active_state() == state_beta);
CHECK(alpha_exits->num_callbacks == 1);
CHECK(beta_entries->num_callbacks == 1);
}
SUBCASE("When entry is not permitted") {
guard->permitted_to_enter = false;
hsm->dispatch("guarded_transition");
CHECK(hsm->get_active_state() == state_alpha);
CHECK(alpha_exits->num_callbacks == 0);
CHECK(beta_entries->num_callbacks == 0);
}
}
SUBCASE("When there is no transition for given event") { SUBCASE("When there is no transition for given event") {
hsm->dispatch("not_found"); hsm->dispatch("not_found");
CHECK(alpha_exits->num_callbacks == 0); CHECK(alpha_exits->num_callbacks == 0);