blob: 5f9238255c22266b04635ab656cc301f5a8b4a9a [file] [log] [blame]
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/transient/wpd_node.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000012
13#include <string.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "test/gtest.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000016
17namespace webrtc {
18
19static const size_t kDataLength = 5;
20static const float kTolerance = 0.0001f;
21
22static const size_t kParentDataLength = kDataLength * 2;
Yves Gerey665174f2018-06-19 15:03:05 +020023static 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.org788acd12014-12-15 09:41:24 +000025
26static const float kCoefficients[] = {0.2f, -0.3f, 0.5f, -0.7f, 0.11f};
Yves Gerey665174f2018-06-19 15:03:05 +020027static const size_t kCoefficientsLength =
28 sizeof(kCoefficients) / sizeof(kCoefficients[0]);
pbos@webrtc.org788acd12014-12-15 09:41:24 +000029
30TEST(WPDNodeTest, Accessors) {
31 WPDNode node(kDataLength, kCoefficients, kCoefficientsLength);
32 EXPECT_EQ(0, node.set_data(kParentData, kDataLength));
Yves Gerey665174f2018-06-19 15:03:05 +020033 EXPECT_EQ(0, memcmp(node.data(), kParentData,
pbos@webrtc.org788acd12014-12-15 09:41:24 +000034 kDataLength * sizeof(node.data()[0])));
35}
36
37TEST(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
46TEST(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
56TEST(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