forked from gka/chroma.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmix.test.js
99 lines (80 loc) · 3.87 KB
/
mix.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require('es6-shim');
const vows = require('vows');
const assert = require('assert');
const chroma = require('../index');
vows
.describe('Some tests for chroma.color()')
.addBatch({
'hsv interpolation white <-> red': {
topic: chroma('white').interpolate('red', 0.5, 'hsv'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff8080'); }
},
'use mix as alias': {
topic: chroma('white').mix('red', 0.5, 'hsv'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff8080'); }
},
'alternative mix syntax': {
topic: chroma.mix('red', 'blue', 0.25, 'rgb'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#bf0040'); }
},
'hsl interpolation white <-> red': {
topic: chroma('white').interpolate('red', 0.5, 'hsl'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff8080'); }
},
'rgb interpolation white <-> red': {
topic: chroma('white').interpolate('red', 0.5, 'rgb'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff8080'); }
},
'hsv interpolation red <-> white': {
topic: chroma('red').interpolate('white', 0.5, 'hsv'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff8080'); }
},
'hsl interpolation red <-> white': {
topic: chroma('red').interpolate('white', 0.5, 'hsl'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff8080'); }
},
'rgb interpolation red <-> white': {
topic: chroma('red').interpolate('white', 0.5, 'rgb'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff8080'); }
},
'interpolation short function': {
topic: {
f(t) { return chroma.interpolate('#ff0000', '#ffffff', t, 'hsv').hex(); }
},
'starts at red'(topic) { return assert.equal(topic.f(0), '#ff0000'); },
'goes over light red'(topic) { return assert.equal(topic.f(0.5), '#ff8080'); },
'ends at white'(topic) { return assert.equal(topic.f(1), '#ffffff'); }
},
'num interpolation white <-> red': {
topic: chroma(0xffffff).interpolate(0xff0000, 0.5, 'num'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff7fff'); }
},
'num interpolation red <-> white': {
topic: chroma(0xff0000).interpolate(0xffffff, 0.5, 'num'),
'works'(topic) { return assert.deepEqual(topic.hex(), '#ff7fff'); }
},
'interpolation short function with num provided': {
topic: {
f(t) { return chroma.interpolate(0xff0000, 0xffffff, t, 'num').hex(); }
},
'starts at red'(topic) { return assert.equal(topic.f(0), '#ff0000'); },
'goes over light red'(topic) { return assert.equal(topic.f(0.5), '#ff7fff'); },
'ends at white'(topic) { return assert.equal(topic.f(1), '#ffffff'); }
},
'interpolate in num': {
topic: chroma.interpolate(chroma.num(0xffffe0), chroma.num(0x102180), 0.5, 'num'),
'hex'(topic) { return assert.equal(topic.hex(), '#8810b0'); },
'num'(topic) { return assert.equal(topic.num(), 8917168); }
},
'interpolate in hsv': {
topic: chroma.interpolate('white', 'black', 0.5, 'hsv'),
'hex'(topic) { return assert.equal(topic.hex(), '#808080'); }
},
'interpolate in hsl': {
topic: chroma.interpolate('lightyellow', 'navy', 0.5, 'hsl'),
'hex'(topic) { return assert.equal(topic.hex(), '#31ff98'); }
},
'interpolate in lrgb': {
topic: chroma.interpolate('red', 'blue', 0.5, 'lrgb'),
'hex'(topic) { return assert.equal(topic.hex(), '#b400b4'); }
}}).export(module);