Skip to content

Commit

Permalink
Add tests to bring color-harmony coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
apipkin committed Oct 21, 2012
1 parent d07851b commit feaa3f1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 53 deletions.
101 changes: 69 additions & 32 deletions src/color/tests/unit/assets/color-harmony-tests.js
@@ -1,106 +1,102 @@
YUI.add('color-harmony-tests', function(Y) {

function addOutput (title, input, colors) {
var output = Y.one('#output dl');
output.append('<dt>' + title + '</dt>');

var dd = '<dd>';
dd += 'test: <span class="color" style="background: ' + input + ';"></span>';
dd += '</dd><dd>result: ';

colors = Y.Array(colors);
Y.Array.each(colors, function(color) {
dd += color + ' <span class="color" style="background: ' + color + ';"></span>';
});
dd += '</dd>';
output.append(dd);
}

var testBasic = new Y.Test.Case({
name: "Color Convertion Tests",

'complementary of "blue"': function() {
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() {
Expand All @@ -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)
}
}


Expand Down
22 changes: 1 addition & 21 deletions src/color/tests/unit/color-harmony.html
Expand Up @@ -3,26 +3,6 @@
<head>
<title>Color Tests</title>
<script type="text/javascript" src="../../../../build/yui/yui.js"></script>
<style>
.color {
border: 1px solid rgba(0,0,0,0.5);
box-shadow: 1px 1px 2px 0px rgba(0,0,0,0.3);
display: inline-block;
zoom: 1;
*display: inline;
width: 12px;
height: 12px;
vertical-align: top;
margin: 0 0.3em;
}
#output dl {
height: 50px;
overflow: hidden;
}
#output:focus dl {
height: auto;
}
</style>

</head>

Expand All @@ -42,7 +22,7 @@ <h1>Color Tests</h1>
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');

Expand Down

0 comments on commit feaa3f1

Please sign in to comment.