From 6a0112af9aae430e3dca9566e670d3b6a3ab212f Mon Sep 17 00:00:00 2001 From: David Luu Date: Mon, 20 Apr 2015 16:13:07 -0700 Subject: [PATCH 1/3] Add toBeCloseTo as Jasmine assertion matcher --- dependencies/jasmine.js | 25 +++++++++++++++++++++++++ test/jasmine.specs | 10 ++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/jasmine.specs diff --git a/dependencies/jasmine.js b/dependencies/jasmine.js index 1adab61..707fb3e 100644 --- a/dependencies/jasmine.js +++ b/dependencies/jasmine.js @@ -1409,6 +1409,31 @@ jasmine.Matchers.prototype.toThrow = function(expected) { return result; }; +/** + * toBeCloseTo: compares that actual is close to the value of expected, based on given precision value for number of decimal places. + * + * @param expected + * @param precision + */ +jasmine.Matchers.prototype.toBeCloseTo = function() { + + function toBeCloseTo() { + return { + compare: function(actual, expected, precision) { + if (precision !== 0) { + precision = precision || 2; + } + + return { + pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) + }; + } + }; + } + + return toBeCloseTo; +}; + jasmine.Matchers.Any = function(expectedClass) { this.expectedClass = expectedClass; }; diff --git a/test/jasmine.specs b/test/jasmine.specs new file mode 100644 index 0000000..1023a24 --- /dev/null +++ b/test/jasmine.specs @@ -0,0 +1,10 @@ +describe('Jasmine unit tests against Jasmine changes', function () { + it("The 'toBeCloseTo' matcher is for precision math comparison", function() { + var pi = 3.1415926, + e = 2.78; + + //expect(pi).not.toBeCloseTo(e, 2); + expect(pi).toBeCloseTo(e, 0); + expect(12.34).toBeCloseTo(12.3, 1); // success + }); +}); \ No newline at end of file From 6f992a12034e3f92cc59d416cec0a6a9f4048bb4 Mon Sep 17 00:00:00 2001 From: David Luu Date: Mon, 27 Apr 2015 18:00:46 -0700 Subject: [PATCH 2/3] Update README --- README | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README b/README index 6a3d0a2..39139ca 100644 --- a/README +++ b/README @@ -1,11 +1,6 @@ -Extendables is an MIT-licensed developers' framework for Adobe ExtendScript. It is currently unmaintained and there are no guarantees it will continue to work with the latest versions of the Creative Suite and/or ExtendScript. +This is my fork of http://debrouwere.github.com/Extendables. See the source project for documentation and more info. -Extendables comes with three big blocks of functionality. +The difference with my fork is: -1. Additional methods on built-in objects like String and Array that give you the Javascript 1.8 features you're used to (think `forEach`), conveniences for functional programming (think `map`, `reduce`, `filter`), easy serialization to JSON or base64 and more. -2. Additional methods on InDesign DOM objects that make coding in InDesign less verbose. -3. Packages for logging, unit testing, http, user interface development, and a couple of other goodies. - -If you're writing heavy-duty automations for a Creative Suite app like InDesign, or anything more than just a throwaway script, this is for you. - -Read the documentation at http://debrouwere.github.com/Extendables/docs/ to learn more and get started. +* have issue tracker to track issues with Extendables framework, since the original source project has no issue tracker currently. +* fix issues and offer enhancements as I get to them. See the issue tracker of open and closed issues for details. Some info might be put on the wiki as well. From c63ca9e595bbf3ec11a09964dbadf39070b6d385 Mon Sep 17 00:00:00 2001 From: David Luu Date: Mon, 27 Apr 2015 18:01:04 -0700 Subject: [PATCH 3/3] Update README --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index 39139ca..75ea326 100644 --- a/README +++ b/README @@ -3,4 +3,5 @@ This is my fork of http://debrouwere.github.com/Extendables. See the source proj The difference with my fork is: * have issue tracker to track issues with Extendables framework, since the original source project has no issue tracker currently. + * fix issues and offer enhancements as I get to them. See the issue tracker of open and closed issues for details. Some info might be put on the wiki as well.