Skip to content

Commit b535188

Browse files
committed
added tests for levenshtein distance algorithm
1 parent 766c111 commit b535188

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
var mod = require('../../src/others/levenshtein-distance.js');
4+
var levenshteinDistance = mod.levenshteinDistance;
5+
6+
describe('Levenstein\'s minimum edit distance algorithm', function () {
7+
it('"" -> "" should return 0.', function () {
8+
expect(levenshteinDistance('', '')).toBe(0);
9+
});
10+
11+
it('"T" -> "" should return 1.', function () {
12+
expect(levenshteinDistance('T', '')).toBe(1);
13+
});
14+
15+
it('"cake" -> "rake" should return 1.', function () {
16+
expect(levenshteinDistance('cake', 'rake')).toBe(1);
17+
});
18+
19+
it('"Sofia" -> "Sof" should return 2.', function () {
20+
expect(levenshteinDistance('Sofia', 'Sof')).toBe(2);
21+
});
22+
23+
it('"google" -> "lookat" should return 4.', function () {
24+
expect(levenshteinDistance('google', 'lookat')).toBe(4);
25+
});
26+
27+
it('"emacs" -> "vim" should return 5.', function () {
28+
expect(levenshteinDistance('emacs', 'vim')).toBe(5);
29+
});
30+
31+
it('"coffee" -> "cocoa" should return 4.', function () {
32+
expect(levenshteinDistance('coffee', 'cocoa')).toBe(4);
33+
});
34+
35+
it('"Munich" -> "Muenchen" should return 4.', function () {
36+
expect(levenshteinDistance('Munich', 'Muenchen')).toBe(4);
37+
});
38+
39+
it('"rosebud" -> "budrose" should return 6.', function () {
40+
expect(levenshteinDistance('rosebud', 'budrose')).toBe(6);
41+
});
42+
});

0 commit comments

Comments
 (0)