From 2fde03e4e44704019966016c70f50abf34996acf Mon Sep 17 00:00:00 2001 From: flyingapricot Date: Mon, 29 Jul 2024 03:38:33 +0800 Subject: [PATCH 1/2] Updating some unit tests --- .plastic/plastic.changes | Bin 3622123 -> 3624466 bytes .plastic/plastic.wktree | Bin 3690078 -> 3692465 bytes Assets/Scripts/Main.asmdef | 19 +++++++++++++++ Assets/Scripts/Main.asmdef.meta | 7 ++++++ Assets/Tests.meta | 8 +++++++ Assets/Tests/EditMode.meta | 8 +++++++ Assets/Tests/EditMode/DirectionTests.cs | 15 ++++++++++++ Assets/Tests/EditMode/DirectionTests.cs.meta | 11 +++++++++ Assets/Tests/EditMode/Tests.asmdef | 24 +++++++++++++++++++ Assets/Tests/EditMode/Tests.asmdef.meta | 7 ++++++ 10 files changed, 99 insertions(+) create mode 100644 Assets/Scripts/Main.asmdef create mode 100644 Assets/Scripts/Main.asmdef.meta create mode 100644 Assets/Tests.meta create mode 100644 Assets/Tests/EditMode.meta create mode 100644 Assets/Tests/EditMode/DirectionTests.cs create mode 100644 Assets/Tests/EditMode/DirectionTests.cs.meta create mode 100644 Assets/Tests/EditMode/Tests.asmdef create mode 100644 Assets/Tests/EditMode/Tests.asmdef.meta diff --git a/.plastic/plastic.changes b/.plastic/plastic.changes index e487281dbfa7911f6bff33d437782005b68b71e4..0deb3fa6f22ad89c1da233460b5c2375bbeb5cd8 100644 GIT binary patch delta 650 zcmYk(O-~b16b9hFG6OB0LdOsMsxmEBYUQg`XN)uvwG^xpYvQ7D*Vry5Y8#+`z?Cs3 zCNSznMUpB-ml_sbXpBDr!w$lNgdH1=?%ep!To*2$|DZ_8ulti)au8)R}q_E%|z?zRcr*E^lOShg8#VHI5 z=Oz~2>!FLyJO;2RXL@g76hh{WJZE0WeC0YW;JM7duW{cqnM--@b7amowKI>31<*cf zBZX9Irw;N{fI2Bi8ilBfx+zRL?WY5DkPcA~9i}66l#bDHiqHuLsi{S<>NN@(gaV4s=hNH?G14μTrqcHOPa3GcPvd8Lq^wP!1L>vpZmp19m$ u8F(u@eE9!5Kex;{8eS(5`nR>>=v@Yy;^BQ{+T8Kz6D@}Kt@&~5j`9~jOxzIw delta 298 zcmW;GKTg7M96<4YwN#M`MM3_lEh>rv6$D!j;NoCn94H=w!Nkc67&oKC&w<6=!Gxg+ zvj>2Xm@sex7ZWEp9}b`4ZSSc+ldp%FyeCDfYUnzpfiKOG(bhE0xKyuc-x)lPKX26Z z!z+i^XEKRBTX(wZy_v51y^@#z>R!m6m`T#^hxV4pHrR7Y{E6QJ5kWr5@^~KDt2tbdfI601eV*8lqv+DMnW)P6@h7Bh4@0@8dyix^T!Sx51Xz%m@ delta 293 zcmWm8xsE|$06<|suCZKPgd Date: Mon, 29 Jul 2024 12:59:31 +0800 Subject: [PATCH 2/2] Updated Unit Tests --- .plastic/plastic.changes | Bin 3624466 -> 3624456 bytes .plastic/plastic.wktree | Bin 3692465 -> 3692455 bytes Assets/Scripts/Player/PlayerMovement.cs | 17 +++ Assets/Scripts/Player/PlayerStats.cs | 2 + Assets/Tests/EditMode/DirectionTests.cs | 15 --- Assets/Tests/EditMode/GameTests.cs | 113 ++++++++++++++++++ ...rectionTests.cs.meta => GameTests.cs.meta} | 0 7 files changed, 132 insertions(+), 15 deletions(-) delete mode 100644 Assets/Tests/EditMode/DirectionTests.cs create mode 100644 Assets/Tests/EditMode/GameTests.cs rename Assets/Tests/EditMode/{DirectionTests.cs.meta => GameTests.cs.meta} (100%) diff --git a/.plastic/plastic.changes b/.plastic/plastic.changes index 0deb3fa6f22ad89c1da233460b5c2375bbeb5cd8..c080d4592bad01ddbda6cd68662addc42a4a70f7 100644 GIT binary patch delta 152 zcmWm0ITFE80D$2MLJ&*ry9lxGOWqN@15jraDOE0@_zNvf8pkl>H143+p!jCK+x?|n ze$FTa2ogdiOazT6G2-YXNRlFrL53_j@)RgiqD+M^8)hb|=a0Sy0OwpdJ_L1K`26N5KlGJMl_ zy1s?;&k+F|b{vQ}apA^;7ax8CNCXKX6DC5G7z%L`BuSAbLzWyWc?uLMQKmwb8g&{p zY0;)bmmYlv3>h(I!t}1KbxB^Bdt+mnyY0$2SeMUpstUKuXD-aV%D)~jU0aG@w_Z3t diff --git a/.plastic/plastic.wktree b/.plastic/plastic.wktree index 95924013b380f67c51404f46749271b2bdfc0ce5..64eb25d187ecdaaf34873a240aee6e9bbb5884fe 100644 GIT binary patch delta 154 zcmWm0Ne;nK0D$2gQDVr%NsuIkLYfR&a^xvcq(qqtRch2xY0#uan+{!i z^ckQrWW<;WQ)bLruzc!%Lz36l$=uu4@vt+`w)1{3OO9sfD^d9mXS>nW*VWJ^;R~|h BI&S~~ diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index a380a70d..db3538a9 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -91,4 +91,21 @@ void Move() // Apply the movement to the Rigidbody2D's velocity player.velocity = movement; } + + public void MoveRight() + { + movementVector.x = 1; + } + public void MoveLeft() + { + movementVector.x = -1; + } + public void MoveUp() + { + movementVector.y = 1; + } + public void MoveDown() + { + movementVector.x = -1; + } } diff --git a/Assets/Scripts/Player/PlayerStats.cs b/Assets/Scripts/Player/PlayerStats.cs index 058c4c4d..9b28838d 100644 --- a/Assets/Scripts/Player/PlayerStats.cs +++ b/Assets/Scripts/Player/PlayerStats.cs @@ -444,6 +444,8 @@ public void DestroySingleton() Destroy(gameObject); } + + private IEnumerator DestroyAfterAnimation(GameObject statusEffect) { Animator statusAnimator = statusEffect.GetComponent(); diff --git a/Assets/Tests/EditMode/DirectionTests.cs b/Assets/Tests/EditMode/DirectionTests.cs deleted file mode 100644 index 8aed38b6..00000000 --- a/Assets/Tests/EditMode/DirectionTests.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using NUnit.Framework; -using UnityEngine; -using UnityEngine.TestTools; - -public class NewTestScript -{ - // A Test behaves as an ordinary method - [Test] - public void straight() - { - //Assert.AreEqual(new Vector3(0, 1, 0)); - } -} diff --git a/Assets/Tests/EditMode/GameTests.cs b/Assets/Tests/EditMode/GameTests.cs new file mode 100644 index 00000000..2511cdfa --- /dev/null +++ b/Assets/Tests/EditMode/GameTests.cs @@ -0,0 +1,113 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; +using UnityEngine; +using UnityEngine.TestTools; + +public class NewTestScript +{ + private GameObject player; + private Rigidbody2D rb; + private PlayerMovement playerMove; + + [SetUp] + public void SetUp() + { + // Create a new GameObject with a PlayerController and Rigidbody2D + player = new GameObject("Player"); + rb = player.AddComponent(); + + // Optionally set up initial conditions here + rb.gravityScale = 0; // Disable gravity if not needed + } + + [TearDown] + public void TearDown() + { + // Clean up after each test + Object.Destroy(player); + } + + + [Test] + public IEnumerator PlayerMovesRight() + { + PlayerStats.instance.MoveSpeed = 10f; + + // Simulate movement + Vector3 initialPosition = player.transform.position; + playerMove.MoveRight(); + + // Allow some time for movement + yield return new WaitForSeconds(0.1f); + + // Assert that the player has moved to the right + Vector3 newPosition = player.transform.position; + Assert.Greater(newPosition.x, initialPosition.x, "Player moves to the right."); + } + + public IEnumerator PlayerMovesLeft() + { + PlayerStats.instance.MoveSpeed = 10f; + + // Simulate movement + Vector3 initialPosition = player.transform.position; + playerMove.MoveLeft(); + + // Allow some time for movement + yield return new WaitForSeconds(0.1f); + + // Assert that the player has moved to the left + Vector3 newPosition = player.transform.position; + Assert.Greater(newPosition.x, initialPosition.x, "Player moves to the left."); + } + + public IEnumerator PlayerMovesUp() + { + PlayerStats.instance.MoveSpeed = 10f; + + // Simulate movement + Vector3 initialPosition = player.transform.position; + playerMove.MoveUp(); + + // Allow some time for movement + yield return new WaitForSeconds(0.1f); + + // Assert that the player has moved up + Vector3 newPosition = player.transform.position; + Assert.Greater(newPosition.x, initialPosition.x, "Player moves up."); + } + + public IEnumerator PlayerMovesDown() + { + PlayerStats.instance.MoveSpeed = 10f; + + // Simulate movement + Vector3 initialPosition = player.transform.position; + playerMove.MoveDown(); + + // Allow some time for movement + yield return new WaitForSeconds(0.1f); + + // Assert that the player has moved down + Vector3 newPosition = player.transform.position; + Assert.Greater(newPosition.x, initialPosition.x, "Player moves down."); + } + + [Test] + public void PlayerHealthDoesNotGoBelowZero() + { + // Arrange + PlayerStats.instance.CurrentHealth = 10; // Set current health close to zero + int damageAmount = 15; + + // Act + PlayerStats.instance.TakeDamage(damageAmount); + + // Assert + Assert.AreEqual(0, PlayerStats.instance.CurrentHealth, "Player's health should not go below zero."); + } + + + +} diff --git a/Assets/Tests/EditMode/DirectionTests.cs.meta b/Assets/Tests/EditMode/GameTests.cs.meta similarity index 100% rename from Assets/Tests/EditMode/DirectionTests.cs.meta rename to Assets/Tests/EditMode/GameTests.cs.meta