blob: e28ca196207cc705846fdfa875b96f83b53294d7 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "Utils.h"
25
26#include "TypePrinter.h"
27#include "validation/Validation.h"
28
29#include "boost_wrapper.h"
30
31#include <stdexcept>
32
33using namespace arm_compute;
34using namespace arm_compute::test;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035using namespace arm_compute::test::validation;
36
37#ifndef DOXYGEN_SKIP_THIS
38BOOST_AUTO_TEST_SUITE(UNIT)
39BOOST_AUTO_TEST_SUITE(Utils)
40
41BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
42BOOST_DATA_TEST_CASE(RoundHalfUp, boost::unit_test::data::make({ 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }) ^ boost::unit_test::data::make({ 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -3.f, -4.f, -4.f, -4.f }),
43 value, result)
44{
Moritz Pflanzerd0ae8b82017-06-29 14:51:57 +010045 BOOST_TEST(round_half_up(value) == result);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046}
47
48BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
49BOOST_DATA_TEST_CASE(RoundHalfEven, boost::unit_test::data::make({ 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }) ^ boost::unit_test::data::make({ 1.f, 1.f, 2.f, 2.f, 3.f, -3.f, -4.f, -4.f, -4.f, -4.f }),
50 value, result)
51{
Moritz Pflanzerd0ae8b82017-06-29 14:51:57 +010052 BOOST_TEST(round_half_even(value) == result);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053}
54
55BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
56BOOST_DATA_TEST_CASE(Index2Coord, boost::unit_test::data::make({ TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }) ^ boost::unit_test::data::make({ 0, 1, 2 }) ^
57 boost::unit_test::data::make({ Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } }), shape, index, ref_coordinate)
58{
59 Coordinates coordinate = index2coord(shape, index);
60
61 BOOST_TEST(compare_dimensions(coordinate, ref_coordinate));
62}
63
64//FIXME: Negative tests only work in debug mode
65#if 0
66BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
67BOOST_DATA_TEST_CASE(Index2CoordFail, boost::unit_test::data::make({ TensorShape{}, TensorShape{ 2U }, TensorShape{ 2U } }) ^ boost::unit_test::data::make({ 0, -1, 2 }), shape, index)
68{
69 BOOST_CHECK_THROW(index2coord(shape, index), std::runtime_error);
70}
Anthony Barbierac69aa12017-07-03 17:39:37 +010071#endif /* 0 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072
73BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
74BOOST_DATA_TEST_CASE(Coord2Index, boost::unit_test::data::make({ TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }) ^ boost::unit_test::data::make({ Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })
75 ^ boost::unit_test::data::make({ 0, 1, 2 }),
76 shape, coordinate, ref_index)
77{
78 int index = coord2index(shape, coordinate);
79
80 BOOST_TEST(index == ref_index);
81}
82
83//FIXME: Negative tests only work in debug mode
84#if 0
85BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
86BOOST_DATA_TEST_CASE(Coord2IndexFail, boost::unit_test::data::make({ TensorShape{}, TensorShape{ 2U } }) ^ boost::unit_test::data::make({ Coordinates{ 0 }, Coordinates{} }), shape, coordinate)
87{
88 BOOST_CHECK_THROW(coord2index(shape, coordinate), std::runtime_error);
89}
Anthony Barbierac69aa12017-07-03 17:39:37 +010090#endif /* 0 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010091
92BOOST_AUTO_TEST_SUITE_END()
93BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +010094#endif /* DOXYGEN_SKIP_THIS */