| OLD | NEW |
| 1 function writeString(s, a, offset) { | 1 function writeString(s, a, offset) { |
| 2 for (var i = 0; i < s.length; ++i) { | 2 for (var i = 0; i < s.length; ++i) { |
| 3 a[offset + i] = s.charCodeAt(i); | 3 a[offset + i] = s.charCodeAt(i); |
| 4 } | 4 } |
| 5 } | 5 } |
| 6 | 6 |
| 7 function writeInt16(n, a, offset) { | 7 function writeInt16(n, a, offset) { |
| 8 n = Math.floor(n); | 8 n = Math.floor(n); |
| 9 | 9 |
| 10 var b1 = n & 255; | 10 var b1 = n & 255; |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 this._success = false; | 400 this._success = false; |
| 401 | 401 |
| 402 // If the number of errors is greater than this, the rest of error | 402 // If the number of errors is greater than this, the rest of error |
| 403 // messages are suppressed. the value is fairly arbitrary, but shouldn't | 403 // messages are suppressed. the value is fairly arbitrary, but shouldn't |
| 404 // be too small or too large. | 404 // be too small or too large. |
| 405 this.NUM_ERRORS_LOG = opts.numberOfErrorLog; | 405 this.NUM_ERRORS_LOG = opts.numberOfErrorLog; |
| 406 | 406 |
| 407 // If the number of array elements is greater than this, the rest of | 407 // If the number of array elements is greater than this, the rest of |
| 408 // elements will be omitted. | 408 // elements will be omitted. |
| 409 this.NUM_ARRAY_LOG = opts.numberOfArrayLog; | 409 this.NUM_ARRAY_LOG = opts.numberOfArrayLog; |
| 410 |
| 411 // If true, verbose output for the failure case is printed, for methods
where this makes |
| 412 // sense. |
| 413 this.verbose = opts.verbose; |
| 414 |
| 415 // If set, this is the precision with which numbers will be printed. |
| 416 this.PRINT_PRECISION = opts.precision; |
| 410 } | 417 } |
| 411 | 418 |
| 412 // Internal methods starting with a underscore. | 419 // Internal methods starting with a underscore. |
| 413 ShouldModel.prototype._testPassed = function (msg) { | 420 ShouldModel.prototype._testPassed = function (msg) { |
| 414 testPassed(this.desc + ' ' + msg + '.'); | 421 testPassed(this.desc + ' ' + msg + '.'); |
| 415 this._success = true; | 422 this._success = true; |
| 416 }; | 423 }; |
| 417 | 424 |
| 418 ShouldModel.prototype._testFailed = function (msg) { | 425 ShouldModel.prototype._testFailed = function (msg) { |
| 419 testFailed(this.desc + ' ' + msg + '.'); | 426 testFailed(this.desc + ' ' + msg + '.'); |
| 420 this._success = false; | 427 this._success = false; |
| 421 }; | 428 }; |
| 422 | 429 |
| 423 ShouldModel.prototype._isArray = function (arg) { | 430 ShouldModel.prototype._isArray = function (arg) { |
| 424 return arg instanceof Array || arg instanceof Float32Array; | 431 return arg instanceof Array || arg instanceof Float32Array; |
| 425 }; | 432 }; |
| 426 | 433 |
| 427 ShouldModel.prototype._assert = function (expression, reason) { | 434 ShouldModel.prototype._assert = function (expression, reason, value) { |
| 428 if (expression) | 435 if (expression) |
| 429 return; | 436 return; |
| 430 | 437 |
| 431 var failureMessage = 'Assertion failed: ' + reason + ' ' + this.desc +'.
'; | 438 var failureMessage = 'Assertion failed: ' + reason + ' ' + this.desc +'.
'; |
| 439 if (arguments.length >= 3) |
| 440 failureMessage += ": " + value; |
| 432 testFailed(failureMessage); | 441 testFailed(failureMessage); |
| 433 throw failureMessage; | 442 throw failureMessage; |
| 434 }; | 443 }; |
| 435 | 444 |
| 436 // Check if |target| is equal to |value|. | 445 // Check if |target| is equal to |value|. |
| 437 // | 446 // |
| 438 // Example: | 447 // Example: |
| 439 // Should('Zero', 0).beEqualTo(0); | 448 // Should('Zero', 0).beEqualTo(0); |
| 440 // Result: | 449 // Result: |
| 441 // "PASS Zero is equal to 0." | 450 // "PASS Zero is equal to 0." |
| 442 ShouldModel.prototype.beEqualTo = function (value) { | 451 ShouldModel.prototype.beEqualTo = function (value) { |
| 443 var type = typeof value; | 452 var type = typeof value; |
| 444 this._assert(type === 'number' || type === 'string', | 453 this._assert(type === 'number' || type === 'string', |
| 445 'value should be number or string for'); | 454 'value should be number or string for', value); |
| 446 | 455 |
| 447 if (this.target === value) | 456 if (this.target === value) |
| 448 this._testPassed('is equal to ' + value); | 457 this._testPassed('is equal to ' + value); |
| 449 else | 458 else |
| 450 this._testFailed('was ' + this.target + ' instead of ' + value); | 459 this._testFailed('was ' + this.target + ' instead of ' + value); |
| 451 return this._success; | 460 return this._success; |
| 452 }; | 461 }; |
| 453 | 462 |
| 454 // Check if |target| is not equal to |value|. | 463 // Check if |target| is not equal to |value|. |
| 455 // | 464 // |
| 456 // Example: | 465 // Example: |
| 457 // Should('One', one).notBeEqualTo(0); | 466 // Should('One', one).notBeEqualTo(0); |
| 458 // Result: | 467 // Result: |
| 459 // "PASS One is not equal to 0." | 468 // "PASS One is not equal to 0." |
| 460 ShouldModel.prototype.notBeEqualTo = function (value) { | 469 ShouldModel.prototype.notBeEqualTo = function (value) { |
| 461 var type = typeof value; | 470 var type = typeof value; |
| 462 this._assert(type === 'number' || type === 'string', | 471 this._assert(type === 'number' || type === 'string', |
| 463 'value should be number or string for'); | 472 'value should be number or string for', value); |
| 464 | 473 |
| 465 if (this.target === value) | 474 if (this.target === value) |
| 466 this._testFailed('should not be equal to ' + value); | 475 this._testFailed('should not be equal to ' + value); |
| 467 else | 476 else |
| 468 this._testPassed('is not equal to ' + value); | 477 this._testPassed('is not equal to ' + value); |
| 469 return this._success; | 478 return this._success; |
| 470 }; | 479 }; |
| 471 | 480 |
| 472 // Check if |target| is greater than or equal to |value|. | 481 // Check if |target| is greater than or equal to |value|. |
| 473 // | 482 // |
| 474 // Example: | 483 // Example: |
| 475 // Should("SNR", snr).beGreaterThanOrEqualTo(100); | 484 // Should("SNR", snr).beGreaterThanOrEqualTo(100); |
| 476 // Result: | 485 // Result: |
| 477 // "PASS SNR exceeds 100" | 486 // "PASS SNR exceeds 100" |
| 478 // "FAIL SNR (n) is not greater than or equal to 100" | 487 // "FAIL SNR (n) is not greater than or equal to 100" |
| 479 ShouldModel.prototype.beGreaterThanOrEqualTo = function (value) { | 488 ShouldModel.prototype.beGreaterThanOrEqualTo = function (value) { |
| 480 var type = typeof value; | 489 var type = typeof value; |
| 481 this._assert(type === 'number' || type === 'string', | 490 this._assert(type === 'number' || type === 'string', |
| 482 'value should be number or string for'); | 491 'value should be number or string for', value); |
| 483 | 492 |
| 484 if (this.target >= value) | 493 if (this.target >= value) |
| 485 this._testPassed("is greater than or equal to " + value); | 494 this._testPassed("is greater than or equal to " + value); |
| 486 else | 495 else |
| 487 this._testFailed("(" + this.target + ") is not greater than or equal
to " + value); | 496 this._testFailed("(" + this.target + ") is not greater than or equal
to " + value); |
| 488 return this._success; | 497 return this._success; |
| 489 } | 498 } |
| 490 | 499 |
| 491 // Check if |target| is lest than or equal to |value|. | 500 // Check if |target| is lest than or equal to |value|. |
| 492 // | 501 // |
| 493 // Example: | 502 // Example: |
| 494 // maxError = 1e-6; | 503 // maxError = 1e-6; |
| 495 // Should("max error", maxError).beLessThanOrEqualTo(1e-5); | 504 // Should("max error", maxError).beLessThanOrEqualTo(1e-5); |
| 496 // Should("max error", maxError).beLessThanOrEqualTo(-1); | 505 // Should("max error", maxError).beLessThanOrEqualTo(-1); |
| 497 // Result: | 506 // Result: |
| 498 // "PASS max error is less than or equal to 1e-5" | 507 // "PASS max error is less than or equal to 1e-5" |
| 499 // "FAIL max error (1e-6) is not less than or equal to -1" | 508 // "FAIL max error (1e-6) is not less than or equal to -1" |
| 500 ShouldModel.prototype.beLessThanOrEqualTo = function (value) { | 509 ShouldModel.prototype.beLessThanOrEqualTo = function (value) { |
| 501 var type = typeof value; | 510 var type = typeof value; |
| 502 this._assert(type === 'number', 'value should be number or string for'); | 511 this._assert(type === 'number', 'value should be number or string for',
value); |
| 503 | 512 |
| 504 if (this.target <= value) | 513 if (this.target <= value) |
| 505 this._testPassed("is less than or equal to " + value); | 514 this._testPassed("is less than or equal to " + value); |
| 506 else | 515 else |
| 507 this._testFailed("(" + this.target + ") is not less than or equal to
" + value); | 516 this._testFailed("(" + this.target + ") is not less than or equal to
" + value); |
| 508 return this._success; | 517 return this._success; |
| 509 } | 518 } |
| 510 | 519 |
| 511 // Check if |target| is close to |value| using the given relative error |thr
eshold|. |value| | 520 // Check if |target| is close to |value| using the given relative error |thr
eshold|. |value| |
| 512 // should not be zero, but no check is made for that. The |target| value is
printed to | 521 // should not be zero, but no check is made for that. The |target| value is
printed to |
| 513 // precision |precision|, with |precision| defaulting to 7. | 522 // precision |precision|, with |precision| defaulting to 7. |
| 514 // | 523 // |
| 515 // If |value| is 0, however, |threshold| is treated as an absolute threshold
. | 524 // If |value| is 0, however, |threshold| is treated as an absolute threshold
. |
| 516 // | 525 // |
| 517 // Example: | 526 // Example: |
| 518 // Should("One", 1.001).beCloseTo(1, .1); | 527 // Should("One", 1.001).beCloseTo(1, .1); |
| 519 // Should("One", 2).beCloseTo(1, .1); | 528 // Should("One", 2).beCloseTo(1, .1); |
| 520 // Result: | 529 // Result: |
| 521 // "PASS One is 1 within a relative error of 0.1." | 530 // "PASS One is 1 within a relative error of 0.1." |
| 522 // "FAIL One is not 1 within a relative error of 0.1: 2" | 531 // "FAIL One is not 1 within a relative error of 0.1: 2" |
| 523 ShouldModel.prototype.beCloseTo = function (value, errorThreshold, precision
) { | 532 ShouldModel.prototype.beCloseTo = function (value, errorThreshold, precision
) { |
| 524 var type = typeof value; | 533 var type = typeof value; |
| 525 this._assert(type === 'number', 'value should be number for'); | 534 this._assert(type === 'number', 'value should be number for', value); |
| 526 | 535 |
| 527 if (value) { | 536 if (value) { |
| 528 var relativeError = Math.abs(this.target - value) / Math.abs(value); | 537 var relativeError = Math.abs(this.target - value) / Math.abs(value); |
| 529 if (relativeError <= errorThreshold) { | 538 if (relativeError <= errorThreshold) { |
| 530 this._testPassed("is " + value.toPrecision(precision) + | 539 this._testPassed("is " + value.toPrecision(precision) + |
| 531 " within a relative error of " + errorThreshold); | 540 " within a relative error of " + errorThreshold); |
| 532 } else { | 541 } else { |
| 533 // Include actual relative error so the failed test case can be
updated with the actual | 542 // Include actual relative error so the failed test case can be
updated with the actual |
| 534 // relative error, if appropriate. | 543 // relative error, if appropriate. |
| 535 this._testFailed("is not " + value.toPrecision(precision) + | 544 this._testFailed("is not " + value.toPrecision(precision) + |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 this.target(); | 583 this.target(); |
| 575 this._testFailed('did not throw an exception'); | 584 this._testFailed('did not throw an exception'); |
| 576 } catch (error) { | 585 } catch (error) { |
| 577 if (errorType === undefined) | 586 if (errorType === undefined) |
| 578 this._testPassed('threw an exception of type ' + error.name); | 587 this._testPassed('threw an exception of type ' + error.name); |
| 579 else if (error.name === errorType) | 588 else if (error.name === errorType) |
| 580 this._testPassed('threw ' + errorType + ': ' + error.message); | 589 this._testPassed('threw ' + errorType + ': ' + error.message); |
| 581 else if (self.hasOwnProperty(errorType) && error instanceof self[err
orType]) | 590 else if (self.hasOwnProperty(errorType) && error instanceof self[err
orType]) |
| 582 this._testPassed('threw ' + errorType + ': ' + error.message); | 591 this._testPassed('threw ' + errorType + ': ' + error.message); |
| 583 else | 592 else |
| 584 this._testFailed('threw ' + error.name + ' instead of ' + except
ion); | 593 this._testFailed('threw ' + error.name + ' instead of ' + errorT
ype); |
| 585 } | 594 } |
| 586 return this._success; | 595 return this._success; |
| 587 }; | 596 }; |
| 588 | 597 |
| 589 // Check if |func| does not throw an exception. | 598 // Check if |func| does not throw an exception. |
| 590 // | 599 // |
| 591 // Example: | 600 // Example: |
| 592 // Should('var foo = "bar"', function () { var foo = 'bar'; }).notThrow(); | 601 // Should('var foo = "bar"', function () { var foo = 'bar'; }).notThrow(); |
| 593 // Result: | 602 // Result: |
| 594 // "PASS var foo = "bar" did not throw an exception." | 603 // "PASS var foo = "bar" did not throw an exception." |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 }; | 646 }; |
| 638 | 647 |
| 639 // Check if |target| array is identical to |expected| array element-wise. | 648 // Check if |target| array is identical to |expected| array element-wise. |
| 640 // | 649 // |
| 641 // Example: | 650 // Example: |
| 642 // Should('[1, 2, 3]', [1, 2, 3]).beEqualToArray([1, 2, 3]); | 651 // Should('[1, 2, 3]', [1, 2, 3]).beEqualToArray([1, 2, 3]); |
| 643 // Result: | 652 // Result: |
| 644 // "PASS [1, 2, 3] is identical to the array [1,2,3]." | 653 // "PASS [1, 2, 3] is identical to the array [1,2,3]." |
| 645 ShouldModel.prototype.beEqualToArray = function (array) { | 654 ShouldModel.prototype.beEqualToArray = function (array) { |
| 646 this._assert(this._isArray(array) && this.target.length === array.length
, | 655 this._assert(this._isArray(array) && this.target.length === array.length
, |
| 647 'Invalid array or the length does not match.'); | 656 'Invalid array or the length does not match.', array); |
| 648 | 657 |
| 649 var mismatches = {}; | 658 var mismatches = {}; |
| 650 for (var i = 0; i < this.target.length; i++) { | 659 for (var i = 0; i < this.target.length; i++) { |
| 651 if (this.target[i] !== array[i]) | 660 if (this.target[i] !== array[i]) |
| 652 mismatches[i] = this.target[i]; | 661 mismatches[i] = this.target[i]; |
| 653 } | 662 } |
| 654 | 663 |
| 655 var numberOfmismatches = Object.keys(mismatches).length; | 664 var numberOfmismatches = Object.keys(mismatches).length; |
| 656 var arrStr = (array.length > this.NUM_ARRAY_LOG) ? | 665 var arrStr = (array.length > this.NUM_ARRAY_LOG) ? |
| 657 array.slice(0, this.NUM_ARRAY_LOG).toString() + '...' : array.toString()
; | 666 array.slice(0, this.NUM_ARRAY_LOG).toString() + '...' : array.toString()
; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 669 break; | 678 break; |
| 670 } | 679 } |
| 671 } | 680 } |
| 672 | 681 |
| 673 this._testFailed(failureMessage); | 682 this._testFailed(failureMessage); |
| 674 } | 683 } |
| 675 return this._success; | 684 return this._success; |
| 676 }; | 685 }; |
| 677 | 686 |
| 678 // Check if |target| array is close to |expected| array element-wise within | 687 // Check if |target| array is close to |expected| array element-wise within |
| 679 // the range of |maxAllowedError|. | 688 // an certain error bound given by |absoluteThresholdOrOptions|. |
| 689 // |
| 690 // The error criterion is: |
| 691 // |
| 692 // Math.abs(target[k] - expected[k]) < Math.max(abserr, relerr * Math.abs(
expected)) |
| 693 // |
| 694 // If |absoluteThresholdOrOptions| is a number, t, then abserr = t and reler
r = 0. That is the |
| 695 // max difference is bounded by t. |
| 696 // |
| 697 // If |absoluteThresholdOrOptions| is a property bag, then abserr is the val
ue of the |
| 698 // absoluteThreshold property and relerr is the value of the relativeThresho
ld property. If |
| 699 // nothing is given, then abserr = relerr = 0. If abserr = 0, then the erro
r criterion is a |
| 700 // relative error. A non-zero abserr value produces a mix intended to handl
e the case where the |
| 701 // expected value is 0, allowing the target value to differ by abserr from t
he expected. |
| 680 // | 702 // |
| 681 // Example: | 703 // Example: |
| 682 // Should('My array', [0.11, 0.19]).beCloseToArray([0.1, 0.2], 0.02); | 704 // Should('My array', [0.11, 0.19]).beCloseToArray([0.1, 0.2], 0.02); |
| 683 // Result: | 705 // Result: |
| 684 // "PASS My array equals [0.1,0.2] within an element-wise tolerance of 0.02.
" | 706 // "PASS My array equals [0.1,0.2] within an element-wise tolerance of 0.02.
" |
| 685 ShouldModel.prototype.beCloseToArray = function (array, maxAllowedError) { | 707 ShouldModel.prototype.beCloseToArray = function (expected, absoluteThreshold
OrOptions) { |
| 686 // For the comparison, the target length must be bigger than the expecte
d. | 708 // For the comparison, the target length must be bigger than the expecte
d. |
| 687 this._assert(this.target.length >= array.length, | 709 this._assert(this.target.length >= expected.length, |
| 688 'The target array length must be longer than ' + array.length + | 710 'The target array length must be longer than ' + expected.length + |
| 689 ' but got ' + this.target.length + '.'); | 711 ' but got ' + this.target.length + '.'); |
| 690 | 712 |
| 713 var absoluteErrorThreshold = 0; |
| 714 var relativeErrorThreshold = 0; |
| 715 // A collection of all of the values that satisfy the error criterion.
This holds the |
| 716 // absolute difference between the target element and the expected eleme
nt. |
| 691 var mismatches = {}; | 717 var mismatches = {}; |
| 692 var maxDiff = 0.0; | 718 |
| 693 var maxDiffIndex = 0; | 719 // Keep track of the max absolute error found |
| 694 for (var i = 0; i < array.length; i++) { | 720 var maxAbsError = -Infinity; |
| 695 var diff = Math.abs(this.target[i] - array[i]); | 721 var maxAbsErrorIndex = -1; |
| 696 if (diff > maxAllowedError) | 722 // Keep trac of the max relative error found, ignoring cases where the r
elative error is |
| 723 // Infinity because the expected value is 0. |
| 724 var maxRelError = -Infinity; |
| 725 var maxRelErrorIndex = -1; |
| 726 |
| 727 // A number or string for printing out the actual thresholds used for th
e error criterion. |
| 728 var maxAllowedError; |
| 729 |
| 730 // Set up the thresholds based on |absoluteThresholdOrOptions|. |
| 731 if (typeof(absoluteThresholdOrOptions) === 'number') { |
| 732 absoluteErrorThreshold = absoluteThresholdOrOptions; |
| 733 maxAllowedError = absoluteErrorThreshold; |
| 734 } else { |
| 735 var opts = absoluteThresholdOrOptions; |
| 736 if (opts.hasOwnProperty('absoluteThreshold')) |
| 737 absoluteErrorThreshold = opts.absoluteThreshold; |
| 738 if (opts.hasOwnProperty('relativeThreshold')) |
| 739 relativeErrorThreshold = opts.relativeThreshold; |
| 740 maxAllowedError = '{absoluteThreshold: ' + absoluteErrorThreshold |
| 741 + ', relativeThreshold: ' + relativeErrorThreshold |
| 742 + '}'; |
| 743 } |
| 744 |
| 745 for (var i = 0; i < expected.length; i++) { |
| 746 var diff = Math.abs(this.target[i] - expected[i]); |
| 747 if (diff > Math.max(absoluteErrorThreshold, relativeErrorThreshold *
Math.abs(expected[i]))) { |
| 697 mismatches[i] = diff; | 748 mismatches[i] = diff; |
| 698 if (diff > maxDiff) { | 749 // Keep track of the location of the absolute max difference. |
| 699 maxDiff = diff; | 750 if (diff > maxAbsError) { |
| 700 maxDiffIndex = i; | 751 maxAbsErrorIndex = i; |
| 752 maxAbsError = diff; |
| 753 } |
| 754 // Keep track of the location of the max relative error, ignorin
g cases where the |
| 755 // relative error is ininfinity (because the expected value = 0)
. |
| 756 var relError = diff / Math.abs(expected[i]); |
| 757 if (isFinite(relError) && relError > maxRelError) { |
| 758 maxRelErrorIndex = i; |
| 759 maxRelError = relError; |
| 760 } |
| 701 } | 761 } |
| 702 } | 762 } |
| 703 | 763 |
| 704 var numberOfmismatches = Object.keys(mismatches).length; | 764 var numberOfmismatches = Object.keys(mismatches).length; |
| 705 var arrStr = (array.length > this.NUM_ARRAY_LOG) ? | 765 var arrSlice = expected.slice(0, Math.min(expected.length, this.NUM_ARRA
Y_LOG)); |
| 706 array.slice(0, this.NUM_ARRAY_LOG).toString() + ',...' : array.toString(
); | 766 var arrStr; |
| 707 | 767 |
| 768 arrStr = arrSlice[0].toPrecision(this.PRINT_PRECISION); |
| 769 for (var k = 1; k < arrSlice.length; ++k) |
| 770 arrStr += ',' + arrSlice[k].toPrecision(this.PRINT_PRECISION); |
| 771 |
| 772 if (expected.length > this.NUM_ARRAY_LOG) |
| 773 arrStr += ',...'; |
| 708 if (numberOfmismatches === 0) { | 774 if (numberOfmismatches === 0) { |
| 709 this._testPassed('equals [' + arrStr + | 775 this._testPassed('equals [' + arrStr + |
| 710 '] with an element-wise tolerance of ' + maxAllowedError); | 776 '] with an element-wise tolerance of ' + maxAllowedError); |
| 711 } else { | 777 } else { |
| 712 var counter = 0; | 778 var counter = 0; |
| 713 var failureMessage = 'does not equal [' + arrStr + | 779 var failureMessage = 'does not equal [' + arrStr + |
| 714 '] with an element-wise tolerance of ' + maxAllowedError; | 780 '] with an element-wise tolerance of ' + maxAllowedError; |
| 715 failureMessage += '\nIndex\t Diff\t\t Actual\t\t Expected'; | 781 |
| 782 // Print a nice header for the table to follow. |
| 783 if (this.verbose) |
| 784 failureMessage += "\nIndex Actual Expected
Diff Relative"; |
| 785 else |
| 786 failureMessage += "\nDifference between expected and actual:"; |
| 787 |
| 716 for (var index in mismatches) { | 788 for (var index in mismatches) { |
| 717 failureMessage += '\n[' + index + '] :\t' + mismatches[index] + | 789 failureMessage += '\n[' + index + ']: '; |
| 718 '\t' + this.target[index] + '\t' + array[index]; | 790 if (this.verbose) { |
| 719 if (++counter >= this.NUM_ERRORS_LOG || counter === numberOfmism
atches) { | 791 // When verbose, print out actual, expected, absolute error,
and relative error. |
| 792 // TODO: print these out in nice columns to make it easier t
o read. |
| 793 var relError = Math.abs(this.target[index] - expected[index]
) / Math.abs(expected[index]); |
| 794 failureMessage += this.target[index].toExponential(16) + '
' |
| 795 + expected[index].toExponential(16) + ' ' |
| 796 + mismatches[index].toExponential(16) + ' ' |
| 797 + relError.toExponential(16) + ' ' |
| 798 + Math.max(absoluteErrorThreshold, |
| 799 relativeErrorThreshold * Math.abs(expecte
d[index])); |
| 800 } else { |
| 801 // Otherwise, just the print the absolute error. |
| 802 failureMessage += mismatches[index]; |
| 803 } |
| 804 if (++counter >= this.NUM_ERRORS_LOG) { |
| 720 failureMessage += '\nand ' + (numberOfmismatches - counter)
+ | 805 failureMessage += '\nand ' + (numberOfmismatches - counter)
+ |
| 721 ' more differences with the maximum error of ' + maxDiff
+ | 806 ' more differences, with max absolute error'; |
| 722 ' at index ' + maxDiffIndex; | 807 if (this.verbose) { |
| 808 // When verbose, print out the location of both the max
absolute error and |
| 809 // the max relative error so we can adjust thresholds ap
propriately in the |
| 810 // test. |
| 811 var relError = Math.abs(this.target[maxAbsErrorIndex] -
expected[maxAbsErrorIndex]) |
| 812 / Math.abs(expected[maxAbsErrorIndex]); |
| 813 failureMessage += ' at index ' + maxAbsErrorIndex + ':'; |
| 814 failureMessage += '\n[' + maxAbsErrorIndex + ']: '; |
| 815 failureMessage += this.target[maxAbsErrorIndex].toExpone
ntial(16) + ' ' |
| 816 + expected[maxAbsErrorIndex].toExponential(16) +
' ' |
| 817 + mismatches[maxAbsErrorIndex].toExponential(16)
+ ' ' |
| 818 + relError.toExponential(16) + ' ' |
| 819 + Math.max(absoluteErrorThreshold, |
| 820 relativeErrorThreshold * Math.abs(expected[m
axAbsErrorIndex])); |
| 821 failureMessage += '\nand max relative error'; |
| 822 failureMessage += ' at index ' + maxRelErrorIndex + ':'; |
| 823 failureMessage += '\n[' + maxRelErrorIndex + ']: '; |
| 824 failureMessage += this.target[maxRelErrorIndex].toExpone
ntial(16) + ' ' |
| 825 + expected[maxRelErrorIndex].toExponential(16) +
' ' |
| 826 + mismatches[maxRelErrorIndex].toExponential(16)
+ ' ' |
| 827 + maxRelError.toExponential(16) + ' ' |
| 828 + Math.max(absoluteErrorThreshold, |
| 829 relativeErrorThreshold * Math.abs(expected[m
axRelErrorIndex])); |
| 830 } else { |
| 831 // Not verbose, so just print out the max absolute error |
| 832 failureMessage += ' of ' + maxAbsError + ' at index ' +
maxAbsErrorIndex; |
| 833 } |
| 723 break; | 834 break; |
| 724 } | 835 } |
| 725 } | 836 } |
| 726 | 837 |
| 727 this._testFailed(failureMessage); | 838 this._testFailed(failureMessage); |
| 728 } | 839 } |
| 729 return this._success; | 840 return this._success; |
| 730 }; | 841 }; |
| 731 | 842 |
| 732 // Check if |target| array contains a set of values in a certain order. | 843 // Check if |target| array contains a set of values in a certain order. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 var _opts = { | 925 var _opts = { |
| 815 numberOfErrorLog: 8, | 926 numberOfErrorLog: 8, |
| 816 numberOfArrayLog: 16 | 927 numberOfArrayLog: 16 |
| 817 }; | 928 }; |
| 818 | 929 |
| 819 if (opts instanceof Object) { | 930 if (opts instanceof Object) { |
| 820 if (opts.hasOwnProperty('numberOfErrorLog')) | 931 if (opts.hasOwnProperty('numberOfErrorLog')) |
| 821 _opts.numberOfErrorLog = opts.numberOfErrorLog; | 932 _opts.numberOfErrorLog = opts.numberOfErrorLog; |
| 822 if (opts.hasOwnProperty('numberOfArrayLog')) | 933 if (opts.hasOwnProperty('numberOfArrayLog')) |
| 823 _opts.numberOfArrayLog = opts.numberOfArrayLog; | 934 _opts.numberOfArrayLog = opts.numberOfArrayLog; |
| 935 if (opts.hasOwnProperty('verbose')) |
| 936 _opts.verbose = opts.verbose; |
| 937 if (opts.hasOwnProperty('precision')) |
| 938 _opts.precision = opts.precision; |
| 824 } | 939 } |
| 825 | 940 |
| 826 return new ShouldModel(desc, target, _opts); | 941 return new ShouldModel(desc, target, _opts); |
| 827 }; | 942 }; |
| 828 | 943 |
| 829 })(); | 944 })(); |
| OLD | NEW |