-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
94 lines (79 loc) · 1.79 KB
/
example_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
package levenshtein_test
import (
"fmt"
"github.com/nathanjcochran/levenshtein"
)
func Example() {
matrix := levenshtein.Build("horse", "arose")
fmt.Printf("Matrix:\n%s\n\n", matrix)
fmt.Printf("Edit distance: %d\n", matrix.Distance())
fmt.Printf("Operations:\n")
for _, op := range matrix.Operations() {
fmt.Printf(" %s\n", op)
}
// Output:
// Matrix:
// a r o s e
// 0 1 2 3 4 5
// h 1 1 2 3 4 5
// o 2 2 2 2 3 4
// r 3 3 2 3 3 4
// s 4 4 3 3 3 4
// e 5 5 4 4 4 3
//
// Edit distance: 3
// Operations:
// swap a at index 0: aorse
// remove o at index 1: arse
// keep r at index 1: arse
// insert o at index 2: arose
// keep s at index 3: arose
// keep e at index 4: arose
}
func ExampleBuild() {
fmt.Println(levenshtein.Build("horse", "arose"))
// Output:
// a r o s e
// 0 1 2 3 4 5
// h 1 1 2 3 4 5
// o 2 2 2 2 3 4
// r 3 3 2 3 3 4
// s 4 4 3 3 3 4
// e 5 5 4 4 4 3
}
func ExampleMatrix_Distance() {
matrix := levenshtein.Build("horse", "arose")
fmt.Println(matrix.Distance())
// Output:
// 3
}
func ExampleDistance() {
fmt.Println(levenshtein.Distance("horse", "arose"))
// Output:
// 3
}
func ExampleMatrix_Operations() {
matrix := levenshtein.Build("horse", "arose")
for _, op := range matrix.Operations() {
fmt.Println(op)
}
// Output:
// swap a at index 0: aorse
// remove o at index 1: arse
// keep r at index 1: arse
// insert o at index 2: arose
// keep s at index 3: arose
// keep e at index 4: arose
}
func ExampleOperations() {
for _, op := range levenshtein.Operations("horse", "arose") {
fmt.Println(op)
}
// Output:
// swap a at index 0: aorse
// remove o at index 1: arse
// keep r at index 1: arse
// insert o at index 2: arose
// keep s at index 3: arose
// keep e at index 4: arose
}