Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ill-conceived test wrapper.

  • Loading branch information...
commit 7234da421b1beb5c7b3d40c1415a4eed446f8b48 1 parent 1afb214
@brianloveswords authored
Showing with 28 additions and 20 deletions.
  1. +6 −0 runner.js
  2. +22 −20 test.js
View
6 runner.js
@@ -0,0 +1,6 @@
+var assert = require("assert");
+
+exports['test'] = function(suite, tests){
+ console.log('Running', suite, 'tests');
+ tests(assert);
+};
View
42 test.js
@@ -1,30 +1,32 @@
-var assert = require("assert");
+var run = require("./runner");
var dist = require("./distance");
-assert.equal(dist.hamming('awesome', 'aewsome'), 2);
-assert.equal(dist.hamming('a', 'ba'), 2);
-assert.equal(dist.hamming('cab', 'abra'), 4);
+run.test('Hamming', function(t){
+ t.equal(dist.hamming('awesome', 'aewsome'), 2);
+ t.equal(dist.hamming('a', 'ba'), 2);
+ t.equal(dist.hamming('cab', 'abra'), 4);
+});
-// tests shameleslly ripped from the wikipedia article
-assert.equal(dist.jaro('great', 'great'), 1);
-assert.equal(dist.jaro('dicksonx', 'dixon'), (1/3)*(4/5+4/8+1));
-assert.equal(dist.jaro('martha', 'marhta'), (1/3)*(1+1+5/6));
-assert.equal(dist.jaro('duane', 'dwayne'), (1/3)*(4/6+4/5+1));
-assert.equal(dist.jaro('jones', 'johnson'), (1/3)*(4/5+4/7+1));
+run.test("Jaro", function(t){
+ // tests shameleslly ripped from the wikipedia article
+ t.equal(dist.jaro('great', 'great'), 1);
+ t.equal(dist.jaro('dicksonx', 'dixon'), (1/3)*(4/5+4/8+1));
+ t.equal(dist.jaro('martha', 'marhta'), (1/3)*(1+1+5/6));
+ t.equal(dist.jaro('duane', 'dwayne'), (1/3)*(4/6+4/5+1));
+ t.equal(dist.jaro('jones', 'johnson'), (1/3)*(4/5+4/7+1));
+});
-// testing jarowinkler
-(function(){
+run.test("Jaro-Winkler", function(t){
var f = function(distance, prefix) {
return distance + (prefix * 0.1 * (1 - distance));
};
-
- var test = function(str1, str2, prefix){
+ var affirm = function(str1, str2, prefix){
var d = dist.jaro(str1, str2);
- assert.equal(dist.jarowinkler(str1, str2), f(d,prefix));
+ t.equal(dist.jarowinkler(str1, str2), f(d,prefix));
};
- test('dicksonx', 'dixon', 2);
- test('martha', 'marhta', 3);
- test('duane', 'dwayne', 1);
- test('jones', 'johnson', 2);
-})();
+ affirm('dicksonx', 'dixon', 2);
+ affirm('martha', 'marhta', 3);
+ affirm('duane', 'dwayne', 1);
+ affirm('jones', 'johnson', 2);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.