-
Notifications
You must be signed in to change notification settings - Fork 0
/
gocova_test.go
98 lines (76 loc) · 2.17 KB
/
gocova_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
package main
import (
"fmt"
"os"
"reflect"
"testing"
)
func TestNormalImage(t *testing.T) {
src := readImage("testdata/normal._png")
pattern := 3
filter := filter{
hue: float64(360.0 / (pattern + 1)),
saturation: 0,
lightness: 0,
}
hueInterval := filter.hue
filter.isBitonal = bitonalDetect(src)
filter.isGrayscale = grayscaleDetect(src)
var resultImage imageFile
for i := 1; i <= pattern; i++ {
filter.hue = hueInterval * float64(i)
writeImage(filterImage(&src, filter), "/tmp/testdata.png")
testImage := readImage("/tmp/testdata.png")
resultImage = readImage(fmt.Sprintf("testdata/result_normal/filtered_%d._png", i))
if !reflect.DeepEqual(testImage.image, resultImage.image) {
t.Fail()
}
}
os.Remove("/tmp/testdata.png")
}
func TestGrayscaleImage(t *testing.T) {
src := readImage("testdata/grayscale._png")
pattern := 3
filter := filter{
hue: float64(360.0 / (pattern + 1)),
saturation: 0,
lightness: 0,
}
hueInterval := filter.hue
filter.isBitonal = bitonalDetect(src)
filter.isGrayscale = grayscaleDetect(src)
var resultImage imageFile
for i := 1; i <= pattern; i++ {
filter.hue = hueInterval * float64(i)
writeImage(filterImage(&src, filter), "/tmp/testdata.png")
testImage := readImage("/tmp/testdata.png")
resultImage = readImage(fmt.Sprintf("testdata/result_grayscale/filtered_%d._png", i))
if !reflect.DeepEqual(testImage.image, resultImage.image) {
t.Fail()
}
}
os.Remove("/tmp/testdata.png")
}
func TestBitonalImage(t *testing.T) {
src := readImage("testdata/bitonal._png")
pattern := 3
filter := filter{
hue: float64(360.0 / (pattern + 1)),
saturation: 0,
lightness: 0,
}
hueInterval := filter.hue
filter.isBitonal = bitonalDetect(src)
filter.isGrayscale = grayscaleDetect(src)
var resultImage imageFile
for i := 1; i <= pattern; i++ {
filter.hue = hueInterval * float64(i)
writeImage(filterImage(&src, filter), "/tmp/testdata.png")
testImage := readImage("/tmp/testdata.png")
resultImage = readImage(fmt.Sprintf("testdata/result_bitonal/filtered_%d._png", i))
if !reflect.DeepEqual(testImage.image, resultImage.image) {
t.Fail()
}
}
os.Remove("/tmp/testdata.png")
}