[Pkg-javascript-commits] [science.js] 08/87: Vows-based unit tests!
bhuvan krishna
bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:11:52 UTC 2016
This is an automated email from the git hooks/post-receive script.
bhuvan-guest pushed a commit to branch master
in repository science.js.
commit 64af7f869a35000f6025501199f13fc6dab40fe6
Author: Jason Davies <jason at jasondavies.com>
Date: Wed Aug 17 21:03:13 2011 +0100
Vows-based unit tests!
---
Makefile | 12 ++++--------
science.js | 15 ++++++++++++++-
science.min.js | 2 +-
src/core/core.js | 2 +-
test/core/hypot-test.js | 17 +++++++++++++++++
test/core/zeroes-test.js | 32 ++++++++++++++++++++++++++++++++
test/stats/bandwidth-test.js | 24 ++++++++++++++++++++++++
test/stats/iqr-test.js | 23 +++++++++++++++++++++++
test/stats/mean-test.js | 22 ++++++++++++++++++++++
test/stats/median-test.js | 22 ++++++++++++++++++++++
test/stats/mode-test.js | 19 +++++++++++++++++++
test/stats/variance-test.js | 22 ++++++++++++++++++++++
tests/test-hypot.js | 5 -----
tests/test-hypot.out | 1 -
tests/test-stats-bandwidth.js | 13 -------------
tests/test-stats-bandwidth.out | 6 ------
tests/test-stats-iqr.js | 12 ------------
tests/test-stats-iqr.out | 21 ---------------------
tests/test-stats-mean.js | 12 ------------
tests/test-stats-mean.out | 18 ------------------
tests/test-stats-median.js | 12 ------------
tests/test-stats-median.out | 18 ------------------
tests/test-stats-mode.js | 14 --------------
tests/test-stats-variance.js | 12 ------------
tests/test-stats-variance.out | 18 ------------------
tests/test-zeroes.js | 10 ----------
tests/test-zeroes.out | 15 ---------------
27 files changed, 201 insertions(+), 198 deletions(-)
diff --git a/Makefile b/Makefile
index 33fd861..a205860 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,8 @@ all: \
science.core.js: \
src/core/core.js \
src/core/functor.js \
- src/core/hypot.js
+ src/core/hypot.js \
+ src/core/zeroes.js
science.lin.js: \
src/start.js \
@@ -39,13 +40,8 @@ science.stats.js: \
src/stats/variance.js \
src/end.js
-tests: \
- tests/test-hypot.test \
- tests/test-stats-bandwidth.test \
- tests/test-stats-iqr.test \
- tests/test-stats-mean.test \
- tests/test-stats-median.test \
- tests/test-stats-variance.test
+test: all
+ @vows
%.min.js: %.js Makefile
@rm -f $@
diff --git a/science.js b/science.js
index 89ceae4..7bda6f8 100644
--- a/science.js
+++ b/science.js
@@ -1,4 +1,4 @@
-(function(){science = {version: "1.1.0"}; // semver
+(function(){science = {version: "1.2.0"}; // semver
science.functor = function(v) {
return typeof v === "function" ? v : function() { return v; };
};
@@ -14,4 +14,17 @@ science.hypot = function(x, y) {
var r = min / max;
return max * Math.sqrt(1 + r * r);
};
+// Constructs a multi-dimensional array filled with zeroes.
+science.zeroes = function(n) {
+ var i = -1,
+ a = [];
+ if (arguments.length === 1)
+ while (++i < n)
+ a[i] = 0;
+ else
+ while (++i < n)
+ a[i] = science.zeroes.apply(
+ this, Array.prototype.slice.call(arguments, 1));
+ return a;
+};
})()
\ No newline at end of file
diff --git a/science.min.js b/science.min.js
index c6c441a..1006fae 100644
--- a/science.min.js
+++ b/science.min.js
@@ -1 +1 @@
-(function(){science={version:"1.1.0"},science.functor=function(a){return typeof a=="function"?a:function(){return a}},science.hypot=function(a,b){a=Math.abs(a),b=Math.abs(b);var c,d;a>b?(c=a,d=b):(c=b,d=a);var e=d/c;return c*Math.sqrt(1+e*e)}})()
\ No newline at end of file
+(function(){science={version:"1.2.0"},science.functor=function(a){return typeof a=="function"?a:function(){return a}},science.hypot=function(a,b){a=Math.abs(a),b=Math.abs(b);var c,d;a>b?(c=a,d=b):(c=b,d=a);var e=d/c;return c*Math.sqrt(1+e*e)},science.zeroes=function(a){var b=-1,c=[];if(arguments.length===1)while(++b<a)c[b]=0;else while(++b<a)c[b]=science.zeroes.apply(this,Array.prototype.slice.call(arguments,1));return c}})()
\ No newline at end of file
diff --git a/src/core/core.js b/src/core/core.js
index e1d5047..7047ad6 100644
--- a/src/core/core.js
+++ b/src/core/core.js
@@ -1 +1 @@
-science = {version: "1.1.0"}; // semver
+science = {version: "1.2.0"}; // semver
diff --git a/test/core/hypot-test.js b/test/core/hypot-test.js
new file mode 100644
index 0000000..8cf5000
--- /dev/null
+++ b/test/core/hypot-test.js
@@ -0,0 +1,17 @@
+require("../../science");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.hypot");
+
+suite.addBatch({
+ "hypot": {
+ "maximum supported hypotenuse": function() {
+ var max = Number.MAX_VALUE / Math.sqrt(2);
+ assert.equal(science.hypot(max, max), 1.7976931348623155e+308);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/test/core/zeroes-test.js b/test/core/zeroes-test.js
new file mode 100644
index 0000000..7b6ef6b
--- /dev/null
+++ b/test/core/zeroes-test.js
@@ -0,0 +1,32 @@
+require("../../science");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.zeroes");
+
+suite.addBatch({
+ "zeroes": {
+ "10": function() {
+ assert.deepEqual(science.zeroes(10), [
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ ]);
+ },
+ "10, 10": function() {
+ assert.deepEqual(science.zeroes(10, 10), [
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+ ]);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/test/stats/bandwidth-test.js b/test/stats/bandwidth-test.js
new file mode 100644
index 0000000..21623be
--- /dev/null
+++ b/test/stats/bandwidth-test.js
@@ -0,0 +1,24 @@
+require("../../science");
+require("../../science.stats");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.bandwidth");
+
+suite.addBatch({
+ "bandwidth": {
+ "nrd0": function() {
+ var data = [1, 2, 3, 4];
+ assert.equal(science.stats.bandwidth.nrd0(data),
+ .7635139420854616);
+ },
+ "nrd": function() {
+ var data = [1, 2, 3, 4];
+ assert.equal(science.stats.bandwidth.nrd(data),
+ .899249754011766);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/test/stats/iqr-test.js b/test/stats/iqr-test.js
new file mode 100644
index 0000000..d26e969
--- /dev/null
+++ b/test/stats/iqr-test.js
@@ -0,0 +1,23 @@
+require("../../science");
+require("../../science.stats");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.iqr");
+
+suite.addBatch({
+ "iqr": {
+ "returns correct interquartile ranges": function() {
+ assert.isTrue(isNaN(science.stats.iqr([])));
+ assert.equal(science.stats.iqr([1]), 0);
+ assert.equal(science.stats.iqr([1, 2]), .5);
+ assert.equal(science.stats.iqr([1, 2, 3]), 1);
+ assert.equal(science.stats.iqr([1, 2, 3, 4]), 1.5);
+ assert.equal(science.stats.iqr([1, 2, 3, 4, 5]), 2);
+ assert.equal(science.stats.iqr([1, 2, 3, 4, 5, 6]), 2.5);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/test/stats/mean-test.js b/test/stats/mean-test.js
new file mode 100644
index 0000000..8d3a0d0
--- /dev/null
+++ b/test/stats/mean-test.js
@@ -0,0 +1,22 @@
+require("../../science");
+require("../../science.stats");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.mean");
+
+suite.addBatch({
+ "mean": {
+ "returns correct means": function() {
+ assert.isTrue(isNaN(science.stats.mean([])));
+ assert.equal(science.stats.mean([1]), 1);
+ assert.equal(science.stats.mean([1, 2]), 1.5);
+ assert.equal(science.stats.mean([1, 2, 3]), 2);
+ assert.equal(science.stats.mean([1, 2, 3, 4]), 2.5);
+ assert.equal(science.stats.mean([1, 2, 3, 4, 5]), 3);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/test/stats/median-test.js b/test/stats/median-test.js
new file mode 100644
index 0000000..dd00b59
--- /dev/null
+++ b/test/stats/median-test.js
@@ -0,0 +1,22 @@
+require("../../science");
+require("../../science.stats");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.median");
+
+suite.addBatch({
+ "median": {
+ "returns correct medians": function() {
+ assert.isTrue(isNaN(science.stats.median([])));
+ assert.equal(science.stats.median([1]), 1);
+ assert.equal(science.stats.median([1, 2]), 1.5);
+ assert.equal(science.stats.median([1, 2, 3]), 2);
+ assert.equal(science.stats.median([1, 2, 3, 4]), 2.5);
+ assert.equal(science.stats.median([1, 2, 3, 4, 5]), 3);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/test/stats/mode-test.js b/test/stats/mode-test.js
new file mode 100644
index 0000000..6015c4a
--- /dev/null
+++ b/test/stats/mode-test.js
@@ -0,0 +1,19 @@
+require("../../science");
+require("../../science.stats");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.mode");
+
+suite.addBatch({
+ "mode": {
+ "returns correct modes": function() {
+ assert.isTrue(isNaN(science.stats.mode([])));
+ assert.equal(science.stats.mode([1, 2, 3, 4, 5]), null);
+ assert.equal(science.stats.mode([1, 2, 2, 3, 4, 7, 9]), 2);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/test/stats/variance-test.js b/test/stats/variance-test.js
new file mode 100644
index 0000000..0be1fbd
--- /dev/null
+++ b/test/stats/variance-test.js
@@ -0,0 +1,22 @@
+require("../../science");
+require("../../science.stats");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("science.variance");
+
+suite.addBatch({
+ "variance": {
+ "returns correct variances": function() {
+ assert.isTrue(isNaN(science.stats.variance([])));
+ assert.equal(science.stats.variance([1]), 0);
+ assert.equal(science.stats.variance([1, 2]), .5);
+ assert.equal(science.stats.variance([1, 2, 3]), 1);
+ assert.equal(science.stats.variance([1, 2, 3, 4]), 5/3);
+ assert.equal(science.stats.variance([1, 2, 3, 4, 5]), 2.5);
+ }
+ }
+});
+
+suite.export(module);
diff --git a/tests/test-hypot.js b/tests/test-hypot.js
deleted file mode 100644
index 284185e..0000000
--- a/tests/test-hypot.js
+++ /dev/null
@@ -1,5 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-
-var max = Number.MAX_VALUE / Math.sqrt(2);
-console.log("hypot", science.hypot(max, max));
diff --git a/tests/test-hypot.out b/tests/test-hypot.out
deleted file mode 100644
index 08e7d5f..0000000
--- a/tests/test-hypot.out
+++ /dev/null
@@ -1 +0,0 @@
-hypot 1.7976931348623155e+308
diff --git a/tests/test-stats-bandwidth.js b/tests/test-stats-bandwidth.js
deleted file mode 100644
index 5abd70a..0000000
--- a/tests/test-stats-bandwidth.js
+++ /dev/null
@@ -1,13 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-require("./../science.stats");
-
-var data = [1, 2, 3, 4];
-
-console.log("nrd0:");
-console.log(" ", science.stats.bandwidth.nrd0(data));
-console.log("");
-
-console.log("nrd:");
-console.log(" ", science.stats.bandwidth.nrd(data));
-console.log("");
diff --git a/tests/test-stats-bandwidth.out b/tests/test-stats-bandwidth.out
deleted file mode 100644
index 93ddc4b..0000000
--- a/tests/test-stats-bandwidth.out
+++ /dev/null
@@ -1,6 +0,0 @@
-nrd0:
- 0.7635139420854616
-
-nrd:
- 0.899249754011766
-
diff --git a/tests/test-stats-iqr.js b/tests/test-stats-iqr.js
deleted file mode 100644
index 6cc69c5..0000000
--- a/tests/test-stats-iqr.js
+++ /dev/null
@@ -1,12 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-require("./../science.stats");
-
-var data = [1, 2, 3, 4, 5, 6];
-
-for (var i = 0; i <= data.length; i++) {
- var d = data.slice(0, i);
- console.log("iqr [" + d + "]:");
- console.log(" ", science.stats.iqr(d));
- console.log("");
-}
diff --git a/tests/test-stats-iqr.out b/tests/test-stats-iqr.out
deleted file mode 100644
index bc85489..0000000
--- a/tests/test-stats-iqr.out
+++ /dev/null
@@ -1,21 +0,0 @@
-iqr []:
- NaN
-
-iqr [1]:
- 0
-
-iqr [1,2]:
- 0.5
-
-iqr [1,2,3]:
- 1
-
-iqr [1,2,3,4]:
- 1.5
-
-iqr [1,2,3,4,5]:
- 2
-
-iqr [1,2,3,4,5,6]:
- 2.5
-
diff --git a/tests/test-stats-mean.js b/tests/test-stats-mean.js
deleted file mode 100644
index 3bf8971..0000000
--- a/tests/test-stats-mean.js
+++ /dev/null
@@ -1,12 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-require("./../science.stats");
-
-var data = [1, 2, 3, 4, 5];
-
-for (var i = 0; i <= data.length; i++) {
- var d = data.slice(0, i);
- console.log("mean [" + d + "]:");
- console.log(" ", science.stats.mean(d));
- console.log("");
-}
diff --git a/tests/test-stats-mean.out b/tests/test-stats-mean.out
deleted file mode 100644
index 483bf6d..0000000
--- a/tests/test-stats-mean.out
+++ /dev/null
@@ -1,18 +0,0 @@
-mean []:
- NaN
-
-mean [1]:
- 1
-
-mean [1,2]:
- 1.5
-
-mean [1,2,3]:
- 2
-
-mean [1,2,3,4]:
- 2.5
-
-mean [1,2,3,4,5]:
- 3
-
diff --git a/tests/test-stats-median.js b/tests/test-stats-median.js
deleted file mode 100644
index bb88083..0000000
--- a/tests/test-stats-median.js
+++ /dev/null
@@ -1,12 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-require("./../science.stats");
-
-var data = [1, 2, 3, 4, 5];
-
-for (var i = 0; i <= data.length; i++) {
- var d = data.slice(0, i);
- console.log("median [" + d + "]:");
- console.log(" ", science.stats.median(d));
- console.log("");
-}
diff --git a/tests/test-stats-median.out b/tests/test-stats-median.out
deleted file mode 100644
index 1ab19af..0000000
--- a/tests/test-stats-median.out
+++ /dev/null
@@ -1,18 +0,0 @@
-median []:
- NaN
-
-median [1]:
- 1
-
-median [1,2]:
- 1.5
-
-median [1,2,3]:
- 2
-
-median [1,2,3,4]:
- 2.5
-
-median [1,2,3,4,5]:
- 3
-
diff --git a/tests/test-stats-mode.js b/tests/test-stats-mode.js
deleted file mode 100644
index e018a0c..0000000
--- a/tests/test-stats-mode.js
+++ /dev/null
@@ -1,14 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-require("./../science.stats");
-
-var data = [
- [1, 2, 3, 4, 5],
- [1, 2, 2, 3, 4, 7, 9]
-];
-
-data.forEach(function(d) {
- console.log("mode [" + d + "]:");
- console.log(" ", science.stats.mode(d));
- console.log("");
-});
diff --git a/tests/test-stats-variance.js b/tests/test-stats-variance.js
deleted file mode 100644
index f2fbe0f..0000000
--- a/tests/test-stats-variance.js
+++ /dev/null
@@ -1,12 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-require("./../science.stats");
-
-var data = [1, 2, 3, 4, 5];
-
-for (var i = 0; i <= data.length; i++) {
- var d = data.slice(0, i);
- console.log("variance [" + d + "]:");
- console.log(" ", science.stats.variance(d));
- console.log("");
-}
diff --git a/tests/test-stats-variance.out b/tests/test-stats-variance.out
deleted file mode 100644
index b8a1957..0000000
--- a/tests/test-stats-variance.out
+++ /dev/null
@@ -1,18 +0,0 @@
-variance []:
- NaN
-
-variance [1]:
- 0
-
-variance [1,2]:
- 0.5
-
-variance [1,2,3]:
- 1
-
-variance [1,2,3,4]:
- 1.6666666666666667
-
-variance [1,2,3,4,5]:
- 2.5
-
diff --git a/tests/test-zeroes.js b/tests/test-zeroes.js
deleted file mode 100644
index f9c654e..0000000
--- a/tests/test-zeroes.js
+++ /dev/null
@@ -1,10 +0,0 @@
-require("./../lib/env-js/envjs/node");
-require("./../science");
-
-console.log("zeroes 10");
-console.log(science.zeroes(10));
-console.log("");
-
-console.log("zeroes 10, 10");
-console.log(science.zeroes(10, 10));
-console.log("");
diff --git a/tests/test-zeroes.out b/tests/test-zeroes.out
deleted file mode 100644
index c659e32..0000000
--- a/tests/test-zeroes.out
+++ /dev/null
@@ -1,15 +0,0 @@
-zeroes 10
-[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
-
-zeroes 10, 10
-[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
- [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ]
-
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/science.js.git
More information about the Pkg-javascript-commits
mailing list