minor adjustments with how tests are named and run
This commit is contained in:
parent
eedeb85b14
commit
2a32545253
|
@ -1,16 +1,12 @@
|
||||||
package pixel_test
|
package pixel_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
"github.com/faiface/pixel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type rectTestInput struct {
|
|
||||||
name string
|
|
||||||
rect pixel.Rect
|
|
||||||
}
|
|
||||||
|
|
||||||
type rectTestTransform struct {
|
type rectTestTransform struct {
|
||||||
name string
|
name string
|
||||||
f func(pixel.Rect) pixel.Rect
|
f func(pixel.Rect) pixel.Rect
|
||||||
|
@ -19,10 +15,10 @@ type rectTestTransform struct {
|
||||||
func TestResizeRect(t *testing.T) {
|
func TestResizeRect(t *testing.T) {
|
||||||
|
|
||||||
// rectangles
|
// rectangles
|
||||||
squareAroundOrigin := rectTestInput{"square around origin", pixel.R(-10, -10, 10, 10)}
|
squareAroundOrigin := pixel.R(-10, -10, 10, 10)
|
||||||
squareAround2020 := rectTestInput{"square around 20, 20", pixel.R(10, 10, 30, 30)}
|
squareAround2020 := pixel.R(10, 10, 30, 30)
|
||||||
rectangleAroundOrigin := rectTestInput{"rectangle around origin", pixel.R(-20, -10, 20, 10)}
|
rectangleAroundOrigin := pixel.R(-20, -10, 20, 10)
|
||||||
rectangleAround2020 := rectTestInput{"rectangle around 20, 20", pixel.R(0, 10, 40, 30)}
|
rectangleAround2020 := pixel.R(0, 10, 40, 30)
|
||||||
|
|
||||||
// resize transformations
|
// resize transformations
|
||||||
resizeByHalfAroundCenter := rectTestTransform{"by half around center", func(rect pixel.Rect) pixel.Rect {
|
resizeByHalfAroundCenter := rectTestTransform{"by half around center", func(rect pixel.Rect) pixel.Rect {
|
||||||
|
@ -42,7 +38,7 @@ func TestResizeRect(t *testing.T) {
|
||||||
}}
|
}}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
input rectTestInput
|
input pixel.Rect
|
||||||
transform rectTestTransform
|
transform rectTestTransform
|
||||||
answer pixel.Rect
|
answer pixel.Rect
|
||||||
}{
|
}{
|
||||||
|
@ -73,9 +69,11 @@ func TestResizeRect(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
testResult := testCase.transform.f(testCase.input.rect)
|
t.Run(fmt.Sprintf("Resize %v %s", testCase.input, testCase.transform.name), func(t *testing.T) {
|
||||||
|
testResult := testCase.transform.f(testCase.input)
|
||||||
if testResult != testCase.answer {
|
if testResult != testCase.answer {
|
||||||
t.Errorf("Resizing %s %s failed, got: %v, wanted: %v\n", testCase.input.name, testCase.transform.name, testResult, testCase.answer)
|
t.Errorf("Got: %v, wanted: %v\n", testResult, testCase.answer)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue