-
-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathTestMaths.cpp
More file actions
65 lines (55 loc) · 1.69 KB
/
Copy pathTestMaths.cpp
File metadata and controls
65 lines (55 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
56
57
58
59
60
61
62
63
64
65
/*
* TestMaths.cpp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include "TestMaths.h"
#include "Maths.h"
using namespace mmp;
void TestMaths::degreesRadiansRoundTrip()
{
QVERIFY(qFuzzyCompare(degreesToRadians(180.0), M_PI));
QVERIFY(qFuzzyCompare(radiansToDegrees(M_PI), 180.0));
QVERIFY(qFuzzyCompare(radiansToDegrees(degreesToRadians(57.3)), 57.3));
}
void TestMaths::wrapAroundInt()
{
// Example taken from the documentation in Maths.h.
QCOMPARE(wrapAround(-1, 3), 2);
QCOMPARE(wrapAround(0, 3), 0);
QCOMPARE(wrapAround(3, 3), 0);
QCOMPARE(wrapAround(5, 3), 2);
QCOMPARE(wrapAround(-4, 3), 2);
}
void TestMaths::wrapAroundReal()
{
QVERIFY(qFuzzyCompare(wrapAround(qreal(-0.5), qreal(1.0)), qreal(0.5)));
QVERIFY(qFuzzyCompare(wrapAround(qreal(1.5), qreal(1.0)), qreal(0.5)));
QVERIFY(qFuzzyCompare(wrapAround(qreal(0.25), qreal(1.0)), qreal(0.25)));
}
void TestMaths::squareAndDistance()
{
QVERIFY(qFuzzyCompare(sq(3.0), 9.0));
QPointF a(0, 0);
QPointF b(3, 4);
QVERIFY(qFuzzyCompare(distSq(a, b), 25.0));
QVERIFY(qFuzzyCompare(dist(a, b), 5.0));
}
void TestMaths::distanceInside()
{
QPointF a(0, 0);
QPointF b(3, 4); // distance 5
QVERIFY(distIsInside(a, b, 6.0));
QVERIFY(!distIsInside(a, b, 5.0)); // strictly inside: equal is outside
QVERIFY(!distIsInside(a, b, 4.0));
}
void TestMaths::booleanXor()
{
QCOMPARE(xOr(true, false), true);
QCOMPARE(xOr(false, true), true);
QCOMPARE(xOr(true, true), false);
QCOMPARE(xOr(false, false), false);
}