Skip to content

Commit 37b69b9

Browse files
committed
Add some tests
1 parent 69efebb commit 37b69b9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

controller_manager/include/controller_manager/controller_spec.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class ControllerChainDependencyGraph
119119
depth_first_search(controller_name, visited, predecessors);
120120
std::vector<std::string> predecessors_list;
121121
std::copy(visited.begin(), visited.end(), std::back_inserter(predecessors_list));
122+
predecessors_list.pop_back(); // Remove the controller itself
122123
return predecessors_list;
123124
}
124125

@@ -128,6 +129,7 @@ class ControllerChainDependencyGraph
128129
depth_first_search(controller_name, visited, successors);
129130
std::vector<std::string> successors_list;
130131
std::copy(visited.begin(), visited.end(), std::back_inserter(successors_list));
132+
successors_list.pop_back(); // Remove the controller itself
131133
return successors_list;
132134
}
133135

controller_manager/test/test_controller_manager.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ class TestControllerManagerWithStrictness
7373
}
7474
};
7575

76+
TEST(ControllerManagerDependencyGraph, controller_chain_dependency_graph)
77+
{
78+
{
79+
controller_manager::ControllerChainDependencyGraph graph;
80+
// Let's test the case of A -> B -> C -> D && B -> E && E -> F
81+
graph.add_dependency("A", "B");
82+
graph.add_dependency("B", "C");
83+
graph.add_dependency("C", "D");
84+
graph.add_dependency("B", "E");
85+
graph.add_dependency("E", "F");
86+
87+
EXPECT_THAT(
88+
graph.get_all_successors("A"), testing::UnorderedElementsAre("B", "C", "D", "E", "F"));
89+
EXPECT_THAT(graph.get_all_successors("B"), testing::UnorderedElementsAre("C", "D", "E", "F"));
90+
EXPECT_THAT(graph.get_all_successors("C"), testing::UnorderedElementsAre("D"));
91+
EXPECT_THAT(graph.get_all_successors("D"), testing::UnorderedElementsAre());
92+
EXPECT_THAT(graph.get_all_successors("E"), testing::UnorderedElementsAre("F"));
93+
EXPECT_THAT(graph.get_all_successors("F"), testing::UnorderedElementsAre());
94+
95+
EXPECT_THAT(graph.get_all_predecessors("A"), testing::UnorderedElementsAre());
96+
EXPECT_THAT(graph.get_all_predecessors("B"), testing::UnorderedElementsAre("A"));
97+
EXPECT_THAT(graph.get_all_predecessors("C"), testing::UnorderedElementsAre("B", "A"));
98+
EXPECT_THAT(graph.get_all_predecessors("D"), testing::UnorderedElementsAre("C", "B", "A"));
99+
EXPECT_THAT(graph.get_all_predecessors("E"), testing::UnorderedElementsAre("B", "A"));
100+
EXPECT_THAT(graph.get_all_predecessors("F"), testing::UnorderedElementsAre("E", "B", "A"));
101+
}
102+
}
103+
76104
class TestControllerManagerRobotDescription
77105
: public ControllerManagerFixture<controller_manager::ControllerManager>
78106
{

0 commit comments

Comments
 (0)