From 41e764c0f0984f6f5b890f857033372e4476dd97 Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Thu, 27 May 2021 16:43:25 +0100 Subject: IVGCVSW-6059 Fixing PermutationVector.end() to cope with dimensions < 5 * PermutationVector.end() was returning the end of the fixed size array m_DimMappings rather than the number of mappings set by the constructor. Signed-off-by: Colm Donelan Change-Id: Ie218f7922e8c9c35c1dc702e43a5ee2fd1a61ff0 --- src/armnn/test/UtilsTests.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src') diff --git a/src/armnn/test/UtilsTests.cpp b/src/armnn/test/UtilsTests.cpp index a813feaf7f..77883ba4fb 100644 --- a/src/armnn/test/UtilsTests.cpp +++ b/src/armnn/test/UtilsTests.cpp @@ -269,6 +269,47 @@ BOOST_AUTO_TEST_CASE(PermuteQuantizationDim) BOOST_CHECK(permuted.GetQuantizationDim().value() == 3U); } +BOOST_AUTO_TEST_CASE(PermuteVectorIterator) +{ + // We're slightly breaking the spirit of std::array.end() because we're using it as a + // variable length rather than fixed length. This test is to use a couple of iterators and + // make sure it still mostly makes sense. + + // Create zero length. + armnn::PermutationVector zeroPVector({}); + // Begin should be equal to end. + BOOST_CHECK(zeroPVector.begin() == zeroPVector.end()); + + // Create length 4. Summing the 4 values should be 6. + armnn::PermutationVector fourPVector({ 0, 3, 2, 1 }); + unsigned int sum = 0; + for (unsigned int it : fourPVector) + { + sum += it; + } + BOOST_CHECK(sum == 6); + // Directly use begin and end, make sure there are 4 iterations. + unsigned int iterations = 0; + auto itr = fourPVector.begin(); + while(itr != fourPVector.end()) + { + ++iterations; + itr++; + } + BOOST_CHECK(iterations == 4); + + // Do the same with 2 elements. + armnn::PermutationVector twoPVector({ 0, 1 }); + iterations = 0; + itr = twoPVector.begin(); + while(itr != twoPVector.end()) + { + ++iterations; + itr++; + } + BOOST_CHECK(iterations == 2); +} + #if defined(ARMNNREF_ENABLED) BOOST_AUTO_TEST_CASE(LayerSupportHandle) { -- cgit v1.2.1