1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#include "Graph.h" |
8 |
|
|
|
9 |
|
|
///Test the graph iteration |
10 |
|
|
/** @param graph : Graph on which to iterate |
11 |
|
|
* @return true on success, false otherwise |
12 |
|
|
*/ |
13 |
|
1 |
bool testIterateGraph(const Graph<bool, long> & graph){ |
14 |
✓✓ |
1 |
std::cout << "testIterateGraph : iterateParent :" << std::endl; |
15 |
|
2 |
std::list<long> listNodeToParent; |
16 |
✓✓✓ |
4 |
while(graph.iterateParent(listNodeToParent)){ |
17 |
✓✓ |
3 |
std::cout << "To parent iteration :" << std::endl; |
18 |
✓✓ |
8 |
for(std::list<long>::iterator it(listNodeToParent.begin()); it != listNodeToParent.end(); ++it){ |
19 |
✓✓✓ |
5 |
std::cout << "\t" << (*it) << std::endl; |
20 |
|
|
} |
21 |
|
|
} |
22 |
✓✓ |
1 |
std::cout << "testIterateGraph : iterateChildren :" << std::endl; |
23 |
|
1 |
std::list<long> listNodeToChldren; |
24 |
✓✓✓ |
4 |
while(graph.iterateChildren(listNodeToChldren)){ |
25 |
✓✓ |
3 |
std::cout << "To children iteration :" << std::endl; |
26 |
✓✓ |
9 |
for(std::list<long>::iterator it(listNodeToChldren.begin()); it != listNodeToChldren.end(); ++it){ |
27 |
✓✓✓ |
6 |
std::cout << "\t" << (*it) << std::endl; |
28 |
|
|
} |
29 |
|
|
} |
30 |
|
2 |
return true; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
///Test the graph iteration |
34 |
|
|
/** @param graph : Graph on which to iterate |
35 |
|
|
* @return true on success, false otherwise |
36 |
|
|
*/ |
37 |
|
1 |
bool testIterateGraphUnique(Graph<bool, long> & graph){ |
38 |
✓✓ |
1 |
std::cout << "testIterateGraphUnique : iterateParentCheckUpdate :" << std::endl; |
39 |
|
2 |
std::list<long> listNodeToParent; |
40 |
✓✓✓ |
4 |
while(graph.iterateParentCheckUpdate(listNodeToParent)){ |
41 |
✓✓ |
3 |
std::cout << "To parent iteration :" << std::endl; |
42 |
✓✓ |
8 |
for(std::list<long>::iterator it(listNodeToParent.begin()); it != listNodeToParent.end(); ++it){ |
43 |
✓✓✓ |
5 |
std::cout << "\t" << (*it) << std::endl; |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
|
47 |
✓✓ |
1 |
std::cout << "testIterateGraphUnique : iterateChildrenCheckUpdate :" << std::endl; |
48 |
|
1 |
std::list<long> listNodeToChldren; |
49 |
✓✓✓ |
3 |
while(graph.iterateChildrenCheckUpdate(listNodeToChldren)){ |
50 |
✓✓ |
2 |
std::cout << "To children iteration :" << std::endl; |
51 |
✓✓ |
7 |
for(std::list<long>::iterator it(listNodeToChldren.begin()); it != listNodeToChldren.end(); ++it){ |
52 |
✓✓✓ |
5 |
std::cout << "\t" << (*it) << std::endl; |
53 |
|
|
} |
54 |
|
|
} |
55 |
|
2 |
return true; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
///Test the graph conversion to dot |
59 |
|
|
/** @return true on success, false otherwise |
60 |
|
|
*/ |
61 |
|
1 |
bool testGraphToDot(){ |
62 |
✓ |
1 |
Graph<bool, long> graph; |
63 |
|
|
|
64 |
✓✓ |
1 |
long nodeA = graph.createNode(true, "0"); |
65 |
✓✓ |
1 |
long nodeB = graph.createNode(true, "1"); |
66 |
✓✓ |
1 |
long nodeC = graph.createNode(true, "2"); |
67 |
✓✓ |
1 |
long nodeD = graph.createNode(true, "3"); |
68 |
✓✓ |
1 |
long nodeE = graph.createNode(true, "4"); |
69 |
|
|
|
70 |
✓ |
1 |
graph.connectNode(nodeA, nodeC); |
71 |
✓ |
1 |
graph.connectNode(nodeB, nodeC); |
72 |
✓ |
1 |
graph.connectNode(nodeC, nodeE); |
73 |
✓ |
1 |
graph.connectNode(nodeD, nodeE); |
74 |
|
|
|
75 |
|
1 |
bool b(true); |
76 |
✓✓ |
1 |
b &= graph.savePng("testGraph.png"); |
77 |
✓✓ |
1 |
b &= !graph.saveDot(""); |
78 |
✓✓ |
1 |
b &= !graph.savePng(""); |
79 |
✓✓ |
1 |
b &= !graph.saveDot("someInexistingDir/someFile.dot"); |
80 |
✓✓ |
1 |
b &= !graph.savePng("someInexistingDir/someFile.png"); |
81 |
|
|
|
82 |
|
1 |
b &= graph.size() == 5lu; |
83 |
|
|
|
84 |
✓ |
1 |
graph.updateFirstLastNode(); |
85 |
✓ |
1 |
b &= testIterateGraph(graph); |
86 |
✓ |
1 |
b &= testIterateGraphUnique(graph); |
87 |
|
|
|
88 |
✓✓✓ |
1 |
std::cout << "testGraphToDot : b = " << b << std::endl; |
89 |
|
2 |
return b; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
|
93 |
|
1 |
int main(int argc, char** argv){ |
94 |
|
1 |
bool b(testGraphToDot()); |
95 |
|
1 |
std::cout << "b = " << b << std::endl; |
96 |
|
1 |
return b - 1; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
|