OLD | NEW |
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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 var type = typeof value; | 520 var type = typeof value; |
521 this._assert(type === 'number', 'value should be number or string for'); | 521 this._assert(type === 'number', 'value should be number or string for'); |
522 | 522 |
523 if (this.target <= value) | 523 if (this.target <= value) |
524 this._testPassed("is less than or equal to " + value); | 524 this._testPassed("is less than or equal to " + value); |
525 else | 525 else |
526 this._testFailed("(" + this.target + ") is not less than or equal to
" + value); | 526 this._testFailed("(" + this.target + ") is not less than or equal to
" + value); |
527 return this._success; | 527 return this._success; |
528 } | 528 } |
529 | 529 |
530 // Check if |target| is close to |value| using the given relative error |thr
eshold|. | 530 // Check if |target| is close to |value| using the given relative error |thr
eshold|. |value| |
531 // |value| should not be zero, but no check is made for that. | 531 // 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. |
532 // | 533 // |
533 // Example: | 534 // Example: |
534 // Should("One", 1.001).beCloseTo(1, .1); | 535 // Should("One", 1.001).beCloseTo(1, .1); |
535 // Should("One", 2).beCloseTo(1, .1); | 536 // Should("One", 2).beCloseTo(1, .1); |
536 // Result: | 537 // Result: |
537 // "PASS One is 1 within a relative error of 0.1." | 538 // "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" | 539 // "FAIL One is not 1 within a relative error of 0.1: 2" |
539 ShouldModel.prototype.beCloseTo = function (value, relativeErrorThreshold) { | 540 ShouldModel.prototype.beCloseTo = function (value, relativeErrorThreshold, p
recision) { |
540 var type = typeof value; | 541 var type = typeof value; |
541 this._assert(type === 'number', 'value should be number for'); | 542 this._assert(type === 'number', 'value should be number for'); |
542 | 543 |
543 var relativeError = Math.abs(this.target - value) / Math.abs(value); | 544 var relativeError = Math.abs(this.target - value) / Math.abs(value); |
544 if (relativeError <= relativeErrorThreshold) { | 545 if (relativeError <= relativeErrorThreshold) { |
545 this._testPassed("is " + value + " within a relative error of " + re
lativeErrorThreshold); | 546 this._testPassed("is " + value.toPrecision(precision) + |
| 547 " within a relative error of " + relativeErrorThreshold); |
546 } else { | 548 } else { |
547 this._testFailed("is not " + value + " within a relative error of "
+ relativeErrorThreshold | 549 // Include actual relative error so the failed test case can be upda
ted with the actual |
548 + ": " + this.target); | 550 // relative error, if appropriate. |
| 551 this._testFailed("is not " + value.toPrecision(precision) + |
| 552 " within a relative error of " + relativeErrorThreshold + |
| 553 ": " + this.target + " with relative error " + relativeError |
| 554 ); |
549 } | 555 } |
550 return this._success; | 556 return this._success; |
551 } | 557 } |
552 | 558 |
553 // Check if |func| throws an exception with a certain |errorType| correctly. | 559 // Check if |func| throws an exception with a certain |errorType| correctly. |
554 // |errorType| is optional. | 560 // |errorType| is optional. |
555 // | 561 // |
556 // Example: | 562 // Example: |
557 // Should('A bad code', function () { var a = b; }).throw(); | 563 // Should('A bad code', function () { var a = b; }).throw(); |
558 // Result: | 564 // Result: |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 if (opts.hasOwnProperty('numberOfErrorLog')) | 781 if (opts.hasOwnProperty('numberOfErrorLog')) |
776 _opts.numberOfErrorLog = opts.numberOfErrorLog; | 782 _opts.numberOfErrorLog = opts.numberOfErrorLog; |
777 if (opts.hasOwnProperty('numberOfArrayLog')) | 783 if (opts.hasOwnProperty('numberOfArrayLog')) |
778 _opts.numberOfArrayLog = opts.numberOfArrayLog; | 784 _opts.numberOfArrayLog = opts.numberOfArrayLog; |
779 } | 785 } |
780 | 786 |
781 return new ShouldModel(desc, target, _opts); | 787 return new ShouldModel(desc, target, _opts); |
782 }; | 788 }; |
783 | 789 |
784 })(); | 790 })(); |
OLD | NEW |