UNPKG

@sencha/cmd-linux-64

Version:

Productivity and performance optimization tool for building applications with Sencha Ext JS

330 lines (324 loc) 8.02 kB
var Fashion = require('../../index.js'); var assert = require('assert'); describe('color conversions', function() { var rgbTests = [ [255,0,0], [255,255,0], [0,255,0], [0,255,255], [0,0,255], [255,0,255], [255,0,0], [255,255,0], [0,255,0], [0,255,255], [0,0,255], [255,0,255], [255,0,0], [255,255,0], [0,255,0], [0,255,255], [0,0,255], [255,0,255], [255,0,0], [255,255,0], [0,255,0], [0,255,255], [0,0,255], [255,0,255], [255,0,0], [255,51,0], [255,102,0], [255,153,0], [255,204,0], [255,255,0], [204,255,0], [153,255,0], [102,255,0], [51,255,0], [0,255,0], [0,255,0], [0,255,51], [0,255,102], [0,255,153], [0,255,204], [0,255,255], [0,204,255], [0,153,255], [0,102,255], [0,51,255], [0,0,255], [0,0,255], [51,0,255], [102,0,255], [153,0,255], [204,0,255], [255,0,255], [255,0,204], [255,0,153], [255,0,102], [255,0,51], [255,0,0], [153,102,102], [204,51,51], [255,0,0], [153,153,102], [204,204,51], [255,255,0], [102,153,102], [51,204,51], [0,255,0], [102,153,153], [51,204,204], [0,255,255], [102,102,153], [51,51,204], [0,0,255], [153,102,153], [204,51,204], [255,0,255], [0,0,0], [51,0,0], [102,0,0], [153,0,0], [204,0,0], [255,0,0], [255,51,51], [255,102,102], [255,153,153], [255,204,204], [255,255,255], [0,0,0], [51,51,0], [102,102,0], [153,153,0], [204,204,0], [255,255,0], [255,255,51], [255,255,102], [255,255,153], [255,255,204], [255,255,255], [0,0,0], [0,51,0], [0,102,0], [0,153,0], [0,204,0], [0,255,0], [51,255,51], [102,255,102], [153,255,153], [204,255,204], [255,255,255], [0,0,0], [0,51,51], [0,102,102], [0,153,153], [0,204,204], [0,255,255], [51,255,255], [102,255,255], [153,255,255], [204,255,255], [255,255,255], [0,0,0], [0,0,51], [0,0,102], [0,0,153], [0,0,204], [0,0,255], [51,51,255], [102,102,255], [153,153,255], [204,204,255], [255,255,255], [0,0,0], [51,0,51], [102,0,102], [153,0,153], [204,0,204], [255,0,255], [255,51,255], [255,102,255], [255,153,255], [255,204,255], [255,255,255] ]; var hslTests = [ [0,100,50], [60,100,50], [120,100,50], [180,100,50], [240,100,50], [300,100,50], [-360,100,50], [-300,100,50], [-240,100,50], [-180,100,50], [-120,100,50], [-60,100,50], [360,100,50], [420,100,50], [480,100,50], [540,100,50], [600,100,50], [660,100,50], [6120,100,50], [-9660,100,50], [99840,100,50], [-900,100,50], [-104880,100,50], [2820,100,50], [0,100,50], [12,100,50], [24,100,50], [36,100,50], [48,100,50], [60,100,50], [72,100,50], [84,100,50], [96,100,50], [108,100,50], [120,100,50], [120,100,50], [132,100,50], [144,100,50], [156,100,50], [168,100,50], [180,100,50], [192,100,50], [204,100,50], [216,100,50], [228,100,50], [240,100,50], [240,100,50], [252,100,50], [264,100,50], [276,100,50], [288,100,50], [300,100,50], [312,100,50], [324,100,50], [336,100,50], [348,100,50], [360,100,50], [0,20,50], [0,60,50], [0,100,50], [60,20,50], [60,60,50], [60,100,50], [120,20,50], [120,60,50], [120,100,50], [180,20,50], [180,60,50], [180,100,50], [240,20,50], [240,60,50], [240,100,50], [300,20,50], [300,60,50], [300,100,50], [0,100,0], [0,100,10], [0,100,20], [0,100,30], [0,100,40], [0,100,50], [0,100,60], [0,100,70], [0,100,80], [0,100,90], [0,100,100], [60,100,0], [60,100,10], [60,100,20], [60,100,30], [60,100,40], [60,100,50], [60,100,60], [60,100,70], [60,100,80], [60,100,90], [60,100,100], [120,100,0], [120,100,10], [120,100,20], [120,100,30], [120,100,40], [120,100,50], [120,100,60], [120,100,70], [120,100,80], [120,100,90], [120,100,100], [180,100,0], [180,100,10], [180,100,20], [180,100,30], [180,100,40], [180,100,50], [180,100,60], [180,100,70], [180,100,80], [180,100,90], [180,100,100], [240,100,0], [240,100,10], [240,100,20], [240,100,30], [240,100,40], [240,100,50], [240,100,60], [240,100,70], [240,100,80], [240,100,90], [240,100,100], [300,100,0], [300,100,10], [300,100,20], [300,100,30], [300,100,40], [300,100,50], [300,100,60], [300,100,70], [300,100,80], [300,100,90], [300,100,100] ]; 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); }); }); }); });