-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathtest.js
84 lines (62 loc) · 1.78 KB
/
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
var colormap = require('.'),
test = require('tape');
test('is object - object', function(t) {
t.plan(1);
var n = 15,
cg,
check = true;
// Display all the colormaps
var cms = ['jet', 'hsv' ,'hot', 'cool', 'spring', 'summer', 'autumn',
'winter', 'greys', 'bone', 'copper'];
for (var i = 0; i < cms.length; i++) {
cg = colormap({'colormap': cms[i], 'nshades': n });
check = check & (cg.length == n);
}
t.ok(check);
});
test('alpha config creates rgba arrays with correct alpha', function (t) {
var alpha = 0.5;
var rgba = colormap({
colormap: 'greys',
format: 'rgba',
alpha: alpha
});
var firstRgba = rgba[0];
var lastRgba = rgba[rgba.length - 1];
t.equal(firstRgba[3], alpha);
t.equal(lastRgba[3], alpha);
t.end();
});
test('user colormap alpha values override alpha config', function (t) {
var alphaconfig = 0.8;
var alpha = 0.5;
var map = [
{index:0, rgb:[0, 0, 0, alpha]},
{index:1, rgb:[255, 255, 255, alpha]}
];
var rgba = colormap({
colormap: map,
alpha: [alphaconfig, alphaconfig],
format: 'rgba'
});
var firstRgba = rgba[0];
var lastRgba = rgba[rgba.length - 1];
t.equal(firstRgba[3], alpha);
t.equal(lastRgba[3], alpha);
t.end();
});
test('alphamap values are computed independently between runs', function(t) {
var blueRed = colormap({
colormap: "bluered",
format: "rgba",
alpha: [0, 1]
});
var blueRed2 = colormap({
colormap: "bluered",
format: "rgba",
alpha: [0, 0.5]
});
t.same(blueRed[blueRed.length - 1], [ 255, 0, 0, 1 ]);
t.same(blueRed2[blueRed2.length - 1], [ 255, 0, 0, 0.5 ]);
t.end();
});