diff options
author | wout <wout@impinc.co.uk> | 2014-02-01 20:13:05 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-02-01 20:13:05 +0100 |
commit | 11376f6ec53092bd3893a168f25a08983d7aff6c (patch) | |
tree | de6a4725bb791549a3e177ec06b0364e913f5659 /spec | |
parent | a19bbab549b2d65b83751c3ef85295ee02065f42 (diff) | |
download | svg.js-11376f6ec53092bd3893a168f25a08983d7aff6c.tar.gz svg.js-11376f6ec53092bd3893a168f25a08983d7aff6c.zip |
added `morph()` and `at()` methods to `SVG.Number` for unit morphing
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/color.js | 8 | ||||
-rw-r--r-- | spec/spec/number.js | 38 |
2 files changed, 28 insertions, 18 deletions
diff --git a/spec/spec/color.js b/spec/spec/color.js index eec3f48..6bae4c8 100644 --- a/spec/spec/color.js +++ b/spec/spec/color.js @@ -68,6 +68,14 @@ describe('Color', function() { expect(morphed.g).toBe(255) expect(morphed.b).toBe(255) }) + + it('morphes color to 0 with lower values', function() { + var destination = new SVG.Color('#fff') + var morphed = color.morph(destination).at(-3) + expect(morphed.r).toBe(0) + expect(morphed.g).toBe(102) + expect(morphed.b).toBe(255) + }) }) }) diff --git a/spec/spec/number.js b/spec/spec/number.js index 1638671..9ee3394 100644 --- a/spec/spec/number.js +++ b/spec/spec/number.js @@ -6,7 +6,6 @@ describe('Number', function() { }) describe('new', function() { - it('is zero', function() { expect(number.value).toBe(0) }) @@ -40,11 +39,9 @@ describe('Number', function() { number = new SVG.Number(-1.7976931348623157E+10308) expect(number.value).toBe(-3.4e+38) }) - }) describe('toString()', function() { - it('converts the number to a string', function() { expect(number.toString()).toBe('0') }) @@ -58,11 +55,9 @@ describe('Number', function() { number.unit = '%' expect(number.toString()).toBe('136%') }) - }) describe('valueOf()', function() { - it('returns a numeric value for default units', function() { expect(typeof number.valueOf()).toBe('number') number = new SVG.Number('12') @@ -82,15 +77,12 @@ describe('Number', function() { number.value = 80 expect(number * 4).toBe(320) }) - }) describe('to()', function() { - beforeEach(function() { number.plus(4) }) - it('changes the unit value', function() { number.to('%') expect(number.unit).toBe('%') @@ -100,11 +92,9 @@ describe('Number', function() { number.to('%') expect(number.toString()).toBe('400%') }) - }) describe('plus()', function() { - it('adds a given number', function() { number.plus(3.5) expect(number.valueOf()).toBe(3.5) @@ -117,11 +107,9 @@ describe('Number', function() { number.plus('83px') expect(number.valueOf()).toBe(83) }) - }) describe('minus()', function() { - it('subtracts a given number', function() { number.minus(3.7) expect(number.valueOf()).toBe(-3.7) @@ -134,15 +122,12 @@ describe('Number', function() { number.minus('85px') expect(number.valueOf()).toBe(-85) }) - }) describe('times()', function() { - beforeEach(function() { number.plus(4) }) - it('multiplies with a given number', function() { number.times(3) expect(number.valueOf()).toBe(12) @@ -155,15 +140,12 @@ describe('Number', function() { number.times('85px') expect(number.valueOf()).toBe(340) }) - }) describe('divide()', function() { - beforeEach(function() { number.plus(90) }) - it('divides by a given number', function() { number.divide(3) expect(number.valueOf()).toBe(30) @@ -176,7 +158,27 @@ describe('Number', function() { number.divide('45px') expect(number.valueOf()).toBe(2) }) + }) + describe('morph()', function() { + it('prepares the color for morphing', function() { + var destination = new SVG.Number + number.morph(destination) + expect(number.destination).toEqual(destination) + }) + }) + + describe('at()', function() { + it('morphes number to a given position', function() { + var destination = new SVG.Number(200) + var morphed = number.morph(destination).at(0.4) + expect(morphed.valueOf()).toBe(80) + }) + it('morphes number to a given percentage position', function() { + var destination = new SVG.Number('100%') + var morphed = number.morph(destination).at(0.72) + expect(morphed.toString()).toBe('72%') + }) }) }) |