alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include "AdPostProcessing.hpp" |
| 19 | #include <catch.hpp> |
| 20 | |
| 21 | TEST_CASE("Softmax_vector") { |
| 22 | |
| 23 | std::vector<float> testVec = {1, 2, 3, 4, 1, 2, 3}; |
| 24 | arm::app::Softmax(testVec); |
| 25 | CHECK((testVec[0] - 0.024) == Approx(0.0).margin(0.001)); |
| 26 | CHECK((testVec[1] - 0.064) == Approx(0.0).margin(0.001)); |
| 27 | CHECK((testVec[2] - 0.175) == Approx(0.0).margin(0.001)); |
| 28 | CHECK((testVec[3] - 0.475) == Approx(0.0).margin(0.001)); |
| 29 | CHECK((testVec[4] - 0.024) == Approx(0.0).margin(0.001)); |
| 30 | CHECK((testVec[5] - 0.064) == Approx(0.0).margin(0.001)); |
| 31 | CHECK((testVec[6] - 0.175) == Approx(0.0).margin(0.001)); |
| 32 | } |
| 33 | |
| 34 | TEST_CASE("Output machine index") { |
| 35 | |
| 36 | auto index = arm::app::OutputIndexFromFileName("test_id_00.wav"); |
| 37 | CHECK(index == 0); |
| 38 | |
| 39 | auto index1 = arm::app::OutputIndexFromFileName("test_id_02.wav"); |
| 40 | CHECK(index1 == 1); |
| 41 | |
| 42 | auto index2 = arm::app::OutputIndexFromFileName("test_id_4.wav"); |
| 43 | CHECK(index2 == 2); |
| 44 | |
| 45 | auto index3 = arm::app::OutputIndexFromFileName("test_id_6.wav"); |
| 46 | CHECK(index3 == 3); |
| 47 | |
| 48 | auto index4 = arm::app::OutputIndexFromFileName("test_id_id_00.wav"); |
| 49 | CHECK(index4 == -1); |
| 50 | |
| 51 | auto index5 = arm::app::OutputIndexFromFileName("test_id_7.wav"); |
| 52 | CHECK(index5 == -1); |
| 53 | } |