File: MathHelperTest.cpp

package info (click to toggle)
kimageannotator 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,904 kB
  • sloc: cpp: 21,502; makefile: 16; ansic: 13
file content (95 lines) | stat: -rw-r--r-- 3,178 bytes parent folder | download | duplicates (3)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright (C) 2018 Damir Porobic <damir.porobic@gmx.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "MathHelperTest.h"

void MathHelperTest::TestRoundAngleTo_Should_ReturnAngleRoundedUpToIncrement()
{
    QFETCH(qreal, angle);
    QFETCH(qreal, increment);
    QFETCH(qreal, result);

    auto newAngle = MathHelper::roundAngleTo(angle, increment);

    QCOMPARE(newAngle, result);
}

void MathHelperTest::TestRoundAngleTo_Should_ReturnAngleRoundedUpToIncrement_data()
{
    QTest::addColumn<qreal>("angle");
    QTest::addColumn<qreal>("increment");
    QTest::addColumn<qreal>("result");

    QTest::newRow("set1") << 50.0 << 45.0 << 45.0;
    QTest::newRow("set2") << 87.0 << 45.0 << 90.0;
    QTest::newRow("set3") << 0.0 << 45.0 << 0.0;
    QTest::newRow("set4") << 355.0 << 45.0 << 360.0;
    QTest::newRow("set5") << 360.0 << 45.0 << 360.0;
    QTest::newRow("set6") << -2.0 << 45.0 << 0.0;
}

void MathHelperTest::TestSmallerValue_Should_AlwaysSmallerOfTwoValues()
{
    QFETCH(qreal, width);
    QFETCH(qreal, height);
    QFETCH(qreal, result);

    auto smallest = MathHelper::smallerValue(width, height);

    QCOMPARE(smallest, result);
}

void MathHelperTest::TestSmallerValue_Should_AlwaysSmallerOfTwoValues_data()
{
    QTest::addColumn<qreal>("width");
    QTest::addColumn<qreal>("height");
    QTest::addColumn<qreal>("result");

    QTest::newRow("set1") << 50.0 << 49.0 << 49.0;
    QTest::newRow("set2") << -87.0 << 1.0 << -1.0;
    QTest::newRow("set3") << 0.0 << -1.0 << 0.0;
    QTest::newRow("set4") << 400.0 << -500.0 << 400.0;
    QTest::newRow("set5") << -3.0 << 2.0 << -2.0;
    QTest::newRow("set6") << -2.0 << 2.0 << -2.0;
}

void MathHelperTest::TestDistanceBetweenPoints_Should_ReturnCorrectDistance()
{
    QFETCH(QPointF, point1);
    QFETCH(QPointF, point2);
    QFETCH(double, expected);

    auto result = MathHelper::distanceBetweenPoints(point1, point2);

    QCOMPARE(result, expected);
}

void MathHelperTest::TestDistanceBetweenPoints_Should_ReturnCorrectDistance_data()
{
    QTest::addColumn<QPointF>("point1");
    QTest::addColumn<QPointF>("point2");
    QTest::addColumn<double>("expected");

    QTest::newRow("set1") << QPointF(10, 10) << QPointF(20, 10) << 10.0;
    QTest::newRow("set2") << QPointF(10, 10) << QPointF(10, 20) << 10.0;
    QTest::newRow("set3") << QPointF(-10, 10) << QPointF(10, 10) << 20.0;
    QTest::newRow("set4") << QPointF(-4, -3) << QPointF(8, 6) << 15.0;
}

TEST_MAIN(MathHelperTest);