@@ -9,6 +9,54 @@ namespace Unity.Netcode.EditorTests
9
9
{
10
10
public class NetworkTimeTests
11
11
{
12
+ [ Test ]
13
+ [ TestCase ( 0d , 0 ) ]
14
+ [ TestCase ( 5d , 0 ) ]
15
+ [ TestCase ( - 5d , 0 ) ]
16
+ [ TestCase ( 0d , - 20 ) ]
17
+ [ TestCase ( 5d , int . MinValue ) ]
18
+ [ TestCase ( - 5d , - 1 ) ]
19
+ public void TestFailCreateInvalidTime ( double time , int tickrate )
20
+ {
21
+ Assert . Throws < UnityEngine . Assertions . AssertionException > ( ( ) => new NetworkTime ( tickrate , time ) ) ;
22
+ }
23
+
24
+ [ Test ]
25
+ [ TestCase ( 0d , 0f , 20 ) ]
26
+ [ TestCase ( 0d , 0f , 30 ) ]
27
+ [ TestCase ( 0d , 0f , 60 ) ]
28
+
29
+ [ TestCase ( 201d , 201f , 20 ) ]
30
+ [ TestCase ( 201d , 201f , 30 ) ]
31
+ [ TestCase ( 201d , 201f , 60 ) ]
32
+
33
+ [ TestCase ( - 4301d , - 4301f , 20 ) ]
34
+ [ TestCase ( - 4301d , - 4301f , 30 ) ]
35
+ [ TestCase ( - 4301d , - 4301f , 60 ) ]
36
+
37
+ [ TestCase ( float . MaxValue , float . MaxValue , 20 ) ]
38
+ [ TestCase ( float . MaxValue , float . MaxValue , 30 ) ]
39
+ [ TestCase ( float . MaxValue , float . MaxValue , 60 ) ]
40
+ public void TestTimeAsFloat ( double d , float f , int tickRate )
41
+ {
42
+ var networkTime = new NetworkTime ( tickRate , d ) ;
43
+ Assert . True ( Mathf . Approximately ( networkTime . TimeAsFloat , f ) ) ;
44
+ }
45
+
46
+ [ Test ]
47
+ [ TestCase ( 53.55d , 53.5d , 10 ) ]
48
+ [ TestCase ( 1013553.55d , 1013553.5d , 10 ) ]
49
+ [ TestCase ( 0d , 0d , 10 ) ]
50
+ [ TestCase ( - 27.41d , - 27.5d , 10 ) ]
51
+
52
+ [ TestCase ( 53.55d , 53.54d , 50 ) ]
53
+ [ TestCase ( 1013553.55d , 1013553.54d , 50 ) ]
54
+ [ TestCase ( 0d , 0d , 50 ) ]
55
+ [ TestCase ( - 27.4133d , - 27.42d , 50 ) ]
56
+ public void TestToFixedTime ( double time , double expectedFixedTime , int tickRate )
57
+ {
58
+ Assert . AreEqual ( expectedFixedTime , new NetworkTime ( tickRate , time ) . ToFixedTime ( ) . Time ) ;
59
+ }
12
60
13
61
[ Test ]
14
62
public void NetworkTimeCreate ( )
@@ -104,7 +152,6 @@ public void NetworkTimeSubFloatTest()
104
152
Assert . IsTrue ( Approximately ( floatResultE , timeE . Time ) ) ;
105
153
}
106
154
107
-
108
155
[ Test ]
109
156
public void NetworkTimeAddNetworkTimeTest ( )
110
157
{
@@ -170,7 +217,6 @@ public void NetworkTimeAdvanceTest()
170
217
NetworkTimeAdvanceTestInternal ( randomSteps , 30 , 0f ) ;
171
218
NetworkTimeAdvanceTestInternal ( randomSteps , 144 , 0f ) ;
172
219
173
-
174
220
NetworkTimeAdvanceTestInternal ( randomSteps , 60 , 23132.231f ) ;
175
221
NetworkTimeAdvanceTestInternal ( randomSteps , 1 , 23132.231f ) ;
176
222
NetworkTimeAdvanceTestInternal ( randomSteps , 10 , 23132.231f ) ;
@@ -220,6 +266,5 @@ private static bool Approximately(double a, double b, double epsilon = 0.000001d
220
266
var dif = Math . Abs ( a - b ) ;
221
267
return dif <= epsilon ;
222
268
}
223
-
224
269
}
225
270
}
0 commit comments