aboutsummaryrefslogtreecommitdiff
path: root/tests/tst_TemperatureModel.qml
blob: 301b0959f18952e607d2a2c4f650515f9e3fa2de (plain)
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
import QtQuick 2.0
import QtTest 1.0

import "../harbour-unitmaster/qml/pages"

TestCase {
    name: "TemperatureModelTest"

    TemperatureModel {
        id: model
    }

    function test_to_data() {
        return [
                    { to: "celcius", value: 50, res: 50-273.15 },
                    { to: "celcius", value: 0, res: -273.15 },
                    { to: "fahrenheit", value: 100, res: 100*9/5-459.67 },
                    { to: "rankine", value: 1, res: 1*9/5 }
        ];
    }

    function test_to(data) {
        var result = model.to(data.to, data.value);
        compare(result, data.res);
    }

    function test_from_data() {
        return [
                    { from: "celcius", value: 1, res: 1+273.15 },
                    { from: "fahrenheit", value: 1, res: (1+459.67)*5/9 },
                    { from: "rankine", value: 59, res: 59*5/9 }
        ];
    }

    function test_from(data) {
        var result = model.from(data.from, data.value);
        compare(result, data.res);
    }
}