Skip to content

Commit 4725a4b

Browse files
committed
Merge pull request #104793 from YYF233333/remove_astar_stress_test
Remove stress unit tests
2 parents 879bd6e + 0139ea6 commit 4725a4b

File tree

6 files changed

+0
-311
lines changed

6 files changed

+0
-311
lines changed

tests/core/math/test_astar.h

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -211,149 +211,4 @@ TEST_CASE("[AStar3D] Add/Remove") {
211211
}
212212
// It's been great work, cheers. \(^ ^)/
213213
}
214-
215-
TEST_CASE("[Stress][AStar3D] Find paths") {
216-
// Random stress tests with Floyd-Warshall.
217-
constexpr int N = 30;
218-
Math::seed(0);
219-
220-
for (int test = 0; test < 1000; test++) {
221-
AStar3D a;
222-
Vector3 p[N];
223-
bool adj[N][N] = { { false } };
224-
225-
// Assign initial coordinates.
226-
for (int u = 0; u < N; u++) {
227-
p[u].x = Math::rand() % 100;
228-
p[u].y = Math::rand() % 100;
229-
p[u].z = Math::rand() % 100;
230-
a.add_point(u, p[u]);
231-
}
232-
// Generate a random sequence of operations.
233-
for (int i = 0; i < 1000; i++) {
234-
// Pick two different vertices.
235-
int u, v;
236-
u = Math::rand() % N;
237-
v = Math::rand() % (N - 1);
238-
if (u == v) {
239-
v = N - 1;
240-
}
241-
// Pick a random operation.
242-
int op = Math::rand();
243-
switch (op % 9) {
244-
case 0:
245-
case 1:
246-
case 2:
247-
case 3:
248-
case 4:
249-
case 5:
250-
// Add edge (u, v); possibly bidirectional.
251-
a.connect_points(u, v, op % 2);
252-
adj[u][v] = true;
253-
if (op % 2) {
254-
adj[v][u] = true;
255-
}
256-
break;
257-
case 6:
258-
case 7:
259-
// Remove edge (u, v); possibly bidirectional.
260-
a.disconnect_points(u, v, op % 2);
261-
adj[u][v] = false;
262-
if (op % 2) {
263-
adj[v][u] = false;
264-
}
265-
break;
266-
case 8:
267-
// Remove point u and add it back; clears adjacent edges and changes coordinates.
268-
a.remove_point(u);
269-
p[u].x = Math::rand() % 100;
270-
p[u].y = Math::rand() % 100;
271-
p[u].z = Math::rand() % 100;
272-
a.add_point(u, p[u]);
273-
for (v = 0; v < N; v++) {
274-
adj[u][v] = adj[v][u] = false;
275-
}
276-
break;
277-
}
278-
}
279-
// Floyd-Warshall.
280-
float d[N][N];
281-
for (int u = 0; u < N; u++) {
282-
for (int v = 0; v < N; v++) {
283-
d[u][v] = (u == v || adj[u][v]) ? p[u].distance_to(p[v]) : Math::INF;
284-
}
285-
}
286-
for (int w = 0; w < N; w++) {
287-
for (int u = 0; u < N; u++) {
288-
for (int v = 0; v < N; v++) {
289-
if (d[u][v] > d[u][w] + d[w][v]) {
290-
d[u][v] = d[u][w] + d[w][v];
291-
}
292-
}
293-
}
294-
}
295-
// Display statistics.
296-
int count = 0;
297-
for (int u = 0; u < N; u++) {
298-
for (int v = 0; v < N; v++) {
299-
if (adj[u][v]) {
300-
count++;
301-
}
302-
}
303-
}
304-
print_verbose(vformat("Test #%4d: %3d edges, ", test + 1, count));
305-
count = 0;
306-
for (int u = 0; u < N; u++) {
307-
for (int v = 0; v < N; v++) {
308-
if (!Math::is_inf(d[u][v])) {
309-
count++;
310-
}
311-
}
312-
}
313-
print_verbose(vformat("%3d/%d pairs of reachable points\n", count - N, N * (N - 1)));
314-
315-
// Check A*'s output.
316-
bool match = true;
317-
for (int u = 0; u < N; u++) {
318-
for (int v = 0; v < N; v++) {
319-
if (u != v) {
320-
Vector<int64_t> route = a.get_id_path(u, v);
321-
if (!Math::is_inf(d[u][v])) {
322-
// Reachable.
323-
if (route.size() == 0) {
324-
print_verbose(vformat("From %d to %d: A* did not find a path\n", u, v));
325-
match = false;
326-
goto exit;
327-
}
328-
float astar_dist = 0;
329-
for (int i = 1; i < route.size(); i++) {
330-
if (!adj[route[i - 1]][route[i]]) {
331-
print_verbose(vformat("From %d to %d: edge (%d, %d) does not exist\n",
332-
u, v, route[i - 1], route[i]));
333-
match = false;
334-
goto exit;
335-
}
336-
astar_dist += p[route[i - 1]].distance_to(p[route[i]]);
337-
}
338-
if (!Math::is_equal_approx(astar_dist, d[u][v])) {
339-
print_verbose(vformat("From %d to %d: Floyd-Warshall gives %.6f, A* gives %.6f\n",
340-
u, v, d[u][v], astar_dist));
341-
match = false;
342-
goto exit;
343-
}
344-
} else {
345-
// Unreachable.
346-
if (route.size() > 0) {
347-
print_verbose(vformat("From %d to %d: A* somehow found a nonexistent path\n", u, v));
348-
match = false;
349-
goto exit;
350-
}
351-
}
352-
}
353-
}
354-
}
355-
exit:
356-
CHECK_MESSAGE(match, "Found all paths.");
357-
}
358-
}
359214
} // namespace TestAStar

tests/core/math/test_basis.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -189,32 +189,6 @@ TEST_CASE("[Basis] Euler conversions") {
189189
}
190190
}
191191

192-
TEST_CASE("[Stress][Basis] Euler conversions") {
193-
Vector<EulerOrder> euler_order_to_test;
194-
euler_order_to_test.push_back(EulerOrder::XYZ);
195-
euler_order_to_test.push_back(EulerOrder::XZY);
196-
euler_order_to_test.push_back(EulerOrder::YZX);
197-
euler_order_to_test.push_back(EulerOrder::YXZ);
198-
euler_order_to_test.push_back(EulerOrder::ZXY);
199-
euler_order_to_test.push_back(EulerOrder::ZYX);
200-
201-
Vector<Vector3> vectors_to_test;
202-
// Add 1000 random vectors with weirds numbers.
203-
RandomNumberGenerator rng;
204-
for (int _ = 0; _ < 1000; _ += 1) {
205-
vectors_to_test.push_back(Vector3(
206-
rng.randf_range(-1800, 1800),
207-
rng.randf_range(-1800, 1800),
208-
rng.randf_range(-1800, 1800)));
209-
}
210-
211-
for (int h = 0; h < euler_order_to_test.size(); h += 1) {
212-
for (int i = 0; i < vectors_to_test.size(); i += 1) {
213-
test_rotation(vectors_to_test[i], euler_order_to_test[h]);
214-
}
215-
}
216-
}
217-
218192
TEST_CASE("[Basis] Set axis angle") {
219193
Vector3 axis;
220194
real_t angle;

tests/core/math/test_quaternion.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -406,33 +406,6 @@ void test_quat_vec_rotate(Vector3 euler_yzx, Vector3 v_in) {
406406
CHECK(v_rot.is_equal_approx(v_compare));
407407
}
408408

409-
TEST_CASE("[Stress][Quaternion] Many vector xforms") {
410-
// Many arbitrary quaternions rotate many arbitrary vectors.
411-
// For each trial, check that rotation by Quaternion yields same result as
412-
// rotation by Basis.
413-
constexpr int STEPS = 100; // Number of test steps in each dimension
414-
constexpr double delta = 2.0 * Math::PI / STEPS; // Angle increment per step
415-
constexpr double delta_vec = 20.0 / STEPS; // Vector increment per step
416-
Vector3 vec_arb(1.0, 1.0, 1.0);
417-
double x_angle = -Math::PI;
418-
double y_angle = -Math::PI;
419-
double z_angle = -Math::PI;
420-
for (double i = 0; i < STEPS; ++i) {
421-
vec_arb[0] = -10.0 + i * delta_vec;
422-
x_angle = i * delta - Math::PI;
423-
for (double j = 0; j < STEPS; ++j) {
424-
vec_arb[1] = -10.0 + j * delta_vec;
425-
y_angle = j * delta - Math::PI;
426-
for (double k = 0; k < STEPS; ++k) {
427-
vec_arb[2] = -10.0 + k * delta_vec;
428-
z_angle = k * delta - Math::PI;
429-
Vector3 euler_yzx(x_angle, y_angle, z_angle);
430-
test_quat_vec_rotate(euler_yzx, vec_arb);
431-
}
432-
}
433-
}
434-
}
435-
436409
TEST_CASE("[Quaternion] Finite number checks") {
437410
constexpr real_t x = Math::NaN;
438411

tests/core/string/test_string.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,22 +2185,4 @@ TEST_CASE("[String][URL] Parse URL") {
21852185

21862186
#undef CHECK_URL
21872187
}
2188-
2189-
TEST_CASE("[Stress][String] Empty via ' == String()'") {
2190-
for (int i = 0; i < 100000; ++i) {
2191-
String str = "Hello World!";
2192-
if (str == String()) {
2193-
continue;
2194-
}
2195-
}
2196-
}
2197-
2198-
TEST_CASE("[Stress][String] Empty via `is_empty()`") {
2199-
for (int i = 0; i < 100000; ++i) {
2200-
String str = "Hello World!";
2201-
if (str.is_empty()) {
2202-
continue;
2203-
}
2204-
}
2205-
}
22062188
} // namespace TestString

tests/core/templates/test_command_queue.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -442,48 +442,6 @@ TEST_CASE("[CommandQueue] Test Queue Lapping") {
442442
ProjectSettings::get_singleton()->property_get_revert(COMMAND_QUEUE_SETTING));
443443
}
444444

445-
TEST_CASE("[Stress][CommandQueue] Stress test command queue") {
446-
const char *COMMAND_QUEUE_SETTING = "memory/limits/command_queue/multithreading_queue_size_kb";
447-
ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING, 1);
448-
SharedThreadState sts;
449-
sts.init_threads();
450-
451-
RandomNumberGenerator rng;
452-
453-
rng.set_seed(1837267);
454-
455-
int msgs_to_add = 2048;
456-
457-
for (int i = 0; i < msgs_to_add; i++) {
458-
// randi_range is inclusive, so allow any enum value except MAX.
459-
sts.add_msg_to_write((SharedThreadState::TestMsgType)rng.randi_range(0, SharedThreadState::TEST_MSG_MAX - 1));
460-
}
461-
sts.writer_threadwork.main_start_work();
462-
463-
int max_loop_iters = msgs_to_add * 2;
464-
int loop_iters = 0;
465-
while (sts.func1_count < msgs_to_add && loop_iters < max_loop_iters) {
466-
int remaining = (msgs_to_add - sts.func1_count);
467-
sts.message_count_to_read = rng.randi_range(1, remaining < 128 ? remaining : 128);
468-
if (loop_iters % 3 == 0) {
469-
sts.message_count_to_read = -1;
470-
}
471-
sts.reader_threadwork.main_start_work();
472-
sts.reader_threadwork.main_wait_for_done();
473-
loop_iters++;
474-
}
475-
CHECK_MESSAGE(loop_iters < max_loop_iters,
476-
"Reader needed too many iterations to read messages!");
477-
sts.writer_threadwork.main_wait_for_done();
478-
479-
sts.destroy_threads();
480-
481-
CHECK_MESSAGE(sts.func1_count == msgs_to_add,
482-
"Reader should have read no additional messages after join");
483-
ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING,
484-
ProjectSettings::get_singleton()->property_get_revert(COMMAND_QUEUE_SETTING));
485-
}
486-
487445
TEST_CASE("[CommandQueue] Test Parameter Passing Semantics") {
488446
SharedThreadState sts;
489447
sts.init_threads();

tests/core/templates/test_list.h

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -545,57 +545,4 @@ TEST_CASE("[List] Swap adjacent back and front (reverse order of elements)") {
545545
}
546546
}
547547
}
548-
549-
static void swap_random(List<int> &p_list, List<int>::Element *r_elements[], size_t p_size, size_t p_iterations) {
550-
Math::seed(0);
551-
552-
for (size_t test_i = 0; test_i < p_iterations; ++test_i) {
553-
// A and B elements have corresponding indices as values.
554-
const int a_idx = static_cast<int>(Math::rand() % p_size);
555-
const int b_idx = static_cast<int>(Math::rand() % p_size);
556-
List<int>::Element *a = p_list.find(a_idx); // via find.
557-
List<int>::Element *b = r_elements[b_idx]; // via pointer.
558-
559-
int va = a->get();
560-
int vb = b->get();
561-
562-
p_list.swap(a, b);
563-
564-
CHECK(va == a->get());
565-
CHECK(vb == b->get());
566-
567-
size_t element_count = 0;
568-
569-
// Fully traversable after swap?
570-
List<int>::Element *it = p_list.front();
571-
while (it) {
572-
element_count += 1;
573-
List<int>::Element *prev_it = it;
574-
it = it->next();
575-
if (it == prev_it) {
576-
FAIL_CHECK("Infinite loop detected.");
577-
break;
578-
}
579-
}
580-
// We should not lose anything in the process.
581-
if (element_count != p_size) {
582-
FAIL_CHECK("Element count mismatch.");
583-
break;
584-
}
585-
}
586-
}
587-
588-
TEST_CASE("[Stress][List] Swap random 100 elements, 500 iterations.") {
589-
List<int> list;
590-
List<int>::Element *n[100];
591-
populate_integers(list, n, 100);
592-
swap_random(list, n, 100, 500);
593-
}
594-
595-
TEST_CASE("[Stress][List] Swap random 10 elements, 1000 iterations.") {
596-
List<int> list;
597-
List<int>::Element *n[10];
598-
populate_integers(list, n, 10);
599-
swap_random(list, n, 10, 1000);
600-
}
601548
} // namespace TestList

0 commit comments

Comments
 (0)