swift
Loading...
Searching...
No Matches
tests
misc
math
testmath
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
14
using namespace
swift::misc::math;
15
16
namespace
MiscTest
17
{
19
class
CTestMath
:
public
QObject
20
{
21
Q_OBJECT
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
52
SWIFTTEST_APPLESS_MAIN
(
MiscTest::CTestMath
);
53
54
#include "testmath.moc"
55
CMathUtils::roundToMultipleOf
static int roundToMultipleOf(int value, int divisor)
Round numToRound to the nearest multiple of divisor.
Definition
mathutils.cpp:92
MiscTest::CTestMath
Math unit tests.
Definition
testmath.cpp:20
mathutils.h
QObject::QObject
QObject(QObject *parent)
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
test.h
SWIFTTEST_APPLESS_MAIN
#define SWIFTTEST_APPLESS_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject without instantiating a QApplicati...
Definition
test.h:39
Generated on
for swift by
1.15.0