baseline: OpenMU upstream b5a0961 (fresh source)

This commit is contained in:
Acentech Dev
2026-07-14 19:00:35 +03:00
parent 450402e47d
commit 36fc125d5c
11968 changed files with 748705 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
// <copyright file="BinaryMinHeapTest.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.Pathfinding.Tests;
using System.Diagnostics;
using MUnique.OpenMU.Pathfinding;
/// <summary>
/// Tests the <see cref="BinaryMinHeap{T}"/>.
/// </summary>
[TestFixture]
internal class BinaryMinHeapTest
{
/// <summary>
/// Tests if the heap pops the node with the lowest cost.
/// </summary>
[Test]
public void MinHeapWithNodes()
{
var heap = new BinaryMinHeap<Node>(new NodeComparer());
foreach (var number in Enumerable.Range(1, 10).Reverse())
{
heap.Push(new Node { PredictedTotalCost = number });
}
var minimumNumber = heap.Pop().PredictedTotalCost;
Assert.That(minimumNumber, Is.EqualTo(1));
}
/// <summary>
/// Tests if the heap pops the lowest value.
/// </summary>
[Test]
public void MinHeapWithNumbers()
{
var heap = new BinaryMinHeap<int>();
foreach (var number in Enumerable.Range(1, 10).Reverse())
{
heap.Push(number);
}
var minimumNumber = heap.Pop();
Assert.That(minimumNumber, Is.EqualTo(1));
}
/// <summary>
/// Compares the performance between <see cref="BinaryMinHeap{T}"/> and <see cref="IndexedLinkedList{T}"/>.
/// </summary>
[Test]
public void PerformanceComparison()
{
var simpleHeap = new BinaryMinHeap<Node>(new NodeComparer());
var indexedHeap = new IndexedLinkedList<Node>(new NodeComparer(), new NodeIndexer());
var count = 1000;
this.PushNodes(simpleHeap, count);
this.PushNodes(indexedHeap, count);
var pushSimple = this.PushNodes(simpleHeap, count);
var pushIndexed = this.PushNodes(indexedHeap, count);
this.PopNodes(simpleHeap, count);
this.PopNodes(indexedHeap, count);
var popSimple = this.PopNodes(simpleHeap, count);
var popIndexed = this.PopNodes(indexedHeap, count);
Assert.Pass($"(PUSH) BinaryMinHeap: {pushSimple.Elapsed}, IndexedLinkedList: {pushIndexed.Elapsed}\r\n(POP) BinaryMinHeap: {popSimple.Elapsed}, IndexedLinkedList: {popIndexed.Elapsed}");
}
private Stopwatch PopNodes(IPriorityQueue<Node> queue, int count)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < count; i++)
{
queue.Pop();
}
stopwatch.Stop();
return stopwatch;
}
private Stopwatch PushNodes(IPriorityQueue<Node> queue, int count)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var randomizer = new Random(1);
foreach (var unused in Enumerable.Range(1, count))
{
var node = new Node { PredictedTotalCost = randomizer.Next(1, count) };
queue.Push(node);
}
stopwatch.Stop();
return stopwatch;
}
}

View File

@@ -0,0 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable;CS4014;VSTHRD110;VSTHRD100</WarningsAsErrors>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>bin\Debug\MUnique.OpenMU.Pathfinding.Tests.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>bin\Release\MUnique.OpenMU.Pathfinding.Tests.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\src\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
<Compile Include="..\..\src\SharedGlobalUsings.cs" Link="SharedGlobalUsings.cs" />
<Compile Include="..\SharedTestUsings.cs" Link="SharedTestUsings.cs" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\src\stylecop.json" Link="stylecop.json" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Pathfinding\MUnique.OpenMU.Pathfinding.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,27 @@
// <copyright file="NodeComparerTest.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.Pathfinding.Tests;
using MUnique.OpenMU.Pathfinding;
/// <summary>
/// Tests the <see cref="NodeComparer"/>.
/// </summary>
[TestFixture]
internal class NodeComparerTest
{
/// <summary>
/// Tests if <see cref="NodeComparer.Compare(Node, Node)"/> does return the
/// correct value when comparing two different nodes with different costs.
/// </summary>
[Test]
public void Compare()
{
var node1 = new Node { PredictedTotalCost = 1 };
var node2 = new Node { PredictedTotalCost = 2 };
var comparer = new NodeComparer();
Assert.That(comparer.Compare(node1, node2), Is.Negative);
}
}

View File

@@ -0,0 +1,121 @@
// <copyright file="PathFinderTest.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.Pathfinding.Tests;
using MUnique.OpenMU.Pathfinding;
/// <summary>
/// Tests for the pathfinder.
/// </summary>
[TestFixture]
public class PathFinderTest
{
private IPathFinder _pathFinder = null!;
private byte[,] _grid = null!;
/// <summary>
/// Sets up the path finder with a basic, unrestricted grid.
/// </summary>
[SetUp]
public void SetUp()
{
this._grid = new byte[0x100, 0x100];
for (int x = 100; x < 200; x++)
{
for (int y = 100; y < 200; y++)
{
this._grid[x, y] = 10;
}
}
// Safezone:
for (int x = 50; x < 100; x++)
{
for (int y = 50; y < 100; y++)
{
this._grid[x, y] = 0b1000_0001;
}
}
this._pathFinder = new PathFinder(new ScopedGridNetwork());
}
/// <summary>
/// Tests the straight path.
/// </summary>
[Test]
public void TestStraightPath()
{
var start = new Point(110, 100);
var end = new Point(115, 100);
var result = this._pathFinder.FindPath(start, end, this._grid, false);
Assert.That(result, Is.Not.Null);
var lastNode = result!.LastOrDefault();
Assert.That(lastNode, Is.Not.Null);
Assert.That(lastNode.X, Is.EqualTo(end.X));
Assert.That(lastNode.Y, Is.EqualTo(end.Y));
}
/// <summary>
/// Tests the straight path.
/// </summary>
[Test]
public void TestStraightPath_InSafezone()
{
var start = new Point(51, 60);
var end = new Point(60, 60);
var result = this._pathFinder.FindPath(start, end, this._grid, true);
Assert.That(result, Is.Not.Null);
var lastNode = result!.LastOrDefault();
Assert.That(lastNode, Is.Not.Null);
Assert.That(lastNode.X, Is.EqualTo(end.X));
Assert.That(lastNode.Y, Is.EqualTo(end.Y));
}
/// <summary>
/// Tests the straight path.
/// </summary>
[Test]
public void TestStraightPath_InSafezone_ButNotIncluded()
{
var start = new Point(51, 60);
var end = new Point(60, 60);
var result = this._pathFinder.FindPath(start, end, this._grid, false);
Assert.That(result, Is.Null);
}
/// <summary>
/// Tests the diagonal path.
/// </summary>
[Test]
public void TestDiagonalPath()
{
var start = new Point(100, 100);
var end = new Point(110, 110);
var result = this._pathFinder.FindPath(start, end, this._grid, false);
Assert.That(result, Is.Not.Null);
Assert.That(result!.Count, Is.EqualTo(10));
for (int i = 1; i <= 10; i++)
{
Assert.That(result[i - 1].X, Is.EqualTo(start.X + i));
Assert.That(result[i - 1].Y, Is.EqualTo(start.Y + i));
}
Assert.That(result.Last().X, Is.EqualTo(end.X));
Assert.That(result.Last().Y, Is.EqualTo(end.Y));
}
/// <summary>
/// Tests if no path can be found if the end is on an unreachable coordinate.
/// </summary>
[Test]
public void TestNoPathFound()
{
var start = new Point(110, 100);
var end = new Point(115, 99);
var result = this._pathFinder.FindPath(start, end, this._grid, false);
Assert.That(result, Is.Null);
}
}

View File

@@ -0,0 +1,10 @@
// <copyright file="AssemblyInfo.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
using System.Reflection;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MUnique.OpenMU.Pathfinding.Tests")]