Tests for per-transition guards
This commit is contained in:
parent
bbe71bb378
commit
85eda3c804
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue