time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

mode-test.js (1258B)


      1 var vows = require('vows');
      2 var assert = require('assert');
      3 var suite = vows.describe('jStat.mode');
      4 
      5 require('../env.js');
      6 
      7 suite.addBatch({
      8   'mode': {
      9     'topic': function() {
     10       return jStat;
     11     },
     12     'return basic mode': function(jStat) {
     13       assert.equal(jStat.mode([1, 2, 3, 3]), 3);
     14     },
     15     'mode from instance': function(jStat) {
     16       assert.equal(jStat([1, 2, 3, 3]).mode(), 3);
     17     },
     18     'mode matrix cols': function(jStat) {
     19       assert.deepEqual(jStat([[1, 2], [1, 4]]).mode(), [1, [2, 4]]);
     20     }
     21   },
     22   '#mode vector': {
     23     'topic': function() {
     24       jStat([1, 2, 3, 3]).mode(this.callback);
     25     },
     26     'mode callback': function(val, stat) {
     27       assert.equal(val, 3);
     28     }
     29   },
     30   '#mode matrix cols': {
     31     'topic': function() {
     32       jStat([[1, 2], [1, 4]]).mode(this.callback);
     33     },
     34     'mode matrix cols callback': function(val, stat) {
     35       assert.deepEqual(val, [1, [2, 4]]);
     36     },
     37   },
     38   'mode of a matrix': {
     39     'topic': function() {
     40       return jStat;
     41     },
     42     'mode matrix cols with true returns the "mode of the matrix"': function() {
     43       assert.equal(jStat([[1, 2], [1, 4], [1, 4]]).mode(true), 1);
     44       assert.equal(jStat([[5, 2], [5, 4], [5, 4]]).mode(true), 5);
     45     }
     46   }
     47 });
     48 
     49 suite.export(module);