-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathscore_test.go
89 lines (70 loc) · 2.14 KB
/
score_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
package ssdeep
import (
"testing"
"github.com/stretchr/testify/require"
)
var h1 = "192:MUPMinqP6+wNQ7Q40L/iB3n2rIBrP0GZKF4jsef+0FVQLSwbLbj41iH8nFVYv980:x0CllivQiFmt"
var h2 = "192:JkjRcePWsNVQza3ntZStn5VfsoXMhRD9+xJMinqF6+wNQ7Q40L/i737rPVt:JkjlQyIrx+kll2"
var h3 = "196608:pDSC8olnoL1v/uawvbQD7XlZUFYzYyMb615NktYHF7dREN/JNnQrmhnUPI+/n2Yr:5DHoJXv7XOq7Mb2TwYHXREN/3QrmktPd"
var h4 = "196608:7DSC8olnoL1v/uawvbQD7XlZUFYzYyMb615NktYHF7dREN/JNnQrmhnUPI+/n2Y7:3DHoJXv7XOq7Mb2TwYHXREN/3QrmktPt"
var h5 = "24:YDVLfsT1ds/1H9Wpgq7n4XMijV6h4Z3QCw4qat:YD51H9CiMuV6uACwVat"
var h6 = "24:YDVLfyvDj+C+opg8DV0Mdle6hPZ3QCw4qat:YDMvDj+C+kBOM+6HACwVat"
func assertDistanceEqual(t *testing.T, expected, actual int) {
if expected != actual {
t.Fatalf("Distance mismatch: %d (expected)\n"+
" != %d (actual)", expected, actual)
}
}
func TestHashDistanceSame(t *testing.T) {
d, err := Distance(h1, h1)
require.NoError(t, err)
assertDistanceEqual(t, 100, d)
}
func TestHashDistance1(t *testing.T) {
d, err := Distance(h1, h2)
require.NoError(t, err)
assertDistanceEqual(t, 35, d)
}
func TestHashDistance2(t *testing.T) {
d, err := Distance(h3, h4)
require.NoError(t, err)
assertDistanceEqual(t, 97, d)
}
func TestHashDistance3(t *testing.T) {
d, err := Distance(h5, h6)
require.NoError(t, err)
assertDistanceEqual(t, 54, d)
}
func TestEmptyHash1(t *testing.T) {
d, err := Distance("", h2)
require.Error(t, err)
assertDistanceEqual(t, 0, d)
}
func TestEmptyHash2(t *testing.T) {
d, err := Distance(h1, "")
require.Error(t, err)
if d != 0 {
t.Errorf("hash2 is nil: %d", d)
}
}
func TestInvalidHash1(t *testing.T) {
d, err := Distance("192:asdasd", h1)
require.Error(t, err)
if d != 0 {
t.Errorf("hash1 and hash2 are nil: %d", d)
}
}
func TestInvalidHash2(t *testing.T) {
d, err := Distance(h1, "asd:asdasd:aaaa")
require.Error(t, err)
if d != 0 {
t.Errorf("hash1 and hash2 are nil: %d", d)
}
}
func BenchmarkDistance(b *testing.B) {
var h1 = `7DSC8olnoL1v/uawvbQD7XlZUFYzYyMb615NktYHF7dREN/JNnQrmhnUPI+/n2Y7`
var h2 = `7DSC8olnoL1v/uawvbQD7XlZUFYzYyMb615NktYHF7dREN/JNnQrmhnUPI+/ngrr`
for i := 0; i < b.N; i++ {
distance(h1, h2)
}
}