123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #include "test_astar.h"
- #include "core/math/a_star.h"
- #include "core/os/os.h"
- #include <stdio.h>
- namespace TestAStar {
- class ABCX : public AStar {
- public:
- enum { A,
- B,
- C,
- X };
- ABCX() {
- add_point(A, Vector3(0, 0, 0));
- add_point(B, Vector3(1, 0, 0));
- add_point(C, Vector3(0, 1, 0));
- add_point(X, Vector3(0, 0, 1));
- connect_points(A, B);
- connect_points(A, C);
- connect_points(B, C);
- connect_points(X, A);
- }
-
- float _compute_cost(int p_from, int p_to) {
- if (p_from == A && p_to == C) {
- return 1000;
- }
- return 100;
- }
- };
- bool test_abc() {
- ABCX abcx;
- PoolVector<int> path = abcx.get_id_path(ABCX::A, ABCX::C);
- bool ok = path.size() == 3;
- int i = 0;
- ok = ok && path[i++] == ABCX::A;
- ok = ok && path[i++] == ABCX::B;
- ok = ok && path[i++] == ABCX::C;
- return ok;
- }
- bool test_abcx() {
- ABCX abcx;
- PoolVector<int> path = abcx.get_id_path(ABCX::X, ABCX::C);
- bool ok = path.size() == 4;
- int i = 0;
- ok = ok && path[i++] == ABCX::X;
- ok = ok && path[i++] == ABCX::A;
- ok = ok && path[i++] == ABCX::B;
- ok = ok && path[i++] == ABCX::C;
- return ok;
- }
- typedef bool (*TestFunc)(void);
- TestFunc test_funcs[] = {
- test_abc,
- test_abcx,
- NULL
- };
- MainLoop *test() {
- int count = 0;
- int passed = 0;
- while (true) {
- if (!test_funcs[count])
- break;
- bool pass = test_funcs[count]();
- if (pass)
- passed++;
- OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
- count++;
- }
- OS::get_singleton()->print("\n");
- OS::get_singleton()->print("Passed %i of %i tests\n", passed, count);
- return NULL;
- }
- }
|