Skip to content

Commit 88059fc

Browse files
committed
added DtNodePool all tests
1 parent 8ae375e commit 88059fc

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
## [Unreleased] - yyyy-mm-dd
88

99
### Added
10-
- Added DtNodePool.GetNode, FindNode, FindNodes tests
10+
- Added DtNodePool tests
1111

1212
### Fixed
13-
- Fixed SOH issue in dtNavMeshQuery.Raycast
13+
- Fixed SOH issue in DtNavMeshQuery.Raycast
1414
- Fixed SOH issue in DtProximityGrid.QueryItems
1515

1616
### Changed
17+
- Upgrade NUnit.Analyzers 4.0.1
1718

1819
### Removed
1920

test/DotRecast.Detour.Test/DtNodePoolTest.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Immutable;
2+
using System.Linq;
23
using NUnit.Framework;
34

45
namespace DotRecast.Detour.Test;
@@ -37,6 +38,20 @@ public void TestFindNode()
3738
}
3839
}
3940

41+
int sum = counts.Sum();
42+
Assert.That(sum, Is.EqualTo(10));
43+
44+
// check GetNodeIdx GetNodeAtIdx
45+
for (int i = 0; i < sum; ++i)
46+
{
47+
var node = pool.GetNodeAtIdx(i);
48+
var nodeIdx = pool.GetNodeIdx(node);
49+
var nodeByIdx = pool.GetNodeAtIdx(nodeIdx);
50+
51+
Assert.That(node, Is.SameAs(nodeByIdx));
52+
Assert.That(nodeIdx, Is.EqualTo(i));
53+
}
54+
4055
// check count
4156
for (int i = 0; i < counts.Length; ++i)
4257
{
@@ -47,7 +62,7 @@ public void TestFindNode()
4762

4863
var node = pool.FindNode(i);
4964
Assert.That(nodes[0], Is.SameAs(node));
50-
65+
5166
var node2 = pool.FindNode(i);
5267
Assert.That(nodes[0], Is.SameAs(node2));
5368
}
@@ -58,5 +73,12 @@ public void TestFindNode()
5873
Assert.That(n, Is.EqualTo(0));
5974
Assert.That(nodes, Is.Null);
6075
}
76+
77+
var totalCount = pool.GetNodeMap().Sum(x => x.Value.Count);
78+
Assert.That(totalCount, Is.EqualTo(sum));
79+
80+
pool.Clear();
81+
totalCount = pool.GetNodeMap().Sum(x => x.Value.Count);
82+
Assert.That(totalCount, Is.EqualTo(0));
6183
}
6284
}

0 commit comments

Comments
 (0)