Skip to content

Commit 8773a34

Browse files
test: Move NetworkDeltaPositionTests into the editor test assembly
The fixture is unit tests over NetworkDeltaPosition's encoding math with no session behind it, so it belongs in EditMode rather than paying PlayMode entry. QuantumIsGuardedAtTheTopOfTheRange becomes a [Test] over an array so every data set in the fixture is driven the same way, and the value list in QuantumIsTheSmallestChangeTheEncodingCanSee is hoisted out of the foreach to match the other three. The reference to NetworkTransformHalfFloatPrecisionTests drops its cref because that fixture is internal to Unity.Netcode.Runtime.Tests, which does not expose its internals to the editor test assembly.
1 parent 19ef4f2 commit 8773a34

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkDeltaPositionTests.cs renamed to com.unity.netcode.gameobjects/Tests/Editor/NetworkDeltaPositionTests.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using Unity.Netcode.Components;
55
using UnityEngine;
66

7-
namespace Unity.Netcode.RuntimeTests
7+
namespace Unity.Netcode.GameObjects.EditorTests
88
{
99
/// <summary>
1010
/// Branch coverage for <see cref="NetworkDeltaPosition"/>'s encoding math.
1111
/// </summary>
1212
/// <remarks>
13-
/// Separate from <see cref="NetworkTransformHalfFloatPrecisionTests"/> because none of this needs a
14-
/// session, and that fixture would run it twice over two topologies.
13+
/// Separate from NetworkTransformHalfFloatPrecisionTests because none of this needs a session, and
14+
/// that fixture would run it twice over two topologies.
1515
/// <br /><br />
1616
/// A value that is exactly representable as a half float carries no rounding loss, so a test built on
1717
/// one cannot observe the behavior checked here and will pass against broken code. Keep the constants
@@ -291,7 +291,9 @@ public void FullPrecisionRoundTripsWhenTheBaseIsSynchronized()
291291
public void QuantumIsTheSmallestChangeTheEncodingCanSee()
292292
{
293293
// Exactly representable, so "one step away" is unambiguous.
294-
foreach (var value in new[] { 0.5f, 1.0f, -1.0f, 2.0f, 300.0f, 1024.0f })
294+
var values = new[] { 0.5f, 1.0f, -1.0f, 2.0f, 300.0f, 1024.0f };
295+
296+
foreach (var value in values)
295297
{
296298
var quantum = NetworkDeltaPosition.HalfPrecisionQuantum(value);
297299
Assert.Greater(quantum, 0.0f, $"The step size at {value} should be positive.");
@@ -307,17 +309,23 @@ public void QuantumIsTheSmallestChangeTheEncodingCanSee()
307309
}
308310
}
309311

310-
[TestCase(65504.0f, TestName = "QuantumIsGuarded_AtLargestFiniteHalf")]
311-
[TestCase(-65504.0f, TestName = "QuantumIsGuarded_AtNegativeLargestFiniteHalf")]
312-
[TestCase(70000.0f, TestName = "QuantumIsGuarded_WhenRoundingToInfinity")]
313-
[TestCase(float.PositiveInfinity, TestName = "QuantumIsGuarded_AtPositiveInfinity")]
314-
[TestCase(float.NegativeInfinity, TestName = "QuantumIsGuarded_AtNegativeInfinity")]
315-
[TestCase(float.NaN, TestName = "QuantumIsGuarded_AtNaN")]
316-
public void QuantumIsGuardedAtTheTopOfTheRange(float value)
312+
[Test]
313+
public void QuantumIsGuardedAtTheTopOfTheRange()
317314
{
318-
Assert.AreEqual(NetworkDeltaPosition.MaxDeltaBeforeAdjustment,
319-
NetworkDeltaPosition.HalfPrecisionQuantum(value),
320-
$"{value} is at or past the largest finite half float and should fall back to the maximum delta.");
315+
// 70000f is the finite one: the conversion itself rounds to infinity, which reaches the guard
316+
// by a different path than handing it an infinity outright.
317+
var values = new[]
318+
{
319+
65504.0f, -65504.0f, 70000.0f,
320+
float.PositiveInfinity, float.NegativeInfinity, float.NaN,
321+
};
322+
323+
foreach (var value in values)
324+
{
325+
Assert.AreEqual(NetworkDeltaPosition.MaxDeltaBeforeAdjustment,
326+
NetworkDeltaPosition.HalfPrecisionQuantum(value),
327+
$"{value} is at or past the largest finite half float and should fall back to the maximum delta.");
328+
}
321329
}
322330

323331
[Test]

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkDeltaPositionTests.cs.meta renamed to com.unity.netcode.gameobjects/Tests/Editor/NetworkDeltaPositionTests.cs.meta

File renamed without changes.

0 commit comments

Comments
 (0)