Merged in ValentinaZhuravska/valentina/feature (pull request #78)

Tests for SumTrapezoids method in VAbstractDetail class

--HG--
branch : develop
This commit is contained in:
Roman Telezhinskyi 2015-11-22 18:59:07 +02:00
commit 4c3eae4c80
2 changed files with 83 additions and 0 deletions

View File

@ -32,6 +32,8 @@
#include <QPointF> #include <QPointF>
#include <QVector> #include <QVector>
#include <QtTest>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
TST_VAbstractDetail::TST_VAbstractDetail(QObject *parent) TST_VAbstractDetail::TST_VAbstractDetail(QObject *parent)
:AbstractTest(parent) :AbstractTest(parent)
@ -51,6 +53,18 @@ void TST_VAbstractDetail::EquidistantRemoveLoop() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TST_VAbstractDetail::SumTrapezoids() const
{
// Case3 checks that the method 'SumTrapezoids' returns negative value for three clockwise allocated points
// Case4 checks that the method 'SumTrapezoids' returns positive value for three counterclock-wise allocated points
// Case5 checks that the method 'SumTrapezoids' returns 0 for one point
Case3();
Case4();
Case5();
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VAbstractDetail::Case1() const void TST_VAbstractDetail::Case1() const
{ {
const QVector<QPointF> points = InputPointsCase1(); // Input points. const QVector<QPointF> points = InputPointsCase1(); // Input points.
@ -78,6 +92,33 @@ void TST_VAbstractDetail::Case2() const
Comparison(ekv, ekvOrig); Comparison(ekv, ekvOrig);
} }
//---------------------------------------------------------------------------------------------------------------------
void TST_VAbstractDetail::Case3() const
{
const QVector<QPointF> points = InputPointsCase3(); // Input points.
const qreal result = VAbstractDetail::SumTrapezoids(points);
QVERIFY(result < 0);
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VAbstractDetail::Case4() const
{
const QVector<QPointF> points = InputPointsCase4(); // Input points.
const qreal result = VAbstractDetail::SumTrapezoids(points);
QVERIFY(result > 0);
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VAbstractDetail::Case5() const
{
const QVector<QPointF> points = InputPointsCase5(); // Input points.
const qreal result = VAbstractDetail::SumTrapezoids(points);
QVERIFY(result == 0);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> TST_VAbstractDetail::InputPointsCase1() const QVector<QPointF> TST_VAbstractDetail::InputPointsCase1() const
{ {
@ -324,3 +365,37 @@ QVector<QPointF> TST_VAbstractDetail::OutputPointsCase2() const
return points; return points;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> TST_VAbstractDetail::InputPointsCase3() const
{
QVector<QPointF> points;
points += QPointF(35, 35);
points += QPointF(50, 50);
points += QPointF(15, 50);
return points;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> TST_VAbstractDetail::InputPointsCase4() const
{
QVector<QPointF> points;
points += QPointF(15, 15);
points += QPointF(15, 50);
points += QPointF(50, 50);
return points;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> TST_VAbstractDetail::InputPointsCase5() const
{
QVector<QPointF> points;
points += QPointF(35, 35);
return points;
}

View File

@ -41,10 +41,14 @@ signals:
private slots: private slots:
void EquidistantRemoveLoop() const; void EquidistantRemoveLoop() const;
void SumTrapezoids() const;
private: private:
void Case1() const; void Case1() const;
void Case2() const; void Case2() const;
void Case3() const;
void Case4() const;
void Case5() const;
QVector<QPointF> InputPointsCase1() const; QVector<QPointF> InputPointsCase1() const;
QVector<QPointF> OutputPointsCase1() const; QVector<QPointF> OutputPointsCase1() const;
@ -52,6 +56,10 @@ private:
QVector<QPointF> InputPointsCase2() const; QVector<QPointF> InputPointsCase2() const;
QVector<QPointF> OutputPointsCase2() const; QVector<QPointF> OutputPointsCase2() const;
QVector<QPointF> InputPointsCase3() const;
QVector<QPointF> InputPointsCase4() const;
QVector<QPointF> InputPointsCase5() const;
}; };
#endif // TST_VABSTRACTDETAIL_H #endif // TST_VABSTRACTDETAIL_H