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 "spacecurvetest.h" 0020 #include <plotsfactory.h> 0021 #include "analitzaplot/spacecurve.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( SpaceCurveTest ) 0031 0032 SpaceCurveTest::SpaceCurveTest(QObject *parent) 0033 : QObject(parent) 0034 { 0035 m_vars=new Analitza::Variables; 0036 } 0037 0038 SpaceCurveTest::~SpaceCurveTest() 0039 { 0040 delete m_vars; 0041 } 0042 0043 void SpaceCurveTest::initTestCase() 0044 { 0045 } 0046 0047 void SpaceCurveTest::cleanupTestCase() 0048 {} 0049 0050 void SpaceCurveTest::testCorrect_data() 0051 { 0052 QTest::addColumn<QString>("input"); 0053 0054 QTest::newRow("diag-line") << "t->vector{t, t, t}"; 0055 QTest::newRow("diag-line-translated") << "t->vector{t,sin(t)+t,t}"; 0056 QTest::newRow("cuadric") << "t->vector{t,t,t*t}"; 0057 QTest::newRow("helix1") << "t->vector{t,sin(t),cos(t)}"; 0058 QTest::newRow("helix2") << "t->vector{t,t*sin(t),-t*cos(t)}"; 0059 } 0060 0061 void SpaceCurveTest::testCorrect() 0062 { 0063 QFETCH(QString, input); 0064 0065 QVERIFY(PlotsFactory::self()->requestPlot(Expression(input), Dim3D).canDraw()); 0066 } 0067 0068 void SpaceCurveTest::testIncorrect_data() 0069 { 0070 QTest::addColumn<QString>("input"); 0071 0072 QTest::newRow("wrongvector") << "t->vector{t*vector{t*t}, t, t}"; 0073 QTest::newRow("wrong-dimension") << "t->vector{cos(t),t,t,t,t+7}"; 0074 QTest::newRow("wrong-parametric") << "t->vector{v*s,r}"; 0075 QTest::newRow("wrong-variable") << "t->vector{t(t), 8, 4}"; 0076 QTest::newRow("wrong-inf-2ndcomp") << "t->vector{t, t/0, t}"; 0077 QTest::newRow("wrong-nan-3rdcomp") << "t->vector{t, 3*t*t, t/0}"; 0078 } 0079 0080 void SpaceCurveTest::testIncorrect() 0081 { 0082 QFETCH(QString, input); 0083 0084 PlotBuilder rp = PlotsFactory::self()->requestPlot(Expression(input), Dim3D); 0085 if(rp.canDraw()) { 0086 FunctionGraph* f = rp.create(Qt::red, QStringLiteral("lala")); 0087 SpaceCurve* curve = dynamic_cast<SpaceCurve*>(f); 0088 QVERIFY(curve); 0089 0090 curve->update(QVector3D(-1,-1,-1), QVector3D(1,1,1)); 0091 QVERIFY(!f->isCorrect() || curve->points().isEmpty()); 0092 } 0093 } 0094 0095 //TODO 0096 // typedef QPair<double, double> IntervalValue; 0097 // Q_DECLARE_METATYPE(IntervalValue) 0098 // 0099 // typedef QPair<Analitza::Expression, Analitza::Expression> IntervalExpression; 0100 // Q_DECLARE_METATYPE(IntervalExpression) 0101 // 0102 // void SpaceCurveTest::testParamIntervals_data() 0103 // { 0104 // QTest::addColumn<QString>("input"); 0105 // QTest::addColumn<QString>("param"); 0106 // QTest::addColumn<IntervalValue>("interval_value"); 0107 // QTest::addColumn<IntervalExpression>("interval_expression"); 0108 // 0109 // QTest::newRow("simple_interval_vals") << "x->x*x" << "x" << 0110 // qMakePair(-7.0, 5.0) << qMakePair(Analitza::Expression("a+b-4"), Analitza::Expression("16")); 0111 // 0112 // QTest::newRow("implicit_curve_1_interval_vals") << "x*x+y*y=8" << "y" << 0113 // qMakePair(-9.0+2, 15.0) << qMakePair(Analitza::Expression("-abs(a*b)"), Analitza::Expression("cos(0)*a*a")); 0114 // } 0115 // 0116 // void SpaceCurveTest::testParamIntervals() 0117 // { 0118 // QFETCH(QString, input); 0119 // QFETCH(QString, param); 0120 // QFETCH(IntervalValue, interval_value); 0121 // QFETCH(IntervalExpression, interval_expression); 0122 // 0123 // m_vars->modify("a", -4.0); 0124 // m_vars->modify("b", -9.5); 0125 // 0126 // PlotItem* plot = PlotsFactory::self()->requestPlot(Expression(input), Dim2D).create(Qt::red, "hola", m_vars); 0127 // PlaneCurve* f3 = dynamic_cast<PlaneCurve*>(plot); 0128 // QVERIFY(f3->isCorrect()); 0129 // 0130 // QVERIFY(f3->setInterval(param, interval_value.first, interval_value.second)); 0131 // QCOMPARE(f3->interval(param).first, -7.0); 0132 // 0133 // //Interval as expression 0134 // QVERIFY(f3->setInterval(param, interval_expression.first, interval_expression.second)); 0135 // QCOMPARE(f3->interval(param, true).second.toString(), QStringLiteral("16")); 0136 // 0137 // delete m_vars->take("a"); 0138 // delete m_vars->take("b"); 0139 // } 0140 0141 0142 0143 #include "moc_spacecurvetest.cpp"