From 2bdd7b2d028273c9c4f96a84352bdb54795ba171 Mon Sep 17 00:00:00 2001 From: bloeys Date: Fri, 5 Nov 2021 07:39:55 +0400 Subject: [PATCH] Mat4 tests --- gglm/mat4_test.go | 153 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/gglm/mat4_test.go b/gglm/mat4_test.go index 2aedaee..3b2da19 100755 --- a/gglm/mat4_test.go +++ b/gglm/mat4_test.go @@ -6,6 +6,159 @@ import ( "github.com/bloeys/gglm/gglm" ) +func TestMat4GetSet(t *testing.T) { + + m1 := gglm.Mat4{} + + m1.Set(0, 1, -10) + m1.Set(1, 0, 55) + m1.Set(2, 2, 99) + m1.Set(3, 3, 513) + + if m1.Get(0, 1) != -10 { + t.Errorf("Got: %v; Expected: %v", m1.Get(0, 1), -10) + } + + if m1.Get(1, 0) != 55 { + t.Errorf("Got: %v; Expected: %v", m1.Get(1, 0), 55) + } + + if m1.Get(2, 2) != 99 { + t.Errorf("Got: %v; Expected: %v", m1.Get(2, 2), 99) + } + + if m1.Get(3, 3) != 513 { + t.Errorf("Got: %v; Expected: %v", m1.Get(3, 3), 513) + } +} + +func TestMat4Id(t *testing.T) { + + correctAns := gglm.Mat4{ + Data: [16]float32{ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, + }} + + m1 := gglm.NewMat4Id() + if !m1.Eq(&correctAns) { + t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String()) + } +} + +func TestSubMat4(t *testing.T) { + + correctAns := gglm.Mat4{ + Data: [16]float32{ + -16, -16, -16, -16, + -16, -16, -16, -16, + -16, -16, -16, -16, + -16, -16, -16, -16, + }} + + m1 := &gglm.Mat4{ + Data: [16]float32{ + 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16, + }} + m2 := &gglm.Mat4{ + Data: [16]float32{ + 17, 18, 19, 20, + 21, 22, 23, 24, + 25, 26, 27, 28, + 29, 30, 31, 32, + }} + + result := gglm.SubMat4(m1, m2) + m1.Sub(m2) + + if !result.Eq(&correctAns) { + t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String()) + } + + if !m1.Eq(&correctAns) { + t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String()) + } +} + +func TestAddMat4(t *testing.T) { + + correctAns := gglm.Mat4{ + Data: [16]float32{ + 18, 20, 22, 24, + 26, 28, 30, 32, + 34, 36, 38, 40, + 42, 44, 46, 48, + }} + + m1 := &gglm.Mat4{ + Data: [16]float32{ + 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16, + }} + m2 := &gglm.Mat4{ + Data: [16]float32{ + 17, 18, 19, 20, + 21, 22, 23, 24, + 25, 26, 27, 28, + 29, 30, 31, 32, + }} + + result := gglm.AddMat4(m1, m2) + m1.Add(m2) + + if !result.Eq(&correctAns) { + t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String()) + } + + if !m1.Eq(&correctAns) { + t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String()) + } +} + +func TestMulMat4(t *testing.T) { + + correctAns := gglm.Mat4{ + Data: [16]float32{ + 250, 260, 270, 280, + 618, 644, 670, 696, + 986, 1028, 1070, 1112, + 1354, 1412, 1470, 1528, + }} + + m1 := &gglm.Mat4{ + Data: [16]float32{ + 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16, + }} + m2 := &gglm.Mat4{ + Data: [16]float32{ + 17, 18, 19, 20, + 21, 22, 23, 24, + 25, 26, 27, 28, + 29, 30, 31, 32, + }} + + result := gglm.MulMat4(m1, m2) + m1.Mul(m2) + + if !result.Eq(&correctAns) { + t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String()) + } + + if !m1.Eq(&correctAns) { + t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String()) + } +} + func TestMulMat4Vec4(t *testing.T) { m := &gglm.Mat4{