forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (56 loc) · 1.41 KB
/
Copy pathindex.js
File metadata and controls
61 lines (56 loc) · 1.41 KB
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
var test = require('../util/test')(__filename);
var skewness = require('../../packages/array-skewness');
test('array of numbers returns skewness', function(t) {
t.plan(4);
t.equal(skewness([10, 30, 50, 70]), 0);
t.equal(skewness([1, 2, 3, 2, 4, 1]).toFixed(4), '0.4277');
t.equal(skewness([1, 2, 3, 4, 9]).toFixed(4), '0.7706');
t.equal(skewness([-3, 1, -2]).toFixed(4), '0.9608');
t.end();
});
test('list of numeric arguments returns skewness', function(t) {
t.plan(4);
t.equal(skewness(2, 6, 4), 0);
t.equal(skewness(4, 4, 4, 19), 1.5);
t.equal(skewness(-1, -2, -9).toFixed(4), '-1.3765');
t.equal(skewness(34, 0, 0, 0, 0).toFixed(4), '1.3416');
t.end();
});
test('identical numbers returns NaN', function(t) {
t.plan(2);
t.equal(String(skewness(10, 10, 10, 10)), 'NaN');
t.equal(String(skewness(0, 0, 0)), 'NaN');
t.end();
});
test('one or fewer values throw', function(t) {
t.plan(4);
t.throws(function() {
skewness([1]);
});
t.throws(function() {
skewness(17.1);
});
t.throws(function() {
skewness();
});
t.throws(function() {
skewness([]);
});
t.end();
});
test('non-numeric values throw', function(t) {
t.plan(4);
t.throws(function() {
skewness(['1', '2', '3']);
});
t.throws(function() {
skewness(['a', 'b', 'c']);
});
t.throws(function() {
skewness(undefined);
});
t.throws(function() {
skewness([NaN, NaN]);
});
t.end();
});