Index: third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
index 13220d1674b9410c2f4cfaf0547f2b858d6e0b80..d225547a232cf7c94dbbea804dc525561fa5a56a 100644 |
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
@@ -443,11 +443,13 @@ var Should = (function () { |
return arg instanceof Array || arg instanceof Float32Array; |
}; |
- ShouldModel.prototype._assert = function (expression, reason) { |
+ ShouldModel.prototype._assert = function (expression, reason, value) { |
if (expression) |
return; |
var failureMessage = 'Assertion failed: ' + reason + ' ' + this.desc +'.'; |
+ if (arguments.length >= 3) |
+ failureMessage += ": " + value; |
testFailed(failureMessage); |
throw failureMessage; |
}; |
@@ -461,7 +463,7 @@ var Should = (function () { |
ShouldModel.prototype.beEqualTo = function (value) { |
var type = typeof value; |
this._assert(type === 'number' || type === 'string', |
- 'value should be number or string for'); |
+ 'value should be number or string for', value); |
if (this.target === value) |
this._testPassed('is equal to ' + value); |
@@ -479,7 +481,7 @@ var Should = (function () { |
ShouldModel.prototype.notBeEqualTo = function (value) { |
var type = typeof value; |
this._assert(type === 'number' || type === 'string', |
- 'value should be number or string for'); |
+ 'value should be number or string for', value); |
if (this.target === value) |
this._testFailed('should not be equal to ' + value); |
@@ -498,7 +500,7 @@ var Should = (function () { |
ShouldModel.prototype.beGreaterThanOrEqualTo = function (value) { |
var type = typeof value; |
this._assert(type === 'number' || type === 'string', |
- 'value should be number or string for'); |
+ 'value should be number or string for', value); |
if (this.target >= value) |
this._testPassed("is greater than or equal to " + value); |
@@ -518,7 +520,7 @@ var Should = (function () { |
// "FAIL max error (1e-6) is not less than or equal to -1" |
ShouldModel.prototype.beLessThanOrEqualTo = function (value) { |
var type = typeof value; |
- this._assert(type === 'number', 'value should be number or string for'); |
+ this._assert(type === 'number', 'value should be number or string for', value); |
if (this.target <= value) |
this._testPassed("is less than or equal to " + value); |
@@ -539,7 +541,7 @@ var Should = (function () { |
// "FAIL One is not 1 within a relative error of 0.1: 2" |
ShouldModel.prototype.beCloseTo = function (value, relativeErrorThreshold, precision) { |
var type = typeof value; |
- this._assert(type === 'number', 'value should be number for'); |
+ this._assert(type === 'number', 'value should be number for', value); |
var relativeError = Math.abs(this.target - value) / Math.abs(value); |
if (relativeError <= relativeErrorThreshold) { |
@@ -581,7 +583,7 @@ var Should = (function () { |
else if (error.name === errorType) |
this._testPassed('threw ' + errorType + ': ' + error.message); |
else |
- this._testFailed('threw ' + error.name + ' instead of ' + exception); |
+ this._testFailed('threw ' + error.name + ' instead of ' + errorType); |
} |
return this._success; |
}; |
@@ -644,7 +646,7 @@ var Should = (function () { |
// "PASS [1, 2, 3] is identical to the array [1,2,3]." |
ShouldModel.prototype.beEqualToArray = function (array) { |
this._assert(this._isArray(array) && this.target.length === array.length, |
- 'Invalid array or the length does not match.'); |
+ 'Invalid array or the length does not match.', array); |
var mismatches = {}; |
for (var i = 0; i < this.target.length; i++) { |
@@ -689,10 +691,17 @@ var Should = (function () { |
' but got ' + this.target.length + '.'); |
var mismatches = {}; |
+ var maxError = -Infinity; |
+ var maxErrorIndex = -1; |
for (var i = 0; i < array.length; i++) { |
var diff = Math.abs(this.target[i] - array[i]); |
- if (diff > maxAllowedError) |
+ if (diff > maxAllowedError) { |
mismatches[i] = diff; |
+ if (diff > maxError) { |
+ maxErrorIndex = i; |
+ maxError = diff; |
+ } |
+ } |
} |
var numberOfmismatches = Object.keys(mismatches).length; |
@@ -710,7 +719,8 @@ var Should = (function () { |
failureMessage += '\n[' + index + '] : ' + mismatches[index]; |
if (++counter >= this.NUM_ERRORS_LOG) { |
failureMessage += '\nand ' + (numberOfmismatches - counter) + |
- ' more differences...'; |
+ ' more differences with max difference of ' + maxError + |
+ ' at index ' + maxErrorIndex; |
break; |
} |
} |