~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/d3/test/core/hsl-test.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require("../env");
2
 
 
3
 
var vows = require("vows"),
4
 
    assert = require("assert");
5
 
 
6
 
var suite = vows.describe("d3.hsl");
7
 
 
8
 
suite.addBatch({
9
 
  "hsl": {
10
 
    topic: function() {
11
 
      return d3.hsl;
12
 
    },
13
 
    "does not clamp channel values": function(hsl) {
14
 
      assert.hslEqual(hsl(-100, -1, -2), -100, -1, -2);
15
 
      assert.hslEqual(hsl(400, 2, 3), 400, 2, 3);
16
 
    },
17
 
    "converts string channel values to numbers": function(hsl) {
18
 
      assert.hslEqual(hsl("180", ".5", ".6"), 180, .5, .6);
19
 
    },
20
 
    "converts null channel values to zero": function(hsl) {
21
 
      assert.hslEqual(hsl(null, null, null), 0, 0, 0);
22
 
    },
23
 
    "exposes h, s and l properties": function(hsl) {
24
 
      var color = hsl("hsl(180, 50%, 60%)");
25
 
      assert.equal(color.h, 180);
26
 
      assert.equal(color.s, .5);
27
 
      assert.equal(color.l, .6);
28
 
    },
29
 
    "changing h, s or l affects the string format": function(hsl) {
30
 
      var color = hsl("hsl(180, 50%, 60%)");
31
 
      color.h++;
32
 
      color.s += .1;
33
 
      color.l += .1;
34
 
      assert.equal(color + "", "#85dfe0");
35
 
    },
36
 
    "parses hexadecimal shorthand format (e.g., \"#abc\")": function(hsl) {
37
 
      assert.hslEqual(hsl("#abc"), 210, .25, .733333);
38
 
    },
39
 
    "parses hexadecimal format (e.g., \"#abcdef\")": function(hsl) {
40
 
      assert.hslEqual(hsl("#abcdef"), 210, .68, .803922);
41
 
    },
42
 
    "parses HSL format (e.g., \"hsl(210, 64%, 13%)\")": function(hsl) {
43
 
      assert.hslEqual(hsl("hsl(210, 64.7058%, 13.33333%)"), 210, .647058, .133333);
44
 
    },
45
 
    "parses color names (e.g., \"moccasin\")": function(hsl) {
46
 
      assert.hslEqual(hsl("moccasin"), 38.108108, 1, .854902);
47
 
      assert.hslEqual(hsl("aliceblue"), 208, 1, .970588);
48
 
      assert.hslEqual(hsl("yellow"), 60, 1, .5);
49
 
    },
50
 
    "parses and converts RGB format (e.g., \"rgb(102, 102, 0)\")": function(hsl) {
51
 
      assert.hslEqual(hsl("rgb(102, 102, 0)"), 60, 1, .2);
52
 
    },
53
 
    "can convert from RGB": function(hsl) {
54
 
      assert.hslEqual(hsl(d3.rgb(12, 34, 56)), 210, .647058, .133333);
55
 
    },
56
 
    "can convert from HSL": function(hsl) {
57
 
      assert.hslEqual(hsl(d3.hsl(20, .8, .3)), 20, .8, .3);
58
 
    },
59
 
    "can convert to RGB": function(hsl) {
60
 
      assert.rgbEqual(hsl("steelblue").rgb(), 70, 130, 180);
61
 
    },
62
 
    "can derive a brighter color": function(hsl) {
63
 
      assert.hslEqual(hsl("steelblue").brighter(), 207.272727, .44, .7002801);
64
 
      assert.hslEqual(hsl("steelblue").brighter(.5), 207.272727, .44, .5858964);
65
 
      assert.hslEqual(hsl("steelblue").brighter(1), 207.272727, .44, .7002801);
66
 
      assert.hslEqual(hsl("steelblue").brighter(2), 207.272727, .44, 1.0004002);
67
 
    },
68
 
    "can derive a darker color": function(hsl) {
69
 
      assert.hslEqual(hsl("lightsteelblue").darker(), 213.913043, .4107143, .5462745);
70
 
      assert.hslEqual(hsl("lightsteelblue").darker(.5), 213.913043, .4107143, .6529229);
71
 
      assert.hslEqual(hsl("lightsteelblue").darker(1), 213.913043, .4107143, .5462745);
72
 
      assert.hslEqual(hsl("lightsteelblue").darker(2), 213.913043, .4107143, .38239216);
73
 
    },
74
 
    "string coercion returns RGB format": function(hsl) {
75
 
      assert.strictEqual(hsl("hsl(60, 100%, 20%)") + "", "#666600");
76
 
      assert.strictEqual(hsl(d3.hsl(60, 1, .2)) + "", "#666600");
77
 
    }
78
 
  }
79
 
});
80
 
 
81
 
suite.export(module);