time-to-botec/squiggle/node_modules/jstat/test/vector/cumsum-test.js
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

52 lines
1.4 KiB
JavaScript

var vows = require('vows');
var assert = require('assert');
var suite = vows.describe('jStat.cumsum');
require('../env.js');
suite.addBatch({
'cumsum': {
'topic': function() {
return jStat;
},
'return basic cumsum': function(jStat) {
assert.deepEqual(jStat.cumsum([1, 2, 3]), [1, 3, 6]);
},
'cumsum from instance': function(jStat) {
assert.deepEqual(jStat([1, 2, 3]).cumsum(), [1, 3, 6]);
},
'cumsum matrix cols': function(jStat) {
assert.deepEqual(jStat([[1, 2], [3, 4]]).cumsum(), [[1, 4], [2, 6]]);
},
'cumsum matrix rows': function(jStat) {
assert.deepEqual(jStat([[1, 2], [3, 4]]).cumsum(true), [[1, 3], [3, 7]]);
}
},
'#cumsum vector': {
'topic': function() {
jStat([1, 2, 3]).cumsum(this.callback);
},
'cumsum callback': function(val, stat) {
assert.deepEqual(val, [1, 3, 6]);
}
},
'#cumsum matrix cols': {
'topic': function() {
jStat([[1, 2], [3, 4]]).cumsum(this.callback);
},
'cumsum matrix cols callback': function(val, stat) {
assert.deepEqual(val, [[1, 4], [2, 6]]);
}
},
'#cumsum matrix rows': {
'topic': function() {
jStat([[1, 2], [3, 4]]).cumsum(true, this.callback);
},
'cumsum matrix rows callback': function(val, stat) {
assert.deepEqual(val, [[1, 3], [3, 7]]);
}
}
});
suite.export(module);