mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
45 lines
1.7 KiB
C++
45 lines
1.7 KiB
C++
#include "pathfinderTest.h"
|
|
#include "pathfinder.h"
|
|
#include "map.h"
|
|
|
|
#include <util.h>
|
|
|
|
#include <vector>
|
|
|
|
namespace battleship{
|
|
using namespace std;
|
|
using namespace vb01;
|
|
|
|
void PathfinderTest::testFindPath(){
|
|
vector<Map::Cell> cells = vector<Map::Cell>{
|
|
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 0, 0), Map::Edge(2, 0, 1), Map::Edge(4, 0, 2)}),
|
|
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 1, 1), Map::Edge(1, 1, 2), Map::Edge(9, 1, 3), Map::Edge(13, 1, 4)}),
|
|
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 2, 2), Map::Edge(2, 2, 1), Map::Edge(4, 2, 4), Map::Edge(5, 2, 5)}),
|
|
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 3, 3), Map::Edge(1, 3, 6)}),
|
|
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 4, 4), Map::Edge(1, 4, 0), Map::Edge(1, 4, 3), Map::Edge(3, 4, 6)}),
|
|
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 5, 5), Map::Edge(9, 5, 4), Map::Edge(2, 5, 6)}),
|
|
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 6, 6)})
|
|
};
|
|
|
|
int size = cells.size();
|
|
const u16 INF = u16(0 - 1);
|
|
pathfinder->setImpassibleNodeVal(INF);
|
|
vector<int> path = pathfinder->findPath(cells, 0, size - 1);
|
|
CPPUNIT_ASSERT(path == vector<int>({0, 1, 2, 4, 3, 6}));
|
|
|
|
int sumPathWeights = 0;
|
|
|
|
for(int i = 1; i < path.size(); i++)
|
|
sumPathWeights += cells[path[i - 1]].getEdgeWeight(path[i]);
|
|
|
|
CPPUNIT_ASSERT(sumPathWeights == 9);
|
|
}
|
|
|
|
void PathfinderTest::setUp(){
|
|
pathfinder = Pathfinder::getSingleton();
|
|
}
|
|
|
|
void PathfinderTest::tearDown(){
|
|
}
|
|
}
|