on 90ada3c help sign in
unity8/tests/qmltests/Components/tst_MathLocal.qml
91 lines 2.7 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
18import QtTest 1.0
19import "../../../Components/Math.js" as MathLocal
21TestCase {
22 name: "MathLocal"
24 property int minValue
25 property int maxValue
26 property int clampValue
27 property int clamped
29 function test_clamp_positive_lower() {
30 minValue = 9
31 maxValue = 42
32 clampValue = -7
34 clamped = MathLocal.clamp(clampValue, minValue, maxValue)
35 compare(clamped, minValue, "clamped value not within range")
36 }
38 function test_clamp_positive_greater() {
39 minValue = 9
40 maxValue = 42
41 clampValue = 111
43 clamped = MathLocal.clamp(clampValue, minValue, maxValue)
44 compare(clamped, maxValue, "clamped value not within range")
45 }
47 function test_clamp_positive_within() {
48 minValue = 9
49 maxValue = 53
50 clampValue = 42
52 clamped = MathLocal.clamp(clampValue, minValue, maxValue)
53 compare(clamped, clampValue, "clamped value changed even though it shouldn't have")
54 }
56 function test_clamp_positive_on_border() {
57 minValue = 9
58 maxValue = 42
59 clampValue = 9
61 clamped = MathLocal.clamp(clampValue, minValue, maxValue)
62 compare(clamped, clampValue, "clamped value changed even though it shouldn't have")
63 }
65 function test_clamp_negative_lower() {
66 minValue = -42
67 maxValue = -9
68 clampValue = -50
70 clamped = MathLocal.clamp(clampValue, minValue, maxValue)
71 compare(clamped, minValue, "clamped value not within range")
72 }
74 function test_clamp_negative_greater() {
75 minValue = -42
76 maxValue = -9
77 clampValue = 50
79 clamped = MathLocal.clamp(clampValue, minValue, maxValue)
80 compare(clamped, maxValue, "clamped value not within range")
81 }
83 function test_clamp_postive_and_negative_greater() {
84 minValue = -42
85 maxValue = 9
86 clampValue = 50
88 clamped = MathLocal.clamp(clampValue, minValue, maxValue)
89 compare(clamped, maxValue, "clamped value not within range")
90 }