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 | #include "OutputDecode.hpp" |
| 18 | |
| 19 | #include "catch.hpp" |
| 20 | |
| 21 | TEST_CASE("Running output decode on test vector") { |
| 22 | |
| 23 | std::vector<arm::app::ClassificationResult> vecResult(20); |
| 24 | /* Number of test inputs. */ |
| 25 | const size_t numStrings = 8; |
| 26 | |
| 27 | /* The test inputs. */ |
| 28 | std::string testText[numStrings][20] |
| 29 | { |
| 30 | {"a", "b", "c", "d", "e", "f", "g", "g", "g", " ", "h", "h", "i", " ", " ", "j", "k", "\'", "\'", "l"}, /* initial */ |
| 31 | {" ", "b", "c", "d", "e", "f", "g", "g", "g", " ", "h", "h", "i", " ", " ", "j", "k", "\'", "\'", " "}, /* space start and end */ |
| 32 | {"\'", "b", "c", "d", "e", "f", "g", "g", "g", " ", "h", "h", "i", " ", " ", "j", "k", "\'", "l", "\'"}, /* apostrophe start and end */ |
| 33 | {"a", "a", "c", "d", "e", "f", "g", "g", "g", " ", "h", "h", "i", " ", " ", "j", "k", "\'", "l", "l"}, /* Double start and end */ |
| 34 | {"a", "b", "c", "d", "e", "f", "g", "g", "o", "$", "o", "h", "i", " ", " ", "j", "k", "\'", "\'", "l"}, /* Legit double character */ |
| 35 | {"a", "$", "a", "d", "e", "f", "g", "g", "o", "$", "o", "h", "i", " ", " ", "j", "k", "l", "$", "l"}, /* Legit double character start and end */ |
| 36 | {"$", "a", "b", "d", "e", "f", "g", "g", "o", "$", "o", "h", "i", " ", " ", "j", "k", "l", "$", "$"}, /* $$ */ |
| 37 | {"$", "a", "b", "d", "e", "f", "g", "g", "o", "$", "o", "h", "i", " ", " ", "j", "k", "l", "l", "l"} |
| 38 | }; |
| 39 | |
| 40 | /* The golden outputs for the above test inputs. */ |
| 41 | std::string expectedOutput[numStrings] = |
| 42 | { |
| 43 | {"abcdefg hi jk\'l"}, |
| 44 | {" bcdefg hi jk\' "}, |
| 45 | {"\'bcdefg hi jk\'l\'"}, |
| 46 | {"acdefg hi jk\'l"}, |
| 47 | {"abcdefgoohi jk\'l"}, |
| 48 | {"aadefgoohi jkll"}, |
| 49 | {"abdefgoohi jkl"}, |
| 50 | {"abdefgoohi jkl"} |
| 51 | }; |
| 52 | |
| 53 | /*For each test input. */ |
| 54 | for (size_t h = 0; h < numStrings; ++h) |
| 55 | { |
| 56 | /* Generate fake vecResults.m_label to mimic AsrClassifier output containing the testText. */ |
| 57 | for (size_t i = 0; i < 20; i++) |
| 58 | { |
| 59 | vecResult[i].m_label = testText[h][i]; |
| 60 | } |
| 61 | /* Call function with fake vecResults and save returned string into 'buff'. */ |
| 62 | std::string buff = arm::app::audio::asr::DecodeOutput(vecResult); |
| 63 | |
| 64 | /* Check that the string returned from the function matches the expected output given above. */ |
| 65 | REQUIRE(buff.compare(expectedOutput[h]) == 0); |
| 66 | } |
| 67 | } |