Developer Documentation

unittests_iterators.cc
1 #include <gtest/gtest.h>
2
3 #include <Unittests/unittests_common.hh>
4
5 using namespace OpenVolumeMesh;
6
7 TEST_F(HexahedralMeshBase, HexVertexIterTest) {
8
9 generateHexahedralMesh(mesh_);
10
11 HexVertexIter hv_it = mesh_.hv_iter(CellHandle(0));
12
13 EXPECT_TRUE(hv_it.valid());
14
15 EXPECT_HANDLE_EQ(VertexHandle(0), *hv_it); ++hv_it;
16 EXPECT_HANDLE_EQ(VertexHandle(1), *hv_it); ++hv_it;
17 EXPECT_HANDLE_EQ(VertexHandle(2), *hv_it); ++hv_it;
18 EXPECT_HANDLE_EQ(VertexHandle(3), *hv_it); ++hv_it;
19 EXPECT_HANDLE_EQ(VertexHandle(4), *hv_it); ++hv_it;
20 EXPECT_HANDLE_EQ(VertexHandle(7), *hv_it); ++hv_it;
21 EXPECT_HANDLE_EQ(VertexHandle(6), *hv_it); ++hv_it;
22 EXPECT_HANDLE_EQ(VertexHandle(5), *hv_it);
23 }
24
25 TEST_F(TetrahedralMeshBase, VertexVertexIteratorTest) {
26
27 generateTetrahedralMesh(mesh_);
28
29 {
30
31 VertexVertexIter vv_it = mesh_.vv_iter(VertexHandle(0));
32
33 EXPECT_TRUE(vv_it.valid());
34
35 std::set<VertexHandle> onering;
36 int valence = 0;
37
38 while (vv_it.valid())
39 {
40 ++valence;
41 onering.insert(*vv_it);
42 ++vv_it;
43 }
44
45 // check that there have been three adjacent vertices
46 EXPECT_EQ(3, valence);
47
48 // check that no vertex was visited twice
49 EXPECT_EQ(3u, onering.size());
50
51 // check that no invalid vertex was adjacent
52 EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
53
54 }
55
56 #if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
57 {
58
59 std::set<VertexHandle> onering;
60 int valence = 0;
61
62 for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
63 {
64 ++valence;
65 onering.insert(vh);
66 }
67
68 // check that there have been three adjacent vertices
69 EXPECT_EQ(3, valence);
70
71 // check that no vertex was visited twice
72 EXPECT_EQ(3u, onering.size());
73
74 // check that no invalid vertex was adjacent
75 EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
76
77 }
78 #endif
79
80 }
81
82 TEST_F(TetrahedralMeshBase, VertexFaceIteratorTest) {
83
84 generateTetrahedralMesh(mesh_);
85
86 {
87
88 VertexFaceIter vf_it = mesh_.vf_iter(VertexHandle(0));
89
90 EXPECT_TRUE(vf_it.valid());
91
92 std::set<FaceHandle> incident_faces;
93 int valence = 0;
94
95 while (vf_it.valid())
96 {
97 ++valence;
98 incident_faces.insert(*vf_it);
99 ++vf_it;
100 }
101
102 // check that there have been three adjacent vertices
103 EXPECT_EQ(3, valence);
104
105 // check that no vertex was visited twice
106 EXPECT_EQ(3u, incident_faces.size());
107
108 // check that no invalid vertex was adjacent
109 EXPECT_EQ(incident_faces.end(), std::find(incident_faces.begin(), incident_faces.end(), FaceHandle(-1)));
110
111 }
112
113 #if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
114 {
115
116 std::set<VertexHandle> onering;
117 int valence = 0;
118
119 for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
120 {
121 ++valence;
122 onering.insert(vh);
123 }
124
125 // check that there have been three adjacent vertices
126 EXPECT_EQ(3, valence);
127
128 // check that no vertex was visited twice
129 EXPECT_EQ(3u, onering.size());
130
131 // check that no invalid vertex was adjacent
132 EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
133
134 }
135 #endif
136
137 }
138
139 #if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
140 TEST_F(HexahedralMeshBase, RangeForTest) {
141 // no EXPECTs here, if it compiles, it'll work.
142 generateHexahedralMesh(mesh_);
143 VertexHandle _dummy; // use vh to avoid compiler warnings
144 for (const auto& vh: mesh_.vertices()) { _dummy = vh;}
145 const auto& constref = mesh_;
146 for (const auto& vh: constref.vertices()) { _dummy = vh;}
147 }
148 #endif
TetrahedralMeshBase
Definition: unittests_common.hh:98
OpenVolumeMesh::HandleT< Entity::Cell >
OpenVolumeMesh
Definition: ColorAttrib.hh:53
HexahedralMeshBase
Definition: unittests_common.hh:59
OpenVolumeMesh::HexVertexIter
Iterate over all vertices of a hexahedron in a specific order.
Definition: HexahedralMeshIterators.hh:177
OpenVolumeMesh::VertexVertexIter
Definition: Iterators.hh:304
OpenVolumeMesh::VertexFaceIter
Definition: Iterators.hh:423