gtest_tree.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015-2017 Michele Colledanchise - All Rights Reserved
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #include <gtest/gtest.h>
14 #include "action_test_node.h"
15 #include "condition_test_node.h"
17 
18 using BT::NodeStatus;
19 
20 struct BehaviorTreeTest : testing::Test
21 {
26 
28 
30  : root("root_sequence")
31  , action_1("action_1")
32  , condition_1("condition_1")
33  , condition_2("condition_2")
34  , fal_conditions("fallback_conditions")
35  {
36  root.addChild(&fal_conditions);
37  {
38  fal_conditions.addChild(&condition_1);
39  fal_conditions.addChild(&condition_2);
40  }
41  root.addChild(&action_1);
42  }
44  {
45  haltAllActions(&root);
46  }
47 };
48 
49 /****************TESTS START HERE***************************/
50 
51 TEST_F(BehaviorTreeTest, Condition1ToFalseCondition2True)
52 {
53  condition_1.setBoolean(false);
54  condition_2.setBoolean(true);
55 
57 
58  ASSERT_EQ(NodeStatus::RUNNING, state);
59  ASSERT_EQ(NodeStatus::SUCCESS, fal_conditions.status());
60  ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
61  ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
62  ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
63 }
64 
65 TEST_F(BehaviorTreeTest, Condition2ToFalseCondition1True)
66 {
67  condition_2.setBoolean(false);
68  condition_1.setBoolean(true);
69 
71 
72  ASSERT_EQ(NodeStatus::RUNNING, state);
73  ASSERT_EQ(NodeStatus::SUCCESS, fal_conditions.status());
74  ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
75  ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
76  ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
77 }
78 
79 int main(int argc, char** argv)
80 {
81  testing::InitGoogleTest(&argc, argv);
82  return RUN_ALL_TESTS();
83 }
BT::ConditionTestNode condition_2
Definition: gtest_tree.cpp:25
BT::ConditionTestNode condition_1
Definition: gtest_tree.cpp:24
BT::FallbackNode fal_conditions
Definition: gtest_tree.cpp:27
void setBoolean(bool boolean_value)
void haltAllActions(TreeNode *root_node)
int main(int argc, char **argv)
Definition: gtest_tree.cpp:79
void addChild(TreeNode *child)
NodeStatus status() const
Definition: tree_node.cpp:75
NodeStatus
Definition: basic_types.h:28
BT::SequenceNode root
Definition: gtest_tree.cpp:22
virtual BT::NodeStatus executeTick()
The method that will be executed to invoke tick(); and setStatus();.
Definition: tree_node.cpp:35
The FallbackNode is used to try different strategies, until one succeed. If any child returns RUNNING...
Definition: fallback_node.h:35
The SequenceNode is used to execute a sequence of children. If any child returns RUNNING, previous children will be ticked again.
Definition: sequence_node.h:34
TEST_F(BehaviorTreeTest, Condition1ToFalseCondition2True)
Definition: gtest_tree.cpp:51
BT::AsyncActionTest action_1
Definition: gtest_tree.cpp:23


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sun Feb 3 2019 03:14:32