Skip to content

Commit

Permalink
Linted tests. Bumped version number.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Britton committed Aug 28, 2013
1 parent 3b31db1 commit 5e853df
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "randgen",
"version" : "0.0.4",
"version" : "0.1.0",
"author": "Rob Britton <rob@robbritton.com>",
"description": "Node.js package for generating different kinds of random numbers.",
"dependencies" : {
Expand Down
49 changes: 27 additions & 22 deletions test.js
@@ -1,23 +1,27 @@
/*jslint indent: 2, plusplus: true, sloppy: true */
/*global require*/
var randgen = require("./lib/randgen"),
assert = require('assert');
assert = require('assert');

test_norms(1000, 5, 1);
test_norms(1000, 500, 100);
test_pois(1000, 5, 1);
test_pois(1000, 500, 100);
test_chisq(1000, 5, 1);
test_chisq(1000, 500, 100);
function sum(lhs, rhs) {
return lhs + rhs;
}

function mean(arr) {
var s = arr.reduce(sum, 0);
return s / arr.length;
}

function test_norms(n, mu, sigma) {
var norms, xbar;
norms = randgen.rvnorm(n, mu, sigma);
xbar = mean(norms);

assert.equal(
Math.round(xbar/mu),
Math.round(xbar / mu),
1,
"Generated normal population has xbar " +
xbar + " is not close to its expected value, " + mu + "."
"Generated normal population has xbar " +
xbar + " is not close to its expected value, " + mu + "."
);
}

Expand All @@ -27,10 +31,10 @@ function test_pois(n, lambda) {
xbar = mean(pois);

assert.equal(
Math.round(xbar/lambda),
Math.round(xbar / lambda),
1,
"Poisson population mean " + xbar +
" is not close to the expected value " + lambda + "."
" is not close to the expected value " + lambda + "."
);
}

Expand All @@ -41,23 +45,24 @@ function test_chisq(n, k) {
xbar = mean(chisq);

assert.equal(
Math.round(xbar/k),
Math.round(xbar / k),
1,
"Chi-squared population mean " + xbar +
" is not close to expected value " + k + "."
" is not close to expected value " + k + "."
);
}

function test_cauchy(n, loc, scale) {
var cauchy = randgen.rvcauchy(1000);
// it's complicated
// cauchy is difficult to test using means simply because the true mean for
// a cauchy distribution is undefined
// TODO: figure out a good way to test Cauchy numbers
}

function mean(arr) {
var s = arr.reduce(sum, 0);
return s / arr.length;
}

function sum(lhs, rhs) {
return lhs + rhs;
}
test_norms(1000, 5, 1);
test_norms(1000, 500, 100);
test_pois(1000, 5, 1);
test_pois(1000, 500, 100);
test_chisq(1000, 5, 1);
test_chisq(1000, 500, 100);

0 comments on commit 5e853df

Please sign in to comment.