GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
map_state_test.h
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#ifndef DESIGNLAB_MAP_STATE_TEST_H_
9#define DESIGNLAB_MAP_STATE_TEST_H_
10
11#include <vector>
12
13#include "doctest.h"
14
15#include "map_state.h"
16
17
18TEST_SUITE("MapState::Constructor")
19{
22
23 TEST_CASE("デフォルトコンストラクタの呼び出し時,マップのサイズは0になるべき")
24 {
25 MapState map_state;
26
27 CHECK_EQ(map_state.GetMapPointSize(), 0);
28 }
29
30 TEST_CASE("脚接地点を引数に渡した時,マップの要素は引数のと同じになるべき")
31 {
32 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
33
34 MapState map_state(map_point);
35
36 SUBCASE("マップのサイズは引数と同じサイズになるべき")
37 {
38 CHECK(map_state.GetMapPointSize() == map_point.size());
39 }
40
41 SUBCASE("追加した順番で脚接地可能点を取得できるべき")
42 {
43 CHECK(map_state.GetMapPoint(0) == map_point[0]);
44 CHECK(map_state.GetMapPoint(1) == map_point[1]);
45 }
46 }
47
48 TEST_CASE("コピーコンストラクタの呼び出し時,コピー元と同じになるべき")
49 {
50 SUBCASE("初期化時,コピー元と同じデータサイズになるべき")
51 {
52 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
53
54 MapState map_state(map_point);
55 MapState map_state_copy(map_state);
56
57 CHECK(map_state_copy.GetMapPointSize() == map_state.GetMapPointSize());
58 }
59
60 SUBCASE("初期化時,コピー元と同じデータが取得できるべき")
61 {
62 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
63
64 MapState map_state(map_point);
65 MapState map_state_copy(map_state);
66
67 CHECK(map_state_copy.GetMapPoint(0) == map_state.GetMapPoint(0));
68 CHECK(map_state_copy.GetMapPoint(1) == map_state.GetMapPoint(1));
69 }
70 }
71}
72
73TEST_SUITE("MapState::AssignmentOperator")
74{
77
78 TEST_CASE("代入した時,代入元と同じサイズになるべき")
79 {
80 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
81
82 MapState map_state(map_point);
83 MapState map_state_copy = map_state;
84
85 CHECK(map_state_copy.GetMapPointSize() == map_state.GetMapPointSize());
86 }
87
88 TEST_CASE("代入した時,代入元と同じデータが取得できるべき")
89 {
90 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
91
92 MapState map_state(map_point);
93 MapState map_state_copy = map_state;
94
95 CHECK(map_state_copy.GetMapPoint(0) == map_state.GetMapPoint(0));
96 CHECK(map_state_copy.GetMapPoint(1) == map_state.GetMapPoint(1));
97 }
98}
99
100TEST_SUITE("MapState::SetMapPoint")
101{
103 using designlab::Vector3;
104
105 TEST_CASE("0番目にデータをセットした時,マップのサイズは変わるべきでない")
106 {
107 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
108 Vector3 map_point_set = { 7, 8, 9 };
109
110 MapState map_state(map_point);
111
112 map_state.SetMapPoint(0, map_point_set);
113
114 CHECK(map_state.GetMapPointSize() == map_point.size());
115 }
116
117 TEST_CASE("0番目にデータをセットした時,0番の脚接地点が書き換わるべき")
118 {
119 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
120 Vector3 map_point_set = { 7, 8, 9 };
121
122 MapState map_state(map_point);
123
124 map_state.SetMapPoint(0, map_point_set);
125
126 CHECK(map_state.GetMapPoint(0) == map_point_set);
127 CHECK(map_state.GetMapPoint(1) == map_point[1]);
128 }
129}
130
131TEST_SUITE("MapState::SetMapPointVec")
132{
134 using designlab::Vector3;
135
136 TEST_CASE("3つの脚接地点をセットした時,マップのサイズは3になるべき")
137 {
138 SUBCASE("マップが空の時")
139 {
140 std::vector<Vector3> map_point_set = { {7, 8, 9}, {10, 11, 12}, {13, 14, 15} };
141
142 MapState map_state;
143
144 map_state.SetMapPointVec(map_point_set);
145
146 CHECK(map_state.GetMapPointSize() == map_point_set.size());
147 }
148
149 SUBCASE("マップにデータがある時")
150 {
151 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
152 std::vector<Vector3> map_point_set = { {7, 8, 9}, {10, 11, 12}, {13, 14, 15} };
153
154 MapState map_state(map_point);
155
156 map_state.SetMapPointVec(map_point_set);
157
158 CHECK(map_state.GetMapPointSize() == map_point_set.size());
159 }
160 }
161
162 TEST_CASE("3つの脚接地点をセットした時,0番から順に脚接地点が書き換わるべき")
163 {
164 SUBCASE("マップが空の時")
165 {
166 std::vector<Vector3> map_point_set = { {7, 8, 9}, {10, 11, 12}, {13, 14, 15} };
167
168 MapState map_state;
169
170 map_state.SetMapPointVec(map_point_set);
171
172 CHECK(map_state.GetMapPoint(0) == map_point_set[0]);
173 CHECK(map_state.GetMapPoint(1) == map_point_set[1]);
174 CHECK(map_state.GetMapPoint(2) == map_point_set[2]);
175 }
176
177 SUBCASE("マップにデータがある時")
178 {
179 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
180 std::vector<Vector3> map_point_set = { {7, 8, 9}, {10, 11, 12}, {13, 14, 15} };
181
182 MapState map_state(map_point);
183
184 map_state.SetMapPointVec(map_point_set);
185
186 CHECK(map_state.GetMapPoint(0) == map_point_set[0]);
187 CHECK(map_state.GetMapPoint(1) == map_point_set[1]);
188 CHECK(map_state.GetMapPoint(2) == map_point_set[2]);
189 }
190 }
191}
192
193TEST_SUITE("MapState::AddMapPoint")
194{
196 using designlab::Vector3;
197
198 TEST_CASE("2回呼び出した時,マップのサイズは2増えるべき")
199 {
200 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
201
202 CHECK_EQ(map_point.size(), 2);
203
204 MapState map_state(map_point);
205
206 map_state.AddMapPoint({ 7, 8, 9 });
207 map_state.AddMapPoint({ 10, 11, 12 });
208
209 CHECK_EQ(map_state.GetMapPointSize(), 4);
210 }
211
212 TEST_CASE("2回呼び出した時,追加した順番で脚接地可能点を取得できるべき")
213 {
214 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
215
216 MapState map_state(map_point);
217
218 map_state.AddMapPoint({ 7, 8, 9 });
219 map_state.AddMapPoint({ 10, 11, 12 });
220
221 CHECK_EQ(map_state.GetMapPoint(0), map_point[0]);
222 CHECK_EQ(map_state.GetMapPoint(1), map_point[1]);
223 CHECK_EQ(map_state.GetMapPoint(2), Vector3(7, 8, 9));
224 CHECK_EQ(map_state.GetMapPoint(3), Vector3(10, 11, 12));
225 }
226}
227
228TEST_SUITE("MapState::ClearMapPoint")
229{
231 using designlab::Vector3;
232
233 TEST_CASE("ClearMapPoint")
234 {
235 SUBCASE("2つの脚接地点を消去した時,マップのサイズは0になるべき")
236 {
237 std::vector<Vector3> map_point = { {1, 2, 3}, {4, 5, 6} };
238
239 MapState map_state(map_point);
240
241 map_state.ClearMapPoint();
242
243 CHECK_EQ(map_state.GetMapPointSize(), 0);
244 }
245 }
246}
247
248#endif // DESIGNLAB_MAP_STATE_TEST_H_
マップを表すクラス.
Definition map_state.h:32
TEST_SUITE("MapState::Constructor")
3次元の位置ベクトルを表す構造体.