From 7a72cb06e4a70544377072b3765da32cf583dfde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 May 2020 12:05:39 +0200 Subject: [PATCH] MeshTools: test reducing of last dimension in removeDuplicatesFuzzy(). I spotted a potential bug -- and it clearly *is* a bug. The test doesn't reduce the data size in the last dimension, leaving a duplicate (and unused) item at the end. --- .../MeshTools/Test/RemoveDuplicatesTest.cpp | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp b/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp index c20426086..22d79fa25 100644 --- a/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp +++ b/src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp @@ -48,7 +48,8 @@ struct RemoveDuplicatesTest: TestSuite::Tester { void removeDuplicatesIndexedInPlaceErasedNonContiguous(); void removeDuplicatesIndexedInPlaceErasedWrongIndexSize(); - void removeDuplicatesFuzzyInPlace(); + void removeDuplicatesFuzzyInPlaceOneDimension(); + void removeDuplicatesFuzzyInPlaceMoreDimensions(); void removeDuplicatesFuzzyInPlaceIntoWrongOutputSize(); #ifdef MAGNUM_BUILD_DEPRECATED void removeDuplicatesFuzzyStl(); @@ -91,7 +92,8 @@ RemoveDuplicatesTest::RemoveDuplicatesTest() { &RemoveDuplicatesTest::removeDuplicatesIndexedInPlaceErasedNonContiguous, &RemoveDuplicatesTest::removeDuplicatesIndexedInPlaceErasedWrongIndexSize, - &RemoveDuplicatesTest::removeDuplicatesFuzzyInPlace, + &RemoveDuplicatesTest::removeDuplicatesFuzzyInPlaceOneDimension, + &RemoveDuplicatesTest::removeDuplicatesFuzzyInPlaceMoreDimensions, &RemoveDuplicatesTest::removeDuplicatesFuzzyInPlaceIntoWrongOutputSize, #ifdef MAGNUM_BUILD_DEPRECATED &RemoveDuplicatesTest::removeDuplicatesFuzzyStl, @@ -269,7 +271,27 @@ void RemoveDuplicatesTest::removeDuplicatesIndexedInPlaceErasedWrongIndexSize() "MeshTools::removeDuplicatesIndexedInPlace(): expected index type size 1, 2 or 4 but got 3\n"); } -void RemoveDuplicatesTest::removeDuplicatesFuzzyInPlace() { +void RemoveDuplicatesTest::removeDuplicatesFuzzyInPlaceOneDimension() { + /* Numbers with distance <=1 should be merged. In the first iteration item + 2 gets collapsed into item 1, in the second iteration item 3 gets + collapsed into item 1, reducing to 2 items in total. */ + Math::Vector<1, Float> data[]{ + 1.0f, /* bucket 0 in 1st iteration, bucket 1 in 2nd */ + 2.9f, /* bucket 2 in 1st iteration, bucket 3 in 2nd */ + 0.0f, /* bucket 0 in 1st iteration, bucket 0 in 2nd */ + 3.4f /* bucket 3 in 1st iteration, bucket 3 in 2nd */ + }; + + std::pair, std::size_t> result = MeshTools::removeDuplicatesFuzzyInPlace(Containers::stridedArrayView(data), 1.00001f); + CORRADE_COMPARE_AS(Containers::arrayView(result.first), + Containers::arrayView({0, 1, 0, 1}), + TestSuite::Compare::Container); + CORRADE_COMPARE_AS(Containers::arrayView(data).prefix(result.second), + (Containers::arrayView>({1.0f, 2.9f})), + TestSuite::Compare::Container); +} + +void RemoveDuplicatesTest::removeDuplicatesFuzzyInPlaceMoreDimensions() { /* Numbers with distance 1 should be merged, numbers with distance 2 should be kept. Testing both even-odd and odd-even sequence to verify that half-epsilon translations are applied properly. */