~ubuntu-branches/ubuntu/vivid/regina-normal/vivid

« back to all changes in this revision

Viewing changes to testsuite/dim2/dim2triangulation.cpp

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2014-08-29 17:37:46 UTC
  • mfrom: (19.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140829173746-igmqc9b67y366a7u
Tags: 4.96-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/**************************************************************************
 
3
 *                                                                        *
 
4
 *  Regina - A Normal Surface Theory Calculator                           *
 
5
 *  Test Suite                                                            *
 
6
 *                                                                        *
 
7
 *  Copyright (c) 1999-2014, Ben Burton                                   *
 
8
 *  For further details contact Ben Burton (bab@debian.org).              *
 
9
 *                                                                        *
 
10
 *  This program is free software; you can redistribute it and/or         *
 
11
 *  modify it under the terms of the GNU General Public License as        *
 
12
 *  published by the Free Software Foundation; either version 2 of the    *
 
13
 *  License, or (at your option) any later version.                       *
 
14
 *                                                                        *
 
15
 *  As an exception, when this program is distributed through (i) the     *
 
16
 *  App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or     *
 
17
 *  (iii) Google Play by Google Inc., then that store may impose any      *
 
18
 *  digital rights management, device limits and/or redistribution        *
 
19
 *  restrictions that are required by its terms of service.               *
 
20
 *                                                                        *
 
21
 *  This program is distributed in the hope that it will be useful, but   *
 
22
 *  WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 
24
 *  General Public License for more details.                              *
 
25
 *                                                                        *
 
26
 *  You should have received a copy of the GNU General Public             *
 
27
 *  License along with this program; if not, write to the Free            *
 
28
 *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,       *
 
29
 *  MA 02110-1301, USA.                                                   *
 
30
 *                                                                        *
 
31
 **************************************************************************/
 
32
 
 
33
/* end stub */
 
34
 
 
35
#include <cppunit/extensions/HelperMacros.h>
 
36
#include "dim2/dim2exampletriangulation.h"
 
37
#include "dim2/dim2triangulation.h"
 
38
 
 
39
#include "testsuite/exhaustive.h"
 
40
#include "testsuite/generic/generictriangulation.h"
 
41
#include "testsuite/dim2/testdim2.h"
 
42
 
 
43
using regina::Dim2Triangulation;
 
44
using regina::Dim2ExampleTriangulation;
 
45
 
 
46
class Dim2TriangulationTest : public TriangulationTest<2> {
 
47
    CPPUNIT_TEST_SUITE(Dim2TriangulationTest);
 
48
 
 
49
    // Generic tests:
 
50
    CPPUNIT_TEST(makeCanonical);
 
51
    CPPUNIT_TEST(isomorphismSignature);
 
52
 
 
53
    // Dimension-specific tests:
 
54
    CPPUNIT_TEST(eltMove13);
 
55
 
 
56
    CPPUNIT_TEST_SUITE_END();
 
57
 
 
58
    private:
 
59
        // Trivial:
 
60
        Dim2Triangulation empty;
 
61
            /**< An empty triangulation. */
 
62
 
 
63
        // Closed orientable:
 
64
        Dim2Triangulation s2;
 
65
            /**< A 2-sphere with two triangles. */
 
66
        Dim2Triangulation s2Tet;
 
67
            /**< A 2-sphere with four triangles. */
 
68
        Dim2Triangulation s2Oct;
 
69
            /**< A 2-sphere with eight triangles. */
 
70
        Dim2Triangulation torus;
 
71
            /**< A torus with two triangles. */
 
72
        Dim2Triangulation torus2;
 
73
            /**< A genus two torus. */
 
74
 
 
75
        // Closed non-orientable:
 
76
        Dim2Triangulation rp2;
 
77
            /**< A projective plane with two triangles. */
 
78
        Dim2Triangulation kb;
 
79
            /**< A Klein bottle with two triangles. */
 
80
 
 
81
        // Bounded:
 
82
        Dim2Triangulation disc;
 
83
            /**< A disc with one triangle. */
 
84
        Dim2Triangulation annulus;
 
85
            /**< An annulus with two triangles. */
 
86
        Dim2Triangulation mobius;
 
87
            /**< A Mobius band with one triangle. */
 
88
 
 
89
        // Disconnected triangulations:
 
90
        Dim2Triangulation disjoint2;
 
91
            /**< A disjoint union of two triangulations. */
 
92
        Dim2Triangulation disjoint3;
 
93
            /**< A disjoint union of three triangulations. */
 
94
 
 
95
    public:
 
96
        void copyAndDelete(Dim2Triangulation& dest, Dim2Triangulation* source) {
 
97
            dest.insertTriangulation(*source);
 
98
            dest.setPacketLabel(source->getPacketLabel());
 
99
            delete source;
 
100
        }
 
101
 
 
102
        void setUp() {
 
103
            empty.setPacketLabel("Empty triangulation");
 
104
 
 
105
            copyAndDelete(s2, Dim2ExampleTriangulation::sphere());
 
106
            s2.setPacketLabel("S^2");
 
107
 
 
108
            copyAndDelete(s2Tet, Dim2ExampleTriangulation::sphereTetrahedron());
 
109
            s2Tet.setPacketLabel("Tetrahedron boundary");
 
110
 
 
111
            copyAndDelete(s2Oct, Dim2ExampleTriangulation::sphereOctahedron());
 
112
            s2Oct.setPacketLabel("Octahedron boundary");
 
113
 
 
114
            copyAndDelete(torus, Dim2ExampleTriangulation::torus());
 
115
            torus.setPacketLabel("Torus");
 
116
 
 
117
            copyAndDelete(torus2, Dim2ExampleTriangulation::orientable(2, 0));
 
118
            torus2.setPacketLabel("Genus 2 torus");
 
119
 
 
120
            copyAndDelete(rp2, Dim2ExampleTriangulation::rp2());
 
121
            rp2.setPacketLabel("RP^2");
 
122
 
 
123
            copyAndDelete(kb, Dim2ExampleTriangulation::kb());
 
124
            kb.setPacketLabel("KB");
 
125
 
 
126
            copyAndDelete(disc, Dim2ExampleTriangulation::disc());
 
127
            disc.setPacketLabel("Disc");
 
128
 
 
129
            copyAndDelete(annulus, Dim2ExampleTriangulation::annulus());
 
130
            annulus.setPacketLabel("Annulus");
 
131
 
 
132
            copyAndDelete(mobius, Dim2ExampleTriangulation::mobius());
 
133
            mobius.setPacketLabel("Mobius band");
 
134
 
 
135
            disjoint2.insertTriangulation(torus);
 
136
            disjoint2.insertTriangulation(mobius);
 
137
            disjoint2.setPacketLabel("Torus U Mobius");
 
138
 
 
139
            disjoint3.insertTriangulation(kb);
 
140
            disjoint3.insertTriangulation(annulus);
 
141
            disjoint3.insertTriangulation(s2);
 
142
            disjoint3.setPacketLabel("KB U Annulus U S^2");
 
143
        }
 
144
 
 
145
        void tearDown() {
 
146
        }
 
147
 
 
148
        /**
 
149
         * Run a given test over all hand-coded cases.
 
150
         */
 
151
        void testManualAll(Dim2TriangulationTestFunction f) {
 
152
            f(&empty);
 
153
            f(&s2);
 
154
            f(&s2Tet);
 
155
            f(&s2Oct);
 
156
            f(&torus);
 
157
            f(&torus2);
 
158
            f(&rp2);
 
159
            f(&kb);
 
160
            f(&disc);
 
161
            f(&annulus);
 
162
            f(&mobius);
 
163
            f(&disjoint2);
 
164
            f(&disjoint3);
 
165
        }
 
166
 
 
167
        void makeCanonical() {
 
168
            testManualAll(verifyMakeCanonical);
 
169
        }
 
170
 
 
171
        void isomorphismSignature() {
 
172
            testManualAll(verifyIsomorphismSignature);
 
173
        }
 
174
 
 
175
        static void verifyEltMove13(Dim2Triangulation* tri) {
 
176
            unsigned long n = tri->getNumberOfTriangles();
 
177
            for (unsigned long i = 0; i < n; ++i) {
 
178
                Dim2Triangulation large(*tri);
 
179
                large.oneThreeMove(large.getTriangle(i));
 
180
 
 
181
                if (large.getNumberOfTriangles() != n + 2) {
 
182
                    std::ostringstream msg;
 
183
                    msg << tri->getPacketLabel() << ", tri " << i << ": "
 
184
                        << "1-3 move gives wrong # triangles.";
 
185
                    CPPUNIT_FAIL(msg.str());
 
186
                }
 
187
 
 
188
                if (large.isOrientable() != tri->isOrientable()) {
 
189
                    std::ostringstream msg;
 
190
                    msg << tri->getPacketLabel() << ", tri " << i << ": "
 
191
                        << "1-3 move changes orientability.";
 
192
                    CPPUNIT_FAIL(msg.str());
 
193
                }
 
194
 
 
195
                if (large.isClosed() != tri->isClosed()) {
 
196
                    std::ostringstream msg;
 
197
                    msg << tri->getPacketLabel() << ", tri " << i << ": "
 
198
                        << "1-3 move changes closedness.";
 
199
                    CPPUNIT_FAIL(msg.str());
 
200
                }
 
201
 
 
202
                if (large.getNumberOfBoundaryComponents() !=
 
203
                        tri->getNumberOfBoundaryComponents()) {
 
204
                    std::ostringstream msg;
 
205
                    msg << tri->getPacketLabel() << ", tri " << i << ": "
 
206
                        << "1-3 move changes # boundary components.";
 
207
                    CPPUNIT_FAIL(msg.str());
 
208
                }
 
209
 
 
210
                if (large.getEulerChar() != tri->getEulerChar()) {
 
211
                    std::ostringstream msg;
 
212
                    msg << tri->getPacketLabel() << ", tri " << i << ": "
 
213
                        << "1-3 move changes Euler characteristic.";
 
214
                    CPPUNIT_FAIL(msg.str());
 
215
                }
 
216
            }
 
217
        }
 
218
 
 
219
        void eltMove13() {
 
220
            testManualAll(verifyEltMove13);
 
221
        }
 
222
};
 
223
 
 
224
void addDim2Triangulation(CppUnit::TextUi::TestRunner& runner) {
 
225
    runner.addTest(Dim2TriangulationTest::suite());
 
226
}
 
227