Commit c4333ae6 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add test

parent 30e12007
Pipeline #130509 passed with stages
in 1 minute and 9 seconds
......@@ -7,7 +7,9 @@
#include "Graph.h"
///Test the graph conversion to dot
void testGraphToDot(){
/** @return true on success, false otherwise
*/
bool testGraphToDot(){
Graph<bool, long> graph;
long nodeA = graph.createNode(true, "a");
......@@ -21,13 +23,21 @@ void testGraphToDot(){
graph.connectNode(nodeC, nodeE);
graph.connectNode(nodeD, nodeE);
graph.savePng("testGraph.png");
bool b(true);
b &= graph.savePng("testGraph.png");
b &= !graph.saveDot("");
b &= !graph.savePng("");
b &= !graph.saveDot("someInexistingDir/someFile.dot");
b &= !graph.savePng("someInexistingDir/someFile.png");
std::cout << "testGraphToDot : b = " << b << std::endl;
return b;
}
int main(int argc, char** argv){
testGraphToDot();
return 0;
bool b(testGraphToDot());
std::cout << "b = " << b << std::endl;
return b - 1;
}
......@@ -8,8 +8,6 @@
#include <iostream>
#include "Tree/PNTreeLight.h"
using namespace std;
#define NB_POINT 8lu
#define NB_POINT_TOTAL (NB_POINT*NB_POINT)
......@@ -19,7 +17,9 @@ using namespace std;
///Tests the basis of the quadtree
void testBaseQuadTree(){
/** @return true on success, false otherwise
*/
bool testBaseQuadTree(){
size_t nbPoint(NB_POINT);
float dXY(5.0f);
float shift(dXY/2.0f);
......@@ -33,9 +33,10 @@ void testBaseQuadTree(){
float x, y;
float tabPos[2*NB_POINT_TOTAL];
bool b(true);
std::ofstream fs;
fs.open("pointAddedInQuadTree.txt");
if(!fs.is_open()) return;
b &= fs.is_open();
for(size_t i(0lu); i < nbPoint; ++i){
y = shift + ((float)i)*dXY;
for(size_t j(0lu); j < nbPoint; ++j){
......@@ -43,10 +44,10 @@ void testBaseQuadTree(){
tabPos[(i*nbPoint + j)*2lu] = x;
tabPos[(i*nbPoint + j)*2lu + 1lu] = y;
id = i*nbPoint + j;
cerr << "Add point " << x << "," << y << "\t, id = " << id << endl;
fs << x << "\t" << y << "\t0" << endl;
std::cerr << "Add point " << x << "," << y << "\t, id = " << id << std::endl;
fs << x << "\t" << y << "\t0" << std::endl;
if(!quadTree.addElement(&(tabPos[(i*nbPoint + j)*2lu]), tabId+id)){
cerr << "quadTree.addElement : can't add element : Stop" << endl;
std::cerr << "quadTree.addElement : can't add element : Stop" << std::endl;
i = nbPoint;
break;
}
......@@ -54,19 +55,19 @@ void testBaseQuadTree(){
}
fs.close();
std::string fileTxt("quadTree.txt");
if(quadTree.saveGnuplotData(fileTxt)){
std::cout << "testBaseQuadTree : file '" << fileTxt << "' saved" << std::endl;
}else{
std::cerr << "testBaseQuadTree : can't save file '" << fileTxt << "'" << std::endl;
}
b &= quadTree.saveGnuplotData(fileTxt);
float posLastData[] = {11.0f, 19.0f};
const size_t * data = quadTree.getLastData(posLastData);
if(data != NULL) cout << "testBaseQuadTree : data (11.0, 19.0) = " << *data << endl;
else cout << "testBaseQuadTree : data (11.0, 19.0) = NULL" << endl;
b &= (data != NULL);
std::cout << "testBaseQuadTree : data (11.0, 19.0) = " << *data << std::endl;
std::cout << "testBaseQuadTree : b = " << b << std::endl;
return b;
}
///Tests the basis of the quadtree
void testBaseQuadTree3d(){
/** @return true on success, false otherwise
*/
bool testBaseQuadTree3d(){
size_t nbPoint(NB_POINT_3D);
float dXY(5.0f);
float shift(dXY/2.0f);
......@@ -79,10 +80,10 @@ void testBaseQuadTree3d(){
for(size_t i(0lu); i < NB_POINT_3D_TOTAL; ++i){tabId[i] = i;}
float tabPos[3*NB_POINT_3D_TOTAL];
float x,y,z;
bool b(true);
std::ofstream fs;
fs.open("pointAddedInQuadTree3d.txt");
if(!fs.is_open()) return;
b &= fs.is_open();
for(size_t k(0lu); k < nbPoint; ++k){
z = shift + ((float)k)*dXY;
for(size_t i(0lu); i < nbPoint; ++i){
......@@ -90,13 +91,13 @@ void testBaseQuadTree3d(){
for(size_t j(0lu); j < nbPoint; ++j){
x = shift + ((float)j)*dXY;
id = k*nbPoint*nbPoint + i*nbPoint + j;
// cerr << "Add point " << tabPos[0] << "," << tabPos[1] << "," << tabPos[2] << "\t, id = " << id << endl;
// std::cerr << "Add point " << tabPos[0] << "," << tabPos[1] << "," << tabPos[2] << "\t, id = " << id << std::endl;
tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu] = x;
tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu + 1lu] = y;
tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu + 2lu] = z;
fs << x << "\t" << y << "\t"<< z << endl;
fs << x << "\t" << y << "\t"<< z << std::endl;
if(!quadTree.addElement(&(tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu]), tabId+id)){
cerr << "quadTree.addElement : can't add element : Stop" << endl;
std::cerr << "quadTree.addElement : can't add element : Stop" << std::endl;
i = nbPoint;
break;
}
......@@ -105,15 +106,14 @@ void testBaseQuadTree3d(){
}
fs.close();
std::string fileTxt("quadTree3d.txt");
if(quadTree.saveGnuplotData(fileTxt)){
std::cout << "testBaseQuadTree3d : file '" << fileTxt << "' saved" << std::endl;
}else{
std::cerr << "testBaseQuadTree3d : can't save file '" << fileTxt << "'" << std::endl;
}
b &= quadTree.saveGnuplotData(fileTxt);
float posLastData[] = {11.0f, 19.0f, 10.0f};
const size_t * data = quadTree.getLastData(posLastData);
if(data != NULL) cout << "testBaseQuadTree3d : data (11.0, 19.0) = " << *data << endl;
else cout << "testBaseQuadTree3d : data (11.0, 19.0) = NULL" << endl;
b &= (data != NULL);
std::cout << "testBaseQuadTree3d : data (11.0, 19.0) = " << *data << std::endl;
std::cout << "testBaseQuadTree3d : b = " << b << std::endl;
return b;
}
///Check the function isNeighbourSearchFinised
......@@ -125,14 +125,14 @@ bool checkIsNeigbourFinished(){
b &= isNeighbourSearchFinised(&value, 1lu);
value = false;
b &= !isNeighbourSearchFinised(&value, 1lu);
std::cout << "checkIsNeigbourFinished : b = " << b << std::endl;
return b;
}
int main(int argc, char** argv){
bool b(checkIsNeigbourFinished());
testBaseQuadTree();
testBaseQuadTree3d();
b &= testBaseQuadTree();
b &= testBaseQuadTree3d();
return b - 1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment