| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * @fileOverview WebAudio layout test utility library. Built around W3C's | 7 * @fileOverview WebAudio layout test utility library. Built around W3C's |
| 8 * testharness.js. Includes asynchronous test task manager, | 8 * testharness.js. Includes asynchronous test task manager, |
| 9 * assertion utilities. | 9 * assertion utilities. |
| 10 * @dependency testharness.js | 10 * @dependency testharness.js |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 break; | 74 break; |
| 75 default: | 75 default: |
| 76 targetString = String(target); | 76 targetString = String(target); |
| 77 break; | 77 break; |
| 78 } | 78 } |
| 79 | 79 |
| 80 return targetString; | 80 return targetString; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Return a string suitable for printing one failed element in |
| 84 // |beCloseToArray|. |
| 85 function _formatFailureEntry(index, actual, expected, abserr, threshold) { |
| 86 return '\t[' + index + ']\t' |
| 87 + actual.toExponential(16) + '\t' |
| 88 + expected.toExponential(16) + '\t' |
| 89 + abserr.toExponential(16) + '\t' |
| 90 + (abserr / Math.abs(expected)).toExponential(16) + '\t' |
| 91 + threshold.toExponential(16); |
| 92 } |
| 93 |
| 94 // Compute the error threshold criterion for |beCloseToArray| |
| 95 function _closeToThreshold(abserr, relerr, expected) { |
| 96 return Math.max(abserr, relerr * Math.abs(expected)); |
| 97 } |
| 83 | 98 |
| 84 /** | 99 /** |
| 85 * @class Should | 100 * @class Should |
| 86 * @description Assertion subtask for the Audit task. | 101 * @description Assertion subtask for the Audit task. |
| 87 * @param {Task} parentTask Associated Task object. | 102 * @param {Task} parentTask Associated Task object. |
| 88 * @param {Any} actual Target value to be tested. | 103 * @param {Any} actual Target value to be tested. |
| 89 * @param {String} actualDescription String description of the test target. | 104 * @param {String} actualDescription String description of the test target. |
| 90 */ | 105 */ |
| 91 class Should { | 106 class Should { |
| 92 | 107 |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 } else { | 873 } else { |
| 859 // Failed. Prepare the detailed failure log. | 874 // Failed. Prepare the detailed failure log. |
| 860 passed = false; | 875 passed = false; |
| 861 failDetail = '${actual} does not equal ${expected} with an ' | 876 failDetail = '${actual} does not equal ${expected} with an ' |
| 862 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n'; | 877 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n'; |
| 863 | 878 |
| 864 // Print out actual, expected, absolute error, and relative error. | 879 // Print out actual, expected, absolute error, and relative error. |
| 865 let counter = 0; | 880 let counter = 0; |
| 866 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError' | 881 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError' |
| 867 + '\t\tRelError\t\tTest threshold'; | 882 + '\t\tRelError\t\tTest threshold'; |
| 883 let printedIndices = []; |
| 868 for (let index in errors) { | 884 for (let index in errors) { |
| 869 failDetail += '\n\t[' + index + ']\t' | 885 failDetail += '\n' + _formatFailureEntry( |
| 870 + this._actual[index].toExponential(16) + '\t' | 886 index, this._actual[index], |
| 871 + this._expected[index].toExponential(16) + '\t' | 887 this._expected[index], errors[index], |
| 872 + errors[index].toExponential(16) + '\t' | 888 _closeToThreshold( |
| 873 + (errors[index] / Math.abs(this._expected[index])) | 889 absErrorThreshold, relErrorThreshold, |
| 874 .toExponential(16) + '\t' | 890 this._expected[index])); |
| 875 + Math.max(absErrorThreshold, | 891 |
| 876 relErrorThreshold * Math.abs(this._expected[index])) | 892 printedIndices.push(index); |
| 877 .toExponential(16); | 893 if (++counter > this._options.numberOfErrors) { |
| 878 if (++counter > this._options.numberOfErrors) | 894 failDetail += |
| 895 '\n\t...and ' + (numberOfErrors - counter) + ' more errors.'; |
| 879 break; | 896 break; |
| 897 } |
| 880 } | 898 } |
| 881 | 899 |
| 882 // Finalize the error log: print out the location of both the maxAbs | 900 // Finalize the error log: print out the location of both the maxAbs |
| 883 // error and the maxRel error so we can adjust thresholds appropriately | 901 // error and the maxRel error so we can adjust thresholds appropriately |
| 884 // in the test. | 902 // in the test. |
| 885 failDetail += '\n' | 903 failDetail += '\n' |
| 886 + '\tMax AbsError of ' + maxAbsError.toExponential(16) | 904 + '\tMax AbsError of ' + maxAbsError.toExponential(16) |
| 887 + ' at index of ' + maxAbsErrorIndex + '.\n' | 905 + ' at index of ' + maxAbsErrorIndex + '.\n'; |
| 888 + '\tMax RelError of ' + maxRelError.toExponential(16) | 906 if (printedIndices.find(element => { |
| 889 + ' at index of ' + maxRelErrorIndex + '.'; | 907 return element == maxAbsErrorIndex; |
| 908 }) === undefined) { |
| 909 // Print an entry for this index if we haven't already. |
| 910 failDetail += |
| 911 _formatFailureEntry( |
| 912 maxAbsErrorIndex, this._actual[maxAbsErrorIndex], |
| 913 this._expected[maxAbsErrorIndex], errors[maxAbsErrorIndex], |
| 914 _closeToThreshold( |
| 915 absErrorThreshold, relErrorThreshold, |
| 916 this._expected[maxAbsErrorIndex])) + |
| 917 '\n'; |
| 918 } |
| 919 failDetail += '\tMax RelError of ' + maxRelError.toExponential(16) + |
| 920 ' at index of ' + maxRelErrorIndex + '.\n'; |
| 921 if (printedIndices.find(element => { |
| 922 return element == maxRelErrorIndex; |
| 923 }) === undefined) { |
| 924 // Print an entry for this index if we haven't already. |
| 925 failDetail += |
| 926 _formatFailureEntry( |
| 927 maxRelErrorIndex, this._actual[maxRelErrorIndex], |
| 928 this._expected[maxRelErrorIndex], errors[maxRelErrorIndex], |
| 929 _closeToThreshold( |
| 930 absErrorThreshold, relErrorThreshold, |
| 931 this._expected[maxRelErrorIndex])) + |
| 932 '\n'; |
| 933 } |
| 890 } | 934 } |
| 891 | 935 |
| 892 return this._assert(passed, passDetail, failDetail); | 936 return this._assert(passed, passDetail, failDetail); |
| 893 } | 937 } |
| 894 | 938 |
| 895 /** | 939 /** |
| 896 * A temporary escape hat for printing an in-task message. The description | 940 * A temporary escape hat for printing an in-task message. The description |
| 897 * for the |actual| is required to get the message printed properly. | 941 * for the |actual| is required to get the message printed properly. |
| 898 * | 942 * |
| 899 * TODO(hongchan): remove this method when the transition from the old Audit | 943 * TODO(hongchan): remove this method when the transition from the old Audit |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 | 1227 |
| 1184 /** | 1228 /** |
| 1185 * Load file from a given URL and pass ArrayBuffer to the following promise. | 1229 * Load file from a given URL and pass ArrayBuffer to the following promise. |
| 1186 * See |loadFileFromUrl| method for the detail. | 1230 * See |loadFileFromUrl| method for the detail. |
| 1187 */ | 1231 */ |
| 1188 loadFileFromUrl: loadFileFromUrl | 1232 loadFileFromUrl: loadFileFromUrl |
| 1189 | 1233 |
| 1190 }; | 1234 }; |
| 1191 | 1235 |
| 1192 })(); | 1236 })(); |
| OLD | NEW |