-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
70 lines (57 loc) · 1.74 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
'use strict';
const vm = require('vm');
const fs = require('fs');
const path = require('path');
const fitToWidthPath = require.resolve('./fitToWidth')
const fitToWidthScript = fs.readFileSync(fitToWidthPath);
const fitToWidth = {};
vm.runInNewContext(fitToWidthScript, fitToWidth, {
filename: path.basename(fitToWidthPath),
strict: true
});
const assert = require('assert');
describe('fitToWidth', () => {
describe('coordinates', () => {
it('should work', () => {
const minX = 0; const maxX = 1; const numX = 6;
const minY = 2; const maxY = 4; const numY = 3;
const coordinates = Array.from(fitToWidth.coordinates({
minX, maxX, numX, minY, maxY, numY
}));
assert.deepEqual(coordinates, [
[0, 2], [0.2, 2], [0.4, 2], [0.6, 2], [0.8, 2], [1, 2],
[0, 3], [0.2, 3], [0.4, 3], [0.6, 3], [0.8, 3], [1, 3],
[0, 4], [0.2, 4], [0.4, 4], [0.6, 4], [0.8, 4], [1, 4],
])
})
});
describe('get most common', () => {
it('should work with NaN', () => {
const test = [
1,
'asdf',
NaN,
1,
NaN,
NaN
];
assert(Object.is(fitToWidth.getMostCommon(test), NaN));
});
it('should work with more ordinary values', () => {
const test = [
1,
4,
6,
2,
2,
1,
4,
4,
4,
4,
6
];
assert.deepStrictEqual(fitToWidth.getMostCommon(test), 4);
});
});
});