-
Notifications
You must be signed in to change notification settings - Fork 10
/
custom_test.go
72 lines (52 loc) · 1.74 KB
/
custom_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
package images4
import (
"path"
"testing"
)
func TestCustomSimilar(t *testing.T) {
// Proportions test.
i1, _ := Open(path.Join("testdata", "euclidean", "distorted.jpg"))
i2, _ := Open(path.Join("testdata", "euclidean", "large.jpg"))
icon1 := Icon(i1)
icon2 := Icon(i2)
if Similar(icon1, icon2) {
t.Errorf("distorted.jpg is NOT similar to large.jpg")
}
if !CustomSimilar(icon1, icon2, CustomCoefficients{1, 1, 1, 10}) {
t.Errorf("distorted.jpg IS similar to large.jpg, assuming proportion differences are widely tolerated.")
}
// Euclidean tests.
i1, _ = Open(path.Join("testdata", "custom", "1.jpg"))
i2, _ = Open(path.Join("testdata", "custom", "2.jpg"))
icon1 = Icon(i1)
icon2 = Icon(i2)
if !Similar(icon1, icon2) {
t.Errorf("1.jpg is GENERALLY similar to 2.jpg")
}
// Luma.
if CustomSimilar(icon1, icon2, CustomCoefficients{0, 1, 1, 1}) {
t.Errorf("1.jpg is NOT IDENTICAL to 2.jpg")
}
// Luma.
if CustomSimilar(icon1, icon2, CustomCoefficients{0.4, 1, 1, 1}) {
t.Errorf("1.jpg is similar to 2.jpg, BUT NOT VERY SIMILAR")
}
// Chrominance b.
if CustomSimilar(icon1, icon2, CustomCoefficients{1, 0.1, 1, 1}) {
t.Errorf("1.jpg is similar to 2.jpg, BUT NOT VERY SIMILAR")
}
// Chrominance c.
if CustomSimilar(icon1, icon2, CustomCoefficients{1, 1, 0.1, 1}) {
t.Errorf("1.jpg is similar to 2.jpg, BUT NOT VERY SIMILAR")
}
// Image comparison to itself (or its own copy).
if !CustomSimilar(icon1, icon1, CustomCoefficients{0, 0, 0, 0}) {
t.Errorf("1.jpg IS IDENTICAL to itself")
}
if !CustomSimilar(icon1, icon1, CustomCoefficients{0.5, 0.5, 0.5, 0.5}) {
t.Errorf("1.jpg IS IDENTICAL to itself")
}
if !CustomSimilar(icon1, icon1, CustomCoefficients{1, 1, 1, 1}) {
t.Errorf("1.jpg IS IDENTICAL to itself")
}
}