Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: webrtc/modules/audio_processing/test/bitexactness_tools.cc

Issue 1783203002: Bitexactness test for the noise suppressor (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Corrected comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/test/bitexactness_tools.cc
diff --git a/webrtc/modules/audio_processing/test/bitexactness_tools.cc b/webrtc/modules/audio_processing/test/bitexactness_tools.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b3c10480718dd0f918a37f2f536525a4a12c8df3
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/bitexactness_tools.cc
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include <math.h>
+#include <string>
+
+#include "webrtc/base/array_view.h"
+#include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
hlundin-webrtc 2016/03/16 12:44:28 bitexactness_tools.h should be included first of a
peah-webrtc 2016/03/17 13:15:01 Done.
+
+namespace webrtc {
+namespace test {
+
+::testing::AssertionResult AssertFloatsNotEqual(const char* m_expr,
+ const char* n_expr,
+ const float& output,
+ const float& reference) {
+ // Compare the output in the reference in a soft manner.
+ float threshold = 1.0f / 32768.0f;
hlundin-webrtc 2016/03/16 12:44:28 const float kThreshold
peah-webrtc 2016/03/17 13:15:01 Done.
+ bool equal = (fabs(output - reference) <= threshold);
+
+ // If the values are deemed not to be similar, return a report of the
+ // difference.
+ if (!equal) {
+ // Lambda function that produces a formatted string with the values.
hlundin-webrtc 2016/03/16 12:44:29 Is this a lambda?
peah-webrtc 2016/03/17 13:15:01 No, the comment in the code is not correct. This f
+ return ::testing::AssertionFailure()
+ << "Actual: " << std::to_string(output) + "f" << std::endl
+ << "Expected: " << std::to_string(reference) + "f" << std::endl;
+ }
+ return ::testing::AssertionSuccess();
+}
+
+::testing::AssertionResult AssertVectorsNotEqual(
+ const char* m_expr,
hlundin-webrtc 2016/03/16 12:44:28 It seems to me that you are not using m_expr and n
peah-webrtc 2016/03/17 13:15:01 Awesome!!! Splendid suggestion! Done.
+ const char* n_expr,
+ const rtc::ArrayView<const float>& output,
+ const rtc::ArrayView<const float>& reference) {
+ // Compare the output in the reference in a soft manner.
+ float threshold = 1.0f / 32768.0f;
hlundin-webrtc 2016/03/16 12:44:28 const float kThreshold
peah-webrtc 2016/03/17 13:15:01 Good point. This code has now been refactored, so
+ bool equal = true;
+ for (size_t k = 0; k < reference.size(); ++k) {
hlundin-webrtc 2016/03/16 12:44:29 What if output is shorter than reference? Also, it
peah-webrtc 2016/03/17 13:15:01 Good find! Done.
+ if (fabs(output[k] - reference[k]) > threshold) {
+ equal = false;
+ break;
+ }
+ }
+
hlundin-webrtc 2016/03/16 12:44:28 You may want to consider early return here in the
peah-webrtc 2016/03/17 13:15:01 Done.
+ // If the vectors are deemed not to be similar, return a report of the
+ // difference.
+ if (!equal) {
+ // Lambda function that produces a formatted string with the data in the
+ // vector.
+ auto print_vector_in_c_format = [](const rtc::ArrayView<const float>& v,
+ size_t num_values_to_print) {
+ std::string s = "{ ";
+ for (size_t k = 0; k < num_values_to_print; ++k) {
hlundin-webrtc 2016/03/16 12:44:28 What if num_values_to_print is larger than the len
peah-webrtc 2016/03/17 13:15:01 Done.
+ s += std::to_string(v[k]) + "f";
+ s += (k < (num_values_to_print - 1)) ? ", " : "";
+ }
+ return s + " }";
+ };
+
+ return ::testing::AssertionFailure()
+ << "Actual: " << print_vector_in_c_format(output, reference.size())
+ << std::endl
+ << "Expected: "
+ << print_vector_in_c_format(reference, reference.size())
+ << std::endl;
+ }
+ return ::testing::AssertionSuccess();
+}
+
+} // namespace test
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698