From 75701f8cadd8746509f52e5db41b5077d170982b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 7 Dec 2015 18:35:55 +0200 Subject: [PATCH] New test. Testing arc points. --HG-- branch : develop --- src/test/ValentinaTest/tst_varc.cpp | 149 ++++++++++++++++++++++++++++ src/test/ValentinaTest/tst_varc.h | 2 + 2 files changed, 151 insertions(+) diff --git a/src/test/ValentinaTest/tst_varc.cpp b/src/test/ValentinaTest/tst_varc.cpp index a24cd3809..bc5760fd5 100644 --- a/src/test/ValentinaTest/tst_varc.cpp +++ b/src/test/ValentinaTest/tst_varc.cpp @@ -28,6 +28,8 @@ #include "tst_varc.h" #include "../vgeometry/varc.h" +#include "../vlayout/vabstractdetail.h" +#include "../vmisc/logging.h" #include @@ -73,3 +75,150 @@ void TST_VArc::NegativeArc() QCOMPARE(arc.GetLength(), -length); QCOMPARE(arc.GetEndAngle(), f2); } + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VArc::TestGetPoints_data() +{ + QTest::addColumn("radius"); + QTest::addColumn("startAngle"); + QTest::addColumn("endAngle"); + + QTest::newRow("Full circle: radius 10") << 10.0 << 0.0 << 360.0; + QTest::newRow("Full circle: radius 150") << 150.0 << 0.0 << 360.0; + QTest::newRow("Full circle: radius 1500") << 1500.0 << 0.0 << 360.0; + QTest::newRow("Full circle: radius 50000") << 50000.0 << 0.0 << 360.0; + QTest::newRow("Full circle: radius 90000") << 90000.0 << 0.0 << 360.0; + QTest::newRow("Full circle: radius 900000") << 900000.0 << 0.0 << 360.0; + + QTest::newRow("Arc less than 45 degree, radius 100") << 100.0 << 0.0 << 10.5; + QTest::newRow("Arc less than 45 degree, radius 150") << 150.0 << 0.0 << 10.5; + QTest::newRow("Arc less than 45 degree, radius 1500") << 1500.0 << 0.0 << 10.5; + QTest::newRow("Arc less than 45 degree, radius 50000") << 50000.0 << 0.0 << 10.5; + QTest::newRow("Arc less than 45 degree, radius 90000") << 90000.0 << 0.0 << 10.5; + QTest::newRow("Arc less than 45 degree, radius 900000") << 900000.0 << 0.0 << 10.5; + + QTest::newRow("Arc 45 degree, radius 100") << 100.0 << 0.0 << 45.0; + QTest::newRow("Arc 45 degree, radius 150") << 150.0 << 0.0 << 45.0; + QTest::newRow("Arc 45 degree, radius 1500") << 1500.0 << 0.0 << 45.0; + QTest::newRow("Arc 45 degree, radius 50000") << 50000.0 << 0.0 << 45.0; + QTest::newRow("Arc 45 degree, radius 90000") << 90000.0 << 0.0 << 45.0; + QTest::newRow("Arc 45 degree, radius 900000") << 900000.0 << 0.0 << 45.0; + + QTest::newRow("Arc less than 90 degree, radius 100") << 100.0 << 0.0 << 75.0; + QTest::newRow("Arc less than 90 degree, radius 150") << 150.0 << 0.0 << 75.0; + QTest::newRow("Arc less than 90 degree, radius 1500") << 1500.0 << 0.0 << 75.0; + QTest::newRow("Arc less than 90 degree, radius 50000") << 50000.0 << 0.0 << 75.0; + QTest::newRow("Arc less than 90 degree, radius 90000") << 90000.0 << 0.0 << 75.0; + QTest::newRow("Arc less than 90 degree, radius 900000") << 900000.0 << 0.0 << 75.0; + + QTest::newRow("Arc 90 degree, radius 100") << 100.0 << 0.0 << 90.0; + QTest::newRow("Arc 90 degree, radius 150") << 150.0 << 0.0 << 90.0; + QTest::newRow("Arc 90 degree, radius 1500") << 1500.0 << 0.0 << 90.0; + QTest::newRow("Arc 90 degree, radius 50000") << 50000.0 << 0.0 << 90.0; + QTest::newRow("Arc 90 degree, radius 90000") << 90000.0 << 0.0 << 90.0; + QTest::newRow("Arc 90 degree, radius 900000") << 900000.0 << 0.0 << 90.0; + + QTest::newRow("Arc less than 135 degree, radius 100") << 100.0 << 0.0 << 110.6; + QTest::newRow("Arc less than 135 degree, radius 150") << 150.0 << 0.0 << 110.6; + QTest::newRow("Arc less than 135 degree, radius 1500") << 1500.0 << 0.0 << 110.6; + QTest::newRow("Arc less than 135 degree, radius 50000") << 50000.0 << 0.0 << 110.6; + QTest::newRow("Arc less than 135 degree, radius 90000") << 90000.0 << 0.0 << 110.6; + QTest::newRow("Arc less than 135 degree, radius 900000") << 900000.0 << 0.0 << 110.6; + + QTest::newRow("Arc 135 degree, radius 100") << 100.0 << 0.0 << 135.0; + QTest::newRow("Arc 135 degree, radius 150") << 150.0 << 0.0 << 135.0; + QTest::newRow("Arc 135 degree, radius 1500") << 1500.0 << 0.0 << 135.0; + QTest::newRow("Arc 135 degree, radius 50000") << 50000.0 << 0.0 << 135.0; + QTest::newRow("Arc 135 degree, radius 90000") << 90000.0 << 0.0 << 135.0; + QTest::newRow("Arc 135 degree, radius 900000") << 900000.0 << 0.0 << 135.0; + + QTest::newRow("Arc less than 180 degree, radius 100") << 100.0 << 0.0 << 160.7; + QTest::newRow("Arc less than 180 degree, radius 150") << 150.0 << 0.0 << 160.7; + QTest::newRow("Arc less than 180 degree, radius 1500") << 1500.0 << 0.0 << 160.7; + QTest::newRow("Arc less than 180 degree, radius 50000") << 50000.0 << 0.0 << 160.7; + QTest::newRow("Arc less than 180 degree, radius 90000") << 90000.0 << 0.0 << 160.7; + QTest::newRow("Arc less than 180 degree, radius 900000") << 900000.0 << 0.0 << 160.7; + + QTest::newRow("Arc 180 degree, radius 100") << 100.0 << 0.0 << 180.0; + QTest::newRow("Arc 180 degree, radius 150") << 150.0 << 0.0 << 180.0; + QTest::newRow("Arc 180 degree, radius 1500") << 1500.0 << 0.0 << 180.0; + QTest::newRow("Arc 180 degree, radius 50000") << 50000.0 << 0.0 << 180.0; + QTest::newRow("Arc 180 degree, radius 90000") << 90000.0 << 0.0 << 180.0; + QTest::newRow("Arc 180 degree, radius 900000") << 900000.0 << 0.0 << 180.0; + + QTest::newRow("Arc less than 270 degree, radius 100") << 100.0 << 0.0 << 150.3; + QTest::newRow("Arc less than 270 degree, radius 150") << 150.0 << 0.0 << 150.3; + QTest::newRow("Arc less than 270 degree, radius 1500") << 1500.0 << 0.0 << 150.3; + QTest::newRow("Arc less than 270 degree, radius 50000") << 50000.0 << 0.0 << 150.3; + QTest::newRow("Arc less than 270 degree, radius 90000") << 90000.0 << 0.0 << 150.3; + QTest::newRow("Arc less than 270 degree, radius 900000") << 900000.0 << 0.0 << 150.3; + + QTest::newRow("Arc 270 degree, radius 100") << 100.0 << 0.0 << 270.0; + QTest::newRow("Arc 270 degree, radius 150") << 150.0 << 0.0 << 270.0; + QTest::newRow("Arc 270 degree, radius 1500") << 1500.0 << 0.0 << 270.0; + QTest::newRow("Arc 270 degree, radius 50000") << 50000.0 << 0.0 << 270.0; + QTest::newRow("Arc 270 degree, radius 90000") << 90000.0 << 0.0 << 270.0; + QTest::newRow("Arc 270 degree, radius 900000") << 900000.0 << 0.0 << 270.0; + + QTest::newRow("Arc less than 360 degree, radius 100") << 100.0 << 0.0 << 340.0; + QTest::newRow("Arc less than 360 degree, radius 150") << 150.0 << 0.0 << 340.0; + QTest::newRow("Arc less than 360 degree, radius 1500") << 1500.0 << 0.0 << 340.0; + QTest::newRow("Arc less than 360 degree, radius 50000") << 50000.0 << 0.0 << 340.0; + QTest::newRow("Arc less than 360 degree, radius 90000") << 90000.0 << 0.0 << 340.0; + QTest::newRow("Arc less than 360 degree, radius 900000") << 900000.0 << 0.0 << 340.0; + + QTest::newRow("Arc start 90 degree, angle 45 degree, radius 100") << 100.0 << 90.0 << 135.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radius 150") << 150.0 << 90.0 << 135.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radius 1500") << 1500.0 << 90.0 << 135.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radius 50000") << 50000.0 << 90.0 << 135.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radius 90000") << 90000.0 << 90.0 << 135.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radius 900000") << 900000.0 << 90.0 << 135.0; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VArc::TestGetPoints() +{ + QFETCH(qreal, radius); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + + const VPointF center; + VArc arc(center, radius, startAngle, endAngle); + + QVector points = arc.GetPoints(); + + { + const qreal epsRadius = 1.0; // computing error + + for (int i=0; i < points.size(); ++i) + { + QLineF rLine(center.toQPointF(), points.at(i)); + QVERIFY2(qAbs(rLine.length() - radius) <= epsRadius, + "Broken the first rule. All points should be on the same distance from the center."); + } + } + + { + qreal gSquere = 0.0;// geometry squere + + if (qFuzzyCompare(arc.AngleArc(), 360.0)) + {// circle squere + gSquere = M_PI * radius * radius; + } + else + {// sector squere + gSquere = (M_PI * radius * radius) / 360.0 * arc.AngleArc(); + points.append(center.toQPointF()); + } + + // calculated squere + qreal cSquare = qAbs(VAbstractDetail::SumTrapezoids(points)/2.0); + const qreal value = qAbs(gSquere - cSquare); + const QString errorMsg = + QString("Broken the second rule. Interpolation has too big computing error. Error ='%1'.").arg(value); + const qreal epsSquere = 1.0; // computing error + QVERIFY2(value <= epsSquere, qUtf8Printable(errorMsg)); + } +} diff --git a/src/test/ValentinaTest/tst_varc.h b/src/test/ValentinaTest/tst_varc.h index 44361a84f..de4ce7eb7 100644 --- a/src/test/ValentinaTest/tst_varc.h +++ b/src/test/ValentinaTest/tst_varc.h @@ -40,6 +40,8 @@ public: private slots: void CompareTwoWays(); void NegativeArc(); + void TestGetPoints_data(); + void TestGetPoints(); }; #endif // TST_VARC_H