File indexing completed on 2024-12-01 09:38:44

0001 /*************************************************************************************
0002  *  Copyright (C) 2013 by Punit Mehta <punit9462@gmail.com>                          *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 #include <datastoretest.h>
0020 #include <spacesmodel.h>
0021 #include <spaceitem.h>
0022 
0023 //Qt includes
0024 #include <qtest_kde.h>
0025 
0026 //Analitza includes
0027 #include <analitzaplot/plotsmodel.h>
0028 #include <analitzaplot/plotsfactory.h>
0029 #include <analitzaplot/plotitem.h>
0030 #include <analitzaplot/functiongraph.h>
0031 
0032 using namespace Analitza;
0033 
0034 QTEST_KDEMAIN_CORE( DataStoreTest )
0035 
0036 Q_DECLARE_METATYPE(Analitza::Dimension);
0037 
0038 Q_DECLARE_METATYPE(Qt::GlobalColor);
0039 
0040 DataStoreTest::DataStoreTest(QObject *parent)
0041     : QObject(parent)
0042 {
0043     m_document = new DataStore();
0044 }
0045 
0046 DataStoreTest::~DataStoreTest()
0047 {
0048 }
0049 
0050 void DataStoreTest::initTestCase()
0051 {}
0052 
0053 void DataStoreTest::cleanupTestCase()
0054 {}
0055 
0056 void DataStoreTest::testCorrect_data()
0057 {
0058     QTest::addColumn<QString>("expression");
0059     QTest::addColumn<Analitza::Dimension>("dimension");
0060     QTest::addColumn<Qt::GlobalColor>("color");
0061     QTest::addColumn<QString>("name");
0062 
0063     QTest::newRow("1") << "x->sin(x)" << Analitza::Dim2D << Qt::black << "sin";
0064     QTest::newRow("2") << "x->cos(x)" << Analitza::Dim2D << Qt::blue  << "cos";
0065     QTest::newRow("3") << "x->tan(x)"<<  Analitza::Dim2D << Qt::green  << "tan";
0066     QTest::newRow("4") << "t->vector{t,t}" << Analitza::Dim2D << Qt::red  << "line-2d";
0067     QTest::newRow("5") << "t->vector{t, t, t}" << Analitza::Dim3D << Qt::yellow  << "line-3d";
0068     QTest::newRow("6") << "t->vector{t,sin(t),cos(t)}" << Analitza::Dim3D << Qt::white  << "para-3d";
0069     QTest::newRow("7") << "x+y+z=1" << Analitza::Dim3D << Qt::darkGray  << "plane";
0070     QTest::newRow("8") << "(t,p)->6" << Analitza::Dim3D << Qt::lightGray  << "test-surface";
0071 }
0072 
0073 void DataStoreTest::testCorrect()
0074 {
0075     QFETCH(QString,expression);
0076     QFETCH(Analitza::Dimension,dimension);
0077     QFETCH(Qt::GlobalColor,color);
0078     QFETCH(QString,name);
0079 
0080     SpaceItem* space = m_document->spacesModel()->addSpace(dimension, name, QString(), QPixmap());
0081     m_document->setCurrentSpace(0);
0082     PlotBuilder req = PlotsFactory::self()->requestPlot(Analitza::Expression(expression),dimension);
0083 
0084     QVERIFY(req.canDraw());
0085     const QColor c(color);
0086     FunctionGraph* item = req.create(c, name);
0087     m_document->plotsModel()->addPlot(item);
0088 
0089     QList<Analitza::PlotItem*> plotList=m_document->currentDataMap().values();
0090 
0091     QVERIFY(!plotList.isEmpty());
0092 
0093     Analitza::PlotItem* testitem=plotList.at(0);
0094     QCOMPARE(testitem->name(),QString(name));
0095 
0096     // need to solve in analitza
0097     if(dimension!=Dim3D)
0098         QCOMPARE(testitem->expression(),Analitza::Expression(expression));
0099     QCOMPARE(testitem->color(), c);
0100     QCOMPARE(plotList.removeAll(testitem),1);
0101 
0102     // remove the last spaceitem
0103     m_document->spacesModel()->removeRows(m_document->spacesModel()->rowCount() - 1, 0);
0104 }
0105 
0106 #include "moc_datastoretest.cpp"