Removing wip files

This commit is contained in:
Ben Cragg 2019-03-26 15:41:32 +00:00
parent 09db6d8b38
commit 50ef216e79
8 changed files with 0 additions and 2046 deletions

View File

@ -1,154 +0,0 @@
package pixel_test
import (
"image/color"
"reflect"
"testing"
"github.com/faiface/pixel"
)
func TestNewBatch(t *testing.T) {
type args struct {
container pixel.Triangles
pic pixel.Picture
}
tests := []struct {
name string
args args
want *pixel.Batch
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.NewBatch(tt.args.container, tt.args.pic); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewBatch() = %v, want %v", got, tt.want)
}
})
}
}
func TestBatch_Dirty(t *testing.T) {
tests := []struct {
name string
b *pixel.Batch
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.b.Dirty()
})
}
}
func TestBatch_Clear(t *testing.T) {
tests := []struct {
name string
b *pixel.Batch
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.b.Clear()
})
}
}
func TestBatch_Draw(t *testing.T) {
type args struct {
t pixel.Target
}
tests := []struct {
name string
b *pixel.Batch
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.b.Draw(tt.args.t)
})
}
}
func TestBatch_SetMatrix(t *testing.T) {
type args struct {
m pixel.Matrix
}
tests := []struct {
name string
b *pixel.Batch
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.b.SetMatrix(tt.args.m)
})
}
}
func TestBatch_SetColorMask(t *testing.T) {
type args struct {
c color.Color
}
tests := []struct {
name string
b *pixel.Batch
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.b.SetColorMask(tt.args.c)
})
}
}
func TestBatch_MakeTriangles(t *testing.T) {
type args struct {
t pixel.Triangles
}
tests := []struct {
name string
b *pixel.Batch
args args
want pixel.TargetTriangles
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.b.MakeTriangles(tt.args.t); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Batch.MakeTriangles() = %v, want %v", got, tt.want)
}
})
}
}
func TestBatch_MakePicture(t *testing.T) {
type args struct {
p pixel.Picture
}
tests := []struct {
name string
b *pixel.Batch
args args
want pixel.TargetPicture
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.b.MakePicture(tt.args.p); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Batch.MakePicture() = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -1,101 +0,0 @@
package pixel_test
import (
"reflect"
"testing"
"github.com/faiface/pixel"
)
func TestComposeMethod_Compose(t *testing.T) {
type args struct {
a pixel.RGBA
b pixel.RGBA
}
a := pixel.RGBA{R: 200, G: 200, B: 200, A: .8}
b := pixel.RGBA{R: 100, G: 100, B: 100, A: .5}
c := pixel.RGBA{R: 200, G: 200, B: 200, A: .5}
tests := []struct {
name string
cm pixel.ComposeMethod
args args
want pixel.RGBA
}{
{
name: "ComposeMethod.Compose: ComposeOver",
cm: pixel.ComposeOver,
args: args{a: a, b: b},
want: pixel.RGBA{R: 220, G: 220, B: 220, A: .9},
},
{
name: "ComposeMethod.Compose: ComposeIn",
cm: pixel.ComposeIn,
args: args{a: a, b: b},
want: pixel.RGBA{R: 100, G: 100, B: 100, A: .4},
},
{
name: "ComposeMethod.Compose: ComposeOut",
cm: pixel.ComposeOut,
args: args{a: a, b: b},
want: pixel.RGBA{R: 100, G: 100, B: 100, A: .4},
},
{
name: "ComposeMethod.Compose: ComposeAtop",
cm: pixel.ComposeAtop,
args: args{a: a, b: b},
want: pixel.RGBA{R: 120, G: 120, B: 120, A: .5},
},
{
name: "ComposeMethod.Compose: ComposeRover",
cm: pixel.ComposeRover,
args: args{a: a, b: b},
want: pixel.RGBA{R: 200, G: 200, B: 200, A: .9},
},
{
name: "ComposeMethod.Compose: ComposeRin",
cm: pixel.ComposeRin,
args: args{a: a, b: b},
want: pixel.RGBA{R: 80, G: 80, B: 80, A: .4},
},
{
name: "ComposeMethod.Compose: ComposeRout",
cm: pixel.ComposeRout,
// Using 'c' here to make the "want"ed RGBA rational
args: args{a: c, b: b},
want: pixel.RGBA{R: 50, G: 50, B: 50, A: .25},
},
{
name: "ComposeMethod.Compose: ComposeRatop",
cm: pixel.ComposeRatop,
args: args{a: a, b: b},
want: pixel.RGBA{R: 180, G: 180, B: 180, A: .8},
},
{
name: "ComposeMethod.Compose: ComposeXor",
cm: pixel.ComposeXor,
args: args{a: a, b: b},
want: pixel.RGBA{R: 120, G: 120, B: 120, A: .5},
},
{
name: "ComposeMethod.Compose: ComposePlus",
cm: pixel.ComposePlus,
args: args{a: a, b: b},
want: pixel.RGBA{R: 300, G: 300, B: 300, A: 1.3},
},
{
name: "ComposeMethod.Compose: ComposeCopy",
cm: pixel.ComposeCopy,
args: args{a: a, b: b},
want: pixel.RGBA{R: 200, G: 200, B: 200, A: .8},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cm.Compose(tt.args.a, tt.args.b); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ComposeMethod.Compose() = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -1,325 +0,0 @@
package pixel_test
import (
"image"
"reflect"
"testing"
"github.com/faiface/pixel"
)
func TestMakeTrianglesData(t *testing.T) {
type args struct {
len int
}
tests := []struct {
name string
args args
want *pixel.TrianglesData
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.MakeTrianglesData(tt.args.len); !reflect.DeepEqual(got, tt.want) {
t.Errorf("MakeTrianglesData() = %v, want %v", got, tt.want)
}
})
}
}
func TestTrianglesData_Len(t *testing.T) {
tests := []struct {
name string
td *pixel.TrianglesData
want int
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.td.Len(); got != tt.want {
t.Errorf("TrianglesData.Len() = %v, want %v", got, tt.want)
}
})
}
}
func TestTrianglesData_SetLen(t *testing.T) {
type args struct {
len int
}
tests := []struct {
name string
td *pixel.TrianglesData
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.td.SetLen(tt.args.len)
})
}
}
func TestTrianglesData_Slice(t *testing.T) {
type args struct {
i int
j int
}
tests := []struct {
name string
td *pixel.TrianglesData
args args
want pixel.Triangles
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.td.Slice(tt.args.i, tt.args.j); !reflect.DeepEqual(got, tt.want) {
t.Errorf("TrianglesData.Slice() = %v, want %v", got, tt.want)
}
})
}
}
func TestTrianglesData_Update(t *testing.T) {
type args struct {
t pixel.Triangles
}
tests := []struct {
name string
td *pixel.TrianglesData
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.td.Update(tt.args.t)
})
}
}
func TestTrianglesData_Copy(t *testing.T) {
tests := []struct {
name string
td *pixel.TrianglesData
want pixel.Triangles
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.td.Copy(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("TrianglesData.Copy() = %v, want %v", got, tt.want)
}
})
}
}
func TestTrianglesData_Position(t *testing.T) {
type args struct {
i int
}
tests := []struct {
name string
td *pixel.TrianglesData
args args
want pixel.Vec
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.td.Position(tt.args.i); !reflect.DeepEqual(got, tt.want) {
t.Errorf("TrianglesData.Position() = %v, want %v", got, tt.want)
}
})
}
}
func TestTrianglesData_Color(t *testing.T) {
type args struct {
i int
}
tests := []struct {
name string
td *pixel.TrianglesData
args args
want pixel.RGBA
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.td.Color(tt.args.i); !reflect.DeepEqual(got, tt.want) {
t.Errorf("TrianglesData.Color() = %v, want %v", got, tt.want)
}
})
}
}
func TestTrianglesData_Picture(t *testing.T) {
type args struct {
i int
}
tests := []struct {
name string
td *pixel.TrianglesData
args args
wantPic pixel.Vec
wantIntensity float64
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotPic, gotIntensity := tt.td.Picture(tt.args.i)
if !reflect.DeepEqual(gotPic, tt.wantPic) {
t.Errorf("TrianglesData.Picture() gotPic = %v, want %v", gotPic, tt.wantPic)
}
if gotIntensity != tt.wantIntensity {
t.Errorf("TrianglesData.Picture() gotIntensity = %v, want %v", gotIntensity, tt.wantIntensity)
}
})
}
}
func TestMakePictureData(t *testing.T) {
type args struct {
rect pixel.Rect
}
tests := []struct {
name string
args args
want *pixel.PictureData
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.MakePictureData(tt.args.rect); !reflect.DeepEqual(got, tt.want) {
t.Errorf("MakePictureData() = %v, want %v", got, tt.want)
}
})
}
}
func TestPictureDataFromImage(t *testing.T) {
type args struct {
img image.Image
}
tests := []struct {
name string
args args
want *pixel.PictureData
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.PictureDataFromImage(tt.args.img); !reflect.DeepEqual(got, tt.want) {
t.Errorf("PictureDataFromImage() = %v, want %v", got, tt.want)
}
})
}
}
func TestPictureDataFromPicture(t *testing.T) {
type args struct {
pic pixel.Picture
}
tests := []struct {
name string
args args
want *pixel.PictureData
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.PictureDataFromPicture(tt.args.pic); !reflect.DeepEqual(got, tt.want) {
t.Errorf("PictureDataFromPicture() = %v, want %v", got, tt.want)
}
})
}
}
func TestPictureData_Image(t *testing.T) {
tests := []struct {
name string
pd *pixel.PictureData
want *image.RGBA
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.pd.Image(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("PictureData.Image() = %v, want %v", got, tt.want)
}
})
}
}
func TestPictureData_Index(t *testing.T) {
type args struct {
at pixel.Vec
}
tests := []struct {
name string
pd *pixel.PictureData
args args
want int
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.pd.Index(tt.args.at); got != tt.want {
t.Errorf("PictureData.Index() = %v, want %v", got, tt.want)
}
})
}
}
func TestPictureData_Bounds(t *testing.T) {
tests := []struct {
name string
pd *pixel.PictureData
want pixel.Rect
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.pd.Bounds(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("PictureData.Bounds() = %v, want %v", got, tt.want)
}
})
}
}
func TestPictureData_Color(t *testing.T) {
type args struct {
at pixel.Vec
}
tests := []struct {
name string
pd *pixel.PictureData
args args
want pixel.RGBA
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.pd.Color(tt.args.at); !reflect.DeepEqual(got, tt.want) {
t.Errorf("PictureData.Color() = %v, want %v", got, tt.want)
}
})
}
}

12
go.mod
View File

@ -1,12 +0,0 @@
module github.com/faiface/pixel
require (
github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3
github.com/go-gl/gl v0.0.0-20181026044259-55b76b7df9d2 // indirect
github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f
github.com/go-gl/mathgl v0.0.0-20180804195959-cdf14b6b8f8a
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/pkg/errors v0.8.1
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b
)

16
go.sum
View File

@ -1,16 +0,0 @@
github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380 h1:FvZ0mIGh6b3kOITxUnxS3tLZMh7yEoHo75v3/AgUqg0=
github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380/go.mod h1:zqnPFFIuYFFxl7uH2gYByJwIVKG7fRqlqQCbzAnHs9g=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M=
github.com/go-gl/gl v0.0.0-20181026044259-55b76b7df9d2 h1:78Hza2KHn2PX1jdydQnffaU2A/xM0g3Nx1xmMdep9Gk=
github.com/go-gl/gl v0.0.0-20181026044259-55b76b7df9d2/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f h1:7MsFMbSn8Lcw0blK4+NEOf8DuHoOBDhJsHz04yh13pM=
github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/mathgl v0.0.0-20180804195959-cdf14b6b8f8a h1:2n5w2v3knlspzjJWyQPC0j88Mwvq0SZV0Jdws34GJwc=
github.com/go-gl/mathgl v0.0.0-20180804195959-cdf14b6b8f8a/go.mod h1:dvrdneKbyWbK2skTda0nM4B9zSlS2GZSnjX7itr/skQ=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b h1:VHyIDlv3XkfCa5/a81uzaoDkHH4rr81Z62g+xlnO8uM=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=

View File

@ -1,609 +0,0 @@
package pixel_test
import (
"fmt"
"reflect"
"testing"
"github.com/faiface/pixel"
)
var (
squareAroundOrigin = pixel.R(-10, -10, 10, 10)
squareAround2020 = pixel.R(10, 10, 30, 30)
rectangleAroundOrigin = pixel.R(-20, -10, 20, 10)
rectangleAround2020 = pixel.R(0, 10, 40, 30)
)
func TestR(t *testing.T) {
type args struct {
minX float64
minY float64
maxX float64
maxY float64
}
tests := []struct {
name string
args args
want pixel.Rect
}{
{
name: "R(): square around origin",
args: args{minX: -10, minY: -10, maxX: 10, maxY: 10},
want: squareAroundOrigin,
},
{
name: "R(): square around 20 20",
args: args{minX: 10, minY: 10, maxX: 30, maxY: 30},
want: squareAround2020,
},
{
name: "R(): rectangle around origin",
args: args{minX: -20, minY: -10, maxX: 20, maxY: 10},
want: rectangleAroundOrigin,
},
{
name: "R(): square around 20 20",
args: args{minX: 0, minY: 10, maxX: 40, maxY: 30},
want: rectangleAround2020,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.R(tt.args.minX, tt.args.minY, tt.args.maxX, tt.args.maxY); !reflect.DeepEqual(got, tt.want) {
t.Errorf("R() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_String(t *testing.T) {
tests := []struct {
name string
r pixel.Rect
want string
}{
{
name: "Rect.String(): square around origin",
r: squareAroundOrigin,
want: "Rect(-10, -10, 10, 10)",
},
{
name: "Rect.String(): square around 20 20",
r: squareAround2020,
want: "Rect(10, 10, 30, 30)",
},
{
name: "Rect.String(): rectangle around origin",
r: rectangleAroundOrigin,
want: "Rect(-20, -10, 20, 10)",
},
{
name: "Rect.String(): square around 20 20",
r: rectangleAround2020,
want: "Rect(0, 10, 40, 30)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.String(); got != tt.want {
t.Errorf("Rect.String() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Norm(t *testing.T) {
tests := []struct {
name string
r pixel.Rect
want pixel.Rect
}{
{
name: "Rect.Norm(): square around origin",
r: squareAroundOrigin,
want: squareAroundOrigin,
},
{
name: "Rect.Norm(): square around 20 20",
r: squareAround2020,
want: squareAround2020,
},
{
name: "Rect.Norm(): rectangle around origin",
r: rectangleAroundOrigin,
want: rectangleAroundOrigin,
},
{
name: "Rect.Norm(): square around 20 20",
r: rectangleAround2020,
want: rectangleAround2020,
},
{
name: "Rect.Norm(): square around origin unnormalized",
r: pixel.Rect{Min: squareAroundOrigin.Max, Max: squareAroundOrigin.Min},
want: squareAroundOrigin,
},
{
name: "Rect.Norm(): square around 20 20 unnormalized",
r: pixel.Rect{Min: squareAround2020.Max, Max: squareAround2020.Min},
want: squareAround2020,
},
{
name: "Rect.Norm(): rectangle around origin unnormalized",
r: pixel.Rect{Min: rectangleAroundOrigin.Max, Max: rectangleAroundOrigin.Min},
want: rectangleAroundOrigin,
},
{
name: "Rect.Norm(): square around 20 20 unnormalized",
r: pixel.Rect{Min: rectangleAround2020.Max, Max: rectangleAround2020.Min},
want: rectangleAround2020,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Norm(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Rect.Norm() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_W(t *testing.T) {
tests := []struct {
name string
r pixel.Rect
want float64
}{
{
name: "Rect.W(): square around origin",
r: squareAroundOrigin,
want: 20,
},
{
name: "Rect.W(): square around 20 20",
r: squareAround2020,
want: 20,
},
{
name: "Rect.W(): rectangle around origin",
r: rectangleAroundOrigin,
want: 40,
},
{
name: "Rect.W(): square around 20 20",
r: rectangleAround2020,
want: 40,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.W(); got != tt.want {
t.Errorf("Rect.W() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_H(t *testing.T) {
tests := []struct {
name string
r pixel.Rect
want float64
}{
{
name: "Rect.H(): square around origin",
r: squareAroundOrigin,
want: 20,
},
{
name: "Rect.H(): square around 20 20",
r: squareAround2020,
want: 20,
},
{
name: "Rect.H(): rectangle around origin",
r: rectangleAroundOrigin,
want: 20,
},
{
name: "Rect.H(): square around 20 20",
r: rectangleAround2020,
want: 20,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.H(); got != tt.want {
t.Errorf("Rect.H() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Size(t *testing.T) {
tests := []struct {
name string
r pixel.Rect
want pixel.Vec
}{
{
name: "Rect.Size(): square around origin",
r: squareAroundOrigin,
want: pixel.V(20, 20),
},
{
name: "Rect.Size(): square around 20 20",
r: squareAround2020,
want: pixel.V(20, 20),
},
{
name: "Rect.Size(): rectangle around origin",
r: rectangleAroundOrigin,
want: pixel.V(40, 20),
},
{
name: "Rect.Size(): square around 20 20",
r: rectangleAround2020,
want: pixel.V(40, 20),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Size(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Rect.Size() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Area(t *testing.T) {
tests := []struct {
name string
r pixel.Rect
want float64
}{
{
name: "Rect.Area(): square around origin",
r: squareAroundOrigin,
want: 400,
},
{
name: "Rect.Area(): square around 20 20",
r: squareAround2020,
want: 400,
},
{
name: "Rect.Area(): rectangle around origin",
r: rectangleAroundOrigin,
want: 800,
},
{
name: "Rect.Area(): square around 20 20",
r: rectangleAround2020,
want: 800,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Area(); got != tt.want {
t.Errorf("Rect.Area() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Center(t *testing.T) {
tests := []struct {
name string
r pixel.Rect
want pixel.Vec
}{
{
name: "Rect.Center(): square around origin",
r: squareAroundOrigin,
want: pixel.V(0, 0),
},
{
name: "Rect.Center(): square around 20 20",
r: squareAround2020,
want: pixel.V(20, 20),
},
{
name: "Rect.Center(): rectangle around origin",
r: rectangleAroundOrigin,
want: pixel.V(0, 0),
},
{
name: "Rect.Center(): square around 20 20",
r: rectangleAround2020,
want: pixel.V(20, 20),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Center(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Rect.Center() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Moved(t *testing.T) {
positiveShift := pixel.V(10, 10)
negativeShift := pixel.V(-10, -10)
type args struct {
delta pixel.Vec
}
tests := []struct {
name string
r pixel.Rect
args args
want pixel.Rect
}{
{
name: "Rect.Moved(): positive shift",
r: squareAroundOrigin,
args: args{delta: positiveShift},
want: pixel.R(0, 0, 20, 20),
},
{
name: "Rect.Moved(): negative shift",
r: squareAroundOrigin,
args: args{delta: negativeShift},
want: pixel.R(-20, -20, 0, 0),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Moved(tt.args.delta); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Rect.Moved() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Resized(t *testing.T) {
// resize transformations
resizeByHalfAroundCenter := rectTestTransform{"by half around center", func(rect pixel.Rect) pixel.Rect {
return rect.Resized(rect.Center(), rect.Size().Scaled(0.5))
}}
resizeByHalfAroundMin := rectTestTransform{"by half around Min", func(rect pixel.Rect) pixel.Rect {
return rect.Resized(rect.Min, rect.Size().Scaled(0.5))
}}
resizeByHalfAroundMax := rectTestTransform{"by half around Max", func(rect pixel.Rect) pixel.Rect {
return rect.Resized(rect.Max, rect.Size().Scaled(0.5))
}}
resizeByHalfAroundMiddleOfLeftSide := rectTestTransform{"by half around middle of left side", func(rect pixel.Rect) pixel.Rect {
return rect.Resized(pixel.V(rect.Min.X, rect.Center().Y), rect.Size().Scaled(0.5))
}}
resizeByHalfAroundOrigin := rectTestTransform{"by half around the origin", func(rect pixel.Rect) pixel.Rect {
return rect.Resized(pixel.ZV, rect.Size().Scaled(0.5))
}}
testCases := []struct {
input pixel.Rect
transform rectTestTransform
answer pixel.Rect
}{
{squareAroundOrigin, resizeByHalfAroundCenter, pixel.R(-5, -5, 5, 5)},
{squareAround2020, resizeByHalfAroundCenter, pixel.R(15, 15, 25, 25)},
{rectangleAroundOrigin, resizeByHalfAroundCenter, pixel.R(-10, -5, 10, 5)},
{rectangleAround2020, resizeByHalfAroundCenter, pixel.R(10, 15, 30, 25)},
{squareAroundOrigin, resizeByHalfAroundMin, pixel.R(-10, -10, 0, 0)},
{squareAround2020, resizeByHalfAroundMin, pixel.R(10, 10, 20, 20)},
{rectangleAroundOrigin, resizeByHalfAroundMin, pixel.R(-20, -10, 0, 0)},
{rectangleAround2020, resizeByHalfAroundMin, pixel.R(0, 10, 20, 20)},
{squareAroundOrigin, resizeByHalfAroundMax, pixel.R(0, 0, 10, 10)},
{squareAround2020, resizeByHalfAroundMax, pixel.R(20, 20, 30, 30)},
{rectangleAroundOrigin, resizeByHalfAroundMax, pixel.R(0, 0, 20, 10)},
{rectangleAround2020, resizeByHalfAroundMax, pixel.R(20, 20, 40, 30)},
{squareAroundOrigin, resizeByHalfAroundMiddleOfLeftSide, pixel.R(-10, -5, 0, 5)},
{squareAround2020, resizeByHalfAroundMiddleOfLeftSide, pixel.R(10, 15, 20, 25)},
{rectangleAroundOrigin, resizeByHalfAroundMiddleOfLeftSide, pixel.R(-20, -5, 0, 5)},
{rectangleAround2020, resizeByHalfAroundMiddleOfLeftSide, pixel.R(0, 15, 20, 25)},
{squareAroundOrigin, resizeByHalfAroundOrigin, pixel.R(-5, -5, 5, 5)},
{squareAround2020, resizeByHalfAroundOrigin, pixel.R(5, 5, 15, 15)},
{rectangleAroundOrigin, resizeByHalfAroundOrigin, pixel.R(-10, -5, 10, 5)},
{rectangleAround2020, resizeByHalfAroundOrigin, pixel.R(0, 5, 20, 15)},
}
for _, testCase := range testCases {
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 {
t.Errorf("Got: %v, wanted: %v\n", testResult, testCase.answer)
}
})
}
}
func TestRect_ResizedMin(t *testing.T) {
grow := pixel.V(5, 5)
shrink := pixel.V(-5, -5)
type args struct {
size pixel.Vec
}
tests := []struct {
name string
r pixel.Rect
args args
want pixel.Rect
}{
{
name: "Rect.ResizedMin(): square around origin - growing",
r: squareAroundOrigin,
args: args{size: grow},
want: pixel.R(-10, -10, -5, -5),
},
{
name: "Rect.ResizedMin(): square around 20 20 - growing",
r: squareAround2020,
args: args{size: grow},
want: pixel.R(10, 10, 15, 15),
},
{
name: "Rect.ResizedMin(): rectangle around origin - growing",
r: rectangleAroundOrigin,
args: args{size: grow},
want: pixel.R(-20, -10, -15, -5),
},
{
name: "Rect.ResizedMin(): square around 20 20 - growing",
r: rectangleAround2020,
args: args{size: grow},
want: pixel.R(0, 10, 5, 15),
},
{
name: "Rect.ResizedMin(): square around origin - growing",
r: squareAroundOrigin,
args: args{size: shrink},
want: pixel.R(-10, -10, -15, -15),
},
{
name: "Rect.ResizedMin(): square around 20 20 - growing",
r: squareAround2020,
args: args{size: shrink},
want: pixel.R(10, 10, 5, 5),
},
{
name: "Rect.ResizedMin(): rectangle around origin - growing",
r: rectangleAroundOrigin,
args: args{size: shrink},
want: pixel.R(-20, -10, -25, -15),
},
{
name: "Rect.ResizedMin(): square around 20 20 - growing",
r: rectangleAround2020,
args: args{size: shrink},
want: pixel.R(0, 10, -5, 5),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.ResizedMin(tt.args.size); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Rect.ResizedMin() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Contains(t *testing.T) {
type args struct {
u pixel.Vec
}
tests := []struct {
name string
r pixel.Rect
args args
want bool
}{
{
name: "Rect.Contains(): square and contained vector",
r: squareAroundOrigin,
args: args{u: pixel.V(-5, 5)},
want: true,
},
{
name: "Rect.Contains(): square and seperate vector",
r: squareAroundOrigin,
args: args{u: pixel.V(50, 55)},
want: false,
},
{
name: "Rect.Contains(): square and overlapping vector",
r: squareAroundOrigin,
args: args{u: pixel.V(0, 50)},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Contains(tt.args.u); got != tt.want {
t.Errorf("Rect.Contains() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Union(t *testing.T) {
type args struct {
s pixel.Rect
}
tests := []struct {
name string
r pixel.Rect
args args
want pixel.Rect
}{
{
name: "Rect.Union(): seperate squares",
r: squareAroundOrigin,
args: args{s: squareAround2020},
want: pixel.R(-10, -10, 30, 30),
},
{
name: "Rect.Union(): overlapping squares",
r: squareAroundOrigin,
args: args{s: pixel.R(0, 0, 20, 20)},
want: pixel.R(-10, -10, 20, 20),
},
{
name: "Rect.Union(): square within a square",
r: squareAroundOrigin,
args: args{s: pixel.R(-5, -5, 5, 5)},
want: squareAroundOrigin,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Union(tt.args.s); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Rect.Union() = %v, want %v", got, tt.want)
}
})
}
}
func TestRect_Intersect(t *testing.T) {
type args struct {
s pixel.Rect
}
tests := []struct {
name string
r pixel.Rect
args args
want pixel.Rect
}{
{
name: "Rect.Union(): seperate squares",
r: squareAroundOrigin,
args: args{s: squareAround2020},
want: pixel.R(0, 0, 0, 0),
},
{
name: "Rect.Union(): overlapping squares",
r: squareAroundOrigin,
args: args{s: pixel.R(0, 0, 20, 20)},
want: pixel.R(0, 0, 10, 10),
},
{
name: "Rect.Union(): square within a square",
r: squareAroundOrigin,
args: args{s: pixel.R(-5, -5, 5, 5)},
want: pixel.R(-5, -5, 5, 5),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.r.Intersect(tt.args.s); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Rect.Intersect() = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -1,122 +0,0 @@
package pixel_test
import (
"image/color"
"reflect"
"testing"
"github.com/faiface/pixel"
)
func TestNewSprite(t *testing.T) {
type args struct {
pic pixel.Picture
frame pixel.Rect
}
tests := []struct {
name string
args args
want *pixel.Sprite
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.NewSprite(tt.args.pic, tt.args.frame); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewSprite() = %v, want %v", got, tt.want)
}
})
}
}
func TestSprite_Set(t *testing.T) {
type args struct {
pic pixel.Picture
frame pixel.Rect
}
tests := []struct {
name string
s *pixel.Sprite
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.s.Set(tt.args.pic, tt.args.frame)
})
}
}
func TestSprite_Picture(t *testing.T) {
tests := []struct {
name string
s *pixel.Sprite
want pixel.Picture
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Picture(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Sprite.Picture() = %v, want %v", got, tt.want)
}
})
}
}
func TestSprite_Frame(t *testing.T) {
tests := []struct {
name string
s *pixel.Sprite
want pixel.Rect
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Frame(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Sprite.Frame() = %v, want %v", got, tt.want)
}
})
}
}
func TestSprite_Draw(t *testing.T) {
type args struct {
t pixel.Target
matrix pixel.Matrix
}
tests := []struct {
name string
s *pixel.Sprite
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.s.Draw(tt.args.t, tt.args.matrix)
})
}
}
func TestSprite_DrawColorMask(t *testing.T) {
type args struct {
t pixel.Target
matrix pixel.Matrix
mask color.Color
}
tests := []struct {
name string
s *pixel.Sprite
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.s.DrawColorMask(tt.args.t, tt.args.matrix, tt.args.mask)
})
}
}

View File

@ -1,707 +0,0 @@
package pixel_test
import (
"math"
"reflect"
"testing"
"github.com/faiface/pixel"
)
// closeEnough is a test helper function to establish if vectors are "close enough". This is to resolve floating point
// errors, specifically when dealing with `math.Pi`
func closeEnough(u, v pixel.Vec) bool {
uX, uY := math.Round(u.X), math.Round(u.Y)
vX, vY := math.Round(v.X), math.Round(v.Y)
return uX == vX && uY == vY
}
func TestV(t *testing.T) {
type args struct {
x float64
y float64
}
tests := []struct {
name string
args args
want pixel.Vec
}{
{
name: "V(): both 0",
args: args{x: 0, y: 0},
want: pixel.ZV,
},
{
name: "V(): x < y",
args: args{x: 0, y: 10},
want: pixel.Vec{X: 0, Y: 10},
},
{
name: "V(): x > y",
args: args{x: 10, y: 0},
want: pixel.Vec{X: 10, Y: 0},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.V(tt.args.x, tt.args.y); !reflect.DeepEqual(got, tt.want) {
t.Errorf("V() = %v, want %v", got, tt.want)
}
})
}
}
func TestUnit(t *testing.T) {
type args struct {
angle float64
}
tests := []struct {
name string
args args
want pixel.Vec
}{
{
name: "Unit(): 0 radians",
args: args{angle: 0},
want: pixel.V(1, 0),
},
{
name: "Unit(): pi radians",
args: args{angle: math.Pi},
want: pixel.V(-1, 0),
},
{
name: "Unit(): 10 * pi radians",
args: args{angle: 10 * math.Pi},
want: pixel.V(1, 0),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.Unit(tt.args.angle); !closeEnough(got, tt.want) {
t.Errorf("Unit() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_String(t *testing.T) {
tests := []struct {
name string
u pixel.Vec
want string
}{
{
name: "Vec.String(): both 0",
u: pixel.Vec{X: 0, Y: 0},
want: "Vec(0, 0)",
},
{
name: "Vec.String(): x < y",
u: pixel.Vec{X: 0, Y: 10},
want: "Vec(0, 10)",
},
{
name: "Vec.String(): x > y",
u: pixel.Vec{X: 10, Y: 0},
want: "Vec(10, 0)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.String(); got != tt.want {
t.Errorf("Vec.String() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_XY(t *testing.T) {
tests := []struct {
name string
u pixel.Vec
wantX float64
wantY float64
}{
{
name: "Vec.XY(): both 0",
u: pixel.Vec{X: 0, Y: 0},
wantX: 0,
wantY: 0,
},
{
name: "Vec.XY(): x < y",
u: pixel.Vec{X: 0, Y: 10},
wantX: 0,
wantY: 10,
},
{
name: "Vec.XY(): x > y",
u: pixel.Vec{X: 10, Y: 0},
wantX: 10,
wantY: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotX, gotY := tt.u.XY()
if gotX != tt.wantX {
t.Errorf("Vec.XY() gotX = %v, want %v", gotX, tt.wantX)
}
if gotY != tt.wantY {
t.Errorf("Vec.XY() gotY = %v, want %v", gotY, tt.wantY)
}
})
}
}
func TestVec_Add(t *testing.T) {
type args struct {
v pixel.Vec
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.Add(): positive vector",
u: pixel.V(0, 10),
args: args{v: pixel.V(10, 10)},
want: pixel.V(10, 20),
},
{
name: "Vec.Add(): zero vector",
u: pixel.V(0, 10),
args: args{v: pixel.ZV},
want: pixel.V(0, 10),
},
{
name: "Vec.Add(): negative vector",
u: pixel.V(0, 10),
args: args{v: pixel.V(-20, -30)},
want: pixel.V(-20, -20),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Add(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.Add() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Sub(t *testing.T) {
type args struct {
v pixel.Vec
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.Sub(): positive vector",
u: pixel.V(0, 10),
args: args{v: pixel.V(10, 10)},
want: pixel.V(-10, 0),
},
{
name: "Vec.Sub(): zero vector",
u: pixel.V(0, 10),
args: args{v: pixel.ZV},
want: pixel.V(0, 10),
},
{
name: "Vec.Sub(): negative vector",
u: pixel.V(0, 10),
args: args{v: pixel.V(-20, -30)},
want: pixel.V(20, 40),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Sub(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.Sub() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_To(t *testing.T) {
type args struct {
v pixel.Vec
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.To(): positive vector",
u: pixel.V(0, 10),
args: args{v: pixel.V(10, 10)},
want: pixel.V(10, 0),
},
{
name: "Vec.To(): zero vector",
u: pixel.V(0, 10),
args: args{v: pixel.ZV},
want: pixel.V(0, -10),
},
{
name: "Vec.To(): negative vector",
u: pixel.V(0, 10),
args: args{v: pixel.V(-20, -30)},
want: pixel.V(-20, -40),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.To(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.To() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Scaled(t *testing.T) {
type args struct {
c float64
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.Scaled(): positive scale",
u: pixel.V(0, 10),
args: args{c: 10},
want: pixel.V(0, 100),
},
{
name: "Vec.Scaled(): zero scale",
u: pixel.V(0, 10),
args: args{c: 0},
want: pixel.ZV,
},
{
name: "Vec.Scaled(): identity scale",
u: pixel.V(0, 10),
args: args{c: 1},
want: pixel.V(0, 10),
},
{
name: "Vec.Scaled(): negative scale",
u: pixel.V(0, 10),
args: args{c: -10},
want: pixel.V(0, -100),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Scaled(tt.args.c); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.Scaled() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_ScaledXY(t *testing.T) {
type args struct {
v pixel.Vec
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.ScaledXY(): positive scale",
u: pixel.V(0, 10),
args: args{v: pixel.V(10, 20)},
want: pixel.V(0, 200),
},
{
name: "Vec.ScaledXY(): zero scale",
u: pixel.V(0, 10),
args: args{v: pixel.ZV},
want: pixel.ZV,
},
{
name: "Vec.ScaledXY(): identity scale",
u: pixel.V(0, 10),
args: args{v: pixel.V(1, 1)},
want: pixel.V(0, 10),
},
{
name: "Vec.ScaledXY(): negative scale",
u: pixel.V(0, 10),
args: args{v: pixel.V(-5, -10)},
want: pixel.V(0, -100),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.ScaledXY(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.ScaledXY() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Len(t *testing.T) {
tests := []struct {
name string
u pixel.Vec
want float64
}{
{
name: "Vec.Len(): positive vector",
u: pixel.V(40, 30),
want: 50,
},
{
name: "Vec.Len(): zero vector",
u: pixel.ZV,
want: 0,
},
{
name: "Vec.Len(): negative vector",
u: pixel.V(-5, -12),
want: 13,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Len(); got != tt.want {
t.Errorf("Vec.Len() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Angle(t *testing.T) {
tests := []struct {
name string
u pixel.Vec
want float64
}{
{
name: "Vec.Angle(): positive vector",
u: pixel.V(0, 30),
want: math.Pi / 2,
},
{
name: "Vec.Angle(): zero vector",
u: pixel.ZV,
want: 0,
},
{
name: "Vec.Angle(): negative vector",
u: pixel.V(-5, -0),
want: math.Pi,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Angle(); got != tt.want {
t.Errorf("Vec.Angle() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Unit(t *testing.T) {
tests := []struct {
name string
u pixel.Vec
want pixel.Vec
}{
{
name: "Vec.Unit(): positive vector",
u: pixel.V(0, 30),
want: pixel.V(0, 1),
},
{
name: "Vec.Unit(): zero vector",
u: pixel.ZV,
want: pixel.V(1, 0),
},
{
name: "Vec.Unit(): negative vector",
u: pixel.V(-5, 0),
want: pixel.V(-1, 0),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Unit(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.Unit() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Rotated(t *testing.T) {
type args struct {
angle float64
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.Rotated(): partial rotation",
u: pixel.V(0, 1),
args: args{angle: math.Pi / 2},
want: pixel.V(-1, 0),
},
{
name: "Vec.Rotated(): full rotation",
u: pixel.V(0, 1),
args: args{angle: 2 * math.Pi},
want: pixel.V(0, 1),
},
{
name: "Vec.Rotated(): zero rotation",
u: pixel.V(0, 1),
args: args{angle: 0},
want: pixel.V(0, 1),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Rotated(tt.args.angle); !closeEnough(got, tt.want) {
t.Errorf("Vec.Rotated() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Normal(t *testing.T) {
tests := []struct {
name string
u pixel.Vec
want pixel.Vec
}{
{
name: "Vec.Normal(): positive vector",
u: pixel.V(0, 30),
want: pixel.V(-30, 0),
},
{
name: "Vec.Normal(): zero vector",
u: pixel.ZV,
want: pixel.ZV,
},
{
name: "Vec.Normal(): negative vector",
u: pixel.V(-5, 0),
want: pixel.V(0, -5),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Normal(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.Normal() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Dot(t *testing.T) {
type args struct {
v pixel.Vec
}
tests := []struct {
name string
u pixel.Vec
args args
want float64
}{
{
name: "Vec.Dot(): positive vector",
u: pixel.V(0, 30),
args: args{v: pixel.V(10, 10)},
want: 300,
},
{
name: "Vec.Dot(): zero vector",
u: pixel.ZV,
args: args{v: pixel.V(10, 10)},
want: 0,
},
{
name: "Vec.Dot(): negative vector",
u: pixel.V(-5, 1),
args: args{v: pixel.V(10, 10)},
want: -40,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Dot(tt.args.v); got != tt.want {
t.Errorf("Vec.Dot() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Cross(t *testing.T) {
type args struct {
v pixel.Vec
}
tests := []struct {
name string
u pixel.Vec
args args
want float64
}{
{
name: "Vec.Cross(): positive vector",
u: pixel.V(0, 30),
args: args{v: pixel.V(10, 10)},
want: -300,
},
{
name: "Vec.Cross(): zero vector",
u: pixel.ZV,
args: args{v: pixel.V(10, 10)},
want: 0,
},
{
name: "Vec.Cross(): negative vector",
u: pixel.V(-5, 1),
args: args{v: pixel.V(10, 10)},
want: -60,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Cross(tt.args.v); got != tt.want {
t.Errorf("Vec.Cross() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Project(t *testing.T) {
type args struct {
v pixel.Vec
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.Project(): positive vector",
u: pixel.V(0, 30),
args: args{v: pixel.V(10, 10)},
want: pixel.V(15, 15),
},
{
name: "Vec.Project(): zero vector",
u: pixel.ZV,
args: args{v: pixel.V(10, 10)},
want: pixel.ZV,
},
{
name: "Vec.Project(): negative vector",
u: pixel.V(-30, 0),
args: args{v: pixel.V(10, 10)},
want: pixel.V(-15, -15),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Project(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.Project() = %v, want %v", got, tt.want)
}
})
}
}
func TestVec_Map(t *testing.T) {
type args struct {
f func(float64) float64
}
tests := []struct {
name string
u pixel.Vec
args args
want pixel.Vec
}{
{
name: "Vec.Map(): positive vector",
u: pixel.V(0, 25),
args: args{f: math.Sqrt},
want: pixel.V(0, 5),
},
{
name: "Vec.Map(): zero vector",
u: pixel.ZV,
args: args{f: math.Sqrt},
want: pixel.ZV,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.u.Map(tt.args.f); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Vec.Map() = %v, want %v", got, tt.want)
}
})
}
}
func TestLerp(t *testing.T) {
type args struct {
a pixel.Vec
b pixel.Vec
t float64
}
tests := []struct {
name string
args args
want pixel.Vec
}{
{
name: "Lerp(): t = 0",
args: args{a: pixel.V(10, 10), b: pixel.ZV, t: 0},
want: pixel.V(10, 10),
},
{
name: "Lerp(): t = 1/4",
args: args{a: pixel.V(10, 10), b: pixel.ZV, t: .25},
want: pixel.V(7.5, 7.5),
},
{
name: "Lerp(): t = 1/2",
args: args{a: pixel.V(10, 10), b: pixel.ZV, t: .5},
want: pixel.V(5, 5),
},
{
name: "Lerp(): t = 1",
args: args{a: pixel.V(10, 10), b: pixel.ZV, t: 1},
want: pixel.ZV,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := pixel.Lerp(tt.args.a, tt.args.b, tt.args.t); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Lerp() = %v, want %v", got, tt.want)
}
})
}
}