File indexing completed on 2024-04-21 03:40:39

0001 /*************************************************************************************
0002  *  Copyright (C) 2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@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 "surfacetest.h"
0020 #include "analitzaplot/surface.h"
0021 #include <plotsfactory.h>
0022 #include "analitza/expression.h"
0023 #include "analitza/variables.h"
0024 #include <QTest>
0025 #include <cmath>
0026 
0027 using namespace std;
0028 using namespace Analitza;
0029 
0030 QTEST_MAIN( SurfaceTest )
0031 
0032 SurfaceTest::SurfaceTest(QObject *parent)
0033     : QObject(parent)
0034 {
0035     m_vars=new Analitza::Variables;
0036 }
0037 
0038 SurfaceTest::~SurfaceTest()
0039 {
0040     delete m_vars;
0041 }
0042 
0043 void SurfaceTest::initTestCase()
0044 {}
0045 
0046 void SurfaceTest::cleanupTestCase()
0047 {}
0048 
0049 void SurfaceTest::testCorrect_data()
0050 {
0051     QTest::addColumn<QString>("input");
0052 
0053     QTest::newRow("sphere-cartcoords") << "x*x+y*y+z*z=6";
0054     QTest::newRow("sphere-sphecoords") << "(t,p)->6";
0055 }
0056 
0057 void SurfaceTest::testCorrect()
0058 {
0059     QFETCH(QString, input);
0060 
0061     QVERIFY(PlotsFactory::self()->requestPlot(Expression(input), Dim3D).canDraw());
0062 }
0063 
0064 void SurfaceTest::testIncorrect_data()
0065 {
0066     QTest::addColumn<QString>("input");
0067 
0068     QTest::newRow("hiper-surf") << "x*x+y*y+z*z=w";
0069     QTest::newRow("wrong-inf") << "(x,y)->x/0";
0070     QTest::newRow("wrong-nan-1stcomp") << "(u,v)->{u/0 - v/0, 5*u, -7*v}";
0071     QTest::newRow("wrong-dimension-uv") << "(u,v)->{u, v, 5*u, -7*v}";
0072 }
0073 
0074 void SurfaceTest::testIncorrect()
0075 {
0076     QFETCH(QString, input);
0077 
0078     PlotBuilder rp = PlotsFactory::self()->requestPlot(Expression(input), Dim3D);
0079     if(rp.canDraw()) {
0080         FunctionGraph* f = rp.create(Qt::red, QStringLiteral("lala"));
0081         Surface* surface = dynamic_cast<Surface*>(f);
0082         QVERIFY(surface);
0083         
0084         surface->update(QVector3D(-1,-1,-1), QVector3D(1,1,1));
0085         QVERIFY(!f->isCorrect() || surface->vertices().isEmpty());
0086     }
0087 }
0088 
0089 //TODO
0090 // typedef QPair<double, double> IntervalValue;
0091 // Q_DECLARE_METATYPE(IntervalValue)
0092 // 
0093 // typedef QPair<Analitza::Expression, Analitza::Expression> IntervalExpression;
0094 // Q_DECLARE_METATYPE(IntervalExpression)
0095 // 
0096 // void SurfaceTest::testParamIntervals_data()
0097 // {
0098 //     QTest::addColumn<QString>("input");
0099 //     QTest::addColumn<QString>("param");
0100 //     QTest::addColumn<IntervalValue>("interval_value");
0101 //     QTest::addColumn<IntervalExpression>("interval_expression");
0102 // 
0103 //     QTest::newRow("simple_interval_vals") << "x->x*x" << "x" <<
0104 //                                           qMakePair(-7.0, 5.0) << qMakePair(Analitza::Expression("a+b-4"), Analitza::Expression("16"));
0105 // 
0106 //     QTest::newRow("implicit_curve_1_interval_vals") << "x*x+y*y=8" << "y" <<
0107 //             qMakePair(-9.0+2, 15.0) << qMakePair(Analitza::Expression("-abs(a*b)"), Analitza::Expression("cos(0)*a*a"));
0108 // }
0109 // 
0110 // void SurfaceTest::testParamIntervals()
0111 // {
0112 //     QFETCH(QString, input);
0113 //     QFETCH(QString, param);
0114 //     QFETCH(IntervalValue, interval_value);
0115 //     QFETCH(IntervalExpression, interval_expression);
0116 // 
0117 //     m_vars->modify("a", -4.0);
0118 //     m_vars->modify("b", -9.5);
0119 // 
0120 //     PlotItem* plot = PlotsFactory::self()->requestPlot(Expression(input), Dim2D).create(Qt::red, "hola", m_vars);
0121 //     PlaneCurve* f3 = dynamic_cast<PlaneCurve*>(plot);
0122 //     QVERIFY(f3->isCorrect());
0123 // 
0124 //     QVERIFY(f3->setInterval(param, interval_value.first, interval_value.second));
0125 //     QCOMPARE(f3->interval(param).first, -7.0);
0126 // 
0127 //     //Interval as expression
0128 //     QVERIFY(f3->setInterval(param, interval_expression.first, interval_expression.second));
0129 //     QCOMPARE(f3->interval(param, true).second.toString(), QStringLiteral("16"));
0130 //     
0131 //     delete m_vars->take("a");
0132 //     delete m_vars->take("b");
0133 // }
0134 
0135 
0136 
0137 #include "moc_surfacetest.cpp"