jstat-test.js (1848B)
1 var vows = require('vows'); 2 var assert = require('assert'); 3 var suite = vows.describe('jStat'); 4 5 require('../env.js'); 6 7 suite.addBatch({ 8 'jStat': { 9 'topic': function() { 10 return jStat; 11 }, 12 13 'basic checks': function(jStat) { 14 assert.isFunction(jStat.prototype.toArray); 15 assert.isFunction(jStat.prototype.push); 16 assert.isFunction(jStat.prototype.sort); 17 assert.isFunction(jStat.prototype.splice); 18 19 assert.deepEqual(jStat().toArray(), []); 20 assert.deepEqual(jStat(null).toArray(), []); 21 assert.deepEqual(jStat(undefined).toArray(), []); 22 assert.deepEqual(jStat([]).toArray(), []); 23 24 assert.isTrue(jStat._init.constructor === jStat); 25 assert.isTrue(jStat._init.prototype === jStat.prototype); 26 assert.isTrue(jStat() instanceof jStat); 27 assert.isTrue(jStat(null) instanceof jStat); 28 assert.isTrue(jStat(undefined) instanceof jStat); 29 assert.isTrue(jStat([]) instanceof jStat); 30 31 assert.equal(jStat.prototype.length, 0); 32 assert.equal(jStat([1, 2, 3]).length, 1); 33 assert.equal(jStat([1, 2, 3])[0].length, 3); 34 }, 35 36 'matrix/vector generation': function(jStat) { 37 assert.deepEqual(jStat([1, 2, 3]).toArray(), [1, 2, 3]); 38 assert.deepEqual(jStat([[1, 2], [3, 4]]).toArray(), [[1, 2], [3, 4]]); 39 assert.deepEqual(jStat(jStat([[1, 2], [3, 4]])).toArray(), 40 [[1, 2], [3, 4]]); 41 assert.deepEqual(jStat([[1, 2], [3, 4]], function(x) { 42 return x * 2; 43 }).toArray(), [[2, 4], [6, 8]]); 44 }, 45 46 'sequence generation': function(jStat) { 47 assert.deepEqual(jStat(0, 0.5, 6).toArray(), 48 [0, 0.1, 0.2, 0.3, 0.4, 0.5]); 49 assert.deepEqual(jStat(0, 5, 6, function(x) { 50 return x * 2; 51 }).toArray(), [0, 2, 4, 6, 8, 10]); 52 } 53 } 54 }); 55 56 suite.export(module);