Permalink
Browse files

Update more tests

  • Loading branch information...
1 parent 670f6dd commit 8081920a20c8535c1bf4ceb4de75632adf8c5ecf @tmcw tmcw committed Dec 17, 2012
Showing with 90 additions and 64 deletions.
  1. +29 −27 test/bayes.test.js
  2. +14 −4 test/linear_regression.test.js
  3. +10 −2 test/mean.test.js
  4. +15 −15 test/mixin.test.js
  5. +7 −5 test/sum.test.js
  6. +5 −3 test/t_test.test.js
  7. +10 −8 test/variance.test.js
View
56 test/bayes.test.js
@@ -1,34 +1,36 @@
var assert = require('assert');
var ss = require('../');
-it('makes an easy call with one training round', function() {
- var bayes = ss.bayesian();
- bayes.train({ species: 'Cat' }, 'animal');
- assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 1 });
-});
+describe('bayes', function() {
+ it('makes an easy call with one training round', function() {
+ var bayes = ss.bayesian();
+ bayes.train({ species: 'Cat' }, 'animal');
+ assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 1 });
+ });
-it('makes fify-fifty call', function() {
- var bayes = ss.bayesian();
- bayes.train({ species: 'Cat' }, 'animal');
- bayes.train({ species: 'Cat' }, 'chair');
- assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 0.5, chair: 0.5 });
-});
+ it('makes fify-fifty call', function() {
+ var bayes = ss.bayesian();
+ bayes.train({ species: 'Cat' }, 'animal');
+ bayes.train({ species: 'Cat' }, 'chair');
+ assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 0.5, chair: 0.5 });
+ });
-it('makes seventy-five/twenty-five call', function() {
- var bayes = ss.bayesian();
- bayes.train({ species: 'Cat' }, 'animal');
- bayes.train({ species: 'Cat' }, 'animal');
- bayes.train({ species: 'Cat' }, 'animal');
- bayes.train({ species: 'Cat' }, 'chair');
- assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 0.75, chair: 0.25 });
-});
+ it('makes seventy-five/twenty-five call', function() {
+ var bayes = ss.bayesian();
+ bayes.train({ species: 'Cat' }, 'animal');
+ bayes.train({ species: 'Cat' }, 'animal');
+ bayes.train({ species: 'Cat' }, 'animal');
+ bayes.train({ species: 'Cat' }, 'chair');
+ assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 0.75, chair: 0.25 });
+ });
-it('classifies multiple things', function() {
- var bayes = ss.bayesian();
- bayes.train({ species: 'Cat' }, 'animal');
- bayes.train({ species: 'Dog' }, 'animal');
- bayes.train({ species: 'Dog' }, 'animal');
- bayes.train({ species: 'Cat' }, 'chair');
- assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 0.25, chair: 0.25 });
- assert.deepEqual(bayes.score({ species: 'Dog' }), { animal: 0.5, chair: 0 });
+ it('classifies multiple things', function() {
+ var bayes = ss.bayesian();
+ bayes.train({ species: 'Cat' }, 'animal');
+ bayes.train({ species: 'Dog' }, 'animal');
+ bayes.train({ species: 'Dog' }, 'animal');
+ bayes.train({ species: 'Cat' }, 'chair');
+ assert.deepEqual(bayes.score({ species: 'Cat' }), { animal: 0.25, chair: 0.25 });
+ assert.deepEqual(bayes.score({ species: 'Dog' }), { animal: 0.5, chair: 0 });
+ });
});
View
18 test/linear_regression.test.js
@@ -1,8 +1,18 @@
var assert = require('assert');
var ss = require('../');
-it('correctly generates a line for a 0, 0 to 1, 1 dataset', function() {
- var l = ss.linear_regression().data([[0, 0], [1, 1]]);
- assert.equal(l.line()(0), 0);
- assert.equal(l.line()(1), 1);
+describe('linear regression', function() {
+ it('correctly generates a line for a 0, 0 to 1, 1 dataset', function() {
+ var l = ss.linear_regression().data([[0, 0], [1, 1]]);
+ assert.equal(l.line()(0), 0);
+ assert.equal(l.line()(0.5), 0.5);
+ assert.equal(l.line()(1), 1);
+ });
+
+ it('correctly generates a line for a 0, 0 to 1, 0 dataset', function() {
+ var l = ss.linear_regression().data([[0, 0], [1, 0]]);
+ assert.equal(l.line()(0), 0);
+ assert.equal(l.line()(0.5), 0);
+ assert.equal(l.line()(1), 0);
+ });
});
View
12 test/mean.test.js
@@ -1,6 +1,14 @@
var assert = require('assert');
var ss = require('../');
-it('can get the mean of two numbers', function() {
- assert.equal(ss.mean([1, 2]), 1.5);
+describe('mean', function() {
+ it('can get the mean of two numbers', function() {
+ assert.equal(ss.mean([1, 2]), 1.5);
+ });
+ it('can get the mean of one number', function() {
+ assert.equal(ss.mean([1]), 1);
+ });
+ it('an empty list has no average', function() {
+ assert.equal(ss.mean([]), null);
+ });
});
View
30 test/mixin.test.js
@@ -1,20 +1,20 @@
var assert = require('assert');
var ss = require('../');
-// Data and results from
-// [Wikipedia](http://en.wikipedia.org/wiki/Quantile#Quantiles_of_a_population)
-it('can mix in', function() {
- ss.mixin();
- var even = [2, 4, 6, 8];
- assert.equal(even.sum(), 20);
- assert.equal(even.mean(), 5);
- assert.equal(even.max(), 8);
- assert.equal(even.min(), 2);
-});
+describe('mixin', function() {
+ it('can mix in', function() {
+ ss.mixin();
+ var even = [2, 4, 6, 8];
+ assert.equal(even.sum(), 20);
+ assert.equal(even.mean(), 5);
+ assert.equal(even.max(), 8);
+ assert.equal(even.min(), 2);
+ });
-it('mixins can take arguments', function() {
- ss.mixin();
- var even = [2, 4, 6, 8];
- assert.equal(even.quantile(0.2), 2);
- assert.equal(even.quantile(0.8), 8);
+ it('mixins can take arguments', function() {
+ ss.mixin();
+ var even = [2, 4, 6, 8];
+ assert.equal(even.quantile(0.2), 2);
+ assert.equal(even.quantile(0.8), 8);
+ });
});
View
12 test/sum.test.js
@@ -1,10 +1,12 @@
var assert = require('assert');
var ss = require('../');
-it('can get the sum of two numbers', function() {
- assert.equal(ss.sum([1, 2]), 3);
-});
+describe('sum', function() {
+ it('can get the sum of two numbers', function() {
+ assert.equal(ss.sum([1, 2]), 3);
+ });
-it('the sum of no numbers is zero', function() {
- assert.equal(ss.sum([]), 0);
+ it('the sum of no numbers is zero', function() {
+ assert.equal(ss.sum([]), 0);
+ });
});
View
8 test/t_test.test.js
@@ -1,7 +1,9 @@
var assert = require('assert');
var ss = require('../');
-it('can compare a known value to the mean of samples', function() {
- var t = ss.t_test([1, 2, 3, 4, 5, 6], 3.385);
- assert.equal(t, 0.1649415480881466);
+describe('t test', function() {
+ it('can compare a known value to the mean of samples', function() {
+ var t = ss.t_test([1, 2, 3, 4, 5, 6], 3.385);
+ assert.equal(t, 0.1649415480881466);
+ });
});
View
18 test/variance.test.js
@@ -5,14 +5,16 @@ function rnd(x) {
return Math.round(x * 1000) / 1000;
}
-it('can get the variance of a six-sided die', function() {
- assert.equal(rnd(ss.variance([1, 2, 3, 4, 5, 6])), 2.917);
-});
+describe('variance', function() {
+ it('can get the variance of a six-sided die', function() {
+ assert.equal(rnd(ss.variance([1, 2, 3, 4, 5, 6])), 2.917);
+ });
-it('the variance of one number is zero', function() {
- assert.equal(rnd(ss.variance([1])), 0);
-});
+ it('the variance of one number is zero', function() {
+ assert.equal(rnd(ss.variance([1])), 0);
+ });
-it('the variance of no numbers is null', function() {
- assert.equal(ss.variance([]), null);
+ it('the variance of no numbers is null', function() {
+ assert.equal(ss.variance([]), null);
+ });
});

0 comments on commit 8081920

Please sign in to comment.