-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsimmetrics.test.js
74 lines (65 loc) · 2.56 KB
/
simmetrics.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
/**
* Module dependencies.
*/
var should = require('should');
var Levenshtein = require('../lib/similaritymetrics/Levenshtein');
var ChapmanMatchingSoundex = require('../lib/similaritymetrics/ChapmanMatchingSoundex');
var TokeniserWhitespace = require('../lib/tokenisers/TokeniserWhitespace');
/**
* Globals
*/
var leven, chapman;
/**
* Unit tests
*/
describe('SimMetrics Matching', function () {
describe('Levenshtein Distance Matching', function () {
beforeEach(function (done) {
leven = new Levenshtein();
done();
});
it('should match Andy perfectly', function() {
var res = leven.getSimilarity('Andy', 'Andy');
res.should.equal(1);
});
it('should match like the java version', function() {
var result = leven.getSimilarity("Test String1", "Test String2");
result.should.be.approximately(0.9166667, 0.1);
});
});
describe('SoundEx matching', function() {
beforeEach(function (done) {
chapman = new ChapmanMatchingSoundex();
done();
});
it('should match stuff like the java version', function() {
var result = leven.getSimilarity("Test StringA", "Test StringB");
result.should.be.approximately(0.95555556, 0.1);
});
it('should match like the java version', function() {
var result = leven.getSimilarity("Test String1", "Test String2");
result.should.be.approximately(0.95555556, 0.1);
});
it('will match Jorge and George with a reasonable score', function() {
var res = chapman.getSimilarity("Jorge", "George");
res.should.be.approximately(0.77777785, 0.1);
});
it('will match Abrahms and Abrems with a high score', function() {
var res = chapman.getSimilarity("Abrahms", "Abrems");
res.should.be.approximately(0.88888, 0.1);
});
it('will match Joseph and Jospeh with a high score', function() {
var res = chapman.getSimilarity("Joseph", "Jospeh");
res.should.be.approximately(0.8888, 0.1);
});
it('will match Barbara and Barbara with a high score', function() {
var res = chapman.getSimilarity("Barbara", "Barbara");
res.should.be.approximately(0.95, 0.1);
});
it('will match Aroldin and Aaron with a high score', function() {
var res = chapman.getSimilarity("Aroldin", "Aaron");
res.should.be.approximately(0.3, 0.1);
});
});
});