(t *testing.T)
| 241 | } |
| 242 | |
| 243 | func TestTransformImage(t *testing.T) { |
| 244 | // ref is a 2x2 reference image containing four colors |
| 245 | ref := newImage(2, 2, red, green, blue, yellow) |
| 246 | |
| 247 | // cropRef is a 4x4 image with four colors, each in 2x2 quarter |
| 248 | cropRef := newImage(4, 4, red, red, green, green, red, red, green, green, blue, blue, yellow, yellow, blue, blue, yellow, yellow) |
| 249 | |
| 250 | // use simpler filter while testing that won't skew colors |
| 251 | resampleFilter = imaging.Box |
| 252 | |
| 253 | tests := []struct { |
| 254 | src image.Image // source image to transform |
| 255 | opt Options // options to apply during transform |
| 256 | want image.Image // expected transformed image |
| 257 | }{ |
| 258 | // no transformation |
| 259 | {ref, emptyOptions, ref}, |
| 260 | |
| 261 | // rotations |
| 262 | {ref, Options{Rotate: 45}, ref}, // invalid rotation is a noop |
| 263 | {ref, Options{Rotate: 360}, ref}, |
| 264 | {ref, Options{Rotate: 90}, newImage(2, 2, green, yellow, red, blue)}, |
| 265 | {ref, Options{Rotate: 180}, newImage(2, 2, yellow, blue, green, red)}, |
| 266 | {ref, Options{Rotate: 270}, newImage(2, 2, blue, red, yellow, green)}, |
| 267 | {ref, Options{Rotate: 630}, newImage(2, 2, blue, red, yellow, green)}, |
| 268 | {ref, Options{Rotate: -90}, newImage(2, 2, blue, red, yellow, green)}, |
| 269 | |
| 270 | // flips |
| 271 | { |
| 272 | ref, |
| 273 | Options{FlipHorizontal: true}, |
| 274 | newImage(2, 2, green, red, yellow, blue), |
| 275 | }, |
| 276 | { |
| 277 | ref, |
| 278 | Options{FlipVertical: true}, |
| 279 | newImage(2, 2, blue, yellow, red, green), |
| 280 | }, |
| 281 | { |
| 282 | ref, |
| 283 | Options{FlipHorizontal: true, FlipVertical: true}, |
| 284 | newImage(2, 2, yellow, blue, green, red), |
| 285 | }, |
| 286 | { |
| 287 | ref, |
| 288 | Options{Rotate: 90, FlipHorizontal: true}, |
| 289 | newImage(2, 2, yellow, green, blue, red), |
| 290 | }, |
| 291 | |
| 292 | // resizing |
| 293 | { // can't resize larger than original image |
| 294 | ref, |
| 295 | Options{Width: 100, Height: 100}, |
| 296 | ref, |
| 297 | }, |
| 298 | { // can resize larger than original image |
| 299 | ref, |
| 300 | Options{Width: 4, Height: 4, ScaleUp: true}, |
nothing calls this directly
no test coverage detected