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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit.js

Issue 2700973003: Print additional information on failed beCloseToArray tests (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/unit-tests/audit-failures.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 |beCloseToArray |.
hongchan 2017/02/21 17:05:52 Wrap at 80.
Raymond Toy 2017/02/21 17:43:49 Done.
84 function _formatFailureEntry(index, actual, expected, abserr, threshold) {
85 return '\t[' + index + ']\t'
86 + actual.toExponential(16) + '\t'
87 + expected.toExponential(16) + '\t'
88 + abserr.toExponential(16) + '\t'
89 + (abserr / Math.abs(expected)).toExponential(16) + '\t'
90 + threshold.toExponential(16);
91 }
92
93 // Compute the error threshold criterion for |beCloseToArray|
94 function _closeToThreshold(abserr, relerr, expected) {
95 return Math.max(abserr, relerr * Math.abs(expected));
96 }
83 97
84 /** 98 /**
85 * @class Should 99 * @class Should
86 * @description Assertion subtask for the Audit task. 100 * @description Assertion subtask for the Audit task.
87 * @param {Task} parentTask Associated Task object. 101 * @param {Task} parentTask Associated Task object.
88 * @param {Any} actual Target value to be tested. 102 * @param {Any} actual Target value to be tested.
89 * @param {String} actualDescription String description of the test target. 103 * @param {String} actualDescription String description of the test target.
90 */ 104 */
91 class Should { 105 class Should {
92 106
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 } else { 872 } else {
859 // Failed. Prepare the detailed failure log. 873 // Failed. Prepare the detailed failure log.
860 passed = false; 874 passed = false;
861 failDetail = '${actual} does not equal ${expected} with an ' 875 failDetail = '${actual} does not equal ${expected} with an '
862 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n'; 876 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n';
863 877
864 // Print out actual, expected, absolute error, and relative error. 878 // Print out actual, expected, absolute error, and relative error.
865 let counter = 0; 879 let counter = 0;
866 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError' 880 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError'
867 + '\t\tRelError\t\tTest threshold'; 881 + '\t\tRelError\t\tTest threshold';
882 let printedIndices = [];
868 for (let index in errors) { 883 for (let index in errors) {
869 failDetail += '\n\t[' + index + ']\t' 884 failDetail += '\n' + _formatFailureEntry(
870 + this._actual[index].toExponential(16) + '\t' 885 index, this._actual[index],
871 + this._expected[index].toExponential(16) + '\t' 886 this._expected[index], errors[index],
872 + errors[index].toExponential(16) + '\t' 887 _closeToThreshold(
873 + (errors[index] / Math.abs(this._expected[index])) 888 absErrorThreshold, relErrorThreshold,
874 .toExponential(16) + '\t' 889 this._expected[index]));
875 + Math.max(absErrorThreshold, 890
876 relErrorThreshold * Math.abs(this._expected[index])) 891 printedIndices.push(index);
877 .toExponential(16); 892 if (++counter > this._options.numberOfErrors) {
878 if (++counter > this._options.numberOfErrors) 893 failDetail +=
894 '\n\t...and ' + (numberOfErrors - counter) + ' more errors.';
879 break; 895 break;
896 }
880 } 897 }
881 898
882 // Finalize the error log: print out the location of both the maxAbs 899 // Finalize the error log: print out the location of both the maxAbs
883 // error and the maxRel error so we can adjust thresholds appropriately 900 // error and the maxRel error so we can adjust thresholds appropriately
884 // in the test. 901 // in the test.
885 failDetail += '\n' 902 failDetail += '\n'
886 + '\tMax AbsError of ' + maxAbsError.toExponential(16) 903 + '\tMax AbsError of ' + maxAbsError.toExponential(16)
887 + ' at index of ' + maxAbsErrorIndex + '.\n' 904 + ' at index of ' + maxAbsErrorIndex + '.\n';
888 + '\tMax RelError of ' + maxRelError.toExponential(16) 905 if (printedIndices.find(element => {
889 + ' at index of ' + maxRelErrorIndex + '.'; 906 return element == maxAbsErrorIndex;
907 }) === undefined) {
908 // Print an entry for this index if we haven't already.
909 failDetail +=
910 _formatFailureEntry(
911 maxAbsErrorIndex, this._actual[maxAbsErrorIndex],
912 this._expected[maxAbsErrorIndex], errors[maxAbsErrorIndex],
913 _closeToThreshold(
914 absErrorThreshold, relErrorThreshold,
915 this._expected[maxAbsErrorIndex])) +
916 '\n';
917 }
918 failDetail += '\tMax RelError of ' + maxRelError.toExponential(16) +
919 ' at index of ' + maxRelErrorIndex + '.\n';
920 if (printedIndices.find(element => {
921 return element == maxRelErrorIndex;
922 }) === undefined) {
923 // Print an entry for this index if we haven't already.
924 failDetail +=
925 _formatFailureEntry(
926 maxRelErrorIndex, this._actual[maxRelErrorIndex],
927 this._expected[maxRelErrorIndex], errors[maxRelErrorIndex],
928 _closeToThreshold(
929 absErrorThreshold, relErrorThreshold,
930 this._expected[maxRelErrorIndex])) +
931 '\n';
932 }
890 } 933 }
891 934
892 return this._assert(passed, passDetail, failDetail); 935 return this._assert(passed, passDetail, failDetail);
893 } 936 }
894 937
895 /** 938 /**
896 * A temporary escape hat for printing an in-task message. The description 939 * A temporary escape hat for printing an in-task message. The description
897 * for the |actual| is required to get the message printed properly. 940 * for the |actual| is required to get the message printed properly.
898 * 941 *
899 * TODO(hongchan): remove this method when the transition from the old Audit 942 * TODO(hongchan): remove this method when the transition from the old Audit
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 1226
1184 /** 1227 /**
1185 * Load file from a given URL and pass ArrayBuffer to the following promise. 1228 * Load file from a given URL and pass ArrayBuffer to the following promise.
1186 * See |loadFileFromUrl| method for the detail. 1229 * See |loadFileFromUrl| method for the detail.
1187 */ 1230 */
1188 loadFileFromUrl: loadFileFromUrl 1231 loadFileFromUrl: loadFileFromUrl
1189 1232
1190 }; 1233 };
1191 1234
1192 })(); 1235 })();
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/unit-tests/audit-failures.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698