From feaa3f1d6263fa4d9add4a7f7a300eec249449d9 Mon Sep 17 00:00:00 2001 From: Anthony Pipkin Date: Sun, 21 Oct 2012 12:07:23 -0400 Subject: [PATCH] Add tests to bring color-harmony coverage to 100% --- .../tests/unit/assets/color-harmony-tests.js | 101 ++++++++++++------ src/color/tests/unit/color-harmony.html | 22 +--- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/color/tests/unit/assets/color-harmony-tests.js b/src/color/tests/unit/assets/color-harmony-tests.js index cfe6aa2a4a0..532b4e4f668 100644 --- a/src/color/tests/unit/assets/color-harmony-tests.js +++ b/src/color/tests/unit/assets/color-harmony-tests.js @@ -1,21 +1,5 @@ YUI.add('color-harmony-tests', function(Y) { - function addOutput (title, input, colors) { - var output = Y.one('#output dl'); - output.append('
' + title + '
'); - - var dd = '
'; - dd += 'test: '; - dd += '
result: '; - - colors = Y.Array(colors); - Y.Array.each(colors, function(color) { - dd += color + ' '; - }); - dd += '
'; - output.append(dd); - } - var testBasic = new Y.Test.Case({ name: "Color Convertion Tests", @@ -23,84 +7,96 @@ YUI.add('color-harmony-tests', function(Y) { var c = Y.Color.getComplementary('blue'); Y.Assert.areSame(2, c.length); - addOutput('complementary of "blue"', "blue", c); }, 'complementary of "#ff7700"': function() { var c = Y.Color.getComplementary('#ff7700'); Y.Assert.areSame(2, c.length); - addOutput('complementary of "#ff7700"', "#ff7700", c); }, 'split complementary of "blue"': function() { var c = Y.Color.getSplit('blue'); Y.Assert.areSame(3, c.length, 'length is greater than 1'); - addOutput('split complementary of "blue"', "blue", c); }, 'analogous of "red"': function() { var c = Y.Color.getAnalogous('red'); Y.Assert.areSame(5, c.length, 'length is greater than 1'); - addOutput('analogous of "red"', 'red', c); }, 'triad of "#ff7700"': function() { var c = Y.Color.getTriad('#ff7700'); Y.Assert.areSame(3, c.length, 'length is greater than 1'); - addOutput('triad of "#ff7700"', '#ff7700', c); }, 'tetrad of "#ff00ff"': function() { var c = Y.Color.getTetrad('#ff00ff'); Y.Assert.areSame(4, c.length, 'length is greater than 1'); - addOutput('tetrad of "#ff00ff"', '#ff00ff', c); }, 'square of "#ff00ff"': function() { var c = Y.Color.getSquare('#ff00ff'); Y.Assert.areSame(4, c.length, 'length is greater than 1'); - addOutput('square of "#ff00ff"', '#ff00ff', c); + }, + + 'monochrome of "#ff7700" one time': function() { + var c = Y.Color.getMonochrome('#ff7700', 1); + + Y.Assert.areSame('#ff7700', c, 'color is not returned'); + }, + + 'monochrome of "#ff7700" default count': function() { + var c = Y.Color.getMonochrome('#ff7700'); + + Y.Assert.areSame(5, c.length, 'length is greater than 1'); }, 'monochrome of "#ff7700"': function() { var c = Y.Color.getMonochrome('#ff7700', 5); Y.Assert.areSame(5, c.length, 'length is greater than 1'); - addOutput('monochrome of "#ff7700"', '#ff7700', c); }, - 'similar of "#ff00ff"': function() { - var c = Y.Color.getSimilar('#ff00ff', 5); + 'similar of "#ff00ff" default offset': function() { + var c = Y.Color.getSimilar('#ff00ff'); + + Y.Assert.areSame(6, c.length, 'length is greater than 1'); + }, + + 'similar of "#ff00ff" default count': function() { + var c = Y.Color.getSimilar('#ff00ff', 10); Y.Assert.areSame(6, c.length, 'length is greater than 1'); - addOutput('similar of "#ff00ff"', '#ff00ff', c); + }, + + 'similar of "#ff00ff" custom count': function() { + var c = Y.Color.getSimilar('#ff00ff', 10, 10); + + Y.Assert.areSame(11, c.length, 'length is greater than 1'); }, 'hue offset to +10 of "blue"': function() { var c = Y.Color.getOffset('blue', {h: 10}); Y.Assert.areSame('#2a00ff', c, 'length is greater than 1'); - addOutput('hue offset to +10 of "blue"', 'blue', c); }, 'saturation offset to -10 of "#ff7700"': function() { var c = Y.Color.getOffset('#ff7700', {s: -10}); Y.Assert.areSame('#f2780d', c, 'length is greater than 1'); - addOutput('saturation offset to -10 of "#ff7700"', '#ff7700', c); }, 'luminance offset to -10 of "#ff00ff"': function() { var c = Y.Color.getOffset('#ff00ff', {l: -10}); Y.Assert.areSame('#cc00cc', c, 'length is greater than 1'); - addOutput('luminance offset to -10 of "#ff00ff"', '#ff00ff', c); }, 'brightness of "yellow"': function() { @@ -109,11 +105,52 @@ YUI.add('color-harmony-tests', function(Y) { Y.Assert.areSame(0.97, Math.round(b*100)/100, 'length is greater than 1'); }, + 'similar brightness of "yellow" matching "blue" to rgb': function() { + var c = Y.Color.getSimilarBrightness('yellow', 'blue', 'rgb'); + + Y.Assert.areSame('rgb(71, 71, 0)', c, 'incorrect color matching'); + }, + 'similar brightness of "yellow" matching "blue"': function() { var c = Y.Color.getSimilarBrightness('yellow', 'blue'); - Y.Assert.areSame('#474700', c, 'length is greater than 1'); - addOutput('similar brightness of "yellow" matching "blue"', 'yellow', c); + Y.Assert.areSame('#474700', c, 'incorrect color matching'); + }, + + 'test additive to subtractive and back': function() { + var i = 0, + additive, + subtractive; + + for (; i < 360; i++) { + additive = i; + subtractive = Y.Color._toSubtractive(additive); + Y.Assert.areSame(additive, Y.Color._toAdditive(subtractive)); + } + }, + + 'test additive to subtractive with negative hues ': function() { + var i = -360, + additive, + subtractive; + + for (; i < 0; i++) { + additive = i; + subtractive = Y.Color._toSubtractive(additive); + Y.Assert.isTrue(subtractive >= 0 && subtractive <= 360) + } + }, + + 'test subtractive to additive with negative hues ': function() { + var i = -360, + additive, + subtractive; + + for (; i < 0; i++) { + subtractive = i; + additive = Y.Color._toAdditive(subtractive); + Y.Assert.isTrue(additive >= 0 && additive <= 360) + } } diff --git a/src/color/tests/unit/color-harmony.html b/src/color/tests/unit/color-harmony.html index b0532b5e1fd..779d9663798 100644 --- a/src/color/tests/unit/color-harmony.html +++ b/src/color/tests/unit/color-harmony.html @@ -3,26 +3,6 @@ Color Tests - @@ -42,7 +22,7 @@

Color Tests

requires: [ 'test', 'dump', 'color-harmony' ] } } -}).use("test-console", "color-harmony-tests", "charts", function(Y) { +}).use("test-console", "color-harmony-tests", function(Y) { (new Y.Test.Console()).render('#log');