Add tests for change_active_state()

This commit is contained in:
Serhii Snitsaruk 2024-07-21 14:07:56 +02:00
parent b478c8eb2c
commit 17ccd50806
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
1 changed files with 31 additions and 0 deletions

View File

@ -184,6 +184,37 @@ TEST_CASE("[Modules][LimboAI] HSM") {
CHECK_FALSE(hsm->is_active()); // * not active CHECK_FALSE(hsm->is_active()); // * not active
CHECK(hsm->get_active_state() == nullptr); CHECK(hsm->get_active_state() == nullptr);
} }
SUBCASE("Test change_active_state()") {
REQUIRE(hsm->is_active());
REQUIRE(hsm->get_active_state() == state_alpha);
CHECK(alpha_entries->num_callbacks == 1); // * entered
CHECK(alpha_updates->num_callbacks == 0);
CHECK(alpha_exits->num_callbacks == 0);
CHECK(beta_entries->num_callbacks == 0);
CHECK(beta_updates->num_callbacks == 0);
CHECK(beta_exits->num_callbacks == 0);
hsm->change_active_state(state_beta);
CHECK(hsm->get_active_state() == state_beta);
CHECK(alpha_entries->num_callbacks == 1);
CHECK(alpha_updates->num_callbacks == 0);
CHECK(alpha_exits->num_callbacks == 1); // * exited
CHECK(beta_entries->num_callbacks == 1); // * entered
CHECK(beta_updates->num_callbacks == 0);
CHECK(beta_exits->num_callbacks == 0);
hsm->change_active_state(state_beta); // * should exit and re-enter
CHECK(hsm->get_active_state() == state_beta);
CHECK(alpha_entries->num_callbacks == 1);
CHECK(alpha_updates->num_callbacks == 0);
CHECK(alpha_exits->num_callbacks == 1);
CHECK(beta_entries->num_callbacks == 2); // * re-entered
CHECK(beta_updates->num_callbacks == 0);
CHECK(beta_exits->num_callbacks == 1); // * exited
}
SUBCASE("Test transition with guard") { SUBCASE("Test transition with 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));