Debian Codegraph @

Tests/DetourCrowd/Tests_DetourPathCorridor.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #include "catch2/catch_all.hpp"
2
3 #include "DetourPathCorridor.h"
4
5 TEST_CASE("dtMergeCorridorStartMoved")
6 {
7 SECTION("Should handle empty input")
8 {
9 dtPolyRef* const path = nullptr;
10 const int npath = 0;
11 const int maxPath = 0;
12 const dtPolyRef* const visited = nullptr;
13 const int nvisited = 0;
14 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
15 CHECK(result == 0);
16 }
17
18 SECTION("Should handle empty visited")
19 {
20 dtPolyRef path[] = {1};
21 const int npath = 1;
22 const int maxPath = 1;
23 const dtPolyRef* const visited = nullptr;
24 const int nvisited = 0;
25 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
26 CHECK(result == 1);
27 const dtPolyRef expectedPath[] = {1};
28 CHECK_THAT(path, Catch::Matchers::RangeEquals(expectedPath));
29 }
30
31 SECTION("Should handle empty path")
32 {
33 dtPolyRef* const path = nullptr;
34 const int npath = 0;
35 const int maxPath = 0;
36 const dtPolyRef visited[] = {1};
37 const int nvisited = 1;
38 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
39 CHECK(result == 0);
40 }
41
42 SECTION("Should strip visited points from path except last")
43 {
44 dtPolyRef path[] = {1, 2};
45 const int npath = 2;
46 const int maxPath = 2;
47 const dtPolyRef visited[] = {1, 2};
48 const int nvisited = 2;
49 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
50 CHECK(result == 1);
51 const dtPolyRef expectedPath[] = {2, 2};
52 CHECK_THAT(path, Catch::Matchers::RangeEquals(expectedPath));
53 }
54
55 SECTION("Should add visited points not present in path in reverse order")
56 {
57 dtPolyRef path[] = {1, 2, 0};
58 const int npath = 2;
59 const int maxPath = 3;
60 const dtPolyRef visited[] = {1, 2, 3, 4};
61 const int nvisited = 4;
62 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
63 CHECK(result == 3);
64 const dtPolyRef expectedPath[] = {4, 3, 2};
65 CHECK_THAT(path, Catch::Matchers::RangeEquals(expectedPath));
66 }
67
68 SECTION("Should add visited points not present in path up to the path capacity")
69 {
70 dtPolyRef path[] = {1, 2, 0};
71 const int npath = 2;
72 const int maxPath = 3;
73 const dtPolyRef visited[] = {1, 2, 3, 4, 5};
74 const int nvisited = 5;
75 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
76 CHECK(result == 3);
77 const dtPolyRef expectedPath[] = {5, 4, 3};
78 CHECK_THAT(path, Catch::Matchers::RangeEquals(expectedPath));
79 }
80
81 SECTION("Should not change path if there is no intersection with visited")
82 {
83 dtPolyRef path[] = {1, 2};
84 const int npath = 2;
85 const int maxPath = 2;
86 const dtPolyRef visited[] = {3, 4};
87 const int nvisited = 2;
88 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
89 CHECK(result == 2);
90 const dtPolyRef expectedPath[] = {1, 2};
91 CHECK_THAT(path, Catch::Matchers::RangeEquals(expectedPath));
92 }
93
94 SECTION("Should save unvisited path points")
95 {
96 dtPolyRef path[] = {1, 2, 0};
97 const int npath = 2;
98 const int maxPath = 3;
99 const dtPolyRef visited[] = {1, 3};
100 const int nvisited = 2;
101 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
102 CHECK(result == 3);
103 const dtPolyRef expectedPath[] = {3, 1, 2};
104 CHECK_THAT(path, Catch::Matchers::RangeEquals(expectedPath));
105 }
106
107 SECTION("Should save unvisited path points up to the path capacity")
108 {
109 dtPolyRef path[] = {1, 2};
110 const int npath = 2;
111 const int maxPath = 2;
112 const dtPolyRef visited[] = {1, 3};
113 const int nvisited = 2;
114 const int result = dtMergeCorridorStartMoved(path, npath, maxPath, visited, nvisited);
115 CHECK(result == 2);
116 const dtPolyRef expectedPath[] = {3, 1};
117 CHECK_THAT(path, Catch::Matchers::RangeEquals(expectedPath));
118 }
119 }