~ubuntu-branches/ubuntu/precise/kalgebra/precise-updates

« back to all changes in this revision

Viewing changes to analitzagui/tests/operatorsmodeltest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 16:41:53 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20111216164153-ym1s7jhbqwn2ndz6
Tags: 4:4.7.90-0ubuntu2
PPA rebuild, no changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************************************************
2
 
 *  Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org>                               *
3
 
 *                                                                                   *
4
 
 *  This program is free software; you can redistribute it and/or                    *
5
 
 *  modify it under the terms of the GNU General Public License                      *
6
 
 *  as published by the Free Software Foundation; either version 2                   *
7
 
 *  of the License, or (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 General Public License                *
15
 
 *  along with this program; if not, write to the Free Software                      *
16
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
17
 
 *************************************************************************************/
18
 
 
19
 
#include "operatorsmodeltest.h"
20
 
#include <analitza/expression.h>
21
 
#include <analitza/analyzer.h>
22
 
#include <analitza/variables.h>
23
 
#include <qtest_kde.h>
24
 
#include <cmath>
25
 
#include <analitza/analitzautils.h>
26
 
#include <analitza/value.h>
27
 
 
28
 
using namespace std;
29
 
using Analitza::Expression;
30
 
 
31
 
QTEST_KDEMAIN_CORE( OperatorsModelTest )
32
 
 
33
 
OperatorsModelTest::OperatorsModelTest(QObject *parent)
34
 
        : QObject(parent)
35
 
{}
36
 
 
37
 
OperatorsModelTest::~OperatorsModelTest() {}
38
 
void OperatorsModelTest::initTestCase() {}
39
 
void OperatorsModelTest::cleanupTestCase() {}
40
 
 
41
 
void OperatorsModelTest::testExamples_data()
42
 
{
43
 
        QTest::addColumn<int>("i");
44
 
        for(int i=0; i<m.rowCount(); i++) {
45
 
                QModelIndex idx(m.index(i, 0));
46
 
                QTest::newRow(qPrintable(idx.data().toString())) << i;
47
 
        }
48
 
}
49
 
 
50
 
void OperatorsModelTest::testExamples()
51
 
{
52
 
        QFETCH(int, i);
53
 
        QModelIndex idx(m.index(i, 0));
54
 
        
55
 
        QModelIndex nameIdx, descriptionIdx, sampleIdx, exampleIdx;
56
 
        nameIdx = idx.sibling(idx.row(), 0);
57
 
        descriptionIdx = idx.sibling(idx.row(), 1);
58
 
        sampleIdx = idx.sibling(idx.row(), 2);
59
 
        exampleIdx = idx.sibling(idx.row(), 3);
60
 
        
61
 
        QString name=m.data(nameIdx).toString();
62
 
        QString description=m.data(descriptionIdx).toString();
63
 
        QString sample=m.data(sampleIdx).toString();
64
 
        QString example=m.data(exampleIdx).toString();
65
 
        
66
 
//              qDebug() << "testing: " << name << example;
67
 
        
68
 
        QVERIFY(!name.isEmpty());
69
 
        QVERIFY(!description.isEmpty());
70
 
        QVERIFY(!sample.isEmpty());
71
 
        QVERIFY(!example.isEmpty());
72
 
        Expression ex(example, false);
73
 
        QCOMPARE(ex.toString(), example);
74
 
        QVERIFY(!ex.toMathMLPresentation().isEmpty());
75
 
        ex = ex.lambdaBody();
76
 
        
77
 
        Analitza::Analyzer a;
78
 
        a.setExpression(ex);
79
 
        if(!a.isCorrect()) qDebug() << example << "1. error" << a.errors();// QVERIFY(a.isCorrect());
80
 
        
81
 
        a.simplify();
82
 
        if(!a.isCorrect()) qDebug() << example << "2. error" << a.errors();// QVERIFY(a.isCorrect());
83
 
        a.variables()->modify("x", 0.1);
84
 
        a.setExpression(ex);
85
 
        Expression e = a.calculate();
86
 
        if(!a.isCorrect()) qDebug() << example << "3. error" << a.errors();// QVERIFY(a.isCorrect());
87
 
        if(!e.isCorrect()) qDebug() << example << "4. error" << e.error(); // QVERIFY(e.isCorrect());
88
 
        
89
 
        e = a.evaluate();
90
 
        if(!a.isCorrect()) qDebug() << example << "5. error" << a.errors();// QVERIFY(a.isCorrect());
91
 
        if(!e.isCorrect()) qDebug() << example << "6. error" << e.error(); // QVERIFY(e.isCorrect());
92
 
        QVERIFY(!a.expression().toMathMLPresentation().isEmpty());
93
 
}
94
 
 
95
 
#include "operatorsmodeltest.moc"