From de41bbeb8d6915f86cadc94af097cf70b240e811 Mon Sep 17 00:00:00 2001 From: Minimata Date: Mon, 23 Feb 2026 15:22:57 +0100 Subject: [PATCH] some other tests --- .gitignore | 9 +++- .../interactions/PlayerInteractionsTest.cs | 50 +++++++++++++++++++ .../PlayerInteractionsTest.cs.uid | 1 + .../player_interactions_scene.tscn | 35 +++++++++++++ tests/player/movement/PlayerMovementTest.cs | 19 +++++-- 5 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 tests/player/interactions/PlayerInteractionsTest.cs create mode 100644 tests/player/interactions/PlayerInteractionsTest.cs.uid create mode 100644 tests/player/interactions/player_interactions_scene.tscn diff --git a/.gitignore b/.gitignore index 1de7caf2..82c2b023 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,11 @@ # Imported translations (automatically generated from CSV files) *.translation -.output.txt \ No newline at end of file +.output.txt + +*.suo +*.user +_ReSharper.* +bin +obj +packages diff --git a/tests/player/interactions/PlayerInteractionsTest.cs b/tests/player/interactions/PlayerInteractionsTest.cs new file mode 100644 index 00000000..fcd83f87 --- /dev/null +++ b/tests/player/interactions/PlayerInteractionsTest.cs @@ -0,0 +1,50 @@ +using System.Threading.Tasks; +using Godot; +using GodotStateCharts; + +namespace Movementtests.tests; + +using GdUnit4; +using static GdUnit4.Assertions; + +[TestSuite, RequireGodotRuntime] +public class PlayerInteractionsTest +{ + private ISceneRunner _runner; + private Node _scene; + private PlayerController _player; + + private readonly float _tolerance = 0.01f; + private readonly Vector3 _vectorTolerance = new Vector3(0.01f, 0.01f, 0.01f); + + [BeforeTest] + public void SetupTest() + { + _runner = ISceneRunner.Load("res://tests/player/interactions/player_interactions_scene.tscn"); + + _scene = _runner.Scene()!; + var player = _scene.FindChild("Player") as PlayerController; + _player = player!; + } + [AfterTest] + public void CleanupTest() {} + + [TestCase("BaseLocation")] + public async Task PlayerMoveForward(string markerName) + { + var marker = _scene.FindChild(markerName) as Marker3D; + AssertObject(marker).IsNotNull(); + _player.GlobalPosition = marker!.GlobalPosition; + await _runner.AwaitIdleFrame(); + + var startPos = _player.GlobalPosition; + + _runner.SimulateKeyPress(Key.W); + await _runner.AwaitMillis(300); + _runner.SimulateKeyRelease(Key.W); + + var endPos = _player.GlobalPosition; + var direction = startPos.DirectionTo(endPos); + AssertVector(direction).IsEqualApprox(Vector3.Forward, _vectorTolerance); + } +} \ No newline at end of file diff --git a/tests/player/interactions/PlayerInteractionsTest.cs.uid b/tests/player/interactions/PlayerInteractionsTest.cs.uid new file mode 100644 index 00000000..75e43ca5 --- /dev/null +++ b/tests/player/interactions/PlayerInteractionsTest.cs.uid @@ -0,0 +1 @@ +uid://denedm5b8rmhh diff --git a/tests/player/interactions/player_interactions_scene.tscn b/tests/player/interactions/player_interactions_scene.tscn new file mode 100644 index 00000000..0a7887de --- /dev/null +++ b/tests/player/interactions/player_interactions_scene.tscn @@ -0,0 +1,35 @@ +[gd_scene format=3 uid="uid://l0lflvsjbyvs"] + +[ext_resource type="Material" uid="uid://31aulub2nqov" path="res://assets/materials/greybox/m_greybox.tres" id="1_dv0re"] +[ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://scenes/player_controller/PlayerController.tscn" id="2_52d52"] + +[node name="PlayerMovementScene" type="Node3D" unique_id=231040688] + +[node name="CSGCombiner3D" type="CSGCombiner3D" parent="." unique_id=241909240] +use_collision = true +collision_layer = 256 +collision_mask = 65553 + +[node name="Ground" type="CSGBox3D" parent="CSGCombiner3D" unique_id=432200143] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, -0.5, -3.25) +use_collision = true +collision_layer = 256 +collision_mask = 65553 +size = Vector3(1000, 1, 1000) +material = ExtResource("1_dv0re") + +[node name="Ground2" type="CSGBox3D" parent="CSGCombiner3D" unique_id=854660236] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.75, 0.5, -1.75) +use_collision = true +collision_layer = 256 +collision_mask = 65553 +size = Vector3(1.5, 1, 1.5) +material = ExtResource("1_dv0re") + +[node name="Player" parent="." unique_id=709076448 instance=ExtResource("2_52d52")] +TutorialDone = true + +[node name="BaseLocation" type="Marker3D" parent="." unique_id=1793710692] + +[node name="MantleLocation1" type="Marker3D" parent="." unique_id=550080845] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.75, 0, 0) diff --git a/tests/player/movement/PlayerMovementTest.cs b/tests/player/movement/PlayerMovementTest.cs index e404cc44..1ffbe76d 100644 --- a/tests/player/movement/PlayerMovementTest.cs +++ b/tests/player/movement/PlayerMovementTest.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Godot; +using GodotStateCharts; namespace Movementtests.tests; @@ -44,7 +45,7 @@ public class PlayerMovementTest var startPos = _player.GlobalPosition; _runner.SimulateKeyPress(Key.W); - await _runner.AwaitMillis(300); + await _runner.AwaitMillis(100); _runner.SimulateKeyRelease(Key.W); var endPos = _player.GlobalPosition; @@ -63,17 +64,24 @@ public class PlayerMovementTest var startPos = _player.GlobalPosition; _runner.SimulateKeyPress(Key.Space); - await _runner.AwaitMillis(100); - _runner.SimulateKeyRelease(Key.Space); + await _runner.AwaitIdleFrame(); + var jumping = StateChartState.Of(_player.GetNode("StateChart/Root/Movement/Jump")); + AssertBool(jumping.Active).IsTrue(); + + _runner.SimulateKeyRelease(Key.Space); + await _runner.AwaitIdleFrame(); var endPos = _player.GlobalPosition; var direction = startPos.DirectionTo(endPos); AssertVector(direction).IsEqualApprox(Vector3.Up, _vectorTolerance); AssertVector(_player.Velocity.Normalized()).IsEqualApprox(Vector3.Up, _vectorTolerance); - await _runner.AwaitMillis(500); + await _runner.AwaitMillis(600); endPos = _player.GlobalPosition; AssertVector(endPos - startPos).IsEqualApprox(Vector3.Zero, _vectorTolerance); + + var grounded = StateChartState.Of(_player.GetNode("StateChart/Root/Movement/Grounded")); + AssertBool(grounded.Active).IsTrue(); } [TestCase("MantleLocation1")] @@ -88,6 +96,9 @@ public class PlayerMovementTest _runner.SimulateKeyPress(Key.Space); await _runner.AwaitMillis(100); + var mantling = StateChartState.Of(_player.GetNode("StateChart/Root/Movement/Mantling")); + AssertBool(mantling.Active).IsTrue(); + _runner.SimulateKeyRelease(Key.Space); await _runner.AwaitMillis(500);