test-online-feature.cc (1650B)
1 /** 2 * Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang) 3 * 4 * See LICENSE for clarification regarding multiple authors 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include "gtest/gtest.h" 20 #include "kaldi-native-fbank/csrc/online-feature.h" 21 namespace knf { 22 23 TEST(RecyclingVector, TestUnlimited) { 24 RecyclingVector v(-1); 25 constexpr int32_t N = 100; 26 for (int32_t i = 0; i != N; ++i) { 27 std::unique_ptr<float[]> p(new float[3]{i, i + 1, i + 2}); 28 v.PushBack(std::move(p)); 29 } 30 ASSERT_EQ(v.Size(), N); 31 32 for (int32_t i = 0; i != N; ++i) { 33 const float *t = v.At(i); 34 for (int32_t k = 0; k != 3; ++k) { 35 EXPECT_EQ(t[k], (i + k)); 36 } 37 } 38 } 39 40 TEST(RecyclingVector, Testlimited) { 41 constexpr int32_t K = 3; 42 constexpr int32_t N = 10; 43 RecyclingVector v(K); 44 for (int32_t i = 0; i != N; ++i) { 45 std::unique_ptr<float[]> p(new float[3]{i, i + 1, i + 2}); 46 v.PushBack(std::move(p)); 47 } 48 49 ASSERT_EQ(v.Size(), N); 50 51 for (int32_t i = N - K; i != N; ++i) { 52 const float *t = v.At(i); 53 54 for (int32_t k = 0; k != 3; ++k) { 55 EXPECT_EQ(t[k], (i + k)); 56 } 57 } 58 } 59 } // namespace knf