swift
Loading...
Searching...
No Matches
testmath.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
7
8#include <QTest>
9
10#include "test.h"
11
12#include "misc/math/mathutils.h"
13
14using namespace swift::misc::math;
15
16namespace MiscTest
17{
19 class CTestMath : public QObject
20 {
22
23 private slots:
25 void testRoundToMultipleOf();
26 };
27
28 void CTestMath::testRoundToMultipleOf()
29 {
30 QVERIFY2(CMathUtils::roundToMultipleOf(0, 3) == 0, "Nearest multiple of 3 from 0 should be 0");
31 QVERIFY2(CMathUtils::roundToMultipleOf(1, 3) == 0, "Nearest multiple of 3 from 1 should be 0");
32 QVERIFY2(CMathUtils::roundToMultipleOf(2, 3) == 3, "Nearest multiple of 3 from 2 should be 3");
33 QVERIFY2(CMathUtils::roundToMultipleOf(3, 3) == 3, "Nearest multiple of 3 from 3 should be 3");
34
35 QVERIFY2(CMathUtils::roundToMultipleOf(0, -3) == 0, "Nearest multiple of -3 from 0 should be 0");
36 QVERIFY2(CMathUtils::roundToMultipleOf(1, -3) == 0, "Nearest multiple of -3 from 1 should be 0");
37 QVERIFY2(CMathUtils::roundToMultipleOf(2, -3) == 3, "Nearest multiple of -3 from 2 should be 3");
38 QVERIFY2(CMathUtils::roundToMultipleOf(3, -3) == 3, "Nearest multiple of -3 from 3 should be 3");
39
40 QVERIFY2(CMathUtils::roundToMultipleOf(-1, 3) == 0, "Nearest multiple of 3 from -1 should be 0");
41 QVERIFY2(CMathUtils::roundToMultipleOf(-2, 3) == -3, "Nearest multiple of 3 from -2 should be -3");
42 QVERIFY2(CMathUtils::roundToMultipleOf(-3, 3) == -3, "Nearest multiple of 3 from -3 should be -3");
43
44 QVERIFY2(CMathUtils::roundToMultipleOf(-1, -3) == 0, "Nearest multiple of -3 from -1 should be 0");
45 QVERIFY2(CMathUtils::roundToMultipleOf(-2, -3) == -3, "Nearest multiple of -3 from -2 should be -3");
46 QVERIFY2(CMathUtils::roundToMultipleOf(-3, -3) == -3, "Nearest multiple of -3 from -3 should be -3");
47 }
48
49} // namespace MiscTest
50
53
54#include "testmath.moc"
55
static int roundToMultipleOf(int value, int divisor)
Round numToRound to the nearest multiple of divisor.
Definition mathutils.cpp:92
Math unit tests.
Definition testmath.cpp:20
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
#define SWIFTTEST_APPLESS_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject without instantiating a QApplicati...
Definition test.h:39