-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
levenshtein_test.go
103 lines (99 loc) · 3.14 KB
/
levenshtein_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
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
package edlib
import (
"testing"
)
func Test_levenshteinDistance(t *testing.T) {
type args struct {
str1 string
str2 string
}
tests := []struct {
name string
args args
want int
}{
{"First arg empty", args{"", "abcde"}, 5},
{"Second arg empty", args{"abcde", ""}, 5},
{"Same args", args{"abcde", "abcde"}, 0},
{"ab/aa", args{"ab", "aa"}, 1},
{"ab/ba", args{"ab", "ba"}, 2},
{"ab/aaa", args{"ab", "aaa"}, 2},
{"bbb/a", args{"bbb", "a"}, 3},
{"kitten/sitting", args{"kitten", "sitting"}, 3},
{"distance/difference", args{"distance", "difference"}, 5},
{"a cat/an abct", args{"a cat", "an abct"}, 4},
{"こにんち/こんにちは", args{"こにんち", "こんにちは"}, 3}, // "Hello" in Japanese
{"🙂😄🙂😄/😄🙂😄🙂", args{"🙂😄🙂😄", "😄🙂😄🙂"}, 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := LevenshteinDistance(tt.args.str1, tt.args.str2); got != tt.want {
t.Errorf("levenshteinDistance() = %v, want %v", got, tt.want)
}
})
}
}
func TestOSADamerauLevenshteinDistance(t *testing.T) {
type args struct {
str1 string
str2 string
}
tests := []struct {
name string
args args
want int
}{
{"First arg empty", args{"", "abcde"}, 5},
{"Second arg empty", args{"abcde", ""}, 5},
{"Same args", args{"abcde", "abcde"}, 0},
{"ab/aa", args{"ab", "aa"}, 1},
{"ab/ba", args{"ab", "ba"}, 1},
{"ab/aaa", args{"ab", "aaa"}, 2},
{"bbb/a", args{"bbb", "a"}, 3},
{"ca/abc", args{"ca", "abc"}, 3},
{"a cat/an abct", args{"a cat", "an abct"}, 4},
{"dixon/dicksonx", args{"dixon", "dicksonx"}, 4},
{"jellyfish/smellyfish", args{"jellyfish", "smellyfish"}, 2},
{"こにんち/こんにちは", args{"こにんち", "こんにちは"}, 2}, // "Hello" in Japanese
{"🙂😄🙂😄/😄🙂😄🙂", args{"🙂😄🙂😄", "😄🙂😄🙂"}, 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := OSADamerauLevenshteinDistance(tt.args.str1, tt.args.str2); got != tt.want {
t.Errorf("OSADamerauLevenshteinDistance() = %v, want %v", got, tt.want)
}
})
}
}
func TestDamerauLevenshteinDistance(t *testing.T) {
type args struct {
str1 string
str2 string
}
tests := []struct {
name string
args args
want int
}{
{"First arg empty", args{"", "abcde"}, 5},
{"Second arg empty", args{"abcde", ""}, 5},
{"Same args", args{"abcde", "abcde"}, 0},
{"ab/aa", args{"ab", "aa"}, 1},
{"ab/ba", args{"ab", "ba"}, 1},
{"ab/aaa", args{"ab", "aaa"}, 2},
{"bbb/a", args{"bbb", "a"}, 3},
{"ca/abc", args{"ca", "abc"}, 2},
{"a cat/an abct", args{"a cat", "an abct"}, 3},
{"dixon/dicksonx", args{"dixon", "dicksonx"}, 4},
{"jellyfish/smellyfish", args{"jellyfish", "smellyfish"}, 2},
{"こにんち/こんにちは", args{"こにんち", "こんにちは"}, 2}, // "Hello" in Japanese
{"🙂😄🙂😄/😄🙂😄🙂", args{"🙂😄🙂😄", "😄🙂😄🙂"}, 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := DamerauLevenshteinDistance(tt.args.str1, tt.args.str2); got != tt.want {
t.Errorf("DamerauLevenshteinDistance() = %v, want %v", got, tt.want)
}
})
}
}