@@ -42,96 +42,85 @@ struct Connect : stages::Connect
4242constexpr double INF = std::numeric_limits<double >::infinity();
4343unsigned int Connect::id_ = 0 ;
4444
45- struct TestBase : public testing ::Test
45+ struct TestBase : public TaskTestBase
4646{
47- Task task;
48- TestBase () {
49- resetMockupIds ();
50- Connect::id_ = 0 ;
51- task.setRobotModel (getModel ());
52- }
53-
54- template <typename C, typename S>
55- auto add (C& container, S* stage) -> S* {
56- container.add (Stage::pointer (stage));
57- return stage;
58- }
47+ TestBase () { Connect::id_ = 0 ; }
5948};
6049
6150using ConnectConnect = TestBase;
6251// https://github.com/ros-planning/moveit_task_constructor/issues/182
6352TEST_F (ConnectConnect, SuccSucc) {
64- add (task , new GeneratorMockup ({ 1.0 , 2.0 , 3.0 }));
65- add (task , new Connect ());
66- add (task , new GeneratorMockup ({ 10.0 , 20.0 }));
67- add (task , new Connect ());
68- add (task , new GeneratorMockup ({ 0.0 }));
69-
70- EXPECT_TRUE (task .plan ());
71- ASSERT_EQ (task .solutions ().size (), 3u * 2u );
53+ add (t , new GeneratorMockup ({ 1.0 , 2.0 , 3.0 }));
54+ add (t , new Connect ());
55+ add (t , new GeneratorMockup ({ 10.0 , 20.0 }));
56+ add (t , new Connect ());
57+ add (t , new GeneratorMockup ({ 0.0 }));
58+
59+ EXPECT_TRUE (t .plan ());
60+ ASSERT_EQ (t .solutions ().size (), 3u * 2u );
7261 std::vector<double > expected_costs = { 11 , 12 , 13 , 21 , 22 , 23 };
7362 auto expected_cost = expected_costs.begin ();
74- for (const auto & s : task .solutions ()) {
63+ for (const auto & s : t .solutions ()) {
7564 EXPECT_EQ (s->cost (), *expected_cost);
7665 ++expected_cost;
7766 }
7867}
7968
8069// https://github.com/ros-planning/moveit_task_constructor/issues/218
8170TEST_F (ConnectConnect, FailSucc) {
82- add (task , new GeneratorMockup ());
83- add (task , new Connect ({ INF }, true ));
84- add (task , new GeneratorMockup ());
85- add (task , new Connect ());
86- add (task , new GeneratorMockup ());
87- add (task , new ForwardMockup (PredefinedCosts::constant (0.0 ), 0 ));
88-
89- EXPECT_FALSE (task .plan ());
71+ add (t , new GeneratorMockup ());
72+ add (t , new Connect ({ INF }, true ));
73+ add (t , new GeneratorMockup ());
74+ add (t , new Connect ());
75+ add (t , new GeneratorMockup ());
76+ add (t , new ForwardMockup (PredefinedCosts::constant (0.0 ), 0 ));
77+
78+ EXPECT_FALSE (t .plan ());
9079}
9180
9281using Pruning = TestBase;
9382TEST_F (Pruning, PropagatorFailure) {
94- auto back = add (task , new BackwardMockup ());
95- add (task , new GeneratorMockup ({ 0 }));
96- add (task , new ForwardMockup ({ INF }));
83+ auto back = add (t , new BackwardMockup ());
84+ add (t , new GeneratorMockup ({ 0 }));
85+ add (t , new ForwardMockup ({ INF }));
9786
98- EXPECT_FALSE (task .plan ());
99- ASSERT_EQ (task .solutions ().size (), 0u );
87+ EXPECT_FALSE (t .plan ());
88+ ASSERT_EQ (t .solutions ().size (), 0u );
10089 // ForwardMockup fails, so the backward stage should never compute
10190 EXPECT_EQ (back->runs_ , 0u );
10291}
10392
10493TEST_F (Pruning, PruningMultiForward) {
105- add (task , new BackwardMockup ());
106- add (task , new BackwardMockup ());
107- add (task , new GeneratorMockup ());
94+ add (t , new BackwardMockup ());
95+ add (t , new BackwardMockup ());
96+ add (t , new GeneratorMockup ());
10897 // spawn two solutions for the only incoming state
109- add (task , new ForwardMockup (PredefinedCosts{ { 0.0 , 0.0 } }, 2 ));
98+ add (t , new ForwardMockup (PredefinedCosts{ { 0.0 , 0.0 } }, 2 ));
11099 // fail to extend the second solution
111- add (task , new ForwardMockup ({ 0 , INF }));
100+ add (t , new ForwardMockup ({ 0 , INF }));
112101
113- EXPECT_TRUE (task .plan ());
102+ EXPECT_TRUE (t .plan ());
114103
115104 // the second (infeasible) solution in the last stage must not disable
116105 // the earlier partial solution just because they share stage solutions
117- ASSERT_EQ (task .solutions ().size (), 1u );
118- EXPECT_EQ ((*task .solutions ().begin ())->cost (), 0u );
106+ ASSERT_EQ (t .solutions ().size (), 1u );
107+ EXPECT_EQ ((*t .solutions ().begin ())->cost (), 0u );
119108}
120109
121110TEST_F (Pruning, ConnectConnectForward) {
122- add (task , new GeneratorMockup ());
123- auto c1 = add (task , new Connect ({ INF, 0 })); // 1st attempt is a failue
124- add (task , new GeneratorMockup ({ 0 , 10 , 20 }));
125- add (task , new ForwardMockup ());
126- auto c2 = add (task , new Connect ());
127- add (task , new GeneratorMockup ({ 1 , 2 , 3 }));
111+ add (t , new GeneratorMockup ());
112+ auto c1 = add (t , new Connect ({ INF, 0 })); // 1st attempt is a failue
113+ add (t , new GeneratorMockup ({ 0 , 10 , 20 }));
114+ add (t , new ForwardMockup ());
115+ auto c2 = add (t , new Connect ());
116+ add (t , new GeneratorMockup ({ 1 , 2 , 3 }));
128117
129- task .plan ();
118+ t .plan ();
130119
131- ASSERT_EQ (task .solutions ().size (), 3u * 2u );
120+ ASSERT_EQ (t .solutions ().size (), 3u * 2u );
132121 std::vector<double > expected_costs = { 11 , 12 , 13 , 21 , 22 , 23 };
133122 auto expected_cost = expected_costs.begin ();
134- for (const auto & s : task .solutions ()) {
123+ for (const auto & s : t .solutions ()) {
135124 EXPECT_EQ (s->cost (), *expected_cost);
136125 ++expected_cost;
137126 }
@@ -140,19 +129,19 @@ TEST_F(Pruning, ConnectConnectForward) {
140129}
141130
142131TEST_F (Pruning, ConnectConnectBackward) {
143- add (task , new GeneratorMockup ({ 1 , 2 , 3 }));
144- auto c1 = add (task , new Connect ());
145- add (task , new BackwardMockup ());
146- add (task , new GeneratorMockup ({ 0 , INF, 10 , 20 })); // 2nd is a dummy to postpone creation of 3rd
147- auto c2 = add (task , new Connect ({ INF, 0 })); // 1st attempt is a failure
148- add (task , new GeneratorMockup ());
132+ add (t , new GeneratorMockup ({ 1 , 2 , 3 }));
133+ auto c1 = add (t , new Connect ());
134+ add (t , new BackwardMockup ());
135+ add (t , new GeneratorMockup ({ 0 , INF, 10 , 20 })); // 2nd is a dummy to postpone creation of 3rd
136+ auto c2 = add (t , new Connect ({ INF, 0 })); // 1st attempt is a failure
137+ add (t , new GeneratorMockup ());
149138
150- task .plan ();
139+ t .plan ();
151140
152- ASSERT_EQ (task .solutions ().size (), 3u * 2u );
141+ ASSERT_EQ (t .solutions ().size (), 3u * 2u );
153142 std::vector<double > expected_costs = { 11 , 12 , 13 , 21 , 22 , 23 };
154143 auto expected_cost = expected_costs.begin ();
155- for (const auto & s : task .solutions ()) {
144+ for (const auto & s : t .solutions ()) {
156145 EXPECT_EQ (s->cost (), *expected_cost);
157146 ++expected_cost;
158147 }
@@ -161,60 +150,60 @@ TEST_F(Pruning, ConnectConnectBackward) {
161150}
162151
163152TEST_F (Pruning, PropagateIntoContainer) {
164- add (task , new BackwardMockup ({ INF }));
165- add (task , new GeneratorMockup ({ 0 }));
153+ add (t , new BackwardMockup ({ INF }));
154+ add (t , new GeneratorMockup ({ 0 }));
166155
167- auto inner = add (task , new SerialContainer ());
156+ auto inner = add (t , new SerialContainer ());
168157 auto con = add (*inner, new Connect ());
169158 add (*inner, new GeneratorMockup ({ 0 }));
170159
171- EXPECT_FALSE (task .plan ());
160+ EXPECT_FALSE (t .plan ());
172161
173162 // the failure in the backward stage (outside the container)
174163 // should prune the expected computation of con inside the container
175164 EXPECT_EQ (con->calls_ , 0u );
176165}
177166
178167TEST_F (Pruning, PropagateFromContainerPull) {
179- auto back = add (task , new BackwardMockup ());
180- add (task , new BackwardMockup ());
181- add (task , new GeneratorMockup ({ 0 }));
168+ auto back = add (t , new BackwardMockup ());
169+ add (t , new BackwardMockup ());
170+ add (t , new GeneratorMockup ({ 0 }));
182171
183- auto inner = add (task , new SerialContainer ());
172+ auto inner = add (t , new SerialContainer ());
184173 add (*inner, new ForwardMockup ());
185174 add (*inner, new ForwardMockup ({ INF }));
186175
187- EXPECT_FALSE (task .plan ());
176+ EXPECT_FALSE (t .plan ());
188177
189178 // the failure inside the container should prune computing of back
190179 EXPECT_EQ (back->runs_ , 0u );
191180}
192181
193182TEST_F (Pruning, PropagateFromContainerPush) {
194- auto inner = add (task , new SerialContainer ());
183+ auto inner = add (t , new SerialContainer ());
195184 add (*inner, new BackwardMockup ({ INF }));
196185
197- add (task , new GeneratorMockup ({ 0 }));
198- auto con = add (task , new Connect ());
199- add (task , new GeneratorMockup ({ 0 }));
186+ add (t , new GeneratorMockup ({ 0 }));
187+ auto con = add (t , new Connect ());
188+ add (t , new GeneratorMockup ({ 0 }));
200189
201- EXPECT_FALSE (task .plan ());
190+ EXPECT_FALSE (t .plan ());
202191
203192 // the failure inside container should prune computing of con
204193 EXPECT_EQ (con->calls_ , 0u );
205194}
206195
207196TEST_F (Pruning, PropagateFromParallelContainerMultiplePaths) {
208- auto back = add (task , new BackwardMockup ());
209- add (task , new GeneratorMockup ({ 0 }));
210- auto inner = add (task , new Alternatives ());
197+ auto back = add (t , new BackwardMockup ());
198+ add (t , new GeneratorMockup ({ 0 }));
199+ auto inner = add (t , new Alternatives ());
211200
212201 add (*inner, new ForwardMockup ({ INF }));
213202 auto serial = add (*inner, new SerialContainer ());
214203 add (*serial, new Connect ());
215204 add (*serial, new GeneratorMockup ({ 0 }));
216205
217- EXPECT_TRUE (task .plan ());
206+ EXPECT_TRUE (t .plan ());
218207
219208 // the failure in one branch of Alternatives must not prune computing back
220209 EXPECT_EQ (back->runs_ , 1u );
0 commit comments