2024-02-07 18:03:06 +03:00
|
|
|
|
using System.Collections.Generic;
|
2024-02-09 11:56:16 +03:00
|
|
|
|
using DotRecast.Core;
|
2024-02-07 18:03:06 +03:00
|
|
|
|
using DotRecast.Core.Collections;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.Test;
|
|
|
|
|
|
|
|
|
|
public class DtNodeQueueTest
|
|
|
|
|
{
|
2024-02-09 11:56:16 +03:00
|
|
|
|
private static List<DtNode> ShuffledNodes(int count)
|
|
|
|
|
{
|
|
|
|
|
var nodes = new List<DtNode>();
|
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
var node = new DtNode(i);
|
|
|
|
|
node.total = i;
|
|
|
|
|
nodes.Add(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nodes.Shuffle();
|
|
|
|
|
return nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-07 18:03:06 +03:00
|
|
|
|
[Test]
|
2024-02-09 11:56:16 +03:00
|
|
|
|
public void TestPushAndPop()
|
2024-02-07 18:03:06 +03:00
|
|
|
|
{
|
|
|
|
|
var queue = new DtNodeQueue();
|
|
|
|
|
|
|
|
|
|
// check count
|
|
|
|
|
Assert.That(queue.Count(), Is.EqualTo(0));
|
2024-02-09 11:56:16 +03:00
|
|
|
|
|
|
|
|
|
// null push
|
|
|
|
|
queue.Push(null);
|
|
|
|
|
Assert.That(queue.Count(), Is.EqualTo(0));
|
2024-02-07 18:03:06 +03:00
|
|
|
|
|
2024-02-09 11:56:16 +03:00
|
|
|
|
// test push
|
2024-02-07 18:03:06 +03:00
|
|
|
|
const int count = 1000;
|
2024-02-09 11:56:16 +03:00
|
|
|
|
var expectedNodes = ShuffledNodes(count);
|
|
|
|
|
foreach (var node in expectedNodes)
|
2024-02-07 18:03:06 +03:00
|
|
|
|
{
|
2024-02-09 11:56:16 +03:00
|
|
|
|
queue.Push(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.That(queue.Count(), Is.EqualTo(count));
|
|
|
|
|
|
|
|
|
|
// test pop
|
|
|
|
|
expectedNodes.Sort(DtNode.ComparisonNodeTotal);
|
|
|
|
|
foreach (var node in expectedNodes)
|
|
|
|
|
{
|
|
|
|
|
Assert.That(queue.Peek(), Is.SameAs(node));
|
|
|
|
|
Assert.That(queue.Pop(), Is.SameAs(node));
|
2024-02-07 18:03:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 11:56:16 +03:00
|
|
|
|
Assert.That(queue.Count(), Is.EqualTo(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestClear()
|
|
|
|
|
{
|
|
|
|
|
var queue = new DtNodeQueue();
|
|
|
|
|
|
|
|
|
|
const int count = 555;
|
|
|
|
|
var expectedNodes = ShuffledNodes(count);
|
|
|
|
|
foreach (var node in expectedNodes)
|
2024-02-07 18:03:06 +03:00
|
|
|
|
{
|
|
|
|
|
queue.Push(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.That(queue.Count(), Is.EqualTo(count));
|
2024-02-09 11:56:16 +03:00
|
|
|
|
|
|
|
|
|
queue.Clear();
|
|
|
|
|
Assert.That(queue.Count(), Is.EqualTo(0));
|
|
|
|
|
Assert.That(queue.IsEmpty(), Is.True);
|
2024-02-07 18:03:06 +03:00
|
|
|
|
}
|
2024-02-09 11:56:16 +03:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestModify()
|
|
|
|
|
{
|
|
|
|
|
var queue = new DtNodeQueue();
|
|
|
|
|
|
|
|
|
|
const int count = 5000;
|
|
|
|
|
var expectedNodes = ShuffledNodes(count);
|
|
|
|
|
|
|
|
|
|
foreach (var node in expectedNodes)
|
|
|
|
|
{
|
|
|
|
|
queue.Push(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check modify
|
|
|
|
|
queue.Modify(null);
|
|
|
|
|
|
|
|
|
|
// change total
|
|
|
|
|
var r = new RcRand();
|
|
|
|
|
foreach (var node in expectedNodes)
|
|
|
|
|
{
|
|
|
|
|
node.total = r.NextInt32() % (count / 50); // duplication for test
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// test modify
|
|
|
|
|
foreach (var node in expectedNodes)
|
|
|
|
|
{
|
|
|
|
|
queue.Modify(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
expectedNodes.Sort(DtNode.ComparisonNodeTotal);
|
|
|
|
|
foreach (var node in expectedNodes)
|
|
|
|
|
{
|
|
|
|
|
Assert.That(queue.Pop(), Is.SameAs(node));
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-07 18:03:06 +03:00
|
|
|
|
}
|