From 2cc6f30facabeb622034af06f06534721b456f9f Mon Sep 17 00:00:00 2001 From: John Schneider <8369707+A1steaksa@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:12:05 -0500 Subject: [PATCH 1/7] Added first Angle:Add test --- lua/tests/gmod/classes/Angle/Add.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lua/tests/gmod/classes/Angle/Add.lua diff --git a/lua/tests/gmod/classes/Angle/Add.lua b/lua/tests/gmod/classes/Angle/Add.lua new file mode 100644 index 0000000..7d64463 --- /dev/null +++ b/lua/tests/gmod/classes/Angle/Add.lua @@ -0,0 +1,14 @@ +return{ + groupName = "Angle:Add", + + cases = { + { + name = "Exists in Angle metatable", + func = function() + local metatable = FindMetaTable( "Angle" ) + expect( metatable.Add ).to.beA( "function" ) + end + }, + + } +} \ No newline at end of file From a0db662305cd8899b1661c6f348b67a1d2d24f2c Mon Sep 17 00:00:00 2001 From: John Schneider <8369707+A1steaksa@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:12:19 -0500 Subject: [PATCH 2/7] Added first tests for Angle --- lua/tests/gmod/globals/angle.lua | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lua/tests/gmod/globals/angle.lua diff --git a/lua/tests/gmod/globals/angle.lua b/lua/tests/gmod/globals/angle.lua new file mode 100644 index 0000000..99dc0d9 --- /dev/null +++ b/lua/tests/gmod/globals/angle.lua @@ -0,0 +1,71 @@ +return{ + groupName = "Angle", + + cases = { + { + name = "Function exists globally", + func = function() + expect( Angle ).to.beA( "function" ) + end + }, + + { + name = "Returns an Angle object", + func = function() + local angle = Angle( 1, 2, 3 ) + expect( angle ).to.beA( "Angle" ) + end + }, + + { + name = "Pitch equivalents match input", + func = function() + local angle = Angle( 1, 2, 3 ) + expect( angle.x ).to.equal( 1 ) + expect( angle.p ).to.equal( 1 ) + expect( angle.pitch ).to.equal( 1 ) + end + }, + + { + name = "Yaw equivalents match input", + func = function() + local angle = Angle( 1, 2, 3 ) + expect( angle.y ).to.equal( 2 ) + expect( angle.yaw ).to.equal( 2 ) + end + }, + + { + name = "Roll equivalents match input", + func = function() + local angle = Angle( 1, 2, 3 ) + expect( angle.z ).to.equal( 3 ) + expect( angle.r ).to.equal( 3 ) + expect( angle.roll ).to.equal( 3 ) + end + }, + + { + name = "Accepts negative values", + func = function() + local angle = Angle( -99, -0, 50 ) + expect( angle.pitch ).to.equal( -99 ) + expect( angle.yaw ).to.equal( -0 ) + expect( angle.roll ).to.equal( 50 ) + end + }, + + { + name = "Accepts decimals", + func = function() + local angle = Angle( 0.001, 80, 100.000 ) + expect( angle.pitch ).to.equal( 0.001 ) + expect( angle.yaw ).to.equal( 80 ) + expect( angle.roll ).to.equal( 100 ) + end + }, + + + } +} \ No newline at end of file From 9695e0d6ffdfb90ae93235b70a356893055d664d Mon Sep 17 00:00:00 2001 From: John Schneider <8369707+A1steaksa@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:13:10 -0500 Subject: [PATCH 3/7] =?UTF-8?q?Renamed=20Color=20"returns=20a=20Color=20ob?= =?UTF-8?q?ject"=20to=20"Returns=20a=20table=20with=20the=20Color=20metata?= =?UTF-8?q?ble"=20which=20is=20technically=20more=20accurate=20?= =?UTF-8?q?=F0=9F=A4=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/tests/gmod/globals/Color.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tests/gmod/globals/Color.lua b/lua/tests/gmod/globals/Color.lua index d4fb0ef..a2c897e 100644 --- a/lua/tests/gmod/globals/Color.lua +++ b/lua/tests/gmod/globals/Color.lua @@ -9,7 +9,7 @@ return { }, { - name = "Returns a Color object", + name = "Returns a table with the Color metatable", func = function() local color = Color( 1, 2, 3, 4 ) expect( color ).to.beA( "table" ) From 1e5ab06c95f7d56d9cfdd9f3cc80ef1e738d51a2 Mon Sep 17 00:00:00 2001 From: John Schneider <8369707+A1steaksa@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:13:44 -0500 Subject: [PATCH 4/7] Added .gitignore for VSCode settings --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6f9a44 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/settings.json From f41ae45f8c2c2689edb619175d7a4a60769ea05a Mon Sep 17 00:00:00 2001 From: John Schneider <8369707+A1steaksa@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:42:24 -0500 Subject: [PATCH 5/7] Added regions Added pitch/yaw/roll tests Added Angle copy tests Added String parsing tests --- lua/tests/gmod/globals/angle.lua | 133 ++++++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 18 deletions(-) diff --git a/lua/tests/gmod/globals/angle.lua b/lua/tests/gmod/globals/angle.lua index 99dc0d9..0308a91 100644 --- a/lua/tests/gmod/globals/angle.lua +++ b/lua/tests/gmod/globals/angle.lua @@ -2,21 +2,24 @@ return{ groupName = "Angle", cases = { + --[[ Function Signature ]]-- + --#region { name = "Function exists globally", func = function() expect( Angle ).to.beA( "function" ) end - }, - - { + },{ name = "Returns an Angle object", func = function() local angle = Angle( 1, 2, 3 ) expect( angle ).to.beA( "Angle" ) end }, - + --#endregion + + --[[ Pitch/Yaw/Roll Variable Equivalents ]]-- + --#region { name = "Pitch equivalents match input", func = function() @@ -25,18 +28,14 @@ return{ expect( angle.p ).to.equal( 1 ) expect( angle.pitch ).to.equal( 1 ) end - }, - - { + },{ name = "Yaw equivalents match input", func = function() local angle = Angle( 1, 2, 3 ) expect( angle.y ).to.equal( 2 ) expect( angle.yaw ).to.equal( 2 ) end - }, - - { + },{ name = "Roll equivalents match input", func = function() local angle = Angle( 1, 2, 3 ) @@ -45,8 +44,19 @@ return{ expect( angle.roll ).to.equal( 3 ) end }, - + --#endregion + + --[[ Pitch/Yaw/Roll Constructor ]]-- + --#region { + name = "Accepts decimals", + func = function() + local angle = Angle( 0.001, 80, 100.000 ) + expect( angle.pitch ).to.beBetween( 0.0009, 0.0011 ) + expect( angle.yaw ).to.equal( 80 ) + expect( angle.roll ).to.equal( 100 ) + end + },{ name = "Accepts negative values", func = function() local angle = Angle( -99, -0, 50 ) @@ -54,18 +64,105 @@ return{ expect( angle.yaw ).to.equal( -0 ) expect( angle.roll ).to.equal( 50 ) end - }, + },{ + name = "Accepts numerical strings", + func = function() + local angle = Angle( "5", "10", "15" ) + expect( angle.pitch ).to.equal( 5 ) + expect( angle.yaw ).to.equal( 10 ) + expect( angle.roll ).to.equal( 15 ) + end + },{ + name = "Nil pitch returns 0, 0, 0", + func = function() + local angle = Angle( nil, 10, 22 ) + expect( angle.pitch ).to.equal( 0 ) + expect( angle.yaw ).to.equal( 0 ) + expect( angle.roll ).to.equal( 0 ) + end + },{ + name = "Table pitch returns 0, 0, 0", + func = function() + local angle = Angle( { "test" }, 10, 22 ) + expect( angle.pitch ).to.equal( 0 ) + expect( angle.yaw ).to.equal( 0 ) + expect( angle.roll ).to.equal( 0 ) + end + },{ + name = "Yaw falls back to 0", + func = function() + local nilYawAngle = Angle( 100, nil, 22 ) + expect( nilYawAngle.pitch ).to.equal( 100 ) + expect( nilYawAngle.yaw ).to.equal( 0 ) + expect( nilYawAngle.roll ).to.equal( 22 ) - { - name = "Accepts decimals", + local tableYawAngle = Angle( 100, {}, 22 ) + expect( tableYawAngle.pitch ).to.equal( 100 ) + expect( tableYawAngle.yaw ).to.equal( 0 ) + expect( tableYawAngle.roll ).to.equal( 22 ) + + local nonNumberStringYawAngle = Angle( 100, "test", 22 ) + expect( nonNumberStringYawAngle.pitch ).to.equal( 100 ) + expect( nonNumberStringYawAngle.yaw ).to.equal( 0 ) + expect( nonNumberStringYawAngle.roll ).to.equal( 22 ) + end + },{ + name = "Roll falls back to 0", func = function() - local angle = Angle( 0.001, 80, 100.000 ) - expect( angle.pitch ).to.equal( 0.001 ) - expect( angle.yaw ).to.equal( 80 ) - expect( angle.roll ).to.equal( 100 ) + local nilRollAngle = Angle( 100, 714, nil ) + expect( nilRollAngle.pitch ).to.equal( 100 ) + expect( nilRollAngle.yaw ).to.equal( 714 ) + expect( nilRollAngle.roll ).to.equal( 0 ) + + local tableRollAngle = Angle( 100, 714, {} ) + expect( tableRollAngle.pitch ).to.equal( 100 ) + expect( tableRollAngle.yaw ).to.equal( 714 ) + expect( tableRollAngle.roll ).to.equal( 0 ) + + local nonNumberStringRollAngle = Angle( 100, 714, "test" ) + expect( nonNumberStringRollAngle.pitch ).to.equal( 100 ) + expect( nonNumberStringRollAngle.yaw ).to.equal( 714 ) + expect( nonNumberStringRollAngle.roll ).to.equal( 0 ) end }, + --#endregion + --[[ Angle Copying Constructor ]]-- + --#region + { + name = "Copies other Angles", + func = function() + local angleToCopy = Angle( 0, 80, -100 ) + local angle = Angle( angleToCopy ) + expect( angle.pitch ).to.equal( 0 ) + expect( angle.yaw ).to.equal( 80 ) + expect( angle.roll ).to.equal( -100 ) + end + }, + --#endregion + + --[[ Parse String Constructor ]]-- + --#region + { + name = "Parses String Angles", + func = function() + local positiveIntegerStringAngle = Angle( "5 10 22" ) + expect( positiveIntegerStringAngle.pitch ).to.equal( 5 ) + expect( positiveIntegerStringAngle.yaw ).to.equal( 10 ) + expect( positiveIntegerStringAngle.roll ).to.equal( 22 ) + + local negativeIntegerStringAngle = Angle( "-5 -10 -22" ) + expect( negativeIntegerStringAngle.pitch ).to.equal( -5 ) + expect( negativeIntegerStringAngle.yaw ).to.equal( -10 ) + expect( negativeIntegerStringAngle.roll ).to.equal( -22 ) + + local floatStringAngle = Angle( "0.2 9999.2 -1000" ) + expect( floatStringAngle.pitch ).to.beBetween( 0.19, 0.21 ) + expect( floatStringAngle.yaw ).to.beBetween( 9999.19, 9999.21 ) + expect( floatStringAngle.roll ).to.equal( -1000 ) + end + }, + --#endregion } } \ No newline at end of file From c77bb373c702d0faeb29669fde881f2e894ea0a0 Mon Sep 17 00:00:00 2001 From: John Schneider <8369707+A1steaksa@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:47:26 -0500 Subject: [PATCH 6/7] Removed Angle:Add, will re-add later --- lua/tests/gmod/classes/Angle/Add.lua | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 lua/tests/gmod/classes/Angle/Add.lua diff --git a/lua/tests/gmod/classes/Angle/Add.lua b/lua/tests/gmod/classes/Angle/Add.lua deleted file mode 100644 index 7d64463..0000000 --- a/lua/tests/gmod/classes/Angle/Add.lua +++ /dev/null @@ -1,14 +0,0 @@ -return{ - groupName = "Angle:Add", - - cases = { - { - name = "Exists in Angle metatable", - func = function() - local metatable = FindMetaTable( "Angle" ) - expect( metatable.Add ).to.beA( "function" ) - end - }, - - } -} \ No newline at end of file From 521c652e0b0004ee60b85e03d2118eeb753867a4 Mon Sep 17 00:00:00 2001 From: John Schneider <8369707+A1steaksa@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:34:00 -0500 Subject: [PATCH 7/7] Update lua/tests/gmod/globals/angle.lua Co-authored-by: Brandon Sturgeon --- lua/tests/gmod/globals/angle.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/tests/gmod/globals/angle.lua b/lua/tests/gmod/globals/angle.lua index 0308a91..aab1698 100644 --- a/lua/tests/gmod/globals/angle.lua +++ b/lua/tests/gmod/globals/angle.lua @@ -24,6 +24,7 @@ return{ name = "Pitch equivalents match input", func = function() local angle = Angle( 1, 2, 3 ) + expect( angle[1] ).to.equal( 1 ) expect( angle.x ).to.equal( 1 ) expect( angle.p ).to.equal( 1 ) expect( angle.pitch ).to.equal( 1 ) @@ -32,6 +33,7 @@ return{ name = "Yaw equivalents match input", func = function() local angle = Angle( 1, 2, 3 ) + expect( angle[2] ).to.equal( 2 ) expect( angle.y ).to.equal( 2 ) expect( angle.yaw ).to.equal( 2 ) end @@ -39,6 +41,7 @@ return{ name = "Roll equivalents match input", func = function() local angle = Angle( 1, 2, 3 ) + expect( angle[3] ).to.equal( 3 ) expect( angle.z ).to.equal( 3 ) expect( angle.r ).to.equal( 3 ) expect( angle.roll ).to.equal( 3 )