-
Notifications
You must be signed in to change notification settings - Fork 0
/
hamming_test.go
66 lines (59 loc) · 1.01 KB
/
hamming_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
package textdistance
import (
"fmt"
"testing"
)
func TestHammingDistance(t *testing.T) {
t.Parallel()
tts := []struct {
ins [2]string
want float64
}{
{
ins: [2]string{"heath", "heath"},
want: 0,
},
{
ins: [2]string{"river", "rover"},
want: 1,
},
{
ins: [2]string{"1011101", "1001001"},
want: 2,
},
{
ins: [2]string{"karolin", "kerstin"},
want: 3,
},
{
ins: [2]string{"drummer", "dresser"},
want: 3,
},
{
ins: [2]string{"flaw", "lawn"},
want: 4,
},
}
for _, tt := range tts {
t.Run(fmt.Sprintf("%s", tt.ins), func(t *testing.T) {
h := NewHamming()
got, err := h.Distance(tt.ins[0], tt.ins[1])
if got != tt.want {
t.Errorf("got %f, want %f", got, tt.want)
}
if err != nil {
t.Errorf("expect empty error, got %+v", err)
}
})
}
}
func BenchmarkHammingDistance(b *testing.B) {
h := NewHamming()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, err := h.Distance("karolin", "kerstin")
if err != nil {
b.Fatal(err)
}
}
}