Unit test. Check VToolPointOfIntersectionCurves::FindPoint() method.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-01-25 19:06:36 +02:00
parent 2069713ff6
commit d86c79f290
7 changed files with 244 additions and 4 deletions

View File

@ -32,7 +32,7 @@
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vmisc/logging.h" #include "../vmisc/logging.h"
#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsscene.h"
#include "visualization/visualization.h" #include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include <QDialog> #include <QDialog>

View File

@ -133,6 +133,11 @@ QPointF VToolPointOfIntersectionCurves::FindPoint(const QVector<QPointF> &curve1
const QVector<QPointF> &curve2Points, const QVector<QPointF> &curve2Points,
VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint) VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint)
{ {
if (curve1Points.isEmpty() || curve2Points.isEmpty())
{
return QPointF();
}
QVector<QPointF> intersections; QVector<QPointF> intersections;
for ( auto i = 0; i < curve1Points.count()-1; ++i ) for ( auto i = 0; i < curve1Points.count()-1; ++i )
{ {

View File

@ -33,7 +33,7 @@
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsscene.h"
#include "visualization/visualization.h" #include "../visualization/visualization.h"
class QDomElement; class QDomElement;
class QLineF; class QLineF;

View File

@ -53,7 +53,8 @@ SOURCES += \
tst_misc.cpp \ tst_misc.cpp \
tst_vcommandline.cpp \ tst_vcommandline.cpp \
tst_tstranslation.cpp \ tst_tstranslation.cpp \
tst_vdetail.cpp tst_vdetail.cpp \
tst_findpoint.cpp
HEADERS += \ HEADERS += \
tst_vposter.h \ tst_vposter.h \
@ -74,7 +75,8 @@ HEADERS += \
tst_misc.h \ tst_misc.h \
tst_vcommandline.h \ tst_vcommandline.h \
tst_tstranslation.h \ tst_tstranslation.h \
tst_vdetail.h tst_vdetail.h \
tst_findpoint.h
# Set using ccache. Function enable_ccache() defined in common.pri. # Set using ccache. Function enable_ccache() defined in common.pri.
$$enable_ccache() $$enable_ccache()
@ -145,6 +147,24 @@ CONFIG(debug, debug|release){
} }
} }
#VTools static library (depend on VWidgets, VMisc, VPatternDB)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vtools/$${DESTDIR}/ -lvtools
INCLUDEPATH += $$PWD/../../libs/vtools
DEPENDPATH += $$PWD/../../libs/vtools
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a
#VWidgets static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets
INCLUDEPATH += $$PWD/../../libs/vwidgets
DEPENDPATH += $$PWD/../../libs/vwidgets
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/vwidgets.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/libvwidgets.a
# VFormat static library (depend on VPatternDB, IFC) # VFormat static library (depend on VPatternDB, IFC)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vformat/$${DESTDIR}/ -lvformat unix|win32: LIBS += -L$$OUT_PWD/../../libs/vformat/$${DESTDIR}/ -lvformat

View File

@ -45,6 +45,7 @@
#include "tst_vcommandline.h" #include "tst_vcommandline.h"
#include "tst_tstranslation.h" #include "tst_tstranslation.h"
#include "tst_vdetail.h" #include "tst_vdetail.h"
#include "tst_findpoint.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -59,6 +60,7 @@ int main(int argc, char** argv)
delete obj; delete obj;
}; };
ASSERT_TEST(new TST_FindPoint());
ASSERT_TEST(new TST_VDetail()); ASSERT_TEST(new TST_VDetail());
ASSERT_TEST(new TST_VPoster()); ASSERT_TEST(new TST_VPoster());
ASSERT_TEST(new TST_VAbstractDetail()); ASSERT_TEST(new TST_VAbstractDetail());

View File

@ -0,0 +1,167 @@
/************************************************************************
**
** @file tst_findpoint.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 1, 2016
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2016 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "tst_findpoint.h"
#include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h"
#include <QtTest>
//---------------------------------------------------------------------------------------------------------------------
TST_FindPoint::TST_FindPoint(QObject *parent) :
QObject(parent)
{
}
//---------------------------------------------------------------------------------------------------------------------
void TST_FindPoint::TestPointOfIntersectionCurves_data()
{
QTest::addColumn<QVector<QPointF>>("curve1Points");
QTest::addColumn<QVector<QPointF>>("curve2Points");
QTest::addColumn<int>("vCross");
QTest::addColumn<int>("hCross");
QTest::addColumn<QPointF>("expect");
QVector<QPointF> points1;
QVector<QPointF> points2;
VCrossCurvesPoint v = VCrossCurvesPoint::HighestPoint;
HCrossCurvesPoint h = HCrossCurvesPoint::LeftPoint;
QPointF p;
QTest::newRow("Empty lists of points") << points1 << points2 << static_cast<int>(v) << static_cast<int>(h) << p;
points1.clear();
points1.append(QPointF(10, 10));
points1.append(QPointF(15, 20));
points1.append(QPointF(10, 30));
points2.clear();
points2.append(QPointF(30, 10));
points2.append(QPointF(25, 20));
points2.append(QPointF(30, 30));
QTest::newRow("No intersections") << points1 << points2 << static_cast<int>(v) << static_cast<int>(h) << p;
points1.clear();
points1.append(QPointF(10, 10));
points1.append(QPointF(20, 20));
points1.append(QPointF(10, 30));
points2.clear();
points2.append(QPointF(30, 10));
points2.append(QPointF(20, 20));
points2.append(QPointF(30, 30));
p = QPointF(20, 20);
QTest::newRow("One intersection point") << points1 << points2 << static_cast<int>(v) << static_cast<int>(h) << p;
points1.clear();
points1.append(QPointF(10, 10));
points1.append(QPointF(25, 20));
points1.append(QPointF(10, 30));
points2.clear();
points2.append(QPointF(25, 10));
points2.append(QPointF(15, 20));
points2.append(QPointF(25, 30));
p = QPointF(19, 16);
h = HCrossCurvesPoint::LeftPoint;
QTest::newRow("Two intersection points (highest point, leftmost point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
h = HCrossCurvesPoint::RightPoint;
QTest::newRow("Two intersection points (highest point, rightmost point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
v = VCrossCurvesPoint::LowestPoint;
p = QPointF(19, 24);
h = HCrossCurvesPoint::LeftPoint;
QTest::newRow("Two intersection points (lowest point, leftmost point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
h = HCrossCurvesPoint::RightPoint;
QTest::newRow("Two intersection points (lowest point, rightmost point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
points1.clear();
points1.append(QPointF(10, 10));
points1.append(QPointF(20, 25));
points1.append(QPointF(30, 10));
points2.clear();
points2.append(QPointF(10, 30));
points2.append(QPointF(20, 15));
points2.append(QPointF(30, 30));
h = HCrossCurvesPoint::LeftPoint;
p = QPointF(16.6667, 20);
v = VCrossCurvesPoint::HighestPoint;
QTest::newRow("Two intersection points (leftmost point, highest point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
v = VCrossCurvesPoint::LowestPoint;
QTest::newRow("Two intersection points (leftmost point, lowest point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
h = HCrossCurvesPoint::RightPoint;
p = QPointF(23.3333, 20);
v = VCrossCurvesPoint::HighestPoint;
QTest::newRow("Two intersection points (rightmost point, highest point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
v = VCrossCurvesPoint::LowestPoint;
QTest::newRow("Two intersection points (rightmost point, lowest point)") << points1 << points2
<< static_cast<int>(v)
<< static_cast<int>(h) << p;
}
//---------------------------------------------------------------------------------------------------------------------
void TST_FindPoint::TestPointOfIntersectionCurves()
{
QFETCH(QVector<QPointF>, curve1Points);
QFETCH(QVector<QPointF>, curve2Points);
QFETCH(int, vCross);
QFETCH(int, hCross);
QFETCH(QPointF, expect);
const QPointF result = VToolPointOfIntersectionCurves::FindPoint(curve1Points, curve2Points,
static_cast<VCrossCurvesPoint>(vCross),
static_cast<HCrossCurvesPoint>(hCross));
QCOMPARE(result.toPoint(), expect.toPoint());
}

View File

@ -0,0 +1,46 @@
/************************************************************************
**
** @file tst_findpoint.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 1, 2016
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2016 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef TST_FINDPOINT_H
#define TST_FINDPOINT_H
#include <QObject>
class TST_FindPoint : public QObject
{
Q_OBJECT
public:
explicit TST_FindPoint(QObject *parent = nullptr);
private slots:
void TestPointOfIntersectionCurves_data();
void TestPointOfIntersectionCurves();
};
#endif // TST_FINDPOINT_H