From 29768c8228ae084588981f6d21fa9553366e1c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 25 Jul 2016 21:09:53 +0200 Subject: [PATCH] Take Color#alpha default into account in Color#equals() Relates to #1084 --- src/style/Color.js | 2 +- test/tests/Color.js | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/style/Color.js b/src/style/Color.js index 2205fa4b..4fcb8a9e 100644 --- a/src/style/Color.js +++ b/src/style/Color.js @@ -769,7 +769,7 @@ var Color = Base.extend(new function() { : color; return col === this || col && this._class === col._class && this._type === col._type - && this._alpha === col._alpha + && this.getAlpha() === col.getAlpha() && Base.equals(this._components, col._components) || false; }, diff --git a/test/tests/Color.js b/test/tests/Color.js index 32eef4e9..6e09259d 100644 --- a/test/tests/Color.js +++ b/test/tests/Color.js @@ -109,7 +109,7 @@ test('Get hue from RGB Color', function() { equals(color.saturation, 1); }); -test('Gray Color', function() { +test('Get gray after conversion', function() { var color = new Color(1); equals(color.gray, 1, 'color.gray'); equals(color.red, 1, 'color.red'); @@ -156,12 +156,12 @@ test('Setting Color#gray', function() { equals(color, new Color(0.5)); }); -test('Color.read(channels)', function() { +test('Color.read()', function() { var color = Color.read([0, 0, 1]); equals(color, new Color(0, 0, 1)); }); -test('Cloning colors', function() { +test('Color#clone()', function() { var color = new Color(0, 0, 0); equals(function() { return color.clone() != color; @@ -172,7 +172,7 @@ test('Cloning colors', function() { }, true); }); -test('Color#convert', function() { +test('Color#convert()', function() { var color = new Color(0, 0, 0); var converted = color.convert('rgb'); equals(function() { @@ -183,13 +183,13 @@ test('Color#convert', function() { }, true); }); -test('Saturation from black rgb', function() { +test('Getting saturation from black RGB Color', function() { equals(function() { return new Color(0, 0, 0).saturation === 0; }, true); }); -test('Color#add', function() { +test('Color#add()', function() { var color = new Color(0, 1, 1); equals(color.add([1, 0, 0]), new Color([1, 1, 1])); equals(color.add([1, 0.5, 0]), new Color([1, 1.5, 1])); @@ -197,7 +197,7 @@ test('Color#add', function() { equals(color.add(0.5), new Color([0.5, 1, 0.5])); }); -test('Color#subtract', function() { +test('Color#subtract()', function() { var color = new Color(0, 1, 1); equals(color.subtract([0, 1, 1]), new Color([0, 0, 0])); equals(color.subtract([0, 0.5, 1]), new Color([0, 0.5, 0])); @@ -205,7 +205,7 @@ test('Color#subtract', function() { equals(color.subtract(0.5), new Color([0.5, 0.5, 0.5])); }); -test('Color#multiply', function() { +test('Color#multiply()', function() { var color = new Color(1, 0.5, 0.25); equals(color.multiply([0.25, 0.5, 1]), new Color([0.25, 0.25, 0.25])); var color = new Color(1, 1, 1); @@ -214,7 +214,7 @@ test('Color#multiply', function() { equals(color.multiply(2), new Color([1, 1, 1])); }); -test('Color#divide', function() { +test('Color#divide()', function() { var color = new Color(1, 1, 1); equals(color.divide([1, 2, 4]), new Color([1, 0.5, 0.25])); var color = new Color(1, 0.5, 0.25); @@ -223,6 +223,16 @@ test('Color#divide', function() { equals(color.divide(4), new Color([0.25, 0.25, 0.25])); }); +test('Color#equals()', function() { + var red = new Color('red'); + equals(function() { + return new Color(1, 0, 0).equals(red); + }, true); + equals(function() { + return new Color(1, 0, 0, 1).equals(red); + }, true); +}); + test('Gradient', function() { var stop1 = new GradientStop({ offset: 0.5 }); var stop2 = new GradientStop('red', 0.75);