Abe Mbise | 925ca0f | 2017-10-02 19:16:33 +0100 | [diff] [blame] | 1 | /* |
| 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 "tests/Utils.h" |
| 25 | #include "tests/framework/Asserts.h" |
| 26 | #include "tests/framework/Macros.h" |
| 27 | #include "tests/framework/datasets/Datasets.h" |
| 28 | #include "tests/validation/Validation.h" |
| 29 | #include "utils/TypePrinter.h" |
| 30 | |
| 31 | #include <stdexcept> |
| 32 | |
| 33 | using namespace arm_compute; |
| 34 | using namespace arm_compute::test; |
| 35 | using namespace arm_compute::test::validation; |
| 36 | |
| 37 | TEST_SUITE(UNIT) |
| 38 | TEST_SUITE(Utils) |
| 39 | |
| 40 | DATA_TEST_CASE(RoundHalfUp, framework::DatasetMode::ALL, zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), |
| 41 | framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -3.f, -4.f, -4.f, -4.f })), |
| 42 | value, result) |
| 43 | { |
| 44 | ARM_COMPUTE_EXPECT(round_half_up(value) == result, framework::LogLevel::ERRORS); |
| 45 | } |
| 46 | |
| 47 | DATA_TEST_CASE(RoundHalfEven, framework::DatasetMode::ALL, zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), |
| 48 | framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 2.f, 3.f, -3.f, -4.f, -4.f, -4.f, -4.f })), |
| 49 | value, result) |
| 50 | { |
| 51 | ARM_COMPUTE_EXPECT(round_half_even(value) == result, framework::LogLevel::ERRORS); |
| 52 | } |
| 53 | |
| 54 | DATA_TEST_CASE(Index2Coord, framework::DatasetMode::ALL, zip(zip(framework::dataset::make("Shape", { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }), framework::dataset::make("Index", { 0, 1, 2 })), |
| 55 | framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })), |
| 56 | shape, index, ref_coordinate) |
| 57 | { |
| 58 | Coordinates coordinate = index2coord(shape, index); |
| 59 | |
| 60 | ARM_COMPUTE_EXPECT(compare_dimensions(coordinate, ref_coordinate), framework::LogLevel::ERRORS); |
| 61 | } |
| 62 | |
| 63 | //FIXME: Negative tests only work in debug mode |
| 64 | #if 0 |
| 65 | DISABLED_DATA_TEST_CASE(Index2CoordFail, framework::DatasetMode::ALL, zip(framework::dataset::make("Shape", { TensorShape{}, TensorShape{ 2U }, TensorShape{ 2U } }), framework::dataset::make("Index", { 0, -1, 2 })), |
| 66 | shape, index) |
| 67 | { |
| 68 | ARM_COMPUTE_ASSERT(index2coord(shape, index)); |
| 69 | } |
| 70 | #endif /* 0 */ |
| 71 | |
| 72 | DATA_TEST_CASE(Coord2Index, framework::DatasetMode::ALL, zip(zip(framework::dataset::make("Shape", { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }), |
| 73 | framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })), |
| 74 | framework::dataset::make("Index", { 0, 1, 2 })), |
| 75 | shape, coordinate, ref_index) |
| 76 | { |
| 77 | int index = coord2index(shape, coordinate); |
| 78 | |
| 79 | ARM_COMPUTE_EXPECT(index == ref_index, framework::LogLevel::ERRORS); |
| 80 | } |
| 81 | |
| 82 | //FIXME: Negative tests only work in debug mode |
| 83 | #if 0 |
| 84 | DISABLED_DATA_TEST_CASE(Coord2IndexFail, framework::DatasetMode::ALL, zip(framework::dataset::make("Shape", { TensorShape{}, TensorShape{ 2U } }), framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{} })), |
| 85 | shape, coordinate) |
| 86 | { |
| 87 | ARM_COMPUTE_ASSERT(coord2index(shape, coordinate)); |
| 88 | } |
| 89 | #endif /* 0 */ |
| 90 | |
| 91 | TEST_SUITE_END() |
| 92 | TEST_SUITE_END() |