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

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

Issue 2561573006: Fixing audit.js: should().beCloseTo() and task.run('taskName') (Closed)
Patch Set: Review Created 4 years 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
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 this._actualDescription = 145 this._actualDescription =
146 _generateDescription(this._actual, this._options); 146 _generateDescription(this._actual, this._options);
147 } 147 }
148 148
149 if (!this._expectedDescription) { 149 if (!this._expectedDescription) {
150 this._expectedDescription = 150 this._expectedDescription =
151 _generateDescription(this._expected, this._options); 151 _generateDescription(this._expected, this._options);
152 } 152 }
153 153
154 // For the assertion with a single operand. 154 // For the assertion with a single operand.
155 this._detail = this._detail.replace('${actual}', this._actualDescription); 155 this._detail = this._detail.replace(
156 /\$\{actual\}/g, this._actualDescription);
156 157
157 // If there is a second operand (i.e. expected value), we have to build 158 // If there is a second operand (i.e. expected value), we have to build
158 // the string for it as well. 159 // the string for it as well.
159 if (this._expected) { 160 if (this._expected !== null) {
160 this._detail = this._detail.replace( 161 this._detail = this._detail.replace(
161 '${expected}', this._expectedDescription); 162 /\$\{expected\}/g, this._expectedDescription);
162 } 163 }
163 164
164 // If there is any property in |_options|, replace the property name 165 // If there is any property in |_options|, replace the property name
165 // with the value. 166 // with the value.
166 for (let name in this._options) { 167 for (let name in this._options) {
167 this._detail = this._detail.replace( 168 if (name === 'numberOfErrors'
Raymond Toy 2016/12/08 00:06:02 Why do you have to do this?
hongchan 2016/12/08 17:52:12 Because we don't want to print out 'numberOfErrors
168 '${' + name + '}', 169 || name === 'numberOfArrayElements'
170 || name === 'verbose') {
171 continue;
172 }
173
174 // The RegExp key string contains special character. Take care of it.
175 let re = '\$\{' + name + '\}';
176 re = re.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
177 this._detail = this._detail.replace(new RegExp(re, 'g'),
169 _generateDescription(this._options[name])); 178 _generateDescription(this._options[name]));
170 } 179 }
171 } 180 }
172 181
173 _finalize () { 182 _finalize () {
174 if (this._result) { 183 if (this._result) {
175 _logPassed(' ' + this._detail); 184 _logPassed(' ' + this._detail);
176 } else { 185 } else {
177 _logFailed('X ' + this._detail); 186 _logFailed('X ' + this._detail);
178 } 187 }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 '${actual} has no glitch above the threshold of ${expected}.'; 649 '${actual} has no glitch above the threshold of ${expected}.';
641 650
642 return this._assert(passed, passDetail, failDetail); 651 return this._assert(passed, passDetail, failDetail);
643 } 652 }
644 653
645 /** 654 /**
646 * Check if |actual| is close to |expected| using the given relative error 655 * Check if |actual| is close to |expected| using the given relative error
647 * |threshold|. 656 * |threshold|.
648 * 657 *
649 * @example 658 * @example
650 * should(2.3).beCloseTo(2, 0.3); 659 * should(2.3).beCloseTo(2, { threshold: 0.3 });
651 * 660 *
652 * @result 661 * @result
653 * "PASS 2.3 is 2 within an error of 0.3." 662 * "PASS 2.3 is 2 within an error of 0.3."
654 * 663 * @param {Object} options Options for assertion.
655 * @param {Number} options.threshold Threshold value for the comparison. 664 * @param {Number} options.threshold Threshold value for the comparison.
656 */ 665 */
657 beCloseTo () { 666 beCloseTo () {
658 this._processArguments(arguments); 667 this._processArguments(arguments);
659 668
660 let absExpected = this._expected ? Math.abs(this._expected) : 1; 669 let absExpected = this._expected ? Math.abs(this._expected) : 1;
Raymond Toy 2016/12/08 00:06:02 Because we got confused here when looking at it, w
hongchan 2016/12/08 17:52:11 Done.
661 let error = Math.abs(this._actual - this._expected) / absExpected; 670 let error = Math.abs(this._actual - this._expected) / absExpected;
662 671
663 return this._assert( 672 return this._assert(
664 error < this._options.threshold, 673 error <= this._options.threshold,
665 '${actual} is ${expected} within an error of ${threshold}', 674 '${actual} is ${expected} within an error of ${threshold}.',
666 '${actual} is not ${expected} within a error of ${threshold}: ' + 675 '${actual} is not ${expected} within an error of ${threshold}: ' +
667 '${actual} with error of ${threshold}.'); 676 '${actual} with error of ${threshold}.');
668 } 677 }
669 678
670 /** 679 /**
671 * Check if |target| array is close to |expected| array element-wise within 680 * Check if |target| array is close to |expected| array element-wise within
672 * a certain error bound given by the |options|. 681 * a certain error bound given by the |options|.
673 * 682 *
674 * The error criterion is: 683 * The error criterion is:
675 * abs(actual[k] - expected[k]) < max(absErr, relErr * abs(expected)) 684 * abs(actual[k] - expected[k]) < max(absErr, relErr * abs(expected))
676 * 685 *
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 // to execute them sequentially. Zero argument will perform all defined 943 // to execute them sequentially. Zero argument will perform all defined
935 // tasks in the order of definition. 944 // tasks in the order of definition.
936 run () { 945 run () {
937 // Display the beginning of the test suite. 946 // Display the beginning of the test suite.
938 _logPassed('# AUDIT TASK RUNNER STARTED.'); 947 _logPassed('# AUDIT TASK RUNNER STARTED.');
939 948
940 // If the argument is specified, override the default task sequence with 949 // If the argument is specified, override the default task sequence with
941 // the specified one. 950 // the specified one.
942 if (arguments.length > 0) { 951 if (arguments.length > 0) {
943 this._taskSequence = []; 952 this._taskSequence = [];
944 for (let i = 0; arguments.length; i++) { 953 for (let i = 0; i < arguments.length; i++) {
945 let taskLabel = arguments[i]; 954 let taskLabel = arguments[i];
946 if (!this._tasks.hasOwnProperty(taskLabel)) { 955 if (!this._tasks.hasOwnProperty(taskLabel)) {
947 _throwException('Audit.run:: undefined task.'); 956 _throwException('Audit.run:: undefined task.');
948 } else if (this._taskSequence.includes(taskLabel)) { 957 } else if (this._taskSequence.includes(taskLabel)) {
949 _throwException('Audit.run:: duplicate task request.'); 958 _throwException('Audit.run:: duplicate task request.');
950 } else { 959 } else {
951 this._taskSequence.push[taskLabel]; 960 this._taskSequence.push(taskLabel);
952 } 961 }
953 } 962 }
954 } 963 }
955 964
956 if (this._taskSequence.length === 0) { 965 if (this._taskSequence.length === 0) {
957 _throwException('Audit.run:: no task to run.'); 966 _throwException('Audit.run:: no task to run.');
958 return; 967 return;
959 } 968 }
960 969
961 // Start the first task. 970 // Start the first task.
962 this._currentTaskIndex = 0; 971 this._currentTaskIndex = 0;
963 this._runNextTask(); 972 this._runNextTask();
964 } 973 }
965 974
966 } 975 }
967 976
968 977
969 return { 978 return {
970 979
971 /** 980 /**
972 * Creates an instance of Audit task runner. 981 * Creates an instance of Audit task runner.
973 */ 982 */
974 createTaskRunner: function () { 983 createTaskRunner: function () {
975 return new TaskRunner(); 984 return new TaskRunner();
976 } 985 }
977 986
978 }; 987 };
979 988
980 })(); 989 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698