@@ -9,7 +9,7 @@ namespace MLAPI.RuntimeTests
99 public class TickSystemTests : IDisposable
1010 {
1111 private NetworkTickSystem m_TickSystem = null ;
12- private float m_TestDuration = 5 .0f;
12+ private float m_TestDuration = 3 .0f;
1313 private float m_SleepInterval = 0.001f ;
1414 private float m_TickInterval = 0.010f ;
1515
@@ -25,27 +25,27 @@ public IEnumerator VerifyTickSystem()
2525 {
2626 m_TickSystem = new NetworkTickSystem ( m_TickInterval ) ;
2727
28- ushort tick0 = m_TickSystem . GetTick ( ) ;
29- ushort lastTick = tick0 ;
30- float t0 = Time . unscaledTime ;
31- float t1 ;
28+ var startTick = m_TickSystem . GetTick ( ) ;
29+ var startTime = Time . unscaledTime ;
3230
31+ var lastTick = startTick ;
3332 do
3433 {
35- t1 = Time . unscaledTime ;
36- ushort tick = m_TickSystem . GetTick ( ) ;
34+ var currentTick = m_TickSystem . GetTick ( ) ;
35+ Assert . IsTrue ( currentTick >= lastTick ) ; // check monotonicity of ticks
36+ lastTick = currentTick ;
3737
38- Assert . IsTrue ( tick >= lastTick ) ; // check monotonicity of ticks
39-
40- lastTick = tick ;
4138 yield return new WaitForSeconds ( m_SleepInterval ) ;
42- } while ( t1 - t0 <= m_TestDuration ) ;
39+ } while ( Time . unscaledTime - startTime <= m_TestDuration ) ;
40+
41+ var endTick = m_TickSystem . GetTick ( ) ;
42+ var endTime = Time . unscaledTime ;
4343
44- int ticks = lastTick - tick0 ;
45- int expectedTicks = ( int ) ( m_TestDuration / m_TickInterval ) ;
44+ var elapsedTicks = endTick - startTick ;
45+ var elapsedTime = endTime - startTime ;
4646
47- // check overall number of ticks is within one tick of the expected value
48- Assert . IsTrue ( Math . Abs ( expectedTicks - ticks ) < 2 ) ;
47+ var elapsedTicksExpected = ( int ) ( elapsedTime / m_TickInterval ) ;
48+ Assert . Less ( Math . Abs ( elapsedTicksExpected - elapsedTicks ) , 2 ) ; // +/- 1 is OK
4949 }
5050 }
5151}
0 commit comments