2
* Copyright (C) 2009 Petri Damstén <damu@iki.fi>
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.
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
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.
20
#include "categorytest.h"
21
#include <kunitconversion/unitcategory.h>
23
using namespace KUnitConversion;
25
void CategoryTest::initTestCase()
29
void CategoryTest::testInfo()
31
UnitCategory cg = c.category(AreaCategory);
32
QCOMPARE(cg.name(), QString("Area"));
33
QCOMPARE(cg.description(), QString("Area"));
34
QCOMPARE(cg.id(), AreaCategory);
37
void CategoryTest::testUnits()
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);
48
void CategoryTest::testConvert()
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);
59
void CategoryTest::testInvalid()
61
UnitCategory cg = c.category(CategoryId(99999));
62
QCOMPARE(cg.name(), QString());
63
cg = c.category("don't exist");
64
QCOMPARE(cg.name(), QString());
67
QTEST_MAIN(CategoryTest)