affine: Add ConcatSelf tests

This commit is contained in:
Hajime Hoshi 2017-05-25 22:14:54 +09:00
parent 6db994f0e8
commit c19b233ec6
2 changed files with 60 additions and 9 deletions

View File

@ -19,7 +19,7 @@ import (
"testing"
)
func TestColorInit(t *testing.T) {
func TestColorMInit(t *testing.T) {
var m ColorM
for i := 0; i < ColorMDim-1; i++ {
for j := 0; j < ColorMDim; j++ {
@ -49,7 +49,7 @@ func TestColorInit(t *testing.T) {
}
}
func TestColorAssign(t *testing.T) {
func TestColorMAssign(t *testing.T) {
m := ColorM{}
m.SetElement(0, 0, 1)
m2 := m
@ -61,7 +61,7 @@ func TestColorAssign(t *testing.T) {
}
}
func TestColorTranslate(t *testing.T) {
func TestColorMTranslate(t *testing.T) {
expected := [4][5]float64{
{1, 0, 0, 0, 0.5},
{0, 1, 0, 0, 1.5},
@ -81,7 +81,7 @@ func TestColorTranslate(t *testing.T) {
}
}
func TestColorScale(t *testing.T) {
func TestColorMScale(t *testing.T) {
expected := [4][5]float64{
{0.5, 0, 0, 0, 0},
{0, 1.5, 0, 0, 0},
@ -101,7 +101,7 @@ func TestColorScale(t *testing.T) {
}
}
func TestColorTranslateAndScale(t *testing.T) {
func TestColorMTranslateAndScale(t *testing.T) {
expected := [4][5]float64{
{1, 0, 0, 0, 0},
{0, 1, 0, 0, 0},
@ -122,7 +122,7 @@ func TestColorTranslateAndScale(t *testing.T) {
}
}
func TestColorMonochrome(t *testing.T) {
func TestColorMMonochrome(t *testing.T) {
expected := [4][5]float64{
{0.2990, 0.5870, 0.1140, 0, 0},
{0.2990, 0.5870, 0.1140, 0, 0},
@ -140,3 +140,29 @@ func TestColorMonochrome(t *testing.T) {
}
}
}
func TestColorMConcatSelf(t *testing.T) {
expected := [4][5]float64{
{30, 40, 30, 25, 30},
{40, 54, 43, 37, 37},
{30, 43, 51, 39, 34},
{25, 37, 39, 46, 36},
}
m := ColorM{}
for i := 0; i < 4; i++ {
for j := 0; j < 5; j++ {
println(i, j, float64((i+j)%5+1))
m.SetElement(i, j, float64((i+j)%5+1))
}
}
m.Concat(m)
for i := 0; i < 4; i++ {
for j := 0; j < 5; j++ {
got := m.Element(i, j)
want := expected[i][j]
if want != got {
t.Errorf("m.Element(%d, %d) = %f, want %f", i, j, got, want)
}
}
}
}

View File

@ -21,7 +21,7 @@ import (
. "github.com/hajimehoshi/ebiten"
)
func TestGeometryInit(t *testing.T) {
func TestGeoMInit(t *testing.T) {
var m GeoM
for i := 0; i < GeoMDim-1; i++ {
for j := 0; j < GeoMDim; j++ {
@ -37,7 +37,7 @@ func TestGeometryInit(t *testing.T) {
}
}
func TestGeometryAssign(t *testing.T) {
func TestGeoMAssign(t *testing.T) {
m := GeoM{}
m.SetElement(0, 0, 1)
m2 := m
@ -49,7 +49,7 @@ func TestGeometryAssign(t *testing.T) {
}
}
func TestGeometryConcat(t *testing.T) {
func TestGeoMConcat(t *testing.T) {
matrix1 := GeoM{}
matrix1.Scale(2, 2)
matrix2 := GeoM{}
@ -91,6 +91,31 @@ func TestGeometryConcat(t *testing.T) {
}
}
func TestGeoMConcatSelf(t *testing.T) {
m := GeoM{}
m.SetElement(0, 0, 1)
m.SetElement(0, 1, 2)
m.SetElement(0, 2, 3)
m.SetElement(1, 0, 4)
m.SetElement(1, 1, 5)
m.SetElement(1, 2, 6)
m.Concat(m)
expected := [][]float64{
{9, 12, 18},
{24, 33, 48},
}
for i := 0; i < 2; i++ {
for j := 0; j < 3; j++ {
got := m.Element(i, j)
want := expected[i][j]
if want != got {
t.Errorf("m.Element(%d, %d) = %f, want %f",
i, j, got, want)
}
}
}
}
func BenchmarkGeoM(b *testing.B) {
var m GeoM
for i := 0; i < b.N; i++ {