unittests_iterators.cc 3.72 KB
Newer Older
1
#include <gtest/gtest.h>
2

3
4
#include <Unittests/unittests_common.hh>

5
6
using namespace OpenVolumeMesh;

7
8
9
10
11
12
13
14
TEST_F(HexahedralMeshBase, HexVertexIterTest) {

    generateHexahedralMesh(mesh_);

    HexVertexIter hv_it = mesh_.hv_iter(CellHandle(0));

    EXPECT_TRUE(hv_it.valid());

15
16
17
18
19
20
21
22
    EXPECT_HANDLE_EQ(VertexHandle(0), *hv_it); ++hv_it;
    EXPECT_HANDLE_EQ(VertexHandle(1), *hv_it); ++hv_it;
    EXPECT_HANDLE_EQ(VertexHandle(2), *hv_it); ++hv_it;
    EXPECT_HANDLE_EQ(VertexHandle(3), *hv_it); ++hv_it;
    EXPECT_HANDLE_EQ(VertexHandle(4), *hv_it); ++hv_it;
    EXPECT_HANDLE_EQ(VertexHandle(7), *hv_it); ++hv_it;
    EXPECT_HANDLE_EQ(VertexHandle(6), *hv_it); ++hv_it;
    EXPECT_HANDLE_EQ(VertexHandle(5), *hv_it);
23
}
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
TEST_F(TetrahedralMeshBase, VertexVertexIteratorTest) {

    generateTetrahedralMesh(mesh_);

    {

        VertexVertexIter vv_it = mesh_.vv_iter(VertexHandle(0));

        EXPECT_TRUE(vv_it.valid());

        std::set<VertexHandle> onering;
        int valence = 0;

        while (vv_it.valid())
        {
          ++valence;
          onering.insert(*vv_it);
          ++vv_it;
        }

        // check that there have been three adjacent vertices
        EXPECT_EQ(3, valence);

        // check that no vertex was visited twice
        EXPECT_EQ(3u, onering.size());

        // check that no invalid vertex was adjacent
        EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));

    }

56
#if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    {

      std::set<VertexHandle> onering;
      int valence = 0;

      for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
      {
        ++valence;
        onering.insert(vh);
      }

      // check that there have been three adjacent vertices
      EXPECT_EQ(3, valence);

      // check that no vertex was visited twice
      EXPECT_EQ(3u, onering.size());

      // check that no invalid vertex was adjacent
      EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));

    }
#endif

}

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
TEST_F(TetrahedralMeshBase, VertexFaceIteratorTest) {

    generateTetrahedralMesh(mesh_);

    {

        VertexFaceIter vf_it = mesh_.vf_iter(VertexHandle(0));

        EXPECT_TRUE(vf_it.valid());

        std::set<FaceHandle> incident_faces;
        int valence = 0;

        while (vf_it.valid())
        {
          ++valence;
          incident_faces.insert(*vf_it);
          ++vf_it;
        }

        // check that there have been three adjacent vertices
        EXPECT_EQ(3, valence);

        // check that no vertex was visited twice
        EXPECT_EQ(3u, incident_faces.size());

        // check that no invalid vertex was adjacent
        EXPECT_EQ(incident_faces.end(), std::find(incident_faces.begin(), incident_faces.end(), FaceHandle(-1)));

    }

113
#if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    {

      std::set<VertexHandle> onering;
      int valence = 0;

      for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
      {
        ++valence;
        onering.insert(vh);
      }

      // check that there have been three adjacent vertices
      EXPECT_EQ(3, valence);

      // check that no vertex was visited twice
      EXPECT_EQ(3u, onering.size());

      // check that no invalid vertex was adjacent
      EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));

    }
#endif

}

139
#if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
140
141
142
TEST_F(HexahedralMeshBase, RangeForTest) {
    // no EXPECTs here, if it compiles, it'll work.
    generateHexahedralMesh(mesh_);
143
144
    VertexHandle _dummy; // use vh to avoid compiler warnings
    for (const auto& vh: mesh_.vertices()) { _dummy = vh;}
Max Lyon's avatar
Max Lyon committed
145
    const auto& constref = mesh_;
146
    for (const auto& vh: constref.vertices()) { _dummy = vh;}
147
148
}
#endif