added xunit and a few tests with gdunit
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,3 +14,5 @@
|
|||||||
|
|
||||||
# Imported translations (automatically generated from CSV files)
|
# Imported translations (automatically generated from CSV files)
|
||||||
*.translation
|
*.translation
|
||||||
|
|
||||||
|
.output.txt
|
||||||
@@ -125,11 +125,25 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="addons\" />
|
<Folder Include="addons\" />
|
||||||
<Folder Include="tests\player_movement\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="RustyOptions" Version="0.10.1" />
|
<PackageReference Include="RustyOptions" Version="0.10.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<Import Project="addons/forge/Forge.props" />
|
||||||
|
|
||||||
|
<!-- XUnit -->
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- gdUnit4 package dependencies -->
|
<!-- gdUnit4 package dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
|
||||||
@@ -140,5 +154,4 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="addons/forge/Forge.props"/>
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -5,7 +5,12 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F716d154fef5cbe863cd637bd32beda6e3cec5f12e8fed2dc5b2d8149a0d558ab_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F716d154fef5cbe863cd637bd32beda6e3cec5f12e8fed2dc5b2d8149a0d558ab_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fdf73a4db74df89d59655c5fb6326406f47fbfa9af1fa81518fe0a07c49d34133_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fdf73a4db74df89d59655c5fb6326406f47fbfa9af1fa81518fe0a07c49d34133_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASceneTree_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F8d6960554e939a669841b1ece03d27df4ab42f92bb80be3767eaec8cdaccf84b_003FSceneTree_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASceneTree_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F8d6960554e939a669841b1ece03d27df4ab42f92bb80be3767eaec8cdaccf84b_003FSceneTree_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=dd9a7ac6_002Dbb9b_002D4001_002Db145_002D15e6509b7e78/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=7ce84f90_002D6ae2_002D4e9e_002D860e_002Deb90f45871f3/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Junie Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
|
<TestAncestor>
|
||||||
|
<TestId>VsTest::22FEBE6E-769C-4716-A687-A0AC8F3EF84A::net9.0::executor://gdunit4.testadapter/#Movementtests.tests.PlayerControllerUnitTest</TestId>
|
||||||
|
</TestAncestor>
|
||||||
|
</SessionState></s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=dd9a7ac6_002Dbb9b_002D4001_002Db145_002D15e6509b7e78/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
<Solution />
|
<Solution />
|
||||||
</SessionState></s:String>
|
</SessionState></s:String>
|
||||||
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestRunner/RunConfigurationFilename/@EntryValue">D:\Godot\Projects\movement-tests\.runsettings</s:String>
|
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestRunner/RunConfigurationFilename/@EntryValue">D:\Godot\Projects\movement-tests\.runsettings</s:String>
|
||||||
|
|||||||
28
agents.md
Normal file
28
agents.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
### Project Overview: Godot C# Movement Tests
|
||||||
|
This project is a high-performance 3D character controller for Godot 4.x using C# 13 and .NET 9. It focuses on modular movement systems (Dash, Mantle, Stairs) and robust combat mechanics (Damage, Health, Knockback) decoupled through interfaces.
|
||||||
|
|
||||||
|
### Core Architecture
|
||||||
|
- **Modular Systems**: The `PlayerController.cs` acts as a central hub for multiple specialized "Systems" (e.g., `DashSystem`, `MantleSystem`, `HeadSystem`, `StairsSystem`).
|
||||||
|
- **State Management**: Uses `GodotStateCharts` for complex movement and action states. Look for state transitions and triggers within the system scripts.
|
||||||
|
- **Interface-Driven Design**: Located in `/interfaces/`, these define how objects interact (e.g., `IDamageable`, `IHealthable`, `IKnockbackable`). Always implement these interfaces for new interactable entities.
|
||||||
|
- **Node Composition**: Most systems are attached to the `PlayerController` scene as child nodes and initialized via their respective `Init()` methods or exported fields.
|
||||||
|
|
||||||
|
### Key Directories
|
||||||
|
- `/scenes/player_controller/`: Contains the main player scene, the central `PlayerController.cs`, and its sub-systems.
|
||||||
|
- `/scenes/player_controller/components/`: Modular logic for specific features like Dash, Mantle, and Weapons.
|
||||||
|
- `/interfaces/`: Core C# interfaces and shared records (e.g., `DamageRecord`, `HealthChangedRecord`).
|
||||||
|
- `/tests/`: Automated unit and integration tests using `GdUnit4` and `xUnit`.
|
||||||
|
|
||||||
|
### Coding Standards & Idioms
|
||||||
|
- **C# 13 & .NET 9**: Use modern C# features (records, primary constructors, collection expressions).
|
||||||
|
- **Godot Partial Classes**: All Godot scripts must be `partial` and use `[GlobalClass]` where appropriate for editor visibility.
|
||||||
|
- **RustyOptions**: The project uses `RustyOptions` for safer null handling and result types (`Option<T>`, `Result<T, E>`).
|
||||||
|
- **Signals**: Use `[Signal]` and the `EventHandler` pattern for Godot signals.
|
||||||
|
- **Dependency Injection**: Systems are typically assigned to fields in `PlayerController` via the editor or `GetNode<T>()` in `_Ready()`.
|
||||||
|
|
||||||
|
### LLM Interaction Tips
|
||||||
|
1. **Partial Classes**: When suggesting changes to `PlayerController.cs` or systems, remember they are `partial`. Large files like `PlayerController.cs` (2500+ lines) are often split or contain many regions.
|
||||||
|
2. **Node Hierarchy**: Always check `PlayerController.tscn` or system scenes (`head_system.tscn`) when dealing with node references (`GetNode`).
|
||||||
|
3. **GdUnit4**: For testing, follow the pattern in `tests/PlayerMovementTest.cs`. Use `ISceneRunner` to simulate inputs and await frames/milliseconds.
|
||||||
|
4. **Vector Operations**: Use Godot's built-in `Vector3` methods for movement logic. The project often uses `GlobalPosition` and `DirectionTo`.
|
||||||
|
5. **Boilerplate**: When creating new systems, mirror the `Init()` and `_PhysicsProcess` patterns found in existing systems like `DashSystem.cs` or `MantleSystem.cs`.
|
||||||
5
global.json
Normal file
5
global.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"test": {
|
||||||
|
"runner": "Microsoft.Testing.Platform"
|
||||||
|
}
|
||||||
|
}
|
||||||
79
obj/movement-tests.csproj.nuget.dgspec.json
Normal file
79
obj/movement-tests.csproj.nuget.dgspec.json
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"format": 1,
|
||||||
|
"restore": {
|
||||||
|
"D:\\Godot\\Projects\\movement-tests\\movement-tests.csproj": {}
|
||||||
|
},
|
||||||
|
"projects": {
|
||||||
|
"D:\\Godot\\Projects\\movement-tests\\movement-tests.csproj": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"restore": {
|
||||||
|
"projectUniqueName": "D:\\Godot\\Projects\\movement-tests\\movement-tests.csproj",
|
||||||
|
"projectName": "movement-tests",
|
||||||
|
"projectPath": "D:\\Godot\\Projects\\movement-tests\\movement-tests.csproj",
|
||||||
|
"packagesPath": "C:\\Users\\Minimata\\.nuget\\packages\\",
|
||||||
|
"outputPath": "D:\\Godot\\Projects\\movement-tests\\obj\\",
|
||||||
|
"projectStyle": "PackageReference",
|
||||||
|
"fallbackFolders": [
|
||||||
|
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||||
|
],
|
||||||
|
"configFilePaths": [
|
||||||
|
"C:\\Users\\Minimata\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||||
|
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||||
|
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||||
|
],
|
||||||
|
"originalTargetFrameworks": [
|
||||||
|
"net8.0"
|
||||||
|
],
|
||||||
|
"sources": {
|
||||||
|
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||||
|
"https://api.nuget.org/v3/index.json": {}
|
||||||
|
},
|
||||||
|
"frameworks": {
|
||||||
|
"net8.0": {
|
||||||
|
"targetAlias": "net8.0",
|
||||||
|
"projectReferences": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"warningProperties": {
|
||||||
|
"warnAsError": [
|
||||||
|
"NU1605"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"restoreAuditProperties": {
|
||||||
|
"enableAudit": "true",
|
||||||
|
"auditLevel": "low",
|
||||||
|
"auditMode": "direct"
|
||||||
|
},
|
||||||
|
"SdkAnalysisLevel": "9.0.300"
|
||||||
|
},
|
||||||
|
"frameworks": {
|
||||||
|
"net8.0": {
|
||||||
|
"targetAlias": "net8.0",
|
||||||
|
"dependencies": {
|
||||||
|
"xunit.v3.mtp-v2": {
|
||||||
|
"target": "Package",
|
||||||
|
"version": "[3.2.2, )"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"imports": [
|
||||||
|
"net461",
|
||||||
|
"net462",
|
||||||
|
"net47",
|
||||||
|
"net471",
|
||||||
|
"net472",
|
||||||
|
"net48",
|
||||||
|
"net481"
|
||||||
|
],
|
||||||
|
"assetTargetFallback": true,
|
||||||
|
"warn": true,
|
||||||
|
"frameworkReferences": {
|
||||||
|
"Microsoft.NETCore.App": {
|
||||||
|
"privateAssets": "all"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.301/PortableRuntimeIdentifierGraph.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
obj/movement-tests.csproj.nuget.g.props
Normal file
25
obj/movement-tests.csproj.nuget.g.props
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
|
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||||
|
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||||
|
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||||
|
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||||
|
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Minimata\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||||
|
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||||
|
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.14.0</NuGetToolVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
|
<SourceRoot Include="C:\Users\Minimata\.nuget\packages\" />
|
||||||
|
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
|
<Import Project="$(NuGetPackageRoot)microsoft.testing.platform\2.0.2\buildTransitive\net8.0\Microsoft.Testing.Platform.props" Condition="Exists('$(NuGetPackageRoot)microsoft.testing.platform\2.0.2\buildTransitive\net8.0\Microsoft.Testing.Platform.props')" />
|
||||||
|
<Import Project="$(NuGetPackageRoot)microsoft.testing.platform.msbuild\2.0.2\buildTransitive\Microsoft.Testing.Platform.MSBuild.props" Condition="Exists('$(NuGetPackageRoot)microsoft.testing.platform.msbuild\2.0.2\buildTransitive\Microsoft.Testing.Platform.MSBuild.props')" />
|
||||||
|
<Import Project="$(NuGetPackageRoot)microsoft.testing.extensions.telemetry\2.0.2\buildTransitive\net8.0\Microsoft.Testing.Extensions.Telemetry.props" Condition="Exists('$(NuGetPackageRoot)microsoft.testing.extensions.telemetry\2.0.2\buildTransitive\net8.0\Microsoft.Testing.Extensions.Telemetry.props')" />
|
||||||
|
<Import Project="$(NuGetPackageRoot)xunit.v3.core.mtp-v2\3.2.2\buildTransitive\xunit.v3.core.mtp-v2.props" Condition="Exists('$(NuGetPackageRoot)xunit.v3.core.mtp-v2\3.2.2\buildTransitive\xunit.v3.core.mtp-v2.props')" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
|
<Pkgxunit_analyzers Condition=" '$(Pkgxunit_analyzers)' == '' ">C:\Users\Minimata\.nuget\packages\xunit.analyzers\1.27.0</Pkgxunit_analyzers>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
8
obj/movement-tests.csproj.nuget.g.targets
Normal file
8
obj/movement-tests.csproj.nuget.g.targets
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
|
<Import Project="$(NuGetPackageRoot)microsoft.testing.platform\2.0.2\buildTransitive\net8.0\Microsoft.Testing.Platform.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.testing.platform\2.0.2\buildTransitive\net8.0\Microsoft.Testing.Platform.targets')" />
|
||||||
|
<Import Project="$(NuGetPackageRoot)microsoft.testing.platform.msbuild\2.0.2\buildTransitive\Microsoft.Testing.Platform.MSBuild.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.testing.platform.msbuild\2.0.2\buildTransitive\Microsoft.Testing.Platform.MSBuild.targets')" />
|
||||||
|
<Import Project="$(NuGetPackageRoot)xunit.v3.core.mtp-v2\3.2.2\buildTransitive\xunit.v3.core.mtp-v2.targets" Condition="Exists('$(NuGetPackageRoot)xunit.v3.core.mtp-v2\3.2.2\buildTransitive\xunit.v3.core.mtp-v2.targets')" />
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
1160
obj/project.assets.json
Normal file
1160
obj/project.assets.json
Normal file
File diff suppressed because it is too large
Load Diff
28
obj/project.nuget.cache
Normal file
28
obj/project.nuget.cache
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"dgSpecHash": "C+vE0OBbgVo=",
|
||||||
|
"success": true,
|
||||||
|
"projectFilePath": "D:\\Godot\\Projects\\movement-tests\\movement-tests.csproj",
|
||||||
|
"expectedPackageFiles": [
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.applicationinsights\\2.23.0\\microsoft.applicationinsights.2.23.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.bcl.asyncinterfaces\\6.0.0\\microsoft.bcl.asyncinterfaces.6.0.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.netcore.platforms\\5.0.0\\microsoft.netcore.platforms.5.0.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.testing.extensions.telemetry\\2.0.2\\microsoft.testing.extensions.telemetry.2.0.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.testing.extensions.trxreport.abstractions\\2.0.2\\microsoft.testing.extensions.trxreport.abstractions.2.0.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.testing.platform\\2.0.2\\microsoft.testing.platform.2.0.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.testing.platform.msbuild\\2.0.2\\microsoft.testing.platform.msbuild.2.0.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\microsoft.win32.registry\\5.0.0\\microsoft.win32.registry.5.0.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\system.diagnostics.diagnosticsource\\5.0.0\\system.diagnostics.diagnosticsource.5.0.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\system.security.accesscontrol\\5.0.0\\system.security.accesscontrol.5.0.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\system.security.principal.windows\\5.0.0\\system.security.principal.windows.5.0.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.analyzers\\1.27.0\\xunit.analyzers.1.27.0.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.v3.assert\\3.2.2\\xunit.v3.assert.3.2.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.v3.common\\3.2.2\\xunit.v3.common.3.2.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.v3.core.mtp-v2\\3.2.2\\xunit.v3.core.mtp-v2.3.2.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.v3.extensibility.core\\3.2.2\\xunit.v3.extensibility.core.3.2.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.v3.mtp-v2\\3.2.2\\xunit.v3.mtp-v2.3.2.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.v3.runner.common\\3.2.2\\xunit.v3.runner.common.3.2.2.nupkg.sha512",
|
||||||
|
"C:\\Users\\Minimata\\.nuget\\packages\\xunit.v3.runner.inproc.console\\3.2.2\\xunit.v3.runner.inproc.console.3.2.2.nupkg.sha512"
|
||||||
|
],
|
||||||
|
"logs": []
|
||||||
|
}
|
||||||
187
tests/player/PlayerControllerUnitTest.cs
Normal file
187
tests/player/PlayerControllerUnitTest.cs
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.interfaces;
|
||||||
|
using Movementtests.systems.damage;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class PlayerControllerUnitTest
|
||||||
|
{
|
||||||
|
private PlayerController _player;
|
||||||
|
|
||||||
|
[BeforeTest]
|
||||||
|
public void SetupTest()
|
||||||
|
{
|
||||||
|
_player = new PlayerController();
|
||||||
|
// We don't call _Ready() to avoid node dependency issues,
|
||||||
|
// but we need to initialize some private fields for unit testing.
|
||||||
|
SetPrivateField(_player, "_targetSpeed", 7.0f);
|
||||||
|
SetPrivateField(_player, "_gravity", 9.8f);
|
||||||
|
|
||||||
|
// Setup Combat/Health dependencies
|
||||||
|
var rHealth = new RHealth(100.0f);
|
||||||
|
_player.RHealth = rHealth;
|
||||||
|
_player.CHealth = new CHealth { RHealth = rHealth, CurrentHealth = 100.0f };
|
||||||
|
}
|
||||||
|
|
||||||
|
[AfterTest]
|
||||||
|
public void CleanupTest()
|
||||||
|
{
|
||||||
|
_player?.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetPrivateField(object obj, string fieldName, object value)
|
||||||
|
{
|
||||||
|
var field = typeof(PlayerController).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
field?.SetValue(obj, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestCalculateGravityForce()
|
||||||
|
{
|
||||||
|
_player.Weight = 3.0f;
|
||||||
|
// _gravity is 9.8f
|
||||||
|
AssertFloat(_player.CalculateGravityForce()).IsEqualApprox(29.4f, 0.001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestIsPlayerInputtingForward()
|
||||||
|
{
|
||||||
|
// Test Keyboard Input
|
||||||
|
_player.InputDeviceChanged(false); // isUsingGamepad = false
|
||||||
|
_player.OnInputMoveKeyboard(new Vector3(0, 0, -1)); // Forward is -Z in Godot
|
||||||
|
AssertBool(_player.IsPlayerInputtingForward()).IsTrue();
|
||||||
|
|
||||||
|
_player.OnInputMoveKeyboard(new Vector3(0, 0, 1)); // Backward
|
||||||
|
AssertBool(_player.IsPlayerInputtingForward()).IsFalse();
|
||||||
|
|
||||||
|
// Test Gamepad Input
|
||||||
|
_player.InputDeviceChanged(true); // isUsingGamepad = true
|
||||||
|
_player.OnInputMove(new Vector3(0, 0, -1));
|
||||||
|
AssertBool(_player.IsPlayerInputtingForward()).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestSetVerticalVelocity()
|
||||||
|
{
|
||||||
|
_player.Velocity = new Vector3(1, 0, 2);
|
||||||
|
_player.SetVerticalVelocity(5.0f);
|
||||||
|
AssertVector(_player.Velocity).IsEqual(new Vector3(1, 5, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestComputeHVelocityGround()
|
||||||
|
{
|
||||||
|
_player.Velocity = Vector3.Zero;
|
||||||
|
_player.AccelerationFloor = 10.0f;
|
||||||
|
|
||||||
|
// Moving forward
|
||||||
|
Vector3 direction = Vector3.Forward; // (0, 0, -1)
|
||||||
|
float delta = 0.1f;
|
||||||
|
|
||||||
|
// _targetSpeed is 7.0f
|
||||||
|
// Expected velocity change: Lerp(0, -7.0, 0.1 * 10.0) -> Lerp(0, -7.0, 1.0) -> -7.0
|
||||||
|
Vector3 newVelocity = _player.ComputeHVelocity(delta, _player.AccelerationFloor, _player.DecelerationFloor, direction);
|
||||||
|
|
||||||
|
AssertVector(newVelocity).IsEqual(new Vector3(0, 0, -7.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestComputeHVelocityAir()
|
||||||
|
{
|
||||||
|
_player.Velocity = new Vector3(5, 0, 0);
|
||||||
|
_player.AccelerationAir = 2.0f;
|
||||||
|
_player.DecelerationAir = 2.0f;
|
||||||
|
|
||||||
|
// No input direction (deceleration)
|
||||||
|
Vector3 direction = Vector3.Zero;
|
||||||
|
float delta = 0.5f;
|
||||||
|
|
||||||
|
// Expected velocity change: Lerp(5, 0, 0.5 * 2.0) -> Lerp(5, 0, 1.0) -> 0
|
||||||
|
Vector3 newVelocity = _player.ComputeHVelocity(delta, _player.AccelerationAir, _player.DecelerationAir, direction);
|
||||||
|
|
||||||
|
AssertVector(newVelocity).IsEqual(Vector3.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestReduceHealth()
|
||||||
|
{
|
||||||
|
// Initial health is 100
|
||||||
|
var damageRecord = new DamageRecord(Vector3.Zero, new RDamage(25.0f, EDamageTypes.Normal));
|
||||||
|
_player.ReduceHealth(_player, damageRecord);
|
||||||
|
|
||||||
|
AssertFloat(_player.CHealth.CurrentHealth).IsEqual(75.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestEmpoweredActionsLeft()
|
||||||
|
{
|
||||||
|
// EmpoweredActionsLeft setter calls PlayerUi.SetNumberOfDashesLeft
|
||||||
|
// PlayerUi.SetNumberOfDashesLeft accesses _dashIcons array, which is null if _Ready() isn't called.
|
||||||
|
// We can initialize _dashIcons via reflection to allow the setter to work.
|
||||||
|
var mockUi = new PlayerUi();
|
||||||
|
var dashIcons = new TextureRect[3] { new TextureRect(), new TextureRect(), new TextureRect() };
|
||||||
|
var field = typeof(PlayerUi).GetField("_dashIcons", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
field?.SetValue(mockUi, dashIcons);
|
||||||
|
|
||||||
|
_player.PlayerUi = mockUi;
|
||||||
|
|
||||||
|
_player.EmpoweredActionsLeft = 2;
|
||||||
|
AssertInt(_player.EmpoweredActionsLeft).IsEqual(2);
|
||||||
|
AssertBool(dashIcons[0].Visible).IsTrue();
|
||||||
|
AssertBool(dashIcons[1].Visible).IsTrue();
|
||||||
|
AssertBool(dashIcons[2].Visible).IsFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestDashCooldownTimeout()
|
||||||
|
{
|
||||||
|
SetPrivateField(_player, "_canDash", false);
|
||||||
|
_player.DashCooldownTimeout();
|
||||||
|
bool canDash = (bool)GetPrivateField(_player, "_canDash");
|
||||||
|
AssertBool(canDash).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private object GetPrivateField(object obj, string fieldName)
|
||||||
|
{
|
||||||
|
var field = typeof(PlayerController).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
return field?.GetValue(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestGetInputLocalHDirection()
|
||||||
|
{
|
||||||
|
_player.InputDeviceChanged(false); // Keyboard
|
||||||
|
_player.OnInputMoveKeyboard(new Vector3(1, 0, 1)); // Diagonal
|
||||||
|
|
||||||
|
Vector3 expected = new Vector3(1, 0, 1).Normalized();
|
||||||
|
AssertVector(_player.GetInputLocalHDirection()).IsEqualApprox(expected, new Vector3(0.001f, 0.001f, 0.001f));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestComputeKnockback()
|
||||||
|
{
|
||||||
|
var cKnockback = new CKnockback();
|
||||||
|
cKnockback.RKnockback = new RKnockback(10.0f);
|
||||||
|
_player.CKnockback = cKnockback;
|
||||||
|
|
||||||
|
// Setup knockback record
|
||||||
|
var damageRecord = new DamageRecord(new Vector3(10, 0, 0), new RDamage(0, EDamageTypes.Normal));
|
||||||
|
var knockbackRecord = new KnockbackRecord(damageRecord, 1.0f);
|
||||||
|
|
||||||
|
_player.GlobalPosition = Vector3.Zero;
|
||||||
|
cKnockback.GlobalPosition = Vector3.Zero;
|
||||||
|
|
||||||
|
_player.RegisterKnockback(knockbackRecord);
|
||||||
|
|
||||||
|
// Expected direction: GlobalPosition (0,0,0) - SourceLocation (10,0,0) = (-10,0,0)
|
||||||
|
// Normalized: (-1, 0, 0)
|
||||||
|
// finalKnockback: (-1, 0, 0) * 10.0 (Modifier) * 1.0 (ForceMultiplier) = (-10, 0, 0)
|
||||||
|
|
||||||
|
Vector3 knockback = cKnockback.ComputeKnockback();
|
||||||
|
AssertVector(knockback).IsEqual(new Vector3(-10, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/player/PlayerControllerUnitTest.cs.uid
Normal file
1
tests/player/PlayerControllerUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://kmphtu0ovixi
|
||||||
@@ -24,7 +24,7 @@ public class PlayerMovementTest
|
|||||||
[BeforeTest]
|
[BeforeTest]
|
||||||
public void SetupTest()
|
public void SetupTest()
|
||||||
{
|
{
|
||||||
_runner = ISceneRunner.Load("res://tests/player_movement/player_movement_scene.tscn");
|
_runner = ISceneRunner.Load("res://tests/player/movement/player_movement_scene.tscn");
|
||||||
|
|
||||||
_scene = _runner.Scene()!;
|
_scene = _runner.Scene()!;
|
||||||
var player = _scene.FindChild("Player") as PlayerController;
|
var player = _scene.FindChild("Player") as PlayerController;
|
||||||
@@ -89,10 +89,10 @@ public class PlayerMovementTest
|
|||||||
_runner.SimulateKeyPress(Key.Space);
|
_runner.SimulateKeyPress(Key.Space);
|
||||||
await _runner.AwaitMillis(100);
|
await _runner.AwaitMillis(100);
|
||||||
_runner.SimulateKeyRelease(Key.Space);
|
_runner.SimulateKeyRelease(Key.Space);
|
||||||
await _runner.AwaitMillis(300);
|
await _runner.AwaitMillis(500);
|
||||||
|
|
||||||
var endPos = _player.GlobalPosition;
|
var endPos = _player.GlobalPosition;
|
||||||
AssertFloat((endPos - startPos).Length()).IsGreater(0.0f);
|
AssertFloat((endPos - startPos).Length()).IsGreater(_tolerance);
|
||||||
AssertFloat(endPos.Y).IsEqualApprox(1.0f, _tolerance);
|
AssertFloat(endPos.Y).IsEqualApprox(1.0f, _tolerance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
3
xunit.runner.json
Normal file
3
xunit.runner.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user