DotRecastNetSim/test/DotRecast.Detour.Test/TiledFindPathTest.cs

83 lines
3.2 KiB
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
/*
recast4j Copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Collections.Generic;
2023-03-29 18:59:00 +03:00
using DotRecast.Core;
2023-04-23 08:13:10 +03:00
using DotRecast.Detour.QueryResults;
2023-03-14 08:02:43 +03:00
using NUnit.Framework;
namespace DotRecast.Detour.Test;
2023-04-25 17:22:44 +03:00
[Parallelizable]
2023-03-16 19:48:49 +03:00
public class TiledFindPathTest
{
2023-03-14 08:02:43 +03:00
private static readonly Status[] STATUSES = { Status.SUCCSESS };
2023-03-16 19:48:49 +03:00
private static readonly long[][] RESULTS =
{
new[]
{
281475015507969L, 281475014459393L, 281475014459392L, 281475006070784L,
2023-03-14 08:02:43 +03:00
281475005022208L, 281475003973636L, 281475012362240L, 281475012362241L, 281475012362242L, 281475003973634L,
281475003973635L, 281475003973633L, 281475002925059L, 281475002925057L, 281475002925056L, 281474998730753L,
281474998730754L, 281474994536450L, 281474994536451L, 281474994536452L, 281474994536448L, 281474990342146L,
281474990342145L, 281474991390723L, 281474991390724L, 281474991390725L, 281474987196418L, 281474987196417L,
2023-03-16 19:48:49 +03:00
281474988244996L, 281474988244995L, 281474988244997L, 281474985099266L
}
};
2023-03-14 08:02:43 +03:00
protected static readonly long[] START_REFS = { 281475015507969L };
protected static readonly long[] END_REFS = { 281474985099266L };
2023-03-29 18:59:00 +03:00
protected static readonly Vector3f[] START_POS = { Vector3f.Of(39.447338f, 9.998177f, -0.784811f) };
protected static readonly Vector3f[] END_POS = { Vector3f.Of(19.292645f, 11.611748f, -57.750366f) };
2023-03-14 08:02:43 +03:00
protected NavMeshQuery query;
protected NavMesh navmesh;
[SetUp]
2023-05-05 02:44:48 +03:00
public void SetUp()
2023-03-16 19:48:49 +03:00
{
2023-05-05 02:44:48 +03:00
navmesh = CreateNavMesh();
2023-03-14 08:02:43 +03:00
query = new NavMeshQuery(navmesh);
}
2023-05-05 02:44:48 +03:00
protected NavMesh CreateNavMesh()
2023-03-16 19:48:49 +03:00
{
2023-05-05 02:44:48 +03:00
return new TestTiledNavMeshBuilder().GetNavMesh();
2023-03-14 08:02:43 +03:00
}
[Test]
2023-05-05 02:44:48 +03:00
public void TestFindPath()
2023-03-16 19:48:49 +03:00
{
2023-03-14 08:02:43 +03:00
QueryFilter filter = new DefaultQueryFilter();
2023-03-16 19:48:49 +03:00
for (int i = 0; i < START_REFS.Length; i++)
{
2023-03-14 08:02:43 +03:00
long startRef = START_REFS[i];
long endRef = END_REFS[i];
2023-03-29 18:59:00 +03:00
Vector3f startPos = START_POS[i];
Vector3f endPos = END_POS[i];
2023-05-05 02:44:48 +03:00
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter);
2023-03-14 08:02:43 +03:00
Assert.That(path.status, Is.EqualTo(STATUSES[i]));
Assert.That(path.result.Count, Is.EqualTo(RESULTS[i].Length));
2023-03-16 19:48:49 +03:00
for (int j = 0; j < RESULTS[i].Length; j++)
{
2023-03-14 08:02:43 +03:00
Assert.That(RESULTS[i][j], Is.EqualTo(path.result[j]));
}
}
}
2023-03-16 19:48:49 +03:00
}