From bd229583d4ed5f39d16186909f72de6bb790b925 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 10 Jul 2021 16:13:29 +0300 Subject: [PATCH] Test IsAllowanceValid method. --- src/libs/vlayout/vabstractpiece.cpp | 4 +- src/test/ValentinaTest/share/test_data.qrc | 2 + .../valid_allowance_case3/allowance.json | 389 +++++++++++++++++ .../share/valid_allowance_case3/base.json | 399 ++++++++++++++++++ src/test/ValentinaTest/tst_vabstractpiece.cpp | 36 ++ src/test/ValentinaTest/tst_vabstractpiece.h | 2 + 6 files changed, 830 insertions(+), 2 deletions(-) create mode 100644 src/test/ValentinaTest/share/valid_allowance_case3/allowance.json create mode 100644 src/test/ValentinaTest/share/valid_allowance_case3/base.json diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index f814e65b6..365ab3c86 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -1532,8 +1532,8 @@ bool VAbstractPiece::IsAllowanceValid(const QVector &base, const QVecto return false; // Not enough data } -// DumpVector(base); // Uncomment for dumping test data -// DumpVector(allowance); // Uncomment for dumping test data + DumpVector(base, QStringLiteral("base.json.XXXXXX")); // Uncomment for dumping test data + DumpVector(allowance, QStringLiteral("allowance.json.XXXXXX")); // Uncomment for dumping test data // First check direction const qreal baseDirection = VPiece::SumTrapezoids(base); diff --git a/src/test/ValentinaTest/share/test_data.qrc b/src/test/ValentinaTest/share/test_data.qrc index 738852acf..87be7733a 100644 --- a/src/test/ValentinaTest/share/test_data.qrc +++ b/src/test/ValentinaTest/share/test_data.qrc @@ -145,5 +145,7 @@ smart_pattern_#120_piece_2/output.json smart_pattern_#133/input.json smart_pattern_#133/output.json + valid_allowance_case3/allowance.json + valid_allowance_case3/base.json diff --git a/src/test/ValentinaTest/share/valid_allowance_case3/allowance.json b/src/test/ValentinaTest/share/valid_allowance_case3/allowance.json new file mode 100644 index 000000000..eac899766 --- /dev/null +++ b/src/test/ValentinaTest/share/valid_allowance_case3/allowance.json @@ -0,0 +1,389 @@ +{ + "vector": [ + { + "type": "QPointF", + "x": 92.52561994759033, + "y": 2202.2061793579987 + }, + { + "type": "QPointF", + "x": 92.2772790878172, + "y": 1326.7170103448875 + }, + { + "type": "QPointF", + "x": 91.97507683533829, + "y": 261.34742461356785 + }, + { + "type": "QPointF", + "x": 106.8818073273175, + "y": 259.98160041743677 + }, + { + "type": "QPointF", + "x": 137.38232324564848, + "y": 255.0603139564763 + }, + { + "type": "QPointF", + "x": 158.17729436344507, + "y": 249.89617336979745 + }, + { + "type": "QPointF", + "x": 171.13588768568093, + "y": 245.8762939360861 + }, + { + "type": "QPointF", + "x": 183.5441878371626, + "y": 241.3114353974675 + }, + { + "type": "QPointF", + "x": 195.32179015503095, + "y": 236.24278356546813 + }, + { + "type": "QPointF", + "x": 206.49141930179945, + "y": 230.67800026587307 + }, + { + "type": "QPointF", + "x": 217.07741190258892, + "y": 224.62200069789338 + }, + { + "type": "QPointF", + "x": 227.10500822940557, + "y": 218.07654031559593 + }, + { + "type": "QPointF", + "x": 236.5994666818242, + "y": 211.04004206628608 + }, + { + "type": "QPointF", + "x": 245.58509742928743, + "y": 203.50772328639982 + }, + { + "type": "QPointF", + "x": 254.08433856460397, + "y": 195.47203389468186 + }, + { + "type": "QPointF", + "x": 262.1169987762586, + "y": 186.92336133325725 + }, + { + "type": "QPointF", + "x": 269.6209156939228, + "y": 177.94524558586846 + }, + { + "type": "QPointF", + "x": 280.24821231578767, + "y": 163.37755107526294 + }, + { + "type": "QPointF", + "x": 292.9139140638711, + "y": 141.85503520098874 + }, + { + "type": "QPointF", + "x": 303.86632681987686, + "y": 118.18371124945193 + }, + { + "type": "QPointF", + "x": 313.1867421043998, + "y": 92.23186854093896 + }, + { + "type": "QPointF", + "x": 320.93528277934104, + "y": 63.826799135622935 + }, + { + "type": "QPointF", + "x": 327.9396074726531, + "y": 33.63270638137283 + }, + { + "type": "QPointF", + "x": 331.47901542748485, + "y": 1.0285850987598408 + }, + { + "type": "QPointF", + "x": 334.4654936711189, + "y": -34.069089116676814 + }, + { + "type": "QPointF", + "x": 337.06492259413517, + "y": -89.88560581238215 + }, + { + "type": "QPointF", + "x": 755.0589593624836, + "y": 81.19608223354786 + }, + { + "type": "QPointF", + "x": 736.609138766886, + "y": 127.80263877573647 + }, + { + "type": "QPointF", + "x": 719.3604904848505, + "y": 178.08816959390435 + }, + { + "type": "QPointF", + "x": 703.0134745532514, + "y": 233.0508326580554 + }, + { + "type": "QPointF", + "x": 688.0700705174979, + "y": 290.15129975668845 + }, + { + "type": "QPointF", + "x": 675.0440800520552, + "y": 346.75662531853175 + }, + { + "type": "QPointF", + "x": 664.4353812232487, + "y": 400.2315392200221 + }, + { + "type": "QPointF", + "x": 656.7282750527801, + "y": 447.93899690683065 + }, + { + "type": "QPointF", + "x": 653.2594531347684, + "y": 477.88418396195357 + }, + { + "type": "QPointF", + "x": 652.0414453212609, + "y": 494.3897671909149 + }, + { + "type": "QPointF", + "x": 651.8060316356091, + "y": 510.4752049493997 + }, + { + "type": "QPointF", + "x": 653.3086426448241, + "y": 530.2043953624742 + }, + { + "type": "QPointF", + "x": 655.3752026443186, + "y": 545.8101384800652 + }, + { + "type": "QPointF", + "x": 658.5584573074667, + "y": 563.1680268477246 + }, + { + "type": "QPointF", + "x": 663.0015557834969, + "y": 581.6964468162018 + }, + { + "type": "QPointF", + "x": 668.852212781207, + "y": 600.9318511423511 + }, + { + "type": "QPointF", + "x": 676.2470115628831, + "y": 620.4200106226999 + }, + { + "type": "QPointF", + "x": 685.3103826896315, + "y": 639.7191723213771 + }, + { + "type": "QPointF", + "x": 696.1560114325907, + "y": 658.4074374442621 + }, + { + "type": "QPointF", + "x": 708.968803887299, + "y": 676.1977914955778 + }, + { + "type": "QPointF", + "x": 719.9264769666623, + "y": 688.5704353540432 + }, + { + "type": "QPointF", + "x": 727.7391818856612, + "y": 696.2478567357342 + }, + { + "type": "QPointF", + "x": 736.1962039308098, + "y": 703.5812938875612 + }, + { + "type": "QPointF", + "x": 745.2329152897552, + "y": 710.4460821458293 + }, + { + "type": "QPointF", + "x": 754.8814128293536, + "y": 716.8080984445425 + }, + { + "type": "QPointF", + "x": 765.1788854726277, + "y": 722.6321788768454 + }, + { + "type": "QPointF", + "x": 776.1671520789575, + "y": 727.8805981700134 + }, + { + "type": "QPointF", + "x": 787.891619425379, + "y": 732.5117038125346 + }, + { + "type": "QPointF", + "x": 800.3997769749498, + "y": 736.4789447545836 + }, + { + "type": "QPointF", + "x": 813.8809155042308, + "y": 739.76494255191 + }, + { + "type": "QPointF", + "x": 845.5484535894442, + "y": 745.6456405592226 + }, + { + "type": "QPointF", + "x": 841.4143655756919, + "y": 778.8837473816585 + }, + { + "type": "QPointF", + "x": 839.2350865290254, + "y": 805.1996178416854 + }, + { + "type": "QPointF", + "x": 835.9161011895001, + "y": 862.3048099622779 + }, + { + "type": "QPointF", + "x": 831.693873004494, + "y": 965.4116356694894 + }, + { + "type": "QPointF", + "x": 827.8540427601858, + "y": 1087.310954354911 + }, + { + "type": "QPointF", + "x": 823.114585595346, + "y": 1281.5741119146162 + }, + { + "type": "QPointF", + "x": 820.4843664787782, + "y": 1451.2417377419042 + }, + { + "type": "QPointF", + "x": 820.0163358596512, + "y": 1533.4268890124665 + }, + { + "type": "QPointF", + "x": 821.0509143011902, + "y": 1572.2505146663095 + }, + { + "type": "QPointF", + "x": 827.8638234577412, + "y": 1651.1597197912597 + }, + { + "type": "QPointF", + "x": 869.8910601743813, + "y": 2101.4232016478572 + }, + { + "type": "QPointF", + "x": 875.1648042331244, + "y": 2176.834879067045 + }, + { + "type": "QPointF", + "x": 813.9396120076474, + "y": 2181.83573701641 + }, + { + "type": "QPointF", + "x": 735.5341251972459, + "y": 2186.9448739581426 + }, + { + "type": "QPointF", + "x": 648.8793539199287, + "y": 2191.3042719247806 + }, + { + "type": "QPointF", + "x": 555.471196133076, + "y": 2194.926499889949 + }, + { + "type": "QPointF", + "x": 456.8424236034925, + "y": 2197.8182809981568 + }, + { + "type": "QPointF", + "x": 354.4554366585654, + "y": 2199.9847968442527 + }, + { + "type": "QPointF", + "x": 197.51793975963105, + "y": 2201.9649058358928 + }, + { + "type": "QPointF", + "x": 92.52561994759033, + "y": 2202.2061793579987 + } + ] +} diff --git a/src/test/ValentinaTest/share/valid_allowance_case3/base.json b/src/test/ValentinaTest/share/valid_allowance_case3/base.json new file mode 100644 index 000000000..7cb19ff06 --- /dev/null +++ b/src/test/ValentinaTest/share/valid_allowance_case3/base.json @@ -0,0 +1,399 @@ +{ + "vector": [ + { + "type": "QPointF", + "x": 93.34601574803145, + "y": 2126.6135433070867 + }, + { + "type": "QPointF", + "x": 93.34601574803145, + "y": 1559.684409448819 + }, + { + "type": "QPointF", + "x": 92.19617843603547, + "y": 705.8838909701382 + }, + { + "type": "QPointF", + "x": 92.57171849783603, + "y": 334.4903817714229 + }, + { + "type": "QPointF", + "x": 92.8636004614689, + "y": 287.83352776342883 + }, + { + "type": "QPointF", + "x": 110.19985000692739, + "y": 286.24509969651666 + }, + { + "type": "QPointF", + "x": 142.68693934522423, + "y": 281.0032777763672 + }, + { + "type": "QPointF", + "x": 165.290696688526, + "y": 275.3899503979951 + }, + { + "type": "QPointF", + "x": 179.62815627390916, + "y": 270.942333478028 + }, + { + "type": "QPointF", + "x": 193.34787262661484, + "y": 265.89502130992287 + }, + { + "type": "QPointF", + "x": 206.4586549775985, + "y": 260.25261726292615 + }, + { + "type": "QPointF", + "x": 218.96931255781567, + "y": 254.01972470628417 + }, + { + "type": "QPointF", + "x": 230.8886545982218, + "y": 247.2009470092434 + }, + { + "type": "QPointF", + "x": 242.22549032977236, + "y": 239.80088754105026 + }, + { + "type": "QPointF", + "x": 252.98862898342287, + "y": 231.82414967095104 + }, + { + "type": "QPointF", + "x": 263.1868797901287, + "y": 223.27533676819218 + }, + { + "type": "QPointF", + "x": 272.8290519808455, + "y": 214.15905220202012 + }, + { + "type": "QPointF", + "x": 281.9239547865287, + "y": 204.47989934168118 + }, + { + "type": "QPointF", + "x": 290.48039743813376, + "y": 194.2424815564218 + }, + { + "type": "QPointF", + "x": 302.389273453946, + "y": 177.91802257725897 + }, + { + "type": "QPointF", + "x": 316.3771086041528, + "y": 154.1488378881743 + }, + { + "type": "QPointF", + "x": 328.36966929524556, + "y": 128.22945414584296 + }, + { + "type": "QPointF", + "x": 338.43742937486826, + "y": 100.19669830423614 + }, + { + "type": "QPointF", + "x": 346.6508626906646, + "y": 70.08739731732494 + }, + { + "type": "QPointF", + "x": 353.08044309027844, + "y": 37.9383781390806 + }, + { + "type": "QPointF", + "x": 357.7966444213536, + "y": 3.7864677234742468 + }, + { + "type": "QPointF", + "x": 360.86994053153404, + "y": -32.331506975522956 + }, + { + "type": "QPointF", + "x": 361.74847243745114, + "y": -51.19587766869522 + }, + { + "type": "QPointF", + "x": 720.8335098627776, + "y": 95.77481796543057 + }, + { + "type": "QPointF", + "x": 711.7833466919931, + "y": 118.6366631172392 + }, + { + "type": "QPointF", + "x": 694.1575967053057, + "y": 170.02157048253167 + }, + { + "type": "QPointF", + "x": 677.5296945004579, + "y": 225.92864185095686 + }, + { + "type": "QPointF", + "x": 662.3755913618734, + "y": 283.8342144770952 + }, + { + "type": "QPointF", + "x": 649.1712385739754, + "y": 341.2146256155272 + }, + { + "type": "QPointF", + "x": 638.3925874211877, + "y": 395.5462125208335 + }, + { + "type": "QPointF", + "x": 630.5155891879336, + "y": 444.30531244759425 + }, + { + "type": "QPointF", + "x": 626.9150699255756, + "y": 475.3873989182334 + }, + { + "type": "QPointF", + "x": 625.5990148277461, + "y": 493.2216498238739 + }, + { + "type": "QPointF", + "x": 625.3346118384657, + "y": 511.2878799814551 + }, + { + "type": "QPointF", + "x": 626.9842617015943, + "y": 532.9476815302078 + }, + { + "type": "QPointF", + "x": 629.2338286370648, + "y": 549.9354117337174 + }, + { + "type": "QPointF", + "x": 632.6645776213952, + "y": 568.642855588862 + }, + { + "type": "QPointF", + "x": 637.4591049454809, + "y": 588.636789167028 + }, + { + "type": "QPointF", + "x": 643.8000069002165, + "y": 609.4839885396026 + }, + { + "type": "QPointF", + "x": 651.8698797764976, + "y": 630.7512297779718 + }, + { + "type": "QPointF", + "x": 661.8513198652188, + "y": 652.0052889535226 + }, + { + "type": "QPointF", + "x": 673.9269234572748, + "y": 672.8129421376415 + }, + { + "type": "QPointF", + "x": 688.2792868435611, + "y": 692.740965401715 + }, + { + "type": "QPointF", + "x": 700.728660557709, + "y": 706.7979340765864 + }, + { + "type": "QPointF", + "x": 709.7835961192387, + "y": 715.6960758355142 + }, + { + "type": "QPointF", + "x": 719.5104320429546, + "y": 724.1306216545854 + }, + { + "type": "QPointF", + "x": 729.9319928652181, + "y": 732.0474185427238 + }, + { + "type": "QPointF", + "x": 741.0711031223916, + "y": 739.3923135088523 + }, + { + "type": "QPointF", + "x": 752.9505873508364, + "y": 746.1111535618945 + }, + { + "type": "QPointF", + "x": 765.5932700869149, + "y": 752.1497857107736 + }, + { + "type": "QPointF", + "x": 779.0219758669887, + "y": 757.4540569644129 + }, + { + "type": "QPointF", + "x": 793.2595292274196, + "y": 761.9698143317357 + }, + { + "type": "QPointF", + "x": 808.3287547045696, + "y": 765.6429048216658 + }, + { + "type": "QPointF", + "x": 816.2184566929134, + "y": 767.1080314960631 + }, + { + "type": "QPointF", + "x": 815.0928241314082, + "y": 776.158127961756 + }, + { + "type": "QPointF", + "x": 812.8418244603739, + "y": 803.3400603715177 + }, + { + "type": "QPointF", + "x": 809.5039807203343, + "y": 860.7697229173427 + }, + { + "type": "QPointF", + "x": 805.2593754665681, + "y": 964.3281506300941 + }, + { + "type": "QPointF", + "x": 801.410474020859, + "y": 1086.4777243496678 + }, + { + "type": "QPointF", + "x": 796.6657651401786, + "y": 1280.9287465579719 + }, + { + "type": "QPointF", + "x": 794.0308545255843, + "y": 1450.8314875066817 + }, + { + "type": "QPointF", + "x": 793.5576303056135, + "y": 1533.703811210904 + }, + { + "type": "QPointF", + "x": 793.8519374393269, + "y": 1559.684409448819 + }, + { + "type": "QPointF", + "x": 794.6245773796793, + "y": 1573.7421032657548 + }, + { + "type": "QPointF", + "x": 801.5051913909572, + "y": 1653.4354868006676 + }, + { + "type": "QPointF", + "x": 843.5206921852375, + "y": 2103.581567208798 + }, + { + "type": "QPointF", + "x": 809.0163237412717, + "y": 2106.4056855746167 + }, + { + "type": "QPointF", + "x": 731.7317748936437, + "y": 2111.450016119814 + }, + { + "type": "QPointF", + "x": 645.9475353931566, + "y": 2115.770598189225 + }, + { + "type": "QPointF", + "x": 553.2539204606728, + "y": 2119.36847505834 + }, + { + "type": "QPointF", + "x": 455.24124531705513, + "y": 2122.2446900026507 + }, + { + "type": "QPointF", + "x": 353.499825183166, + "y": 2124.4002862976467 + }, + { + "type": "QPointF", + "x": 197.34423228847493, + "y": 2126.374554245388 + }, + { + "type": "QPointF", + "x": 93.34601574803145, + "y": 2126.6135433070867 + } + ] +} diff --git a/src/test/ValentinaTest/tst_vabstractpiece.cpp b/src/test/ValentinaTest/tst_vabstractpiece.cpp index 022699162..9c08d4ba8 100644 --- a/src/test/ValentinaTest/tst_vabstractpiece.cpp +++ b/src/test/ValentinaTest/tst_vabstractpiece.cpp @@ -1266,6 +1266,42 @@ void TST_VAbstractPiece::PossibleInfiniteClearLoops() const Comparison(res, expect); } +//--------------------------------------------------------------------------------------------------------------------- +void TST_VAbstractPiece::IsAllowanceValid_data() const +{ + QTest::addColumn>("base"); + QTest::addColumn>("allowance"); + QTest::addColumn("valid"); + + auto ASSERT_TEST_CASE = [this](const char *title, const QString &base, const QString &allowance, bool valid) + { + QVector basePoints; + AbstractTest::VectorFromJson(base, basePoints); + + QVector allowancePoints; + AbstractTest::VectorFromJson(allowance, allowancePoints); + + QTest::newRow(title) << basePoints << allowancePoints << valid ; + }; + + // See file src/app/share/collection/valid_allowance/case3.val (private collection) + ASSERT_TEST_CASE("Valid seam allowance. Case 3", + QStringLiteral("://valid_allowance_case3/base.json"), + QStringLiteral("://valid_allowance_case3/allowance.json"), + true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VAbstractPiece::IsAllowanceValid() const +{ + QFETCH(QVector, base); + QFETCH(QVector, allowance); + QFETCH(bool, valid); + + bool result = VAbstractPiece::IsAllowanceValid(base, allowance); + QVERIFY(result == valid); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_VAbstractPiece::Case3() const { diff --git a/src/test/ValentinaTest/tst_vabstractpiece.h b/src/test/ValentinaTest/tst_vabstractpiece.h index 0fceca326..fff210e94 100644 --- a/src/test/ValentinaTest/tst_vabstractpiece.h +++ b/src/test/ValentinaTest/tst_vabstractpiece.h @@ -61,6 +61,8 @@ private slots: void TestCorrectEquidistantPoints() const; void PossibleInfiniteClearLoops_data() const; void PossibleInfiniteClearLoops() const; + void IsAllowanceValid_data() const; + void IsAllowanceValid() const; private: QVector InputPointsCase3() const;