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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js

Issue 1361233004: Implement IIRFilter node for WebAudio. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update according to review Created 5 years, 2 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
OLDNEW
1 if (window.testRunner) 1 if (window.testRunner)
2 testRunner.overridePreference("WebKitWebAudioEnabled", "1"); 2 testRunner.overridePreference("WebKitWebAudioEnabled", "1");
3 3
4 function writeString(s, a, offset) { 4 function writeString(s, a, offset) {
5 for (var i = 0; i < s.length; ++i) { 5 for (var i = 0; i < s.length; ++i) {
6 a[offset + i] = s.charCodeAt(i); 6 a[offset + i] = s.charCodeAt(i);
7 } 7 }
8 } 8 }
9 9
10 function writeInt16(n, a, offset) { 10 function writeInt16(n, a, offset) {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 436
437 ShouldModel.prototype._testFailed = function (msg) { 437 ShouldModel.prototype._testFailed = function (msg) {
438 testFailed(this.desc + ' ' + msg + '.'); 438 testFailed(this.desc + ' ' + msg + '.');
439 this._success = false; 439 this._success = false;
440 }; 440 };
441 441
442 ShouldModel.prototype._isArray = function (arg) { 442 ShouldModel.prototype._isArray = function (arg) {
443 return arg instanceof Array || arg instanceof Float32Array; 443 return arg instanceof Array || arg instanceof Float32Array;
444 }; 444 };
445 445
446 ShouldModel.prototype._assert = function (expression, reason) { 446 ShouldModel.prototype._assert = function (expression, reason, value) {
447 if (expression) 447 if (expression)
448 return; 448 return;
449 449
450 var failureMessage = 'Assertion failed: ' + reason + ' ' + this.desc +'. '; 450 var failureMessage = 'Assertion failed: ' + reason + ' ' + this.desc +'. ';
451 if (arguments.length >= 3)
452 failureMessage += ": " + value;
451 testFailed(failureMessage); 453 testFailed(failureMessage);
452 throw failureMessage; 454 throw failureMessage;
453 }; 455 };
454 456
455 // Check if |target| is equal to |value|. 457 // Check if |target| is equal to |value|.
456 // 458 //
457 // Example: 459 // Example:
458 // Should('Zero', 0).beEqualTo(0); 460 // Should('Zero', 0).beEqualTo(0);
459 // Result: 461 // Result:
460 // "PASS Zero is equal to 0." 462 // "PASS Zero is equal to 0."
461 ShouldModel.prototype.beEqualTo = function (value) { 463 ShouldModel.prototype.beEqualTo = function (value) {
462 var type = typeof value; 464 var type = typeof value;
463 this._assert(type === 'number' || type === 'string', 465 this._assert(type === 'number' || type === 'string',
464 'value should be number or string for'); 466 'value should be number or string for', value);
465 467
466 if (this.target === value) 468 if (this.target === value)
467 this._testPassed('is equal to ' + value); 469 this._testPassed('is equal to ' + value);
468 else 470 else
469 this._testFailed('was ' + value + ' instead of ' + this.target); 471 this._testFailed('was ' + value + ' instead of ' + this.target);
470 return this._success; 472 return this._success;
471 }; 473 };
472 474
473 // Check if |target| is not equal to |value|. 475 // Check if |target| is not equal to |value|.
474 // 476 //
475 // Example: 477 // Example:
476 // Should('One', one).notBeEqualTo(0); 478 // Should('One', one).notBeEqualTo(0);
477 // Result: 479 // Result:
478 // "PASS One is not equal to 0." 480 // "PASS One is not equal to 0."
479 ShouldModel.prototype.notBeEqualTo = function (value) { 481 ShouldModel.prototype.notBeEqualTo = function (value) {
480 var type = typeof value; 482 var type = typeof value;
481 this._assert(type === 'number' || type === 'string', 483 this._assert(type === 'number' || type === 'string',
482 'value should be number or string for'); 484 'value should be number or string for', value);
483 485
484 if (this.target === value) 486 if (this.target === value)
485 this._testFailed('should not be equal to ' + value); 487 this._testFailed('should not be equal to ' + value);
486 else 488 else
487 this._testPassed('is not equal to ' + value); 489 this._testPassed('is not equal to ' + value);
488 return this._success; 490 return this._success;
489 }; 491 };
490 492
491 // Check if |target| is greater than or equal to |value|. 493 // Check if |target| is greater than or equal to |value|.
492 // 494 //
493 // Example: 495 // Example:
494 // Should("SNR", snr).beGreaterThanOrEqualTo(100); 496 // Should("SNR", snr).beGreaterThanOrEqualTo(100);
495 // Result: 497 // Result:
496 // "PASS SNR exceeds 100" 498 // "PASS SNR exceeds 100"
497 // "FAIL SNR (n) is not greater than or equal to 100" 499 // "FAIL SNR (n) is not greater than or equal to 100"
498 ShouldModel.prototype.beGreaterThanOrEqualTo = function (value) { 500 ShouldModel.prototype.beGreaterThanOrEqualTo = function (value) {
499 var type = typeof value; 501 var type = typeof value;
500 this._assert(type === 'number' || type === 'string', 502 this._assert(type === 'number' || type === 'string',
501 'value should be number or string for'); 503 'value should be number or string for', value);
502 504
503 if (this.target >= value) 505 if (this.target >= value)
504 this._testPassed("is greater than or equal to " + value); 506 this._testPassed("is greater than or equal to " + value);
505 else 507 else
506 this._testFailed("(" + this.target + ") is not greater than or equal to " + value); 508 this._testFailed("(" + this.target + ") is not greater than or equal to " + value);
507 return this._success; 509 return this._success;
508 } 510 }
509 511
510 // Check if |target| is lest than or equal to |value|. 512 // Check if |target| is lest than or equal to |value|.
511 // 513 //
512 // Example: 514 // Example:
513 // maxError = 1e-6; 515 // maxError = 1e-6;
514 // Should("max error", maxError).beLessThanOrEqualTo(1e-5); 516 // Should("max error", maxError).beLessThanOrEqualTo(1e-5);
515 // Should("max error", maxError).beLessThanOrEqualTo(-1); 517 // Should("max error", maxError).beLessThanOrEqualTo(-1);
516 // Result: 518 // Result:
517 // "PASS max error is less than or equal to 1e-5" 519 // "PASS max error is less than or equal to 1e-5"
518 // "FAIL max error (1e-6) is not less than or equal to -1" 520 // "FAIL max error (1e-6) is not less than or equal to -1"
519 ShouldModel.prototype.beLessThanOrEqualTo = function (value) { 521 ShouldModel.prototype.beLessThanOrEqualTo = function (value) {
520 var type = typeof value; 522 var type = typeof value;
521 this._assert(type === 'number', 'value should be number or string for'); 523 this._assert(type === 'number', 'value should be number or string for', value);
522 524
523 if (this.target <= value) 525 if (this.target <= value)
524 this._testPassed("is less than or equal to " + value); 526 this._testPassed("is less than or equal to " + value);
525 else 527 else
526 this._testFailed("(" + this.target + ") is not less than or equal to " + value); 528 this._testFailed("(" + this.target + ") is not less than or equal to " + value);
527 return this._success; 529 return this._success;
528 } 530 }
529 531
530 // Check if |target| is close to |value| using the given relative error |thr eshold|. |value| 532 // Check if |target| is close to |value| using the given relative error |thr eshold|. |value|
531 // should not be zero, but no check is made for that. The |target| value is printed to 533 // should not be zero, but no check is made for that. The |target| value is printed to
532 // precision |precision|, with |precision| defaulting to 7. 534 // precision |precision|, with |precision| defaulting to 7.
533 // 535 //
534 // Example: 536 // Example:
535 // Should("One", 1.001).beCloseTo(1, .1); 537 // Should("One", 1.001).beCloseTo(1, .1);
536 // Should("One", 2).beCloseTo(1, .1); 538 // Should("One", 2).beCloseTo(1, .1);
537 // Result: 539 // Result:
538 // "PASS One is 1 within a relative error of 0.1." 540 // "PASS One is 1 within a relative error of 0.1."
539 // "FAIL One is not 1 within a relative error of 0.1: 2" 541 // "FAIL One is not 1 within a relative error of 0.1: 2"
540 ShouldModel.prototype.beCloseTo = function (value, relativeErrorThreshold, p recision) { 542 ShouldModel.prototype.beCloseTo = function (value, relativeErrorThreshold, p recision) {
541 var type = typeof value; 543 var type = typeof value;
542 this._assert(type === 'number', 'value should be number for'); 544 this._assert(type === 'number', 'value should be number for', value);
543 545
544 var relativeError = Math.abs(this.target - value) / Math.abs(value); 546 var relativeError = Math.abs(this.target - value) / Math.abs(value);
545 if (relativeError <= relativeErrorThreshold) { 547 if (relativeError <= relativeErrorThreshold) {
546 this._testPassed("is " + value.toPrecision(precision) + 548 this._testPassed("is " + value.toPrecision(precision) +
547 " within a relative error of " + relativeErrorThreshold); 549 " within a relative error of " + relativeErrorThreshold);
548 } else { 550 } else {
549 // Include actual relative error so the failed test case can be upda ted with the actual 551 // Include actual relative error so the failed test case can be upda ted with the actual
550 // relative error, if appropriate. 552 // relative error, if appropriate.
551 this._testFailed("is not " + value.toPrecision(precision) + 553 this._testFailed("is not " + value.toPrecision(precision) +
552 " within a relative error of " + relativeErrorThreshold + 554 " within a relative error of " + relativeErrorThreshold +
(...skipping 21 matching lines...) Expand all
574 576
575 try { 577 try {
576 this.target(); 578 this.target();
577 this._testFailed('did not throw an exception'); 579 this._testFailed('did not throw an exception');
578 } catch (error) { 580 } catch (error) {
579 if (errorType === undefined) 581 if (errorType === undefined)
580 this._testPassed('threw an exception of type ' + error.name); 582 this._testPassed('threw an exception of type ' + error.name);
581 else if (error.name === errorType) 583 else if (error.name === errorType)
582 this._testPassed('threw ' + errorType + ': ' + error.message); 584 this._testPassed('threw ' + errorType + ': ' + error.message);
583 else 585 else
584 this._testFailed('threw ' + error.name + ' instead of ' + except ion); 586 this._testFailed('threw ' + error.name + ' instead of ' + errorT ype);
585 } 587 }
586 return this._success; 588 return this._success;
587 }; 589 };
588 590
589 // Check if |func| does not throw an exception. 591 // Check if |func| does not throw an exception.
590 // 592 //
591 // Example: 593 // Example:
592 // Should('var foo = "bar"', function () { var foo = 'bar'; }).notThrow(); 594 // Should('var foo = "bar"', function () { var foo = 'bar'; }).notThrow();
593 // Result: 595 // Result:
594 // "PASS var foo = "bar" did not throw an exception." 596 // "PASS var foo = "bar" did not throw an exception."
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 }; 639 };
638 640
639 // Check if |target| array is identical to |expected| array element-wise. 641 // Check if |target| array is identical to |expected| array element-wise.
640 // 642 //
641 // Example: 643 // Example:
642 // Should('[1, 2, 3]', [1, 2, 3]).beEqualToArray([1, 2, 3]); 644 // Should('[1, 2, 3]', [1, 2, 3]).beEqualToArray([1, 2, 3]);
643 // Result: 645 // Result:
644 // "PASS [1, 2, 3] is identical to the array [1,2,3]." 646 // "PASS [1, 2, 3] is identical to the array [1,2,3]."
645 ShouldModel.prototype.beEqualToArray = function (array) { 647 ShouldModel.prototype.beEqualToArray = function (array) {
646 this._assert(this._isArray(array) && this.target.length === array.length , 648 this._assert(this._isArray(array) && this.target.length === array.length ,
647 'Invalid array or the length does not match.'); 649 'Invalid array or the length does not match.', array);
648 650
649 var mismatches = {}; 651 var mismatches = {};
650 for (var i = 0; i < this.target.length; i++) { 652 for (var i = 0; i < this.target.length; i++) {
651 if (this.target[i] !== array[i]) 653 if (this.target[i] !== array[i])
652 mismatches[i] = this.target[i]; 654 mismatches[i] = this.target[i];
653 } 655 }
654 656
655 var numberOfmismatches = Object.keys(mismatches).length; 657 var numberOfmismatches = Object.keys(mismatches).length;
656 var arrStr = (array.length > this.NUM_ARRAY_LOG) ? 658 var arrStr = (array.length > this.NUM_ARRAY_LOG) ?
657 array.slice(0, this.NUM_ARRAY_LOG).toString() + '...' : array.toString() ; 659 array.slice(0, this.NUM_ARRAY_LOG).toString() + '...' : array.toString() ;
(...skipping 24 matching lines...) Expand all
682 // Should('My array', [0.11, 0.19]).beCloseToArray([0.1, 0.2], 0.02); 684 // Should('My array', [0.11, 0.19]).beCloseToArray([0.1, 0.2], 0.02);
683 // Result: 685 // Result:
684 // "PASS My array equals [0.1,0.2] within an element-wise tolerance of 0.02. " 686 // "PASS My array equals [0.1,0.2] within an element-wise tolerance of 0.02. "
685 ShouldModel.prototype.beCloseToArray = function (array, maxAllowedError) { 687 ShouldModel.prototype.beCloseToArray = function (array, maxAllowedError) {
686 // For the comparison, the target length must be bigger than the expecte d. 688 // For the comparison, the target length must be bigger than the expecte d.
687 this._assert(this.target.length >= array.length, 689 this._assert(this.target.length >= array.length,
688 'The target array length must be longer than ' + array.length + 690 'The target array length must be longer than ' + array.length +
689 ' but got ' + this.target.length + '.'); 691 ' but got ' + this.target.length + '.');
690 692
691 var mismatches = {}; 693 var mismatches = {};
694 var maxError = -Infinity;
695 var maxErrorIndex = -1;
692 for (var i = 0; i < array.length; i++) { 696 for (var i = 0; i < array.length; i++) {
693 var diff = Math.abs(this.target[i] - array[i]); 697 var diff = Math.abs(this.target[i] - array[i]);
694 if (diff > maxAllowedError) 698 if (diff > maxAllowedError) {
695 mismatches[i] = diff; 699 mismatches[i] = diff;
700 if (diff > maxError) {
701 maxErrorIndex = i;
702 maxError = diff;
703 }
704 }
696 } 705 }
697 706
698 var numberOfmismatches = Object.keys(mismatches).length; 707 var numberOfmismatches = Object.keys(mismatches).length;
699 var arrStr = (array.length > this.NUM_ARRAY_LOG) ? 708 var arrStr = (array.length > this.NUM_ARRAY_LOG) ?
700 array.slice(0, this.NUM_ARRAY_LOG).toString() + ',...' : array.toString( ); 709 array.slice(0, this.NUM_ARRAY_LOG).toString() + ',...' : array.toString( );
701 710
702 if (numberOfmismatches === 0) { 711 if (numberOfmismatches === 0) {
703 this._testPassed('equals [' + arrStr + 712 this._testPassed('equals [' + arrStr +
704 '] with an element-wise tolerance of ' + maxAllowedError); 713 '] with an element-wise tolerance of ' + maxAllowedError);
705 } else { 714 } else {
706 var counter = 0; 715 var counter = 0;
707 var failureMessage = 'does not equal [' + arrStr + 716 var failureMessage = 'does not equal [' + arrStr +
708 '] with an element-wise tolerance of ' + maxAllowedError; 717 '] with an element-wise tolerance of ' + maxAllowedError;
709 for (var index in mismatches) { 718 for (var index in mismatches) {
710 failureMessage += '\n[' + index + '] : ' + mismatches[index]; 719 failureMessage += '\n[' + index + '] : ' + mismatches[index];
711 if (++counter >= this.NUM_ERRORS_LOG) { 720 if (++counter >= this.NUM_ERRORS_LOG) {
712 failureMessage += '\nand ' + (numberOfmismatches - counter) + 721 failureMessage += '\nand ' + (numberOfmismatches - counter) +
713 ' more differences...'; 722 ' more differences with max difference of ' + maxError +
723 ' at index ' + maxErrorIndex;
714 break; 724 break;
715 } 725 }
716 } 726 }
717 727
718 this._testFailed(failureMessage); 728 this._testFailed(failureMessage);
719 } 729 }
720 return this._success; 730 return this._success;
721 }; 731 };
722 732
723 // Check if |target| array contains a set of values in a certain order. 733 // Check if |target| array contains a set of values in a certain order.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if (opts.hasOwnProperty('numberOfErrorLog')) 791 if (opts.hasOwnProperty('numberOfErrorLog'))
782 _opts.numberOfErrorLog = opts.numberOfErrorLog; 792 _opts.numberOfErrorLog = opts.numberOfErrorLog;
783 if (opts.hasOwnProperty('numberOfArrayLog')) 793 if (opts.hasOwnProperty('numberOfArrayLog'))
784 _opts.numberOfArrayLog = opts.numberOfArrayLog; 794 _opts.numberOfArrayLog = opts.numberOfArrayLog;
785 } 795 }
786 796
787 return new ShouldModel(desc, target, _opts); 797 return new ShouldModel(desc, target, _opts);
788 }; 798 };
789 799
790 })(); 800 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698