Skip to content

Commit d334295

Browse files
committed
add test
1 parent 0312d7e commit d334295

File tree

1 file changed

+148
-2
lines changed

1 file changed

+148
-2
lines changed

kadai1/imura81gt/imgconv/img/convert_test.go

Lines changed: 148 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestEnable(t *testing.T) {
5050
t.Parallel()
5151
actual := tc.iType.Enable()
5252
if !reflect.DeepEqual(actual, tc.expected) {
53-
t.Errorf("\ncaseName:%s\nactual:%+v\niExpected:%+v\n",
53+
t.Errorf("\ncaseName:%s\nactual:%+v\nExpected:%+v\n",
5454
tc.caseName,
5555
actual,
5656
tc.expected,
@@ -65,6 +65,86 @@ func TestAllImageFiles(t *testing.T) {
6565
}
6666

6767
func TestExpectedImageFiles(t *testing.T) {
68+
testcases := []struct {
69+
caseName string
70+
files []string
71+
iType ImageType
72+
expected []string
73+
}{
74+
{
75+
caseName: "png is expected image type.",
76+
files: []string{
77+
"../testdata/pLenna.png",
78+
"../testdata/jLenna.jpg",
79+
"../testdata/gLenna.gif",
80+
"../testdata/chdir/pLenna.png",
81+
"../testdata/chdir/jLenna.jpeg",
82+
"../testdata/chdir/gLenna.gif",
83+
"../testdata/this_is_not_image.png",
84+
"../testdata/this_is_not_image.jpg",
85+
"../testdata/this_is_not_image.gif",
86+
},
87+
iType: ImageType{Png: true, Jpeg: false, Gif: false},
88+
expected: []string{
89+
"../testdata/pLenna.png",
90+
"../testdata/chdir/pLenna.png",
91+
},
92+
},
93+
{
94+
caseName: "jpg is expected image type.",
95+
files: []string{
96+
"../testdata/pLenna.png",
97+
"../testdata/jLenna.jpg",
98+
"../testdata/gLenna.gif",
99+
"../testdata/chdir/pLenna.png",
100+
"../testdata/chdir/jLenna.jpeg",
101+
"../testdata/chdir/gLenna.gif",
102+
"../testdata/this_is_not_image.png",
103+
"../testdata/this_is_not_image.jpg",
104+
"../testdata/this_is_not_image.gif",
105+
},
106+
iType: ImageType{Png: false, Jpeg: true, Gif: false},
107+
expected: []string{
108+
"../testdata/jLenna.jpg",
109+
"../testdata/chdir/jLenna.jpeg",
110+
},
111+
},
112+
{
113+
caseName: "gif is expected image type.",
114+
files: []string{
115+
"../testdata/pLenna.png",
116+
"../testdata/jLenna.jpg",
117+
"../testdata/gLenna.gif",
118+
"../testdata/chdir/pLenna.png",
119+
"../testdata/chdir/jLenna.jpeg",
120+
"../testdata/chdir/gLenna.gif",
121+
"../testdata/this_is_not_image.png",
122+
"../testdata/this_is_not_image.jpg",
123+
"../testdata/this_is_not_image.gif",
124+
},
125+
iType: ImageType{Png: false, Jpeg: false, Gif: true},
126+
expected: []string{
127+
"../testdata/gLenna.gif",
128+
"../testdata/chdir/gLenna.gif",
129+
},
130+
},
131+
}
132+
133+
for _, tc := range testcases {
134+
tc := tc // capture range variable. need to set when run parallel test.
135+
136+
t.Run(tc.caseName, func(t *testing.T) {
137+
t.Parallel()
138+
actual := ExpectedImageFiles(tc.files, tc.iType)
139+
if !reflect.DeepEqual(actual, tc.expected) {
140+
t.Errorf("\ncaseName:%s\nactual:%+v\nExpected:%+v\n",
141+
tc.caseName,
142+
actual,
143+
tc.expected,
144+
)
145+
}
146+
})
147+
}
68148

69149
}
70150

@@ -108,7 +188,7 @@ func TestIsImage(t *testing.T) {
108188
t.Parallel()
109189
actual := IsImage(tc.path)
110190
if !(actual == tc.expected) {
111-
t.Errorf("\ncaseName:%s\nactual:%+v\niExpected:%+v\n",
191+
t.Errorf("\ncaseName:%s\nactual:%+v\nExpected:%+v\n",
112192
tc.caseName,
113193
actual,
114194
tc.expected,
@@ -120,6 +200,72 @@ func TestIsImage(t *testing.T) {
120200
}
121201

122202
func TestIsExpectedImage(t *testing.T) {
203+
testcases := []struct {
204+
caseName string
205+
path string
206+
iType ImageType
207+
expected bool
208+
}{
209+
{
210+
caseName: "png file is expected image file.",
211+
path: "../testdata/pLenna.png",
212+
iType: ImageType{Png: true, Jpeg: false, Gif: false},
213+
expected: true,
214+
},
215+
{
216+
caseName: "jpeg file is expected image file.",
217+
path: "../testdata/jLenna.jpg",
218+
iType: ImageType{Png: false, Jpeg: true, Gif: false},
219+
expected: true,
220+
},
221+
{
222+
caseName: "gif file is expected image file.",
223+
path: "../testdata/gLenna.gif",
224+
iType: ImageType{Png: false, Jpeg: false, Gif: true},
225+
expected: true,
226+
},
227+
228+
{
229+
caseName: "png file is unexpected image file.",
230+
path: "../testdata/pLenna.png",
231+
iType: ImageType{Png: false, Jpeg: true, Gif: true},
232+
expected: false,
233+
},
234+
{
235+
caseName: "jpeg file is unexpected image file.",
236+
path: "../testdata/jLenna.jpg",
237+
iType: ImageType{Png: true, Jpeg: false, Gif: true},
238+
expected: false,
239+
},
240+
{
241+
caseName: "gif file is unexpected image file.",
242+
path: "../testdata/gLenna.gif",
243+
iType: ImageType{Png: true, Jpeg: true, Gif: false},
244+
expected: false,
245+
},
246+
247+
{
248+
caseName: "does not existed.",
249+
path: "../testdata/does_not_existed.gif",
250+
expected: false,
251+
},
252+
}
253+
254+
for _, tc := range testcases {
255+
tc := tc // capture range variable. need to set when run parallel test.
256+
257+
t.Run(tc.caseName, func(t *testing.T) {
258+
t.Parallel()
259+
actual := IsExpectedImage(tc.path, tc.iType)
260+
if !(actual == tc.expected) {
261+
t.Errorf("\ncaseName:%s\nactual:%+v\nExpected:%+v\n",
262+
tc.caseName,
263+
actual,
264+
tc.expected,
265+
)
266+
}
267+
})
268+
}
123269

124270
}
125271

0 commit comments

Comments
 (0)