percentile-test.js (1852B)
1 var vows = require('vows'); 2 var assert = require('assert'); 3 var suite = vows.describe('jStat.percentile'); 4 5 require('../env.js'); 6 7 //could be compared against MS Excel percentile function 8 suite.addBatch({ 9 'percentile': { 10 'topic': function() { 11 return jStat; 12 }, 13 '30th percentile of the list in the range': function(jStat) { 14 assert.deepEqual(jStat.percentile([1, 2, 3, 4], 0.3), 1.9); 15 }, 16 '30th percentile of the list in the range with exclusive flag true': function(jStat) { 17 assert.deepEqual(jStat.percentile([1, 2, 3, 4], 0.3, true), 1.5); 18 }, 19 '30th percentile of the list in the range, unsorted': function(jStat) { 20 assert.deepEqual(jStat.percentile([3, 1, 4, 2], 0.3), 1.9); 21 }, 22 '40th percentile of the list in the range with exclusive flag false': function(jStat) { 23 assert.epsilon(0.0000001, jStat.percentile([15, 20, 35, 40, 50], 0.4, false), 29); 24 }, 25 '40th percentile of the list in the range with exclusive flag true': function(jStat) { 26 assert.epsilon(0.0000001, jStat.percentile([15, 20, 35, 40, 50], 0.4, true), 26); 27 }, 28 '10th percentile of the list in the range with exclusive flag false': function(jStat) { 29 assert.epsilon(0.0000001, jStat.percentile([15, 20, 35, 40, 50], 0.1, false), 17); 30 }, 31 '10th percentile of the list in the range with exclusive flag true': function(jStat) { 32 assert(isNaN(jStat.percentile([15, 20, 35, 40, 50], 0.1, true))); 33 }, 34 '100th percentile of the list in the range with exclusive flag false': function(jStat) { 35 assert.epsilon(0.0000001, jStat.percentile([15, 20, 35, 40, 50], 1, false), 50); 36 }, 37 '100th percentile of the list in the range with exclusive flag true': function(jStat) { 38 assert(isNaN(jStat.percentile([15, 20, 35, 40, 50], 1, true))); 39 } 40 } 41 }); 42 43 suite.export(module);