diff options
Diffstat (limited to 'includes/js/dojox/color/tests')
-rw-r--r-- | includes/js/dojox/color/tests/Generator.js | 128 | ||||
-rw-r--r-- | includes/js/dojox/color/tests/_base.js | 82 | ||||
-rw-r--r-- | includes/js/dojox/color/tests/color.js | 14 | ||||
-rw-r--r-- | includes/js/dojox/color/tests/runTests.html | 9 |
4 files changed, 233 insertions, 0 deletions
diff --git a/includes/js/dojox/color/tests/Generator.js b/includes/js/dojox/color/tests/Generator.js new file mode 100644 index 0000000..6232cc7 --- /dev/null +++ b/includes/js/dojox/color/tests/Generator.js @@ -0,0 +1,128 @@ +if(!dojo._hasResource["dojox.color.tests.Generator"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.color.tests.Generator"] = true; +dojo.provide("dojox.color.tests.Generator"); +dojo.require("dojox.color.Generator"); + +tests.register("dojox.color.tests.Generator", [ + function testAnalogous(t){ + // test the defaults + var args={ base: new dojox.color.Color({ r:128, g:0, b:0 }) }; + var a=dojox.color.Generator.analogous(args); + var s='<h3>dojox.color.Generator.analogous</h3><table cellpadding="0" cellspacing="1" border="0"><tr>'; + var cols=5, c=0; + dojo.forEach(a, function(item){ + if(c++%cols==0){ s+="</tr><tr>"; } + s+='<td width="32" bgcolor="'+item.toHex()+'"> </td>'; + }); + if(c<cols){ + for(; c<cols; c++){ + s+='<td width="32"> </td>'; + } + } + t.debug(s+'</tr></table>'); + }, + + function testMonochromatic(t){ + // test the defaults + var a=dojox.color.Generator.monochromatic({ base:new dojox.color.Color({r:128, g:0, b:0}) }); + var s='<h3>dojox.color.Generator.monochromatic</h3><table cellpadding="0" cellspacing="1" border="0"><tr>'; + var cols=8, c=0; + dojo.forEach(a, function(item){ + if(c++%cols==0){ s+="</tr><tr>"; } + s+='<td width="32" bgcolor="'+item.toHex()+'"> </td>'; + }); + if(c<cols){ + for(; c<cols; c++){ + s+='<td width="32"> </td>'; + } + } + t.debug(s+'</tr></table>'); + }, + + function testTriadic(t){ + // test the defaults + var a=dojox.color.Generator.triadic({ base:new dojox.color.Color({r:128, g:0, b:0}) }); + var s='<h3>dojox.color.Generator.triadic</h3><table cellpadding="0" cellspacing="1" border="0"><tr>'; + var cols=3, c=0; + dojo.forEach(a, function(item){ + if(c++%cols==0){ s+="</tr><tr>"; } + s+='<td width="32" bgcolor="'+item.toHex()+'"> </td>'; + }); + if(c<cols){ + for(; c<cols; c++){ + s+='<td width="32"> </td>'; + } + } + t.debug(s+'</tr></table>'); + }, + + function testComplementary(t){ + // test the defaults + var a=dojox.color.Generator.complementary({ base:new dojox.color.Color({r:128, g:0, b:0}) }); + var s='<h3>dojox.color.Generator.complementary</h3><table cellpadding="0" cellspacing="1" border="0"><tr>'; + var cols=2, c=0; + dojo.forEach(a, function(item){ + if(c++%cols==0){ s+="</tr><tr>"; } + s+='<td width="32" bgcolor="'+item.toHex()+'"> </td>'; + }); + if(c<cols){ + for(; c<cols; c++){ + s+='<td width="32"> </td>'; + } + } + t.debug(s+'</tr></table>'); + }, + + function testSplitComplementary(t){ + // test the defaults + var a=dojox.color.Generator.splitComplementary({ base:new dojox.color.Color({r:128, g:0, b:0}) }); + var s='<h3>dojox.color.Generator.splitComplementary</h3><table cellpadding="0" cellspacing="1" border="0"><tr>'; + var cols=3, c=0; + dojo.forEach(a, function(item){ + if(c++%cols==0){ s+="</tr><tr>"; } + s+='<td width="32" bgcolor="'+item.toHex()+'"> </td>'; + }); + if(c<cols){ + for(; c<cols; c++){ + s+='<td width="32"> </td>'; + } + } + t.debug(s+'</tr></table>'); + }, + + function testCompound(t){ + // test the defaults + var a=dojox.color.Generator.compound({ base:new dojox.color.Color({r:128, g:0, b:0}) }); + var s='<h3>dojox.color.Generator.compound</h3><table cellpadding="0" cellspacing="1" border="0"><tr>'; + var cols=4, c=0; + dojo.forEach(a, function(item){ + if(c++%cols==0){ s+="</tr><tr>"; } + s+='<td width="32" bgcolor="'+item.toHex()+'"> </td>'; + }); + if(c<cols){ + for(; c<cols; c++){ + s+='<td width="32"> </td>'; + } + } + t.debug(s+'</tr></table>'); + }, + + function testShades(t){ + // test the defaults + var a=dojox.color.Generator.shades({ base:new dojox.color.Color({r:128, g:0, b:0}) }); + var s='<table cellpadding="0" cellspacing="1" border="0"><tr>'; + var cols=8, c=0; + dojo.forEach(a, function(item){ + if(c++%cols==0){ s+="</tr><tr>"; } + s+='<td width="32" bgcolor="'+item.toHex()+'"> </td>'; + }); + if(c<cols){ + for(; c<cols; c++){ + s+='<td width="32"> </td>'; + } + } + t.debug(s+'</tr></table>'); + } +]); + +} diff --git a/includes/js/dojox/color/tests/_base.js b/includes/js/dojox/color/tests/_base.js new file mode 100644 index 0000000..cb96223 --- /dev/null +++ b/includes/js/dojox/color/tests/_base.js @@ -0,0 +1,82 @@ +if(!dojo._hasResource["dojox.color.tests._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.color.tests._base"] = true; +dojo.provide("dojox.color.tests._base"); +dojo.require("dojox.color"); + +/************************************************************ + * Note that some color translations are not exact, + * due to the need to round calculations in translation. + * + * These tests work with grey, the primary colors and + * one secondary color to ensure that extreme calculation + * is correct. + ************************************************************/ + +tests.register("dojox.color.tests._base", [ + function testStaticMethods(t){ + // fromCmy + t.assertEqual(dojox.color.fromCmy({ c:50, m:50, y:50}), new dojo.Color({ r:128, g:128, b:128 })); + t.assertEqual(dojox.color.fromCmy({ c:0, m:100, y:100}), new dojo.Color({ r:255, g:0, b:0 })); + t.assertEqual(dojox.color.fromCmy({ c:100, m:0, y:100}), new dojo.Color({ r:0, g:255, b:0 })); + t.assertEqual(dojox.color.fromCmy({ c:100, m:100, y:0}), new dojo.Color({ r:0, g:0, b:255 })); + t.assertEqual(dojox.color.fromCmy({ c:0, m:0, y:100}), new dojo.Color({ r:255, g:255, b:0 })); + + // fromCmyk + t.assertEqual(dojox.color.fromCmyk({ c:0, m:0, y:0, b:50}), new dojo.Color({ r:128, g:128, b:128 })); + t.assertEqual(dojox.color.fromCmyk({ c:0, m:100, y:100, b:0}), new dojo.Color({ r:255, g:0, b:0 })); + t.assertEqual(dojox.color.fromCmyk({ c:100, m:0, y:100, b:0}), new dojo.Color({ r:0, g:255, b:0 })); + t.assertEqual(dojox.color.fromCmyk({ c:100, m:100, y:0, b:0}), new dojo.Color({ r:0, g:0, b:255 })); + t.assertEqual(dojox.color.fromCmyk({ c:0, m:0, y:100, b:0}), new dojo.Color({ r:255, g:255, b:0 })); + + // fromHsl + t.assertEqual(dojox.color.fromHsl({ h:0, s:0, l:50}), new dojo.Color({ r:128, g:128, b:128 })); + t.assertEqual(dojox.color.fromHsl({ h:0, s:100, l:50}), new dojo.Color({ r:255, g:0, b:0 })); + t.assertEqual(dojox.color.fromHsl({ h:120, s:100, l:50}), new dojo.Color({ r:0, g:255, b:0 })); + t.assertEqual(dojox.color.fromHsl({ h:240, s:100, l:50}), new dojo.Color({ r:0, g:0, b:255 })); + t.assertEqual(dojox.color.fromHsl({ h:60, s:100, l:50}), new dojo.Color({ r:255, g:255, b:0 })); + + // fromHsv + t.assertEqual(dojox.color.fromHsv({ h:0, s:0, v:50}), new dojo.Color({ r:128, g:128, b:128 })); + t.assertEqual(dojox.color.fromHsv({ h:0, s:100, v:100}), new dojo.Color({ r:255, g:0, b:0 })); + t.assertEqual(dojox.color.fromHsv({ h:120, s:100, v:100}), new dojo.Color({ r:0, g:255, b:0 })); + t.assertEqual(dojox.color.fromHsv({ h:240, s:100, v:100}), new dojo.Color({ r:0, g:0, b:255 })); + t.assertEqual(dojox.color.fromHsv({ h:60, s:100, v:100}), new dojo.Color({ r:255, g:255, b:0 })); + }, + function testColorExtensions(t){ + var grey=new dojox.color.Color({ r:128, g:128, b:128 }); + var red=new dojox.color.Color({ r:255, g:0, b:0 }); + var green=new dojox.color.Color({ r:0, g:255, b:0 }); + var blue=new dojox.color.Color({ r:0, g:0, b:255 }); + var yellow=new dojox.color.Color({ r:255, g:255, b:0 }); + + // toCmy + t.assertEqual(grey.toCmy(), { c:50, m:50, y:50 }); + t.assertEqual(red.toCmy(), { c:0, m:100, y:100 }); + t.assertEqual(green.toCmy(), { c:100, m:0, y:100 }); + t.assertEqual(blue.toCmy(), { c:100, m:100, y:0 }); + t.assertEqual(yellow.toCmy(), { c:0, m:0, y:100 }); + + // toCmyk + t.assertEqual(grey.toCmyk(), { c:0, m:0, y:0, b:50 }); + t.assertEqual(red.toCmyk(), { c:0, m:100, y:100, b:0 }); + t.assertEqual(green.toCmyk(), { c:100, m:0, y:100, b:0 }); + t.assertEqual(blue.toCmyk(), { c:100, m:100, y:0, b:0 }); + t.assertEqual(yellow.toCmyk(), { c:0, m:0, y:100, b:0 }); + + // toHsl + t.assertEqual(grey.toHsl(), { h:0, s:0, l:50 }); + t.assertEqual(red.toHsl(), { h:0, s:100, l:50 }); + t.assertEqual(green.toHsl(), { h:120, s:100, l:50 }); + t.assertEqual(blue.toHsl(), { h:240, s:100, l:50 }); + t.assertEqual(yellow.toHsl(), { h:60, s:100, l:50 }); + + // toHsv + t.assertEqual(grey.toHsv(), { h:0, s:0, v:50 }); + t.assertEqual(red.toHsv(), { h:0, s:100, v:100 }); + t.assertEqual(green.toHsv(), { h:120, s:100, v:100 }); + t.assertEqual(blue.toHsv(), { h:240, s:100, v:100 }); + t.assertEqual(yellow.toHsv(), { h:60, s:100, v:100 }); + } +]); + +} diff --git a/includes/js/dojox/color/tests/color.js b/includes/js/dojox/color/tests/color.js new file mode 100644 index 0000000..74438f6 --- /dev/null +++ b/includes/js/dojox/color/tests/color.js @@ -0,0 +1,14 @@ +if(!dojo._hasResource["dojox.color.tests.color"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.color.tests.color"] = true; +dojo.provide("dojox.color.tests.color"); +dojo.require("dojox.color"); + +try{ + dojo.require("dojox.color.tests._base"); +// dojo.require("dojox.color.tests.Colorspace"); + dojo.require("dojox.color.tests.Generator"); +}catch(e){ + doh.debug(e); +} + +} diff --git a/includes/js/dojox/color/tests/runTests.html b/includes/js/dojox/color/tests/runTests.html new file mode 100644 index 0000000..9376e20 --- /dev/null +++ b/includes/js/dojox/color/tests/runTests.html @@ -0,0 +1,9 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> + <head> + <title>Dojox.wire Unit Test Runner</title> + <meta http-equiv="REFRESH" content="0;url=../../../util/doh/runner.html?testModule=dojox.color.tests.color"></HEAD> + <BODY> + Redirecting to D.O.H runner. + </BODY> +</HTML> |