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

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

Issue 2568573002: Additional unit test for audit.js: failure cases and logging examples. (Closed)
Patch Set: Adding expected result 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 */ 295 */
296 notThrow () { 296 notThrow () {
297 let didThrowCorrectly = false; 297 let didThrowCorrectly = false;
298 let passDetail, failDetail; 298 let passDetail, failDetail;
299 299
300 try { 300 try {
301 this._actual(); 301 this._actual();
302 passDetail = '${actual} did not throw an exception.'; 302 passDetail = '${actual} did not throw an exception.';
303 } catch (error) { 303 } catch (error) {
304 didThrowCorrectly = true; 304 didThrowCorrectly = true;
305 failDetail = '${actual} threw ' + error.name + ': ' 305 failDetail = '${actual} *INCORRECTLY* threw ' + error.name + ': "'
Raymond Toy 2016/12/09 22:10:26 Do these really need to be highlighted? The "FAIL
hongchan 2016/12/19 22:14:05 Then do we remove all the *HIGHLIGHT*? I felt PASS
306 + error.message + '.'; 306 + error.message + '".';
307 } 307 }
308 308
309 return this._assert(!didThrowCorrectly, passDetail, failDetail); 309 return this._assert(!didThrowCorrectly, passDetail, failDetail);
310 } 310 }
311 311
312 /** 312 /**
313 * Check if |actual| promise is resolved correctly. 313 * Check if |actual| promise is resolved correctly.
314 * 314 *
315 * @example 315 * @example
316 * should('My promise', promise).beResolve().then(nextStuff); 316 * should('My promise', promise).beResolve().then(nextStuff);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 607 }
608 } 608 }
609 609
610 passed = !(indexActual < this._actual.length - 1 610 passed = !(indexActual < this._actual.length - 1
611 || indexExpected < this._expected.length - 1); 611 || indexExpected < this._expected.length - 1);
612 612
613 return this._assert( 613 return this._assert(
614 passed, 614 passed,
615 '${actual} contains all the expected values in the correct order: ' 615 '${actual} contains all the expected values in the correct order: '
616 + '${expected}.', 616 + '${expected}.',
617 '${actual} contains an unexpected value of ' 617 '${actual} contains an *UNEXPECTED* value of '
618 + this._actual[indexActual] + ' at index ' + indexActual + '.'); 618 + this._actual[indexActual] + ' at index ' + indexActual + '.');
619 } 619 }
620 620
621 /** 621 /**
622 * Check if |actual| array does not have any glitches. Note that |threshold| 622 * Check if |actual| array does not have any glitches. Note that |threshold|
623 * is not optional and is to define the desired threshold value. 623 * is not optional and is to define the desired threshold value.
624 * 624 *
625 * @example 625 * @example
626 * should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.06); 626 * should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.06);
627 * 627 *
628 * @result 628 * @result
629 * "PASS [0.5,0.5,0.55,0.5,0.45,0.5] has no glitch above the threshold 629 * "PASS [0.5,0.5,0.55,0.5,0.45,0.5] has no glitch above the threshold
630 * of 0.06." 630 * of 0.06."
631 * 631 *
632 */ 632 */
633 notGlitch () { 633 notGlitch () {
634 this._processArguments(arguments); 634 this._processArguments(arguments);
635 635
636 let passed = true; 636 let passed = true;
637 let passDetail, failDetail; 637 let passDetail, failDetail;
638 638
639 for (let index in this._actual) { 639 for (let index in this._actual) {
640 let diff = Math.abs(this._actual[index - 1] - this._actual[index]); 640 let diff = Math.abs(this._actual[index - 1] - this._actual[index]);
641 if (diff >= this._expected) { 641 if (diff >= this._expected) {
642 passed = false; 642 passed = false;
643 failDetail = '${actual} has a glitch at index ' + index + ' of size ' 643 failDetail = '${actual} has a *GLITCH* at index ' + index + ' of size '
644 + diff + '.'; 644 + diff + '.';
645 } 645 }
646 } 646 }
647 647
648 passDetail = 648 passDetail =
649 '${actual} has no glitch above the threshold of ${expected}.'; 649 '${actual} has no glitch above the threshold of ${expected}.';
650 650
651 return this._assert(passed, passDetail, failDetail); 651 return this._assert(passed, passDetail, failDetail);
652 } 652 }
653 653
(...skipping 13 matching lines...) Expand all
667 this._processArguments(arguments); 667 this._processArguments(arguments);
668 668
669 // The threshold is relative except when |expected| is zero, in which case 669 // The threshold is relative except when |expected| is zero, in which case
670 // it is absolute. 670 // it is absolute.
671 let absExpected = this._expected ? Math.abs(this._expected) : 1; 671 let absExpected = this._expected ? Math.abs(this._expected) : 1;
672 let error = Math.abs(this._actual - this._expected) / absExpected; 672 let error = Math.abs(this._actual - this._expected) / absExpected;
673 673
674 return this._assert( 674 return this._assert(
675 error <= this._options.threshold, 675 error <= this._options.threshold,
676 '${actual} is ${expected} within an error of ${threshold}.', 676 '${actual} is ${expected} within an error of ${threshold}.',
677 '${actual} is not ${expected} within an error of ${threshold}: ' + 677 '${actual} is *NOT* ${expected} within an error of ${threshold}: ' +
678 '${actual} with error of ${threshold}.'); 678 '${actual} with error of ${threshold}.');
679 } 679 }
680 680
681 /** 681 /**
682 * Check if |target| array is close to |expected| array element-wise within 682 * Check if |target| array is close to |expected| array element-wise within
683 * a certain error bound given by the |options|. 683 * a certain error bound given by the |options|.
684 * 684 *
685 * The error criterion is: 685 * The error criterion is:
686 * abs(actual[k] - expected[k]) < max(absErr, relErr * abs(expected)) 686 * abs(actual[k] - expected[k]) < max(absErr, relErr * abs(expected))
687 * 687 *
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 relativeThreshold: relErrorThreshold 744 relativeThreshold: relErrorThreshold
745 }); 745 });
746 746
747 if (numberOfErrors === 0) { 747 if (numberOfErrors === 0) {
748 // The assertion was successful. 748 // The assertion was successful.
749 passDetail = '${actual} equals ${expected} with an element-wise ' 749 passDetail = '${actual} equals ${expected} with an element-wise '
750 + 'tolerance of ' + maxAllowedErrorDetail + '.'; 750 + 'tolerance of ' + maxAllowedErrorDetail + '.';
751 } else { 751 } else {
752 // Failed. Prepare the detailed failure log. 752 // Failed. Prepare the detailed failure log.
753 passed = false; 753 passed = false;
754 failDetail = '${actual} does not equal ${expected} with an ' 754 failDetail = '${actual} does *NOT* equal ${expected} with an '
755 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n'; 755 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n';
756 756
757 // Print out actual, expected, absolute error, and relative error. 757 // Print out actual, expected, absolute error, and relative error.
758 let counter = 0; 758 let counter = 0;
759 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError' 759 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError'
760 + '\t\tRelError\t\tTest threshold'; 760 + '\t\tRelError\t\tTest threshold';
761 for (let index in errors) { 761 for (let index in errors) {
762 failDetail += '\n\t[' + index + ']\t' 762 failDetail += '\n\t[' + index + ']\t'
763 + this._actual[index].toExponential(16) + '\t' 763 + this._actual[index].toExponential(16) + '\t'
764 + this._expected[index].toExponential(16) + '\t' 764 + this._expected[index].toExponential(16) + '\t'
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 /** 982 /**
983 * Creates an instance of Audit task runner. 983 * Creates an instance of Audit task runner.
984 */ 984 */
985 createTaskRunner: function () { 985 createTaskRunner: function () {
986 return new TaskRunner(); 986 return new TaskRunner();
987 } 987 }
988 988
989 }; 989 };
990 990
991 })(); 991 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698