~ubuntu-branches/ubuntu/wily/kunitconversion/wily-proposed

« back to all changes in this revision

Viewing changes to autotests/categorytest.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark
  • Date: 2014-07-14 17:56:16 UTC
  • Revision ID: package-import@ubuntu.com-20140714175616-n92z93yphd8vce6b
Tags: upstream-5.0.0
Import upstream version 5.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2009 Petri Damstén <damu@iki.fi>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License as
 
6
 *   published by the Free Software Foundation; either version 2, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "categorytest.h"
 
21
#include <kunitconversion/unitcategory.h>
 
22
 
 
23
using namespace KUnitConversion;
 
24
 
 
25
void CategoryTest::initTestCase()
 
26
{
 
27
}
 
28
 
 
29
void CategoryTest::testInfo()
 
30
{
 
31
    UnitCategory cg = c.category(AreaCategory);
 
32
    QCOMPARE(cg.name(), QString("Area"));
 
33
    QCOMPARE(cg.description(), QString("Area"));
 
34
    QCOMPARE(cg.id(), AreaCategory);
 
35
}
 
36
 
 
37
void CategoryTest::testUnits()
 
38
{
 
39
    UnitCategory cg = c.category(MassCategory);
 
40
    QCOMPARE(cg.defaultUnit().symbol(), QString("kg"));
 
41
    QCOMPARE(cg.hasUnit(QString("g")), true);
 
42
    QCOMPARE(cg.unit(QString("g")).symbol(), QString("g"));
 
43
    QCOMPARE(cg.unit(Kilogram).symbol(), QString("kg"));
 
44
    QVERIFY(cg.units().size() > 0);
 
45
    QVERIFY(cg.allUnits().size() > 0);
 
46
}
 
47
 
 
48
void CategoryTest::testConvert()
 
49
{
 
50
    UnitCategory cg = c.category(LengthCategory);
 
51
    Value v = cg.convert(Value(3.14, Kilometer), "m");
 
52
    QCOMPARE(v.number(), 3140.0);
 
53
    v = cg.convert(v, "cm");
 
54
    QCOMPARE(v.number(), 314000.0);
 
55
    v = cg.convert(v, cg.defaultUnit());
 
56
    QCOMPARE(v.number(), 3140.0);
 
57
}
 
58
 
 
59
void CategoryTest::testInvalid()
 
60
{
 
61
    UnitCategory cg = c.category(CategoryId(99999));
 
62
    QCOMPARE(cg.name(), QString());
 
63
    cg = c.category("don't exist");
 
64
    QCOMPARE(cg.name(), QString());
 
65
}
 
66
 
 
67
QTEST_MAIN(CategoryTest)
 
68