-
Notifications
You must be signed in to change notification settings - Fork 0
/
grafi-formatter.test.js
33 lines (29 loc) · 1.1 KB
/
grafi-formatter.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
var assert = require('assert')
var grafi = require('./grafi-formatter')
// setup
var length = 400
var width = 10
var height = 10
var imageData = grafi.formatter(new Uint8ClampedArray(length), width, height)
// check what is returned from formatter
assert(imageData.width === width,
'imageData.width is same as requested width')
assert(imageData.height === height,
'imageData.height is same as requested height')
assert(imageData.data.length === length,
'imageData.data is same length as requested pixel data')
assert(imageData.data instanceof Uint8ClampedArray,
'datatype of imageData.data is Uint8ClampedArray')
// try intentionally cause Error
try {
grafi.formatter(new Uint8ClampedArray(length - 1), width, height)
} catch (e) {
assert(e.message === 'data and size of the image does now match',
'it should throw Error if length of pixel data does not match with available pixels')
}
try {
grafi.formatter(new Array(length), width, height)
} catch (e) {
assert(e.message === 'pixel data passed is not an Uint8ClampedArray',
'it should throw Error if non-Uint8ClampedArray is passed as pixel data')
}