pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/transient/wpd_node.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "test/gtest.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | static const size_t kDataLength = 5; |
| 20 | static const float kTolerance = 0.0001f; |
| 21 | |
| 22 | static const size_t kParentDataLength = kDataLength * 2; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 23 | static const float kParentData[kParentDataLength] = {1.f, 2.f, 3.f, 4.f, 5.f, |
| 24 | 6.f, 7.f, 8.f, 9.f, 10.f}; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 25 | |
| 26 | static const float kCoefficients[] = {0.2f, -0.3f, 0.5f, -0.7f, 0.11f}; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 27 | static const size_t kCoefficientsLength = |
| 28 | sizeof(kCoefficients) / sizeof(kCoefficients[0]); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 29 | |
| 30 | TEST(WPDNodeTest, Accessors) { |
| 31 | WPDNode node(kDataLength, kCoefficients, kCoefficientsLength); |
| 32 | EXPECT_EQ(0, node.set_data(kParentData, kDataLength)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 33 | EXPECT_EQ(0, memcmp(node.data(), kParentData, |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 34 | kDataLength * sizeof(node.data()[0]))); |
| 35 | } |
| 36 | |
| 37 | TEST(WPDNodeTest, UpdateThatOnlyDecimates) { |
| 38 | const float kIndentyCoefficient = 1.f; |
| 39 | WPDNode node(kDataLength, &kIndentyCoefficient, 1); |
| 40 | EXPECT_EQ(0, node.Update(kParentData, kParentDataLength)); |
| 41 | for (size_t i = 0; i < kDataLength; ++i) { |
| 42 | EXPECT_FLOAT_EQ(kParentData[i * 2 + 1], node.data()[i]); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | TEST(WPDNodeTest, UpdateWithArbitraryDataAndArbitraryFilter) { |
| 47 | WPDNode node(kDataLength, kCoefficients, kCoefficientsLength); |
| 48 | EXPECT_EQ(0, node.Update(kParentData, kParentDataLength)); |
| 49 | EXPECT_NEAR(0.1f, node.data()[0], kTolerance); |
| 50 | EXPECT_NEAR(0.2f, node.data()[1], kTolerance); |
| 51 | EXPECT_NEAR(0.18f, node.data()[2], kTolerance); |
| 52 | EXPECT_NEAR(0.56f, node.data()[3], kTolerance); |
| 53 | EXPECT_NEAR(0.94f, node.data()[4], kTolerance); |
| 54 | } |
| 55 | |
| 56 | TEST(WPDNodeTest, ExpectedErrorReturnValue) { |
| 57 | WPDNode node(kDataLength, kCoefficients, kCoefficientsLength); |
| 58 | EXPECT_EQ(-1, node.Update(kParentData, kParentDataLength - 1)); |
| 59 | EXPECT_EQ(-1, node.Update(NULL, kParentDataLength)); |
| 60 | EXPECT_EQ(-1, node.set_data(kParentData, kDataLength - 1)); |
| 61 | EXPECT_EQ(-1, node.set_data(NULL, kDataLength)); |
| 62 | } |
| 63 | |
| 64 | } // namespace webrtc |