Skip to content

Commit f558b74

Browse files
lbartolettinyalldawson
authored andcommittedApr 20, 2018
Add tests
1 parent 2702a30 commit f558b74

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
 

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ SET(TESTS
181181
testqgstaskmanager.cpp
182182
testqgstracer.cpp
183183
testqgsfontutils.cpp
184+
testqgsvector.cpp
184185
testqgsvectordataprovider.cpp
185186
testqgsvectorlayercache.cpp
186187
testqgsvectorlayerjoinbuffer.cpp

‎tests/src/core/testqgsvector.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/***************************************************************************
2+
testqgsvector.cpp
3+
--------------------------------------
4+
Date : 18 Apr 2018
5+
Copyright : (C) 2018 by Loïc Bartoletti
6+
Email : loic dot bartoletti @ oslandia.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgstest.h"
17+
18+
#include "qgsvector3d.h"
19+
20+
21+
/**
22+
* \ingroup UnitTests
23+
* This is a unit test for the different geometry operations on vector features.
24+
*/
25+
class TestQgsVector : public QObject
26+
{
27+
Q_OBJECT
28+
29+
private slots:
30+
void initTestCase();// will be called before the first testfunction is executed.
31+
void cleanupTestCase();// will be called after the last testfunction was executed.
32+
33+
// vector3d
34+
void vector3d();
35+
};
36+
37+
void TestQgsVector::initTestCase()
38+
{
39+
QgsApplication::init();
40+
QgsApplication::initQgis();
41+
}
42+
43+
void TestQgsVector::cleanupTestCase()
44+
{
45+
QgsApplication::exitQgis();
46+
}
47+
48+
void TestQgsVector::vector3d()
49+
{
50+
QgsVector3D p0( 0.0, 0.0, 0.0 );
51+
QgsVector3D p1( 1.0, 2.0, 3.0 );
52+
QgsVector3D p2( 4.0, 5.0, 6.0 );
53+
// cross product
54+
QCOMPARE( QgsVector3D::crossProduct( p1, p2 ), QgsVector3D( -3.0, 6.0, -3.0 ) );
55+
56+
// dot product
57+
QCOMPARE( QgsVector3D::dotProduct( p1, p2 ), 32.0 );
58+
59+
// normalize
60+
QgsVector3D p3( 0.0, -6.0, 0.0 );
61+
QgsVector3D p4( 1.0, 2.0, -2.0 );
62+
p0.normalize();
63+
p3.normalize();
64+
p4.normalize();
65+
QCOMPARE( p0, QgsVector3D() );
66+
QCOMPARE( p3, QgsVector3D( 0.0, -1.0, 0.0 ) );
67+
QCOMPARE( p4, QgsVector3D( 1.0 / 3.0, 2.0 / 3.0, -2.0 / 3.0 ) );
68+
69+
}
70+
71+
QGSTEST_MAIN( TestQgsVector )
72+
#include "testqgsvector.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.