Skip to content

Commit

Permalink
Use spawn_npc in behaviour_test
Browse files Browse the repository at this point in the history
We were seeing intermittent failures on Mingw in
check_npc_behavior_tree.

This turned out to be because the NPCs the test constructed in a rather
ad hoc manner violated the invariants for the NPC class (in particular,
its two position members were inconsistent).

To avoid that, create the NPC via the new, safer spawn_npc function from
player_helpers.h.
  • Loading branch information
jbytheway committed Jan 11, 2020
1 parent 6d139c7 commit 962e01a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/behavior_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <memory>
#include <string>

#include "catch/catch.hpp"
#include "behavior.h"
#include "behavior_oracle.h"
#include "behavior_strategy.h"
Expand All @@ -12,6 +11,9 @@
#include "string_id.h"
#include "weather.h"

#include "catch/catch.hpp"
#include "player_helpers.h"

namespace behavior
{
extern sequential_t default_sequential;
Expand Down Expand Up @@ -131,13 +133,12 @@ TEST_CASE( "behavior_tree", "[behavior]" )
}

// Make assertions about loaded behaviors.
TEST_CASE( "check_npc_behavior_tree", "[behavior]" )
TEST_CASE( "check_npc_behavior_tree", "[npc][behavior]" )
{
behavior::tree npc_needs;
npc_needs.add( &string_id<behavior::node_t>( "npc_needs" ).obj() );
npc test_npc;
test_npc.normalize();
test_npc.setpos( { 50, 50, 0 } );
npc &test_npc = spawn_npc( { 50, 50 }, "test_talker" );
clear_character( test_npc );
behavior::character_oracle_t oracle( &test_npc );
CHECK( npc_needs.tick( &oracle ) == "idle" );
SECTION( "Freezing" ) {
Expand Down

0 comments on commit 962e01a

Please sign in to comment.