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
54 lines (50 loc) · 1.18 KB
/
Copy pathindex.js
File metadata and controls
54 lines (50 loc) · 1.18 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
var test = require('../util/test')(__filename);
var stdev = require('../../packages/array-stdev');
test('array of numbers returns standard deviation', function(t) {
t.plan(4);
t.equal(stdev([1, 2, 3]), 1);
t.equal(stdev([1, 2, 3, 2, 4, 1]).toFixed(4), '1.1690');
t.equal(stdev([3, 2.5, 1]).toFixed(4), '1.0408');
t.equal(stdev([1, 2, 3, 4, 5, 6]).toFixed(4), '1.8708');
t.end();
});
test('list of numeric arguments returns standard deviation', function(t) {
t.plan(4);
t.equal(stdev(2, 6, 4), 2);
t.equal(stdev(10, 10, 10, 10), 0);
t.equal(stdev(-1, -2, -3), 1);
t.equal(stdev(0.1, 0.2, 0.3).toFixed(2), '0.10');
t.end();
});
test('one or fewer values throw', function(t) {
t.plan(4);
t.throws(function() {
stdev([1]);
});
t.throws(function() {
stdev(17.1);
});
t.throws(function() {
stdev();
});
t.throws(function() {
stdev([]);
});
t.end();
});
test('non-numeric values throw', function(t) {
t.plan(4);
t.throws(function() {
stdev(['1', '2', '3']);
});
t.throws(function() {
stdev(['a', 'b', 'c']);
});
t.throws(function() {
stdev(undefined);
});
t.throws(function() {
stdev([NaN, NaN]);
});
t.end();
});