graphics: Refactoring tests

This commit is contained in:
Hajime Hoshi 2018-03-11 19:25:19 +09:00
parent c2872017ab
commit 96402c11a2

View File

@ -140,49 +140,47 @@ func TestGeoMApply(t *testing.T) {
cpx.Translate(-2, -3)
cases := []struct {
GeoM GeoM
InX float64
InY float64
OutX float64
OutY float64
Delta float64
GeoM GeoM
InX float64
InY float64
OutX float64
OutY float64
}{
{
GeoM: GeoM{},
InX: 3.14159,
InY: 2.81828,
OutX: 3.14159,
OutY: 2.81828,
Delta: 0.00001,
GeoM: GeoM{},
InX: 3.14159,
InY: 2.81828,
OutX: 3.14159,
OutY: 2.81828,
},
{
GeoM: trans,
InX: 3.14159,
InY: 2.81828,
OutX: 4.14159,
OutY: 4.81828,
Delta: 0.00001,
GeoM: trans,
InX: 3.14159,
InY: 2.81828,
OutX: 4.14159,
OutY: 4.81828,
},
{
GeoM: scale,
InX: 3.14159,
InY: 2.81828,
OutX: 4.71239,
OutY: 7.04570,
Delta: 0.00001,
GeoM: scale,
InX: 3.14159,
InY: 2.81828,
OutX: 4.71239,
OutY: 7.04570,
},
{
GeoM: cpx,
InX: 3.14159,
InY: 2.81828,
OutX: -6.71239,
OutY: -10.04570,
Delta: 0.00001,
GeoM: cpx,
InX: 3.14159,
InY: 2.81828,
OutX: -6.71239,
OutY: -10.04570,
},
}
const delta = 0.00001
for _, c := range cases {
rx, ry := c.GeoM.Apply(c.InX, c.InY)
if math.Abs(rx-c.OutX) > c.Delta || math.Abs(ry-c.OutY) > c.Delta {
if math.Abs(rx-c.OutX) > delta || math.Abs(ry-c.OutY) > delta {
t.Errorf("%s.Apply(%f, %f) = (%f, %f), want (%f, %f)", geoMToString(c.GeoM), c.InX, c.InY, rx, ry, c.OutX, c.OutY)
}
}