From 1fd058947d760045b08137f3a1e305edda261ec9 Mon Sep 17 00:00:00 2001 From: Gbenga Adeyi Date: Thu, 5 Oct 2023 14:26:39 +0100 Subject: [PATCH 1/2] Test V2F and V3F associated Abs and AbsInPlace functions --- abs_test.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 abs_test.go diff --git a/abs_test.go b/abs_test.go new file mode 100644 index 0000000..86cd168 --- /dev/null +++ b/abs_test.go @@ -0,0 +1,95 @@ +package govec + +import "testing" + +func TestV2F_Abs(t *testing.T) { + vectors := []V2F[float64]{ + {X: 0.0, Y: 0.0}, + {X: -1.0, Y: 0.0}, + {X: 0.0, Y: -1.0}, + {X: 1, Y: 1}, + } + expectedAbsResult := []V2F[float64]{ + {X: 0.0, Y: 0.0}, + {X: 1.0, Y: 0.0}, + {X: 0.0, Y: 1.0}, + {X: 1.0, Y: 1.0}, + } + for idx, vector := range vectors { + absV := vector.Abs() + expectedAbsV := expectedAbsResult[idx] + if absV.X != expectedAbsV.X || absV.Y != expectedAbsV.Y { + t.Errorf("%#v.Abs() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, absV) + } + } +} + +func TestV2F_AbsInPlace(t *testing.T) { + vectors := []V2F[float64]{ + {X: 0.0, Y: 0.0}, + {X: -1.0, Y: 0.0}, + {X: 0.0, Y: -1.0}, + {X: 1, Y: 1}, + } + expectedAbsInPlaceResult := []V2F[float64]{ + {X: 0.0, Y: 0.0}, + {X: 1.0, Y: 0.0}, + {X: 0.0, Y: 1.0}, + {X: 1.0, Y: 1.0}, + } + for idx, vector := range vectors { + vector.AbsInPlace() + expectedAbsV := expectedAbsInPlaceResult[idx] + if vector.X != expectedAbsV.X || vector.Y != expectedAbsV.Y { + t.Errorf("%#v.AbsInPlace() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, vector) + } + } +} + +func TestV3F_Abs(t *testing.T) { + vectors := []V3F[float64]{ + {X: 0.0, Y: 0.0, Z: 0.0}, + {X: -1.0, Y: 0.0, Z: 0.0}, + {X: 0.0, Y: -1.0, Z: 0.0}, + {X: 0.0, Y: 1.0, Z: -1.0}, + {X: 1, Y: 1, Z: 0}, + } + expectedAbsResult := []V3F[float64]{ + {X: 0.0, Y: 0.0, Z: 0.0}, + {X: 1.0, Y: 0.0, Z: 0.0}, + {X: 0.0, Y: 1.0, Z: 0.0}, + {X: 0.0, Y: 1.0, Z: 1.0}, + {X: 1.0, Y: 1.0, Z: 0.0}, + } + for idx, vector := range vectors { + absV := vector.Abs() + expectedAbsV := expectedAbsResult[idx] + if absV.X != expectedAbsV.X || absV.Y != expectedAbsV.Y || absV.Z != expectedAbsV.Z { + t.Errorf("%#v.Abs() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, absV) + } + } +} + +func TestV3F_AbsInPlace(t *testing.T) { + vectors := []V3F[float64]{ + {X: 0.0, Y: 0.0, Z: 0.0}, + {X: -1.0, Y: 0.0, Z: 0.0}, + {X: 0.0, Y: -1.0, Z: 0.0}, + {X: 0.0, Y: 1.0, Z: -1.0}, + {X: 1, Y: 1, Z: 0}, + } + expectedAbsInPlaceResult := []V3F[float64]{ + {X: 0.0, Y: 0.0, Z: 0.0}, + {X: 1.0, Y: 0.0, Z: 0.0}, + {X: 0.0, Y: 1.0, Z: 0.0}, + {X: 0.0, Y: 1.0, Z: 1.0}, + {X: 1.0, Y: 1.0, Z: 0.0}, + } + for idx, vector := range vectors { + vector.AbsInPlace() + expectedAbsV := expectedAbsInPlaceResult[idx] + if vector.X != expectedAbsV.X || vector.Y != expectedAbsV.Y || vector.Z != expectedAbsV.Z { + t.Errorf("%#v.Abs() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, vector) + } + } +} From 39df380c416144cc9f8007e6aaf6003f21fb8db1 Mon Sep 17 00:00:00 2001 From: Gbenga Adeyi Date: Thu, 5 Oct 2023 14:31:32 +0100 Subject: [PATCH 2/2] Fix incorrect text --- abs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abs_test.go b/abs_test.go index 86cd168..9c908f0 100644 --- a/abs_test.go +++ b/abs_test.go @@ -89,7 +89,7 @@ func TestV3F_AbsInPlace(t *testing.T) { vector.AbsInPlace() expectedAbsV := expectedAbsInPlaceResult[idx] if vector.X != expectedAbsV.X || vector.Y != expectedAbsV.Y || vector.Z != expectedAbsV.Z { - t.Errorf("%#v.Abs() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, vector) + t.Errorf("%#v.AbsInPlace() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, vector) } } }