Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 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 | |
| 11 #include <math.h> | |
| 12 #include <string> | |
| 13 | |
| 14 #include "webrtc/base/array_view.h" | |
| 15 #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.
| |
| 16 | |
| 17 namespace webrtc { | |
| 18 namespace test { | |
| 19 | |
| 20 ::testing::AssertionResult AssertFloatsNotEqual(const char* m_expr, | |
| 21 const char* n_expr, | |
| 22 const float& output, | |
| 23 const float& reference) { | |
| 24 // Compare the output in the reference in a soft manner. | |
| 25 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.
| |
| 26 bool equal = (fabs(output - reference) <= threshold); | |
| 27 | |
| 28 // If the values are deemed not to be similar, return a report of the | |
| 29 // difference. | |
| 30 if (!equal) { | |
| 31 // 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
| |
| 32 return ::testing::AssertionFailure() | |
| 33 << "Actual: " << std::to_string(output) + "f" << std::endl | |
| 34 << "Expected: " << std::to_string(reference) + "f" << std::endl; | |
| 35 } | |
| 36 return ::testing::AssertionSuccess(); | |
| 37 } | |
| 38 | |
| 39 ::testing::AssertionResult AssertVectorsNotEqual( | |
| 40 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.
| |
| 41 const char* n_expr, | |
| 42 const rtc::ArrayView<const float>& output, | |
| 43 const rtc::ArrayView<const float>& reference) { | |
| 44 // Compare the output in the reference in a soft manner. | |
| 45 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
| |
| 46 bool equal = true; | |
| 47 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.
| |
| 48 if (fabs(output[k] - reference[k]) > threshold) { | |
| 49 equal = false; | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 | |
|
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.
| |
| 54 // If the vectors are deemed not to be similar, return a report of the | |
| 55 // difference. | |
| 56 if (!equal) { | |
| 57 // Lambda function that produces a formatted string with the data in the | |
| 58 // vector. | |
| 59 auto print_vector_in_c_format = [](const rtc::ArrayView<const float>& v, | |
| 60 size_t num_values_to_print) { | |
| 61 std::string s = "{ "; | |
| 62 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.
| |
| 63 s += std::to_string(v[k]) + "f"; | |
| 64 s += (k < (num_values_to_print - 1)) ? ", " : ""; | |
| 65 } | |
| 66 return s + " }"; | |
| 67 }; | |
| 68 | |
| 69 return ::testing::AssertionFailure() | |
| 70 << "Actual: " << print_vector_in_c_format(output, reference.size()) | |
| 71 << std::endl | |
| 72 << "Expected: " | |
| 73 << print_vector_in_c_format(reference, reference.size()) | |
| 74 << std::endl; | |
| 75 } | |
| 76 return ::testing::AssertionSuccess(); | |
| 77 } | |
| 78 | |
| 79 } // namespace test | |
| 80 } // namespace webrtc | |
| OLD | NEW |