Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <math.h> | 11 #include <math.h> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "webrtc/base/array_view.h" | 14 #include "webrtc/base/array_view.h" |
| 15 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h" | 15 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 namespace test { | 18 namespace test { |
| 19 | 19 |
| 20 ::testing::AssertionResult AssertIntegersNotEqual(const char* m_expr, | |
|
hlundin-webrtc
2016/03/16 12:57:05
Consider using EXPECT_NEAR instead of this custom
peah-webrtc
2016/03/17 14:18:06
Done.
| |
| 21 const char* n_expr, | |
| 22 const int& output, | |
| 23 const int& reference) { | |
| 24 // Compare the output in the reference in a soft manner. | |
| 25 const int kThreshold = 1.0; | |
| 26 bool equal = (abs(output - reference) <= kThreshold); | |
| 27 | |
| 28 // If the values are deemed not to be similar, return a report of the | |
| 29 // difference. | |
| 30 if (!equal) { | |
| 31 return ::testing::AssertionFailure() | |
| 32 << "Actual: " << std::to_string(output) << std::endl | |
| 33 << "Expected: " << std::to_string(reference) << std::endl; | |
| 34 } | |
| 35 return ::testing::AssertionSuccess(); | |
| 36 } | |
| 37 | |
| 20 ::testing::AssertionResult AssertFloatsNotEqual(const char* m_expr, | 38 ::testing::AssertionResult AssertFloatsNotEqual(const char* m_expr, |
| 21 const char* n_expr, | 39 const char* n_expr, |
| 22 const float& output, | 40 const float& output, |
| 23 const float& reference) { | 41 const float& reference) { |
| 24 // Compare the output in the reference in a soft manner. | 42 // Compare the output in the reference in a soft manner. |
| 25 float threshold = 1.0f / 32768.0f; | 43 const float kThreshold = 1.0f / 32768.0f; |
| 26 bool equal = (fabs(output - reference) <= threshold); | 44 bool equal = (fabs(output - reference) <= kThreshold); |
| 27 | 45 |
| 28 // If the values are deemed not to be similar, return a report of the | 46 // If the values are deemed not to be similar, return a report of the |
| 29 // difference. | 47 // difference. |
| 30 if (!equal) { | 48 if (!equal) { |
| 31 // Lambda function that produces a formatted string with the values. | |
| 32 return ::testing::AssertionFailure() | 49 return ::testing::AssertionFailure() |
| 33 << "Actual: " << std::to_string(output) + "f" << std::endl | 50 << "Actual: " << std::to_string(output) + "f" << std::endl |
| 34 << "Expected: " << std::to_string(reference) + "f" << std::endl; | 51 << "Expected: " << std::to_string(reference) + "f" << std::endl; |
| 35 } | 52 } |
| 36 return ::testing::AssertionSuccess(); | 53 return ::testing::AssertionSuccess(); |
| 37 } | 54 } |
| 38 | 55 |
| 39 ::testing::AssertionResult AssertVectorsNotEqual( | 56 ::testing::AssertionResult AssertVectorsNotEqual( |
| 40 const char* m_expr, | 57 const char* m_expr, |
| 41 const char* n_expr, | 58 const char* n_expr, |
| 42 const rtc::ArrayView<const float>& output, | 59 const rtc::ArrayView<const float>& output, |
| 43 const rtc::ArrayView<const float>& reference) { | 60 const rtc::ArrayView<const float>& reference) { |
| 44 // Compare the output in the reference in a soft manner. | 61 // Compare the output in the reference in a soft manner. |
| 45 float threshold = 1.0f / 32768.0f; | 62 float kThreshold = 1.0f / 32768.0f; |
| 46 bool equal = true; | 63 bool equal = true; |
| 47 for (size_t k = 0; k < reference.size(); ++k) { | 64 for (size_t k = 0; k < reference.size(); ++k) { |
| 48 if (fabs(output[k] - reference[k]) > threshold) { | 65 if (fabs(output[k] - reference[k]) > kThreshold) { |
| 49 equal = false; | 66 equal = false; |
| 50 break; | 67 break; |
| 51 } | 68 } |
| 52 } | 69 } |
| 53 | 70 |
| 54 // If the vectors are deemed not to be similar, return a report of the | 71 // If the vectors are deemed not to be similar, return a report of the |
| 55 // difference. | 72 // difference. |
| 56 if (!equal) { | 73 if (!equal) { |
| 57 // Lambda function that produces a formatted string with the data in the | 74 // Lambda function that produces a formatted string with the data in the |
| 58 // vector. | 75 // vector. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 71 << std::endl | 88 << std::endl |
| 72 << "Expected: " | 89 << "Expected: " |
| 73 << print_vector_in_c_format(reference, reference.size()) | 90 << print_vector_in_c_format(reference, reference.size()) |
| 74 << std::endl; | 91 << std::endl; |
| 75 } | 92 } |
| 76 return ::testing::AssertionSuccess(); | 93 return ::testing::AssertionSuccess(); |
| 77 } | 94 } |
| 78 | 95 |
| 79 } // namespace test | 96 } // namespace test |
| 80 } // namespace webrtc | 97 } // namespace webrtc |
| OLD | NEW |