Directory: | ./ |
---|---|
File: | TESTS/TEST_PNTREE_LIGHT/main.cpp |
Date: | 2025-03-14 11:38:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 81 | 87 | 93.1% |
Branches: | 69 | 79 | 87.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | /*************************************** | ||
3 | Auteur : Pierre Aubert | ||
4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
5 | Licence : CeCILL-C | ||
6 | ****************************************/ | ||
7 | |||
8 | #include <iostream> | ||
9 | #include "Tree/PNTreeLight.h" | ||
10 | |||
11 | #define NB_POINT 8lu | ||
12 | #define NB_POINT_TOTAL (NB_POINT*NB_POINT) | ||
13 | |||
14 | #define NB_POINT_3D 8lu | ||
15 | #define NB_POINT_3D_TOTAL (NB_POINT_3D*NB_POINT_3D*NB_POINT_3D) | ||
16 | |||
17 | |||
18 | |||
19 | ///Tests the basis of the quadtree | ||
20 | /** @return true on success, false otherwise | ||
21 | */ | ||
22 | 1 | bool testBaseQuadTree(){ | |
23 | 1 | size_t nbPoint(NB_POINT); | |
24 | 1 | float dXY(5.0f); | |
25 | 1 | float shift(dXY/2.0f); | |
26 | |||
27 | 1 | float posXY(0.0f), sizeXY(((size_t)(2.0f*shift + ((float)(nbPoint - 1lu))*dXY))); | |
28 | 1 | float posTab[] = {posXY, posXY}; | |
29 | 1 | float sizeTab[] = {sizeXY, sizeXY}; | |
30 |
1/1✓ Branch 1 taken 1 times.
|
1 | PNTreeLight<float, size_t, 2> quadTree(posTab, sizeTab, 1.0f); |
31 | size_t tabId[NB_POINT_TOTAL], id; | ||
32 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 1 times.
|
65 | for(size_t i(0lu); i < NB_POINT_TOTAL; ++i){tabId[i] = i;} |
33 | float x, y; | ||
34 | float tabPos[2*NB_POINT_TOTAL]; | ||
35 | |||
36 | 1 | bool b(true); | |
37 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::ofstream fs; |
38 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.open("pointAddedInQuadTree.txt"); |
39 |
1/1✓ Branch 1 taken 1 times.
|
1 | b &= fs.is_open(); |
40 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for(size_t i(0lu); i < nbPoint; ++i){ |
41 | 8 | y = shift + ((float)i)*dXY; | |
42 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
|
72 | for(size_t j(0lu); j < nbPoint; ++j){ |
43 | 64 | x = shift + ((float)j)*dXY; | |
44 | 64 | tabPos[(i*nbPoint + j)*2lu] = x; | |
45 | 64 | tabPos[(i*nbPoint + j)*2lu + 1lu] = y; | |
46 | 64 | id = i*nbPoint + j; | |
47 |
7/7✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 64 times.
✓ Branch 10 taken 64 times.
✓ Branch 13 taken 64 times.
✓ Branch 16 taken 64 times.
✓ Branch 19 taken 64 times.
|
64 | std::cerr << "Add point " << x << "," << y << "\t, id = " << id << std::endl; |
48 |
5/5✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 64 times.
✓ Branch 10 taken 64 times.
✓ Branch 13 taken 64 times.
|
64 | fs << x << "\t" << y << "\t0" << std::endl; |
49 |
2/3✓ Branch 1 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 64 times.
|
64 | if(!quadTree.addElement(&(tabPos[(i*nbPoint + j)*2lu]), tabId+id)){ |
50 | ✗ | std::cerr << "quadTree.addElement : can't add element : Stop" << std::endl; | |
51 | ✗ | i = nbPoint; | |
52 | ✗ | break; | |
53 | } | ||
54 | } | ||
55 | } | ||
56 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.close(); |
57 |
1/1✓ Branch 2 taken 1 times.
|
1 | std::string fileTxt("quadTree.txt"); |
58 |
1/1✓ Branch 1 taken 1 times.
|
1 | b &= quadTree.saveGnuplotData(fileTxt); |
59 | 1 | float posLastData[] = {11.0f, 19.0f}; | |
60 |
1/1✓ Branch 1 taken 1 times.
|
1 | const size_t * data = quadTree.getLastData(posLastData); |
61 | 1 | b &= (data != NULL); | |
62 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | std::cout << "testBaseQuadTree : data (11.0, 19.0) = " << *data << std::endl; |
63 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | std::cout << "testBaseQuadTree : b = " << b << std::endl; |
64 | 1 | return b; | |
65 | 1 | } | |
66 | |||
67 | ///Tests the basis of the quadtree | ||
68 | /** @return true on success, false otherwise | ||
69 | */ | ||
70 | 1 | bool testBaseQuadTree3d(){ | |
71 | 1 | size_t nbPoint(NB_POINT_3D); | |
72 | 1 | float dXY(5.0f); | |
73 | 1 | float shift(dXY/2.0f); | |
74 | |||
75 | 1 | float posXY(0.0f), sizeXY(((size_t)(2.0f*shift + ((float)(nbPoint - 1lu))*dXY))); | |
76 | 1 | float posTab[] = {posXY, posXY, posXY}; | |
77 | 1 | float sizeTab[] = {sizeXY, sizeXY, sizeXY}; | |
78 |
1/1✓ Branch 1 taken 1 times.
|
1 | PNTreeLight<float, size_t, 3> quadTree(posTab, sizeTab); |
79 | size_t tabId[NB_POINT_3D_TOTAL], id; | ||
80 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1 times.
|
513 | for(size_t i(0lu); i < NB_POINT_3D_TOTAL; ++i){tabId[i] = i;} |
81 | float tabPos[3*NB_POINT_3D_TOTAL]; | ||
82 | float x,y,z; | ||
83 | 1 | bool b(true); | |
84 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::ofstream fs; |
85 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.open("pointAddedInQuadTree3d.txt"); |
86 |
1/1✓ Branch 1 taken 1 times.
|
1 | b &= fs.is_open(); |
87 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for(size_t k(0lu); k < nbPoint; ++k){ |
88 | 8 | z = shift + ((float)k)*dXY; | |
89 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
|
72 | for(size_t i(0lu); i < nbPoint; ++i){ |
90 | 64 | y = shift + ((float)i)*dXY; | |
91 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 64 times.
|
576 | for(size_t j(0lu); j < nbPoint; ++j){ |
92 | 512 | x = shift + ((float)j)*dXY; | |
93 | 512 | id = k*nbPoint*nbPoint + i*nbPoint + j; | |
94 | // std::cerr << "Add point " << tabPos[0] << "," << tabPos[1] << "," << tabPos[2] << "\t, id = " << id << std::endl; | ||
95 | 512 | tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu] = x; | |
96 | 512 | tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu + 1lu] = y; | |
97 | 512 | tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu + 2lu] = z; | |
98 |
6/6✓ Branch 1 taken 512 times.
✓ Branch 4 taken 512 times.
✓ Branch 7 taken 512 times.
✓ Branch 10 taken 512 times.
✓ Branch 13 taken 512 times.
✓ Branch 16 taken 512 times.
|
512 | fs << x << "\t" << y << "\t"<< z << std::endl; |
99 |
2/3✓ Branch 1 taken 512 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 512 times.
|
512 | if(!quadTree.addElement(&(tabPos[(k*nbPoint*nbPoint + i*nbPoint + j)*3lu]), tabId+id)){ |
100 | ✗ | std::cerr << "quadTree.addElement : can't add element : Stop" << std::endl; | |
101 | ✗ | i = nbPoint; | |
102 | ✗ | break; | |
103 | } | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.close(); |
108 |
1/1✓ Branch 2 taken 1 times.
|
1 | std::string fileTxt("quadTree3d.txt"); |
109 |
1/1✓ Branch 1 taken 1 times.
|
1 | b &= quadTree.saveGnuplotData(fileTxt); |
110 | |||
111 | 1 | float posLastData[] = {11.0f, 19.0f, 10.0f}; | |
112 |
1/1✓ Branch 1 taken 1 times.
|
1 | const size_t * data = quadTree.getLastData(posLastData); |
113 | 1 | b &= (data != NULL); | |
114 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | std::cout << "testBaseQuadTree3d : data (11.0, 19.0) = " << *data << std::endl; |
115 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | std::cout << "testBaseQuadTree3d : b = " << b << std::endl; |
116 | 1 | return b; | |
117 | 1 | } | |
118 | |||
119 | ///Check the function isNeighbourSearchFinised | ||
120 | /** @return true on success, false otherwise | ||
121 | */ | ||
122 | 1 | bool checkIsNeigbourFinished(){ | |
123 | 1 | bool value(true); | |
124 | 1 | bool b(true); | |
125 |
1/1✓ Branch 1 taken 1 times.
|
1 | b &= isNeighbourSearchFinised(&value, 1lu); |
126 | 1 | value = false; | |
127 |
1/1✓ Branch 1 taken 1 times.
|
1 | b &= !isNeighbourSearchFinised(&value, 1lu); |
128 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | std::cout << "checkIsNeigbourFinished : b = " << b << std::endl; |
129 | 1 | return b; | |
130 | } | ||
131 | |||
132 | 1 | int main(int argc, char** argv){ | |
133 | 1 | bool b(checkIsNeigbourFinished()); | |
134 | 1 | b &= testBaseQuadTree(); | |
135 | 1 | b &= testBaseQuadTree3d(); | |
136 | 1 | return b - 1; | |
137 | } | ||
138 | |||
139 | |||
140 | |||
141 |