@sencha/cmd-linux-64
Version:
Productivity and performance optimization tool for building applications with Sencha Ext JS
330 lines (324 loc) • 8.02 kB
JavaScript
var Fashion = require('../../index.js');
var assert = require('assert');
describe('color conversions', function() {
var rgbTests = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
];
var hslTests = [
[],
[],
[],
[],
[],
[],
[-360,100,50],
[-300,100,50],
[-240,100,50],
[-180,100,50],
[-120,100,50],
[-60,100,50],
[],
[],
[],
[],
[],
[],
[],
[-9660,100,50],
[],
[-900,100,50],
[-104880,100,50],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
];
function compareValues(actual, expected) {
assert(Math.abs(expected - actual) < 0.0001);
}
describe('rbg to hsl', function() {
rgbTests.forEach(function(values, index) {
it('should properly convert rgb(' + values[0] + ', ' + values[1] + ', ' + values[2] + ') to hsl(' + hslTests[index][0] + ', ' + hslTests[index][1] + ', ' + hslTests[index][2] + ')', function() {
var color = new Fashion.ColorRGBA(values[0], values[1], values[2]),
expected = new Fashion.ColorHSLA(hslTests[index][0], hslTests[index][1], hslTests[index][2]),
result = color.getHSLA(),
white = expected.l == 100,
black = expected.l == 0,
grayscale = white || black || expected.saturation == 0;
if (!grayscale) {
compareValues(result.h, expected.h);
}
if (!white && !black) {
compareValues(result.s, expected.s);
}
compareValues(result.l, expected.l);
});
});
});
describe('hsl to rgb', function() {
hslTests.forEach(function(values, index) {
it('should properly convert hsl(' + values[0] + ', ' + values[1] + ', ' + values[2] + ') to rgb(' + rgbTests[index][0] + ', ' + rgbTests[index][1] + ', ' + rgbTests[index][2] + ')', function() {
var color = new Fashion.ColorHSLA(values[0], values[1], values[2]),
expected = new Fashion.ColorRGBA(rgbTests[index][0], rgbTests[index][1], rgbTests[index][2]),
result = color.getRGBA();
compareValues(result.r, expected.r);
compareValues(result.g, expected.g);
compareValues(result.b, expected.b);
});
});
});
});