3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "harness_task.hpp"
24 #include "test_debug.hpp"
26 #include "Task/Factory/AbstractTaskFactory.hpp"
27 #include "Task/Factory/TaskFactoryConstraints.hpp"
28 #include "Engine/Task/Ordered/OrderedTask.hpp"
29 #include "Engine/Task/Ordered/Points/StartPoint.hpp"
30 #include "Engine/Task/Ordered/Points/FinishPoint.hpp"
31 #include "Engine/Task/Ordered/Points/ASTPoint.hpp"
32 #include "Engine/Task/Ordered/Points/AATPoint.hpp"
33 #include "Task/ObservationZones/CylinderZone.hpp"
34 #include "Task/ObservationZones/SymmetricSectorZone.hpp"
35 #include "Task/Visitors/TaskPointVisitor.hpp"
36 #include "Engine/Waypoint/Waypoints.hpp"
37 #include "Util/StaticArray.hpp"
39 #include "harness_waypoints.hpp"
45 class AnnularSectorZone
;
47 class ObservationZoneVisitorPrint
50 void Visit(const KeyholeZone
& oz
) {
51 printf("# kehole zone\n");
53 void Visit(const SectorZone
& oz
) {
54 printf("# sector zone\n");
56 void Visit(const AnnularSectorZone
& oz
) {
57 printf("# annular sector zone\n");
59 void Visit(const LineSectorZone
& oz
) {
60 printf("# line zone\n");
62 void Visit(const CylinderZone
& oz
) {
63 printf("# cylinder zone\n");
66 void Visit(const SymmetricSectorZone
&oz
) {
67 printf("# symmetric quadrant\n");
70 void Visit(const ObservationZonePoint
&oz
) {
71 switch (oz
.GetShape()) {
72 case ObservationZone::Shape::FAI_SECTOR
:
73 case ObservationZone::Shape::SECTOR
:
74 Visit((const SectorZone
&)oz
);
77 case ObservationZone::Shape::LINE
:
78 Visit((const LineSectorZone
&)oz
);
81 case ObservationZone::Shape::MAT_CYLINDER
:
82 case ObservationZone::Shape::CYLINDER
:
83 Visit((const CylinderZone
&)oz
);
86 case ObservationZone::Shape::CUSTOM_KEYHOLE
:
87 case ObservationZone::Shape::DAEC_KEYHOLE
:
88 case ObservationZone::Shape::BGAFIXEDCOURSE
:
89 case ObservationZone::Shape::BGAENHANCEDOPTION
:
90 case ObservationZone::Shape::BGA_START
:
91 Visit((const KeyholeZone
&)oz
);
94 case ObservationZone::Shape::ANNULAR_SECTOR
:
95 Visit((const AnnularSectorZone
&)oz
);
98 case ObservationZone::Shape::SYMMETRIC_QUADRANT
:
99 Visit((const SymmetricSectorZone
&)oz
);
105 class TaskPointVisitorPrint
: public TaskPointConstVisitor
108 virtual void Visit(const TaskPoint
& tp
) override
{
109 switch (tp
.GetType()) {
110 case TaskPointType::UNORDERED
:
111 printf("# got a tp\n");
114 case TaskPointType::FINISH
:
115 printf("# got an ftp\n");
116 ozv
.Visit(((const FinishPoint
&)tp
).GetObservationZone());
119 case TaskPointType::START
:
120 printf("# got an stp\n");
121 ozv
.Visit(((const StartPoint
&)tp
).GetObservationZone());
124 case TaskPointType::AAT
:
125 printf("# got an aat\n");
126 ozv
.Visit(((const AATPoint
&)tp
).GetObservationZone());
129 case TaskPointType::AST
:
130 printf("# got an ast\n");
131 ozv
.Visit(((const ASTPoint
&)tp
).GetObservationZone());
137 ObservationZoneVisitorPrint ozv
;
140 void test_note(const char* text
)
147 void task_report(TaskManager
& task_manager
, const char* text
)
153 const AbstractTask
*task
= task_manager
.GetActiveTask();
155 switch (task
->GetType()) {
157 printf("# task is none\n");
160 case TaskType::ORDERED
:
161 printf("# task is ordered\n");
164 case TaskType::ABORT
:
165 printf("# task is abort\n");
169 printf("# task is goto\n");
173 TaskPointVisitorPrint tpv
;
174 task
->AcceptTaskPointVisitor(tpv
);
175 printf("# - dist nominal %g\n",
176 (double)task
->GetStats().distance_nominal
);
178 if (task
->GetType() == TaskType::ORDERED
&&
179 task
->GetStats().distance_max
> task
->GetStats().distance_min
) {
180 printf("# - dist max %g\n", (double)task
->GetStats().distance_max
);
181 printf("# - dist min %g\n", (double)task
->GetStats().distance_min
);
185 PrintHelper::taskmanager_print(task_manager
, ac
);
193 bool test_task_manip(TaskManager
& task_manager
,
194 const Waypoints
&waypoints
)
196 if (!test_task_mixed(task_manager
, waypoints
)) {
199 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
201 task_report(task_manager
, "# removing tp 2\n");
202 if (!fact
.Remove(2)) {
206 task_report(task_manager
, "# removing tp 0\n");
207 if (!fact
.Remove(0)) {
211 task_report(task_manager
, "# removing tp -1 (illegal)\n");
212 if (fact
.Remove(0-1)) {
216 task_report(task_manager
, "# removing tp 50 (illegal)\n");
217 if (fact
.Remove(50)) {
221 OrderedTaskPoint
*tp
;
224 task_report(task_manager
, "# inserting at 3\n");
225 wp
= waypoints
.LookupId(3);
227 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER
,*wp
);
228 if (!fact
.Insert(*tp
,3)) return false;
232 task_report(task_manager
, "# auto-replacing at 2 (no morph)\n");
233 wp
= waypoints
.LookupId(9);
235 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER
,*wp
);
236 if (!fact
.Replace(*tp
,2)) return false;
240 task_report(task_manager
, "# auto-replacing at 2 (morph)\n");
241 wp
= waypoints
.LookupId(9);
243 tp
= fact
.CreateStart(*wp
);
244 if (!fact
.Replace(*tp
,2)) return false;
248 task_report(task_manager
, "# auto-replacing at 0 (morph this)\n");
249 wp
= waypoints
.LookupId(12);
251 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER
,*wp
);
252 if (!fact
.Replace(*tp
,0)) return false;
256 task_report(task_manager
, "# auto-replacing at end (morph this)\n");
257 wp
= waypoints
.LookupId(14);
259 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER
,*wp
);
260 if (!fact
.Replace(*tp
,task_manager
.TaskSize()-1)) return false;
264 task_report(task_manager
, "# removing finish point\n");
265 if (!fact
.Remove(task_manager
.TaskSize()-1)) {
269 task_report(task_manager
, "# inserting at 50 (equivalent to append)\n");
270 wp
= waypoints
.LookupId(8);
272 tp
= fact
.CreateFinish(*wp
);
273 if (!fact
.Insert(*tp
,50)) return false;
277 task_report(task_manager
, "# inserting at 0 (morph this)\n");
278 wp
= waypoints
.LookupId(3);
280 tp
= fact
.CreateFinish(*wp
);
281 if (!fact
.Insert(*tp
,0)) return false;
285 task_report(task_manager
, "# inserting at 2 (morph this)\n");
286 wp
= waypoints
.LookupId(4);
288 tp
= fact
.CreateStart(*wp
);
289 if (!fact
.Insert(*tp
,2)) return false;
293 task_report(task_manager
, "# inserting at 2 (direct)\n");
294 wp
= waypoints
.LookupId(6);
296 tp
= fact
.CreateIntermediate(*wp
);
297 if (!fact
.Insert(*tp
,2,false)) return false;
301 task_report(task_manager
, "# checking task\n");
303 if (task_manager
.CheckOrderedTask()) {
304 task_manager
.Reset();
305 task_manager
.SetActiveTaskPoint(0);
306 task_manager
.Resume();
313 bool test_task_type_manip(TaskManager
& task_manager
,
314 const Waypoints
&waypoints
, unsigned n_points
)
316 if (!test_task_random_RT_AAT_FAI(task_manager
, waypoints
, n_points
))
321 task_manager
.SetFactory(TaskFactoryType::AAT
);
322 test_note("# switched FACTORY TYPE to AAT\n");
325 task_manager
.SetFactory(TaskFactoryType::RACING
);
326 test_note("# switched FACTORY TYPE to RT\n");
329 task_manager
.SetFactory(TaskFactoryType::FAI_GENERAL
);
330 test_note("# switched FACTORY TYPE to FAI GENERAL\n");
333 task_manager
.SetFactory(TaskFactoryType::MAT
);
334 test_note("# switched FACTORY TYPE to MAT\n");
337 test_note("# unknown task type\n");
340 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
341 fact
.MutateTPsToTaskType();
343 test_note("# checking mutated start..\n");
344 if (!fact
.IsValidStartType(fact
.GetType(task_manager
.GetOrderedTask().GetTaskPoint(0))))
349 sprintf(tmp
, "# checking mutated intermediates. task_size():%d..\n",
350 task_manager
.TaskSize());
353 for (unsigned i
= 1; i
< (task_manager
.TaskSize() - 1); i
++) {
354 sprintf(tmp
, "# checking mutated intermediate point %d..\n", i
);
356 if (!fact
.IsValidIntermediateType(fact
.GetType(task_manager
.GetOrderedTask().GetTaskPoint(i
))))
360 test_note("# checking mutated finish..\n");
361 if (!fact
.IsValidFinishType(
362 fact
.GetType(task_manager
.GetOrderedTask().GetTaskPoint(task_manager
.TaskSize() - 1))))
365 test_note("# validating task..\n");
366 if (!fact
.Validate()) {
369 test_note("# checking task..\n");
370 if (!task_manager
.CheckOrderedTask()) {
374 if (task_manager
.GetOrderedTask().GetFactoryType() ==
375 TaskFactoryType::FAI_GENERAL
) {
376 test_note("# checking OZs for FAI task..\n");
377 if (!fact
.ValidateFAIOZs())
381 if (task_manager
.GetOrderedTask().GetFactoryType() ==
382 TaskFactoryType::MAT
) {
383 test_note("# checking OZs for MAT task..\n");
384 if (!fact
.ValidateMATOZs())
390 bool test_task_mixed(TaskManager
& task_manager
,
391 const Waypoints
&waypoints
)
393 const TaskProjection
&projection
=
394 task_manager
.GetOrderedTask().GetTaskProjection();
396 OrderedTaskPoint
*tp
;
399 task_manager
.SetFactory(TaskFactoryType::MIXED
);
400 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
402 task_report(task_manager
, "# adding start\n");
403 wp
= waypoints
.LookupId(1);
405 tp
= fact
.CreateStart(TaskPointFactoryType::START_LINE
,*wp
);
406 if (tp
->GetObservationZone().GetShape() == ObservationZone::Shape::CYLINDER
) {
407 CylinderZone
&cz
= (CylinderZone
&)tp
->GetObservationZone();
408 cz
.SetRadius(fixed(5000.0));
409 tp
->UpdateOZ(projection
);
411 if (!fact
.Append(*tp
,false)) return false;
417 task_manager
.SetActiveTaskPoint(0);
418 task_manager
.Resume();
420 task_report(task_manager
, "# adding intermdiate\n");
421 wp
= waypoints
.LookupId(2);
423 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER
,*wp
);
424 if (!fact
.Append(*tp
,false)) return false;
430 task_report(task_manager
, "# adding intermdiate\n");
431 wp
= waypoints
.LookupId(3);
433 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AAT_CYLINDER
,*wp
);
434 if (tp
->GetObservationZone().GetShape() == ObservationZone::Shape::CYLINDER
) {
435 CylinderZone
&cz
= (CylinderZone
&)tp
->GetObservationZone();
436 cz
.SetRadius(fixed(30000.0));
437 tp
->UpdateOZ(projection
);
439 if (!fact
.Append(*tp
,false)) return false;
445 task_report(task_manager
, "# adding intermediate\n");
446 wp
= waypoints
.LookupId(4);
448 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AAT_CYLINDER
,*wp
);
449 if (!fact
.Append(*tp
,false)) return false;
455 task_report(task_manager
, "# adding intermediate\n");
456 wp
= waypoints
.LookupId(5);
458 tp
= fact
.CreateIntermediate(TaskPointFactoryType::AAT_CYLINDER
,*wp
);
459 if (tp
->GetObservationZone().GetShape() == ObservationZone::Shape::CYLINDER
) {
460 CylinderZone
&cz
= (CylinderZone
&)tp
->GetObservationZone();
461 cz
.SetRadius(fixed(30000.0));
462 tp
->UpdateOZ(projection
);
464 if (!fact
.Append(*tp
,false)) return false;
470 task_report(task_manager
, "# adding finish\n");
471 wp
= waypoints
.LookupId(1);
473 tp
= fact
.CreateFinish(TaskPointFactoryType::FINISH_LINE
,*wp
);
474 if (!fact
.Append(*tp
,false)) return false;
480 task_report(task_manager
, "# checking task\n");
481 if (!fact
.Validate()) {
485 if (!task_manager
.CheckOrderedTask()) {
492 bool test_task_fai(TaskManager
& task_manager
,
493 const Waypoints
&waypoints
)
495 task_manager
.SetFactory(TaskFactoryType::FAI_GENERAL
);
496 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
499 task_report(task_manager
, "# adding start\n");
500 wp
= waypoints
.LookupId(1);
502 OrderedTaskPoint
*tp
= fact
.CreateStart(*wp
);
503 if (!fact
.Append(*tp
)) {
509 task_manager
.SetActiveTaskPoint(0);
510 task_manager
.Resume();
512 task_report(task_manager
, "# adding intermdiate\n");
513 wp
= waypoints
.LookupId(2);
515 OrderedTaskPoint
*tp
= fact
.CreateIntermediate(*wp
);
516 if (!fact
.Append(*tp
, false)) {
522 task_report(task_manager
, "# adding intermdiate\n");
523 wp
= waypoints
.LookupId(3);
525 OrderedTaskPoint
*tp
= fact
.CreateIntermediate(*wp
);
526 if (!fact
.Append(*tp
,false)) {
532 task_report(task_manager
, "# adding finish\n");
533 wp
= waypoints
.LookupId(1);
535 OrderedTaskPoint
*tp
= fact
.CreateFinish(*wp
);
536 if (!fact
.Append(*tp
,false)) {
542 task_report(task_manager
, "# checking task\n");
543 if (!fact
.Validate()) {
547 if (!task_manager
.CheckOrderedTask()) {
554 bool test_task_aat(TaskManager
& task_manager
,
555 const Waypoints
&waypoints
)
557 const TaskProjection
&projection
=
558 task_manager
.GetOrderedTask().GetTaskProjection();
560 task_manager
.SetFactory(TaskFactoryType::AAT
);
561 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
564 task_report(task_manager
, "# adding start\n");
565 wp
= waypoints
.LookupId(1);
567 OrderedTaskPoint
*tp
= fact
.CreateStart(*wp
);
568 if (!fact
.Append(*tp
,false)) {
574 task_manager
.SetActiveTaskPoint(0);
575 task_manager
.Resume();
577 task_report(task_manager
, "# adding intermediate\n");
578 wp
= waypoints
.LookupId(2);
580 OrderedTaskPoint
* tp
= fact
.CreateIntermediate(TaskPointFactoryType::AAT_CYLINDER
,*wp
);
581 if (tp
->GetObservationZone().GetShape() == ObservationZone::Shape::CYLINDER
) {
582 CylinderZone
&cz
= (CylinderZone
&)tp
->GetObservationZone();
583 cz
.SetRadius(fixed(30000.0));
584 tp
->UpdateOZ(projection
);
586 if (!fact
.Append(*tp
,false)) {
592 task_report(task_manager
, "# adding intermediate\n");
593 wp
= waypoints
.LookupId(3);
595 OrderedTaskPoint
* tp
= fact
.CreateIntermediate(TaskPointFactoryType::AAT_CYLINDER
,*wp
);
596 if (tp
->GetObservationZone().GetShape() == ObservationZone::Shape::CYLINDER
) {
597 CylinderZone
&cz
= (CylinderZone
&)tp
->GetObservationZone();
598 cz
.SetRadius(fixed(40000.0));
599 tp
->UpdateOZ(projection
);
601 if (!fact
.Append(*tp
,false)) {
607 task_report(task_manager
, "# adding finish\n");
608 wp
= waypoints
.LookupId(1);
610 OrderedTaskPoint
*tp
= fact
.CreateFinish(*wp
);
611 if (!fact
.Append(*tp
,false)) {
617 task_report(task_manager
, "# checking task..\n");
618 if (!fact
.Validate()) {
622 if (!task_manager
.CheckOrderedTask()) {
629 test_task_mat(TaskManager
&task_manager
, const Waypoints
&waypoints
)
631 const TaskProjection
&projection
=
632 task_manager
.GetOrderedTask().GetTaskProjection();
634 task_manager
.SetFactory(TaskFactoryType::MAT
);
635 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
638 task_report(task_manager
, "# adding start\n");
639 wp
= waypoints
.LookupId(1);
641 OrderedTaskPoint
*tp
= fact
.CreateStart(*wp
);
642 if (!fact
.Append(*tp
,false)) {
648 task_manager
.SetActiveTaskPoint(0);
649 task_manager
.Resume();
651 task_report(task_manager
, "# adding intermediate\n");
652 wp
= waypoints
.LookupId(2);
654 OrderedTaskPoint
* tp
= fact
.CreateIntermediate(TaskPointFactoryType::MAT_CYLINDER
,*wp
);
655 if (tp
->GetObservationZone().GetShape() == ObservationZone::Shape::MAT_CYLINDER
) {
656 tp
->UpdateOZ(projection
);
658 if (!fact
.Append(*tp
,false)) {
664 task_report(task_manager
, "# adding intermediate\n");
665 wp
= waypoints
.LookupId(3);
667 OrderedTaskPoint
* tp
= fact
.CreateIntermediate(TaskPointFactoryType::MAT_CYLINDER
,*wp
);
668 if (tp
->GetObservationZone().GetShape() == ObservationZone::Shape::MAT_CYLINDER
) {
669 tp
->UpdateOZ(projection
);
671 if (!fact
.Append(*tp
,false)) {
677 task_report(task_manager
, "# adding finish\n");
678 wp
= waypoints
.LookupId(1);
680 OrderedTaskPoint
*tp
= fact
.CreateFinish(*wp
);
681 if (!fact
.Append(*tp
,false)) {
687 task_report(task_manager
, "# checking task..\n");
688 if (!fact
.Validate()) {
692 if (!task_manager
.CheckOrderedTask()) {
699 bool test_task_or(TaskManager
& task_manager
,
700 const Waypoints
&waypoints
)
704 task_manager
.SetFactory(TaskFactoryType::FAI_OR
);
705 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
707 task_report(task_manager
, "# adding start\n");
708 wp
= waypoints
.LookupId(1);
710 OrderedTaskPoint
*tp
= fact
.CreateStart(*wp
);
711 if (!fact
.Append(*tp
)) {
717 task_manager
.SetActiveTaskPoint(0);
718 task_manager
.Resume();
720 task_report(task_manager
, "# adding intermediate\n");
721 wp
= waypoints
.LookupId(2);
723 OrderedTaskPoint
*tp
= fact
.CreateIntermediate(*wp
);
724 if (!fact
.Append(*tp
)) {
730 task_report(task_manager
, "# adding finish\n");
731 wp
= waypoints
.LookupId(1);
733 OrderedTaskPoint
*tp
= fact
.CreateFinish(*wp
);
734 if (!fact
.Append(*tp
)) {
740 task_report(task_manager
, "# checking task..\n");
741 if (!fact
.Validate()) {
745 if (!task_manager
.CheckOrderedTask()) {
753 bool test_task_dash(TaskManager
& task_manager
,
754 const Waypoints
&waypoints
)
758 task_manager
.SetFactory(TaskFactoryType::TOURING
);
759 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
761 task_report(task_manager
, "# adding start\n");
762 wp
= waypoints
.LookupId(1);
764 OrderedTaskPoint
*tp
= fact
.CreateStart(*wp
);
765 if (!fact
.Append(*tp
)) {
771 task_manager
.SetActiveTaskPoint(0);
772 task_manager
.Resume();
774 task_report(task_manager
, "# adding finish\n");
775 wp
= waypoints
.LookupId(3);
777 OrderedTaskPoint
*tp
= fact
.CreateFinish(*wp
);
778 if (!fact
.Append(*tp
)) {
784 task_report(task_manager
, "# checking task..\n");
785 if (!fact
.Validate()) {
789 if (!task_manager
.CheckOrderedTask()) {
797 bool test_task_fg(TaskManager
& task_manager
,
798 const Waypoints
&waypoints
)
802 task_manager
.SetFactory(TaskFactoryType::FAI_GOAL
);
803 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
805 task_report(task_manager
, "# adding start\n");
806 wp
= waypoints
.LookupId(1);
808 OrderedTaskPoint
*tp
= fact
.CreateStart(*wp
);
809 if (!fact
.Append(*tp
, false)) {
815 task_manager
.SetActiveTaskPoint(0);
816 task_manager
.Resume();
818 task_report(task_manager
, "# adding finish\n");
819 wp
= waypoints
.LookupId(6);
821 OrderedTaskPoint
*tp
= fact
.CreateFinish(*wp
);
822 if (!fact
.Append(*tp
, false)) {
828 task_report(task_manager
, "# checking task..\n");
829 if (!fact
.Validate()) {
833 if (!task_manager
.CheckOrderedTask()) {
840 const Waypoint
* random_waypoint(const Waypoints
&waypoints
) {
841 static unsigned id_last
= 0;
844 id
= rand() % waypoints
.size()+1;
845 } while (id
==id_last
);
847 return waypoints
.LookupId(id
);
850 static TaskPointFactoryType
851 GetRandomType(const LegalPointSet
&l
)
853 StaticArray
<TaskPointFactoryType
, LegalPointSet::N
> types
;
854 l
.CopyTo(std::back_inserter(types
));
855 return types
[(rand() % types
.size())];
858 bool test_task_random(TaskManager
& task_manager
,
859 const Waypoints
&waypoints
,
860 const unsigned num_points
)
864 OrderedTaskPoint
*tp
;
866 task_manager
.SetFactory(TaskFactoryType::MIXED
);
867 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
869 task_report(task_manager
, "# adding start\n");
870 wp
= random_waypoint(waypoints
);
872 const TaskPointFactoryType s
= GetRandomType(fact
.GetStartTypes());
874 tp
= fact
.CreateStart(s
,*wp
);
875 if (!fact
.Append(*tp
,false)) {
881 task_manager
.SetActiveTaskPoint(0);
882 task_manager
.Resume();
884 for (unsigned i
=0; i
<num_points
; i
++) {
885 task_report(task_manager
, "# adding intermediate\n");
886 wp
= random_waypoint(waypoints
);
888 const TaskPointFactoryType s
= GetRandomType(fact
.GetIntermediateTypes());
890 tp
= fact
.CreateIntermediate(s
,*wp
);
891 if (!fact
.Append(*tp
,false)) {
898 task_report(task_manager
, "# adding finish\n");
899 wp
= random_waypoint(waypoints
);
901 const TaskPointFactoryType s
= GetRandomType(fact
.GetFinishTypes());
903 tp
= fact
.CreateFinish(s
,*wp
);
904 if (!fact
.Append(*tp
,false)) {
910 task_report(task_manager
, "# validating task..\n");
911 if (!fact
.Validate()) {
914 task_report(task_manager
, "# checking task..\n");
915 if (!task_manager
.CheckOrderedTask()) {
921 bool test_task_random_RT_AAT_FAI(TaskManager
& task_manager
,
922 const Waypoints
&waypoints
,
923 const unsigned _num_points
)
927 OrderedTaskPoint
*tp
;
935 task_manager
.SetFactory(TaskFactoryType::AAT
);
936 strcpy(tskType
,"AAT");
937 test_note("# creating random AAT task\n");
940 task_manager
.SetFactory(TaskFactoryType::RACING
);
941 strcpy(tskType
,"RT");
942 test_note("# creating random RT task\n");
945 task_manager
.SetFactory(TaskFactoryType::FAI_GENERAL
);
946 strcpy(tskType
,"FAI");
947 test_note("# creating random FAI GENERAL\n");
951 AbstractTaskFactory
&fact
= task_manager
.GetFactory();
953 //max points includes start & finish
954 const TaskFactoryConstraints
&constraints
=
955 task_manager
.GetOrderedTask().GetFactoryConstraints();
956 const unsigned num_points_total
=
957 std::max(constraints
.min_points
,
958 _num_points
% constraints
.max_points
) + 1;
959 const unsigned num_int_points
= num_points_total
- 2;
961 test_note("# adding start\n");
962 wp
= random_waypoint(waypoints
);
964 const TaskPointFactoryType s
= GetRandomType(fact
.GetStartTypes());
966 tp
= fact
.CreateStart(s
,*wp
);
967 if (!fact
.Append(*tp
,false)) {
973 for (unsigned i
=0; i
<num_int_points
; i
++) {
974 test_note("# adding intermediate\n");
975 wp
= random_waypoint(waypoints
);
977 const TaskPointFactoryType s
= GetRandomType(fact
.GetIntermediateTypes());
979 tp
= fact
.CreateIntermediate(s
,*wp
);
980 if (!fact
.Append(*tp
,false)) {
987 test_note("# adding finish\n");
988 wp
= random_waypoint(waypoints
);
990 const TaskPointFactoryType s
= GetRandomType(fact
.GetFinishTypes());
992 tp
= fact
.CreateFinish(s
,*wp
);
993 if (!fact
.Append(*tp
,false)) {
999 test_note("# validating task..\n");
1000 if (!fact
.Validate()) {
1003 if (task_manager
.GetOrderedTask().GetFactoryType()
1004 == TaskFactoryType::FAI_GENERAL
)
1006 test_note("# checking OZs for FAI General..\n");
1007 if (!fact
.ValidateFAIOZs())
1011 if (task_manager
.GetOrderedTask().GetFactoryType()
1012 == TaskFactoryType::MAT
)
1014 test_note("# checking OZs for MAT General..\n");
1015 if (!fact
.ValidateMATOZs())
1018 task_manager
.Resume();
1019 sprintf(tmp
, "# SUCCESS CREATING %s task! task_size():%d..\n",
1021 task_manager
.TaskSize());
1026 bool test_task(TaskManager
& task_manager
,
1027 const Waypoints
&waypoints
,
1030 unsigned n_points
= rand()%8+1;
1033 return test_task_mixed(task_manager
,waypoints
);
1035 return test_task_fai(task_manager
,waypoints
);
1037 return test_task_aat(task_manager
,waypoints
);
1039 return test_task_or(task_manager
,waypoints
);
1041 return test_task_dash(task_manager
,waypoints
);
1043 return test_task_fg(task_manager
,waypoints
);
1045 return test_task_manip(task_manager
,waypoints
);
1047 return test_task_random(task_manager
,waypoints
,n_points
);
1049 return test_task_mat(task_manager
,waypoints
);
1056 const char* task_name(int test_num
)