-
Notifications
You must be signed in to change notification settings - Fork 1
/
osa_test.go
43 lines (40 loc) · 915 Bytes
/
osa_test.go
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
package disfun
import "testing"
var osatests = []struct {
s1 string
s2 string
dist int
}{
// insertion
{"car", "cars", 1},
// substitution
{"library", "librari", 1},
// deletion
{"library", "librar", 1},
// transposition
{"library", "librayr", 1},
// one empty, left
{"", "library", 7},
// one empty, right
{"library", "", 7},
// two empties
{"", "", 0},
// unicode stuff!
{"Schüßler", "Schübler", 1},
{"Schüßler", "Schußler", 1},
{"Schüßler", "Schüßler", 0},
{"Schßüler", "Schüßler", 1},
{"Schüßler", "Schüler", 1},
{"Schüßler", "Schüßlers", 1},
// difference between DL and OSA. This is OSA, so it should be 3.
{"ca", "abc", 3},
}
// OSA (Optimal String Alignment)
func TestOSA(t *testing.T) {
for _, tt := range osatests {
dist := OSA(tt.s1, tt.s2)
if dist != tt.dist {
t.Errorf("OSA('%s', '%s') = %v, want %v", tt.s1, tt.s2, dist, tt.dist)
}
}
}