-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
152 lines (141 loc) · 2.5 KB
/
main_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package svgr_test
import (
"io/ioutil"
"reflect"
"testing"
"github.com/rmfarrell/svgr"
)
var input svgr.Input = svgr.Input{
Path: "./testdata/doge.png",
Resolution: &svgr.Resolution{
Width: 10,
Height: 10,
},
ID: "",
}
func TestNewMosaic(t *testing.T) {
t.Skip()
fixtures := []struct {
input *svgr.Input
err error
}{
// okay
{
&svgr.Input{
Path: "./testdata/doge.png",
Resolution: &svgr.Resolution{
Width: 10,
Height: 10,
},
ID: "",
},
nil,
},
}
for _, fix := range fixtures {
m, err := svgr.NewMosaic(fix.input)
if fix.err != nil && err.Error() != fix.err.Error() {
t.Errorf("Expected %v \n Received %v", fix.err, err)
}
if err != nil {
continue
}
// check that type if Mosaic
if (reflect.TypeOf(m) != reflect.TypeOf(&svgr.Mosaic{})) {
t.Errorf("Expected *svgr.Mosaic \n Received %v", m)
}
// check that it's not empty
if (&svgr.Mosaic{}) == m {
t.Error("Mosaic should be non-empty")
}
}
}
func TestTriangles(t *testing.T) {
m, err := svgr.NewMosaic(&input)
if err != nil {
t.Error(err)
}
svg := m.Triangles(3)
if svg == "" {
t.Error("svg should not be blank")
}
// TODO: test number of polygons
}
func TestSquares(t *testing.T) {
m, err := svgr.NewMosaic(&input)
if err != nil {
t.Error(err)
}
svg := m.Squares(0)
if svg == "" {
t.Error("svg should not be blank")
}
}
func TestDots(t *testing.T) {
m, err := svgr.NewMosaic(&input)
if err != nil {
t.Error(err)
}
svg := m.Dots(0.8)
if svg == "" {
t.Error("svg should not be blank")
}
}
func TestHexagaons(t *testing.T) {
m, err := svgr.NewMosaic(&input)
if err != nil {
t.Error(err)
}
svg := m.Hexagons()
if svg == "" {
t.Error("svg should not be blank")
}
}
func TestHalftone(t *testing.T) {
m, err := svgr.NewMosaic(&svgr.Input{
Path: "./testdata/normal-guy.jpg",
Resolution: &svgr.Resolution{
Width: 60,
Height: 60,
},
ID: "",
})
if err != nil {
t.Error(err)
}
svg, err := m.Halftone(svgr.ScreenSet{
&svgr.Screen{
Color: "r",
Saturation: 50,
Lightness: 50,
},
&svgr.Screen{
Color: "g",
Saturation: 50,
Lightness: 50,
},
&svgr.Screen{
Color: "b",
Saturation: 50,
Lightness: 50,
},
})
if err != nil {
t.Error(err)
}
err = writeFile(svg)
if err != nil {
t.Error(err)
}
if svg == "" {
t.Error("svg should not be blank")
}
}
func writeFile(in string) error {
b := []byte(in)
err := ioutil.WriteFile("./out.svg", b, 0644)
if err != nil {
return err
}
return nil
}