test.js
4.38 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
var levenshtien = require("./../index");
var assert = require("assert");
describe("Damerau - Levenshtein", function() {
describe("Equality", function() {
it("returns 0 steps for equal strings", function() {
assert.deepEqual(levenshtien("test", "test"), {
steps: 0,
relative: 0,
similarity: 1
});
});
});
describe("Additions", function() {
it("returns 1 step when appending one char", function() {
assert.deepEqual(levenshtien("test", "tests"), {
steps: 1,
relative: 1 / 5,
similarity: 1 - 1 / 5
});
});
it("returns 1 step when prepending one char", function() {
assert.deepEqual(levenshtien("test", "stest"), {
steps: 1,
relative: 1 / 5,
similarity: 1 - 1 / 5
});
});
it("returns 2 steps when appending two char", function() {
assert.deepEqual(levenshtien("test", "mytest"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
it("returns 7 steps when appending seven char", function() {
assert.deepEqual(levenshtien("test", "mycrazytest"), {
steps: 7,
relative: 7 / 11,
similarity: 1 - 7 / 11
});
});
it("returns 9 steps when prepend two chars and append seven chars", function() {
assert.deepEqual(levenshtien("test", "mytestiscrazy"), {
steps: 9,
relative: 9 / 13,
similarity: 1 - 9 / 13
});
});
});
describe("Addition of repeated chars", function() {
it("returns 1 step when repeating a character", function() {
assert.deepEqual(levenshtien("test", "teest"), {
steps: 1,
relative: 1 / 5,
similarity: 1 - 1 / 5
});
});
it("returns 2 step when repeating a character twice", function() {
assert.deepEqual(levenshtien("test", "teeest"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
});
describe("#Deletion", function() {
it("returns 1 step when removing one char", function() {
assert.deepEqual(levenshtien("test", "tst"), {
steps: 1,
relative: 1 / 4,
similarity: 1 - 1 / 4
});
});
});
describe("Transposition", function() {
it("returns 1 step when transposing one char", function() {
assert.deepEqual(levenshtien("test", "tset"), {
steps: 1,
relative: 1 / 4,
similarity: 1 - 1 / 4
});
});
});
describe("Addition with transposition", function() {
it("returns 2 step when transposing one char and append another", function() {
assert.deepEqual(levenshtien("test", "tsets"), {
steps: 2,
relative: 2 / 5,
similarity: 1 - 2 / 5
});
});
it("returns 2 step when transposing a char and repeating it", function() {
assert.deepEqual(levenshtien("test", "tsset"), {
steps: 2,
relative: 2 / 5,
similarity: 1 - 2 / 5
});
});
});
describe("Transposition of multiple chars", function() {
it("returns 1 step when transposing two neighbouring characters", function() {
assert.deepEqual(levenshtien("banana", "banaan"), {
steps: 1,
relative: 1 / 6,
similarity: 1 - 1 / 6
});
});
it("returns 2 step when transposing two neighbouring characters by two places", function() {
assert.deepEqual(levenshtien("banana", "nabana"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
it("returns 2 step when transposing two pairs of characters", function() {
assert.deepEqual(levenshtien("banana", "abnaan"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
});
describe("Empty strings", function() {
it("returns 0 step and 0 relative when both are empty", function() {
assert.deepEqual(levenshtien("", ""), {
steps: 0,
relative: 0,
similarity: 1
});
});
it("returns steps equal to first string lenght when second string is empty", function() {
assert.deepEqual(levenshtien("test", ""), {
steps: 4,
relative: 4 / 4,
similarity: 0
});
});
it("returns steps equal to second string lenght when first string is empty", function() {
assert.deepEqual(levenshtien("", "test"), {
steps: 4,
relative: 1,
similarity: 0
});
});
});
});