Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…for-2024-fall-swpp-team-16 into refactor/final-refactor
  • Loading branch information
silee1103 committed Dec 21, 2024
2 parents 3233eb7 + 8627834 commit 46c455a
Show file tree
Hide file tree
Showing 21 changed files with 307 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Assets/02.Scripts/Managers/StageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public void Awake()
LoadStages();
}

public void TurnOffDevelopmentMode()
{
developmentMode = false;
}

private void LoadStages()
{
accomplishedStages = new bool[totalStages];
Expand Down
2 changes: 1 addition & 1 deletion Assets/02.Scripts/Objects/DoorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void ResetColoredNotes()
}
}

private bool CheckNotes()
public bool CheckNotes()
{
for (int i = 0; i < playedNotes.Count; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/02.Scripts/Objects/TreeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TreeController : Interactable
[SerializeField, Range(3f, 15f)] private float prefabHeight = 13.5f;
[SerializeField, Range(3f, 15f)] private float minHeight = 3f;
[SerializeField, Range(3f, 15f)] private float maxHeight = 13f;
[SerializeField, Range(3f, 15f)] private float currentHeight = 8f;
[SerializeField, Range(3f, 15f)] public float currentHeight = 8f;
[SerializeField, Range(0f, 1f)] private float radius = 0.7f;

private const float HeightChangeSmoothTime = 0.6f;
Expand Down
8 changes: 8 additions & 0 deletions Assets/02.Scripts/Tests/EditMode.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Assets/02.Scripts/Tests/EditMode/DoorControllerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using NUnit.Framework;
using UnityEngine;

public class DoorControllerCheckNotesTest
{
private GameObject doorControllerObject;
private DoorController doorController;

[SetUp]
public void Setup()
{
doorControllerObject = new GameObject();
doorController = doorControllerObject.AddComponent<DoorController>();

// Initialize answerNotes for testing
doorController.answerNotes = new int[] { 1, 2, 3 };
}

[Test]
public void TestCheckNotes_ReturnsTrue_WhenNotesMatch()
{
// Arrange
doorController.playedNotes.Add(1);
doorController.playedNotes.Add(2);
doorController.playedNotes.Add(3);

// Act
bool result = doorController.CheckNotes();

// Assert
Assert.IsTrue(result, "CheckNotes should return true when played notes match answer notes.");
}

[Test]
public void TestCheckNotes_ReturnsFalse_WhenNotesDoNotMatch()
{
// Arrange
doorController.playedNotes.Add(1);
doorController.playedNotes.Add(2);
doorController.playedNotes.Add(4); // Incorrect note

// Act
bool result = doorController.CheckNotes();

// Assert
Assert.IsFalse(result, "CheckNotes should return false when played notes do not match answer notes.");
}

[TearDown]
public void Teardown()
{
Object.DestroyImmediate(doorControllerObject);
}
}
11 changes: 11 additions & 0 deletions Assets/02.Scripts/Tests/EditMode/DoorControllerTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Tests",
"name": "EditModeTests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void SetUp()
GameObject gameObject = new GameObject();
stageManager = gameObject.AddComponent<StageManager>();
stageManager.totalStages = 5;
stageManager.TurnOffDevelopmentMode();
testFilePath = Path.Combine(Application.persistentDataPath, "progress.txt");
if (File.Exists(testFilePath))
{
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/PlayModeTests.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "PlayModeTests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"Scripts"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/PlayModeTests.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/Stage1Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;

public class Stage1Test
{
[SetUp]
public void Setup()
{
// Load the scene
string sceneName = "Stage1";
SceneManager.LoadScene(sceneName);
}

[TearDown]
public void Teardown()
{

}

[UnityTest]
public IEnumerator TestSettingsModal()
{
yield return null;

var canvas = GameObject.Find("Canvas");
Assert.IsNotNull(canvas, "Canvas not found in the scene.");

var settingsModal = canvas.transform.Find("SettingsModal")?.gameObject;
Assert.IsNotNull(settingsModal, "SettingsModal not found under Canvas.");
Assert.IsFalse(settingsModal.activeSelf, "SettingsModal should start inactive.");

// Input.GetKeyDown(KeyCode.Escape);
// yield return null;
// Assert.IsTrue(settingsModal.activeSelf, "SettingsModal should be active after ESC key is pressed.");
}

[UnityTest]
public IEnumerator TestScoreCountInit()
{
yield return null;

Assert.IsFalse(GameManager.im.HasAllScores(), "All scores are not collected yet!");
}
}
11 changes: 11 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/Stage1Test.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/Stage4Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;

public class Stage4Test
{
[SetUp]
public void Setup()
{
// Load the scene
string sceneName = "Stage4";
SceneManager.LoadScene(sceneName);
}

[TearDown]
public void Teardown()
{

}

[UnityTest]
public IEnumerator TestWater_PlayerDiesAndRespawn()
{
yield return null;

GameObject player = GameObject.Find("Player");
Vector3 waterPosition = new Vector3(0, 0.5f, 0);

// player falls into water
player.transform.position = waterPosition;

yield return new WaitForSeconds(1);

// player transform should be respawned
Assert.AreNotEqual(waterPosition, player.transform.position);
}
}
11 changes: 11 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/Stage4Test.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/StageTutorialPlate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;

public class StageTutorialPlateTest
{
[SetUp]
public void Setup()
{
// Load the scene
string sceneName = "Stage7";
SceneManager.LoadScene(sceneName);
}

[TearDown]
public void Teardown()
{

}

[UnityTest]
public IEnumerator TestTree_GrowWhenResonate()
{
yield return null;

GameObject tree = GameObject.Find("Tree");
Assert.IsNotNull(tree, "Tree not found in the scene.");

Debug.Log("tree: " + tree);

TreeController treeController = tree.GetComponent<TreeController>();
float y1 = treeController.currentHeight;

Debug.Log("y1: " + y1);

float interval = 0.2f; // Set the interval for triggering resonance
float duration = 1f; // Total duration for triggering resonance

float elapsedTime = 0f;
while (elapsedTime < duration)
{
tree.GetComponent<ResonatableObject>().resonate(PitchType.So);
elapsedTime += interval;
yield return new WaitForSeconds(interval);
}

float y2 = treeController.currentHeight;

Debug.Log("y2: " + y2);

Assert.IsTrue(y2 > y1);

elapsedTime = 0f;
while (elapsedTime < duration)
{
tree.GetComponent<ResonatableObject>().resonate(PitchType.La);
elapsedTime += interval;
yield return new WaitForSeconds(interval);
}

float y3 = treeController.currentHeight;

Debug.Log("y3: " + y3);

Assert.IsTrue(y3 < y2);
}
}
11 changes: 11 additions & 0 deletions Assets/02.Scripts/Tests/PlayMode/StageTutorialPlate.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46c455a

Please sign in to comment.