~zsombi/ubuntu-ui-toolkit/50-custom-delegates

« back to all changes in this revision

Viewing changes to tests/unit/tst_components/tst_math_utils.qml

prereq sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import Ubuntu.Components 1.1
 
20
 
 
21
TestCase {
 
22
    name: "MathUtils"
 
23
 
 
24
    function test_clamp_positive_lower() {
 
25
        var minValue = 9
 
26
        var maxValue = 42
 
27
        var clampValue = -7
 
28
 
 
29
        var clamped = MathUtils.clamp(clampValue, minValue, maxValue)
 
30
        compare(clamped, minValue, "clamped value not within range")
 
31
    }
 
32
 
 
33
    function test_clamp_positive_greater() {
 
34
        var minValue = 9
 
35
        var maxValue = 42
 
36
        var clampValue = 111
 
37
 
 
38
        var clamped = MathUtils.clamp(clampValue, minValue, maxValue)
 
39
        compare(clamped, maxValue, "clamped value not within range")
 
40
    }
 
41
 
 
42
    function test_clamp_positive_within() {
 
43
        var minValue = 9
 
44
        var maxValue = 53
 
45
        var clampValue = 42
 
46
 
 
47
        var clamped = MathUtils.clamp(clampValue, minValue, maxValue)
 
48
        compare(clamped, clampValue, "clamped value changed even though it shouldn't have")
 
49
    }
 
50
 
 
51
    function test_clamp_positive_on_border() {
 
52
        var minValue = 9
 
53
        var maxValue = 42
 
54
        var clampValue = 9
 
55
 
 
56
        var clamped = MathUtils.clamp(clampValue, minValue, maxValue)
 
57
        compare(clamped, clampValue, "clamped value changed even though it shouldn't have")
 
58
    }
 
59
 
 
60
    function test_clamp_negative_lower() {
 
61
        var minValue = -42
 
62
        var maxValue = -9
 
63
        var clampValue = -50
 
64
 
 
65
        var clamped = MathUtils.clamp(clampValue, minValue, maxValue)
 
66
        compare(clamped, minValue, "clamped value not within range")
 
67
    }
 
68
 
 
69
    function test_clamp_negative_greater() {
 
70
        var minValue = -42
 
71
        var maxValue = -9
 
72
        var clampValue = 50
 
73
 
 
74
        var clamped = MathUtils.clamp(clampValue, minValue, maxValue)
 
75
        compare(clamped, maxValue, "clamped value not within range")
 
76
    }
 
77
 
 
78
    function test_clamp_postive_and_negative_greater() {
 
79
        var minValue = -42
 
80
        var maxValue = 9
 
81
        var clampValue = 50
 
82
 
 
83
        var clamped = MathUtils.clamp(clampValue, minValue, maxValue)
 
84
        compare(clamped, maxValue, "clamped value not within range")
 
85
    }
 
86
 
 
87
    function test_lerp() {
 
88
        var lerped = MathUtils.lerp(0.25, 90, 0)
 
89
        compare(lerped, 67.5)
 
90
    }
 
91
 
 
92
    function test_project_value() {
 
93
        var projectedValue = MathUtils.projectValue(5, 1, 100, 2, 200)
 
94
        compare(projectedValue, 10)
 
95
    }
 
96
 
 
97
    function test_clamp_and_project() {
 
98
        var clampedAndProjectedValue = MathUtils.clampAndProject(5, 1, 10, 2, 200)
 
99
        compare(clampedAndProjectedValue, 90)
 
100
    }
 
101
}