histogram-test.js (1083B)
1 var vows = require('vows'); 2 var assert = require('assert'); 3 var suite = vows.describe('jStat.histogram'); 4 5 require('../env.js'); 6 7 suite.addBatch({ 8 'histogram': { 9 'topic': function() { 10 return jStat; 11 }, 12 'returns histogram (bin counts)': function(jStat) { 13 assert.deepEqual( 14 jStat.histogram([1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8]), [4, 2, 3, 2]); 15 }, 16 'histogram from instance': function(jStat) { 17 assert.deepEqual( 18 jStat([1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8]).histogram(), [4, 2, 3, 2]); 19 }, 20 'histogram with numBins parameter': function(jStat) { 21 assert.deepEqual( 22 jStat([1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 10]).histogram(10), 23 [2, 2, 1, 1, 2, 1, 1, 1, 0, 1]); 24 }, 25 'histogram with floating point values': function(jStat) { 26 assert.deepEqual( 27 jStat([0.1, 0.1, 0.3, 0.5]).histogram(3), [2, 1, 1]); 28 }, 29 'documentation values': function(jStat) { 30 assert.deepEqual( 31 jStat.histogram([100, 101, 102, 230, 304, 305, 400], 3), [3, 1, 3]); 32 } 33 } 34 }); 35 36 suite.export(module);