Skip to content

Commit ee68e15

Browse files
committed
Add test related to issue BehaviorTree#539
1 parent d1641cf commit ee68e15

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

tests/gtest_postconditions.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,28 @@ TEST(PostConditions, BasicTest)
3737
ASSERT_EQ(tree.rootBlackboard()->get<int>("C"), 42);
3838
ASSERT_EQ(tree.rootBlackboard()->get<int>("D"), 42);
3939
}
40+
41+
TEST(PostConditions, Issue539)
42+
{
43+
const std::string xml_text = R"(
44+
<root BTCPP_format="4" >
45+
<BehaviorTree ID="MainTree">
46+
<Sequence>
47+
<Script code = "x:=0; y:=0" />
48+
<RetryUntilSuccessful num_attempts="5">
49+
<AlwaysFailure _onFailure="x += 1" _post="y += 1" />
50+
</RetryUntilSuccessful>
51+
</Sequence>
52+
</BehaviorTree>
53+
</root>)";
54+
55+
BehaviorTreeFactory factory;
56+
auto tree = factory.createTreeFromText(xml_text);
57+
const auto status = tree.tickWhileRunning();
58+
ASSERT_EQ(status, NodeStatus::FAILURE);
59+
60+
ASSERT_EQ(tree.rootBlackboard()->get<int>("x"), 5);
61+
ASSERT_EQ(tree.rootBlackboard()->get<int>("y"), 5);
62+
}
63+
64+

tests/script_parser_test.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ TEST(ParserTest, Equations)
120120
EXPECT_EQ(GetResult("x+=1").cast<double>(), 4.0);
121121
EXPECT_EQ(variables->get<double>("x"), 4.0);
122122

123-
EXPECT_EQ(GetResult("x-=1").cast<double>(), 3.0);
123+
EXPECT_EQ(GetResult("x += 1").cast<double>(), 5.0);
124+
EXPECT_EQ(variables->get<double>("x"), 5.0);
125+
126+
EXPECT_EQ(GetResult("x-=1").cast<double>(), 4.0);
127+
EXPECT_EQ(variables->get<double>("x"), 4.0);
128+
129+
EXPECT_EQ(GetResult("x -= 1").cast<double>(), 3.0);
124130
EXPECT_EQ(variables->get<double>("x"), 3.0);
125131

126132
EXPECT_EQ(GetResult("x*=2").cast<double>(), 6.0);

0 commit comments

Comments
 (0)