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

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 histograms.xml 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|. 532 // Check if |target| is close to |value| using the given relative error |thr eshold|.
531 // |value| should not be zero, but no check is made for that. 533 // |value| should not be zero, but no check is made for that.
532 // 534 //
533 // Example: 535 // Example:
534 // Should("One", 1.001).beCloseTo(1, .1); 536 // Should("One", 1.001).beCloseTo(1, .1);
535 // Should("One", 2).beCloseTo(1, .1); 537 // Should("One", 2).beCloseTo(1, .1);
536 // Result: 538 // Result:
537 // "PASS One is 1 within a relative error of 0.1." 539 // "PASS One is 1 within a relative error of 0.1."
538 // "FAIL One is not 1 within a relative error of 0.1: 2" 540 // "FAIL One is not 1 within a relative error of 0.1: 2"
539 ShouldModel.prototype.beCloseTo = function (value, relativeErrorThreshold) { 541 ShouldModel.prototype.beCloseTo = function (value, relativeErrorThreshold) {
540 var type = typeof value; 542 var type = typeof value;
541 this._assert(type === 'number', 'value should be number for'); 543 this._assert(type === 'number', 'value should be number for', value);
542 544
543 var relativeError = Math.abs(this.target - value) / Math.abs(value); 545 var relativeError = Math.abs(this.target - value) / Math.abs(value);
544 if (relativeError <= relativeErrorThreshold) { 546 if (relativeError <= relativeErrorThreshold) {
545 this._testPassed("is " + value + " within a relative error of " + re lativeErrorThreshold); 547 this._testPassed("is " + value + " within a relative error of " + re lativeErrorThreshold);
546 } else { 548 } else {
547 this._testFailed("is not " + value + " within a relative error of " + relativeErrorThreshold 549 this._testFailed("is not " + value + " within a relative error of " + relativeErrorThreshold
548 + ": " + this.target); 550 + ": " + this.target);
549 } 551 }
550 return this._success; 552 return this._success;
551 } 553 }
(...skipping 16 matching lines...) Expand all
568 570
569 try { 571 try {
570 this.target(); 572 this.target();
571 this._testFailed('did not throw an exception'); 573 this._testFailed('did not throw an exception');
572 } catch (error) { 574 } catch (error) {
573 if (errorType === undefined) 575 if (errorType === undefined)
574 this._testPassed('threw an exception of type ' + error.name); 576 this._testPassed('threw an exception of type ' + error.name);
575 else if (error.name === errorType) 577 else if (error.name === errorType)
576 this._testPassed('threw ' + errorType + ': ' + error.message); 578 this._testPassed('threw ' + errorType + ': ' + error.message);
577 else 579 else
578 this._testFailed('threw ' + error.name + ' instead of ' + except ion); 580 this._testFailed('threw ' + error.name + ' instead of ' + errorT ype);
579 } 581 }
580 return this._success; 582 return this._success;
581 }; 583 };
582 584
583 // Check if |func| does not throw an exception. 585 // Check if |func| does not throw an exception.
584 // 586 //
585 // Example: 587 // Example:
586 // Should('var foo = "bar"', function () { var foo = 'bar'; }).notThrow(); 588 // Should('var foo = "bar"', function () { var foo = 'bar'; }).notThrow();
587 // Result: 589 // Result:
588 // "PASS var foo = "bar" did not throw an exception." 590 // "PASS var foo = "bar" did not throw an exception."
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 }; 633 };
632 634
633 // Check if |target| array is identical to |expected| array element-wise. 635 // Check if |target| array is identical to |expected| array element-wise.
634 // 636 //
635 // Example: 637 // Example:
636 // Should('[1, 2, 3]', [1, 2, 3]).beEqualToArray([1, 2, 3]); 638 // Should('[1, 2, 3]', [1, 2, 3]).beEqualToArray([1, 2, 3]);
637 // Result: 639 // Result:
638 // "PASS [1, 2, 3] is identical to the array [1,2,3]." 640 // "PASS [1, 2, 3] is identical to the array [1,2,3]."
639 ShouldModel.prototype.beEqualToArray = function (array) { 641 ShouldModel.prototype.beEqualToArray = function (array) {
640 this._assert(this._isArray(array) && this.target.length === array.length , 642 this._assert(this._isArray(array) && this.target.length === array.length ,
641 'Invalid array or the length does not match.'); 643 'Invalid array or the length does not match.', array);
642 644
643 var mismatches = {}; 645 var mismatches = {};
644 for (var i = 0; i < this.target.length; i++) { 646 for (var i = 0; i < this.target.length; i++) {
645 if (this.target[i] !== array[i]) 647 if (this.target[i] !== array[i])
646 mismatches[i] = this.target[i]; 648 mismatches[i] = this.target[i];
647 } 649 }
648 650
649 var numberOfmismatches = Object.keys(mismatches).length; 651 var numberOfmismatches = Object.keys(mismatches).length;
650 var arrStr = (array.length > this.NUM_ARRAY_LOG) ? 652 var arrStr = (array.length > this.NUM_ARRAY_LOG) ?
651 array.slice(0, this.NUM_ARRAY_LOG).toString() + '...' : array.toString() ; 653 array.slice(0, this.NUM_ARRAY_LOG).toString() + '...' : array.toString() ;
(...skipping 24 matching lines...) Expand all
676 // Should('My array', [0.11, 0.19]).beCloseToArray([0.1, 0.2], 0.02); 678 // Should('My array', [0.11, 0.19]).beCloseToArray([0.1, 0.2], 0.02);
677 // Result: 679 // Result:
678 // "PASS My array equals [0.1,0.2] within an element-wise tolerance of 0.02. " 680 // "PASS My array equals [0.1,0.2] within an element-wise tolerance of 0.02. "
679 ShouldModel.prototype.beCloseToArray = function (array, maxAllowedError) { 681 ShouldModel.prototype.beCloseToArray = function (array, maxAllowedError) {
680 // For the comparison, the target length must be bigger than the expecte d. 682 // For the comparison, the target length must be bigger than the expecte d.
681 this._assert(this.target.length >= array.length, 683 this._assert(this.target.length >= array.length,
682 'The target array length must be longer than ' + array.length + 684 'The target array length must be longer than ' + array.length +
683 ' but got ' + this.target.length + '.'); 685 ' but got ' + this.target.length + '.');
684 686
685 var mismatches = {}; 687 var mismatches = {};
688 var maxError = -Infinity;
689 var maxErrorIndex = -1;
686 for (var i = 0; i < array.length; i++) { 690 for (var i = 0; i < array.length; i++) {
687 var diff = Math.abs(this.target[i] - array[i]); 691 var diff = Math.abs(this.target[i] - array[i]);
688 if (diff > maxAllowedError) 692 if (diff > maxAllowedError) {
689 mismatches[i] = diff; 693 mismatches[i] = diff;
694 if (diff > maxError) {
695 maxErrorIndex = i;
696 maxError = diff;
697 }
698 }
690 } 699 }
691 700
692 var numberOfmismatches = Object.keys(mismatches).length; 701 var numberOfmismatches = Object.keys(mismatches).length;
693 var arrStr = (array.length > this.NUM_ARRAY_LOG) ? 702 var arrStr = (array.length > this.NUM_ARRAY_LOG) ?
694 array.slice(0, this.NUM_ARRAY_LOG).toString() + ',...' : array.toString( ); 703 array.slice(0, this.NUM_ARRAY_LOG).toString() + ',...' : array.toString( );
695 704
696 if (numberOfmismatches === 0) { 705 if (numberOfmismatches === 0) {
697 this._testPassed('equals [' + arrStr + 706 this._testPassed('equals [' + arrStr +
698 '] with an element-wise tolerance of ' + maxAllowedError); 707 '] with an element-wise tolerance of ' + maxAllowedError);
699 } else { 708 } else {
700 var counter = 0; 709 var counter = 0;
701 var failureMessage = 'does not equal [' + arrStr + 710 var failureMessage = 'does not equal [' + arrStr +
702 '] with an element-wise tolerance of ' + maxAllowedError; 711 '] with an element-wise tolerance of ' + maxAllowedError;
703 for (var index in mismatches) { 712 for (var index in mismatches) {
704 failureMessage += '\n[' + index + '] : ' + mismatches[index]; 713 failureMessage += '\n[' + index + '] : ' + mismatches[index];
705 if (++counter >= this.NUM_ERRORS_LOG) { 714 if (++counter >= this.NUM_ERRORS_LOG) {
706 failureMessage += '\nand ' + (numberOfmismatches - counter) + 715 failureMessage += '\nand ' + (numberOfmismatches - counter) +
707 ' more differences...'; 716 ' more differences with max difference of ' + maxError +
717 ' at index ' + maxErrorIndex;
708 break; 718 break;
709 } 719 }
710 } 720 }
711 721
712 this._testFailed(failureMessage); 722 this._testFailed(failureMessage);
713 } 723 }
714 return this._success; 724 return this._success;
715 }; 725 };
716 726
717 // Check if |target| array contains a set of values in a certain order. 727 // 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
775 if (opts.hasOwnProperty('numberOfErrorLog')) 785 if (opts.hasOwnProperty('numberOfErrorLog'))
776 _opts.numberOfErrorLog = opts.numberOfErrorLog; 786 _opts.numberOfErrorLog = opts.numberOfErrorLog;
777 if (opts.hasOwnProperty('numberOfArrayLog')) 787 if (opts.hasOwnProperty('numberOfArrayLog'))
778 _opts.numberOfArrayLog = opts.numberOfArrayLog; 788 _opts.numberOfArrayLog = opts.numberOfArrayLog;
779 } 789 }
780 790
781 return new ShouldModel(desc, target, _opts); 791 return new ShouldModel(desc, target, _opts);
782 }; 792 };
783 793
784 })(); 794 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698