com.wallstop-studios.unity-helpers 2.0.0-rc43 → 2.0.0-rc45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +16 -0
  2. package/Runtime/Core/Helper/FormattingHelpers.cs +32 -0
  3. package/Runtime/Core/Helper/FormattingHelpers.cs.meta +3 -0
  4. package/Runtime/Core/Helper/Objects.cs +2 -2
  5. package/Runtime/Core/Helper/ReflectionHelpers.cs +156 -1
  6. package/Runtime/Core/Helper/SpriteHelpers.cs +7 -52
  7. package/Runtime/Core/Helper/WallMath.cs +5 -5
  8. package/Runtime/Core/Random/AbstractRandom.cs +6 -5
  9. package/Runtime/Core/Random/DotNetRandom.cs +2 -0
  10. package/Runtime/Core/Random/IRandom.cs +1 -0
  11. package/Runtime/Core/Random/LinearCongruentialGenerator.cs +49 -0
  12. package/Runtime/Core/Random/LinearCongruentialGenerator.cs.meta +3 -0
  13. package/Runtime/Core/Random/PcgRandom.cs +1 -1
  14. package/Runtime/Core/Random/RomuDuo.cs +1 -1
  15. package/Runtime/Core/Random/SplitMix64.cs +1 -1
  16. package/Runtime/Core/Random/SystemRandom.cs +1 -1
  17. package/Runtime/Core/Random/WyRandom.cs +1 -1
  18. package/Runtime/Core/Random/XorShiftRandom.cs +13 -8
  19. package/Runtime/Core/Random/XorShiroRandom.cs +2 -0
  20. package/Runtime/UI/LayeredImage.cs +2 -2
  21. package/Runtime/Utils/SpriteRendererMetadata.cs +104 -42
  22. package/Tests/Runtime/Helper/ArrayConverterTests.cs +3 -3
  23. package/Tests/Runtime/Helper/FormattingHelperTests.cs +129 -0
  24. package/Tests/Runtime/Helper/FormattingHelperTests.cs.meta +3 -0
  25. package/Tests/Runtime/Helper/ObjectHelperTests.cs +2 -2
  26. package/Tests/Runtime/Helper/ReflectionHelperTests.cs +356 -35
  27. package/Tests/Runtime/Helper/WallMathTests.cs +4 -4
  28. package/Tests/Runtime/Performance/RandomPerformanceTests.cs +21 -3
  29. package/Tests/Runtime/Random/LinearCongruentialGeneratorTests.cs +12 -0
  30. package/Tests/Runtime/Random/LinearCongruentialGeneratorTests.cs.meta +3 -0
  31. package/package.json +1 -1
@@ -1,30 +1,31 @@
1
- namespace UnityHelpers.Tests.Tests.Runtime.Helper
1
+ namespace UnityHelpers.Tests.Helper
2
2
  {
3
3
  using System;
4
4
  using System.Collections;
5
5
  using System.Collections.Generic;
6
- using Core.Helper;
6
+ using System.Reflection;
7
7
  using NUnit.Framework;
8
+ using UnityHelpers.Core.Helper;
9
+ using UnityHelpers.Core.Random;
8
10
 
9
11
  public struct TestStruct
10
12
  {
13
+ public static int staticIntValue;
11
14
  public int intValue;
12
15
  }
13
16
 
14
17
  public sealed class TestClass
15
18
  {
19
+ public static int staticIntValue;
16
20
  public int intValue;
17
21
  }
18
22
 
19
23
  public sealed class ReflectionHelperTests
20
24
  {
21
- internal const int NumTries = 1_000;
25
+ private const int NumTries = 1_000;
22
26
 
23
- private readonly Random _random = new();
24
-
25
- // TODO: Test on static fields
26
27
  [Test]
27
- public void GetFieldGetterClass()
28
+ public void GetFieldGetterClassMemberField()
28
29
  {
29
30
  TestClass testClass = new();
30
31
  Func<object, object> classGetter = ReflectionHelpers.GetFieldGetter(
@@ -33,14 +34,59 @@
33
34
  Assert.AreEqual(testClass.intValue, classGetter(testClass));
34
35
  for (int i = 0; i < NumTries; ++i)
35
36
  {
36
- testClass.intValue = _random.Next(int.MinValue, int.MaxValue);
37
+ testClass.intValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
37
38
  Assert.AreEqual(testClass.intValue, classGetter(testClass));
38
39
  }
39
40
  }
40
41
 
41
- // TODO: Test on static fields
42
42
  [Test]
43
- public void GetFieldGetterStruct()
43
+ public void GetFieldGetterClassStaticField()
44
+ {
45
+ TestClass testClass = new();
46
+ Func<object, object> classGetter = ReflectionHelpers.GetFieldGetter(
47
+ typeof(TestClass).GetField(
48
+ nameof(TestClass.staticIntValue),
49
+ BindingFlags.Static | BindingFlags.Public
50
+ )
51
+ );
52
+ Assert.AreEqual(TestClass.staticIntValue, classGetter(testClass));
53
+ for (int i = 0; i < NumTries; ++i)
54
+ {
55
+ TestClass.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
56
+ Assert.AreEqual(TestClass.staticIntValue, classGetter(testClass));
57
+ }
58
+ }
59
+
60
+ [Test]
61
+ public void GetStaticFieldGetterThrowsOnNonStaticField()
62
+ {
63
+ Assert.Throws<ArgumentException>(
64
+ () =>
65
+ ReflectionHelpers.GetStaticFieldGetter(
66
+ typeof(TestClass).GetField(nameof(TestClass.intValue))
67
+ )
68
+ );
69
+ }
70
+
71
+ [Test]
72
+ public void GetStaticFieldGetterClassStaticField()
73
+ {
74
+ Func<object> classGetter = ReflectionHelpers.GetStaticFieldGetter(
75
+ typeof(TestClass).GetField(
76
+ nameof(TestClass.staticIntValue),
77
+ BindingFlags.Static | BindingFlags.Public
78
+ )
79
+ );
80
+ Assert.AreEqual(TestClass.staticIntValue, classGetter());
81
+ for (int i = 0; i < NumTries; ++i)
82
+ {
83
+ TestClass.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
84
+ Assert.AreEqual(TestClass.staticIntValue, classGetter());
85
+ }
86
+ }
87
+
88
+ [Test]
89
+ public void GetFieldGetterStructMemberField()
44
90
  {
45
91
  TestStruct testStruct = new();
46
92
  Func<object, object> structGetter = ReflectionHelpers.GetFieldGetter(
@@ -49,14 +95,48 @@
49
95
  Assert.AreEqual(testStruct.intValue, structGetter(testStruct));
50
96
  for (int i = 0; i < NumTries; ++i)
51
97
  {
52
- testStruct.intValue = _random.Next(int.MinValue, int.MaxValue);
98
+ testStruct.intValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
53
99
  Assert.AreEqual(testStruct.intValue, structGetter(testStruct));
54
100
  }
55
101
  }
56
102
 
57
- // TODO: Test on static fields
58
103
  [Test]
59
- public void GetFieldSetterClass()
104
+ public void GetFieldGetterStructStaticField()
105
+ {
106
+ TestStruct testStruct = new();
107
+ Func<object, object> structGetter = ReflectionHelpers.GetFieldGetter(
108
+ typeof(TestStruct).GetField(
109
+ nameof(TestStruct.staticIntValue),
110
+ BindingFlags.Static | BindingFlags.Public
111
+ )
112
+ );
113
+ Assert.AreEqual(TestStruct.staticIntValue, structGetter(testStruct));
114
+ for (int i = 0; i < NumTries; ++i)
115
+ {
116
+ TestStruct.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
117
+ Assert.AreEqual(TestStruct.staticIntValue, structGetter(testStruct));
118
+ }
119
+ }
120
+
121
+ [Test]
122
+ public void GetStaticFieldGetterStructStaticField()
123
+ {
124
+ Func<object> structGetter = ReflectionHelpers.GetStaticFieldGetter(
125
+ typeof(TestStruct).GetField(
126
+ nameof(TestStruct.staticIntValue),
127
+ BindingFlags.Static | BindingFlags.Public
128
+ )
129
+ );
130
+ Assert.AreEqual(TestStruct.staticIntValue, structGetter());
131
+ for (int i = 0; i < NumTries; ++i)
132
+ {
133
+ TestStruct.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
134
+ Assert.AreEqual(TestStruct.staticIntValue, structGetter());
135
+ }
136
+ }
137
+
138
+ [Test]
139
+ public void GetFieldSetterClassMemberField()
60
140
  {
61
141
  TestClass testClass = new();
62
142
  Action<object, object> structSetter = ReflectionHelpers.GetFieldSetter(
@@ -64,15 +144,60 @@
64
144
  );
65
145
  for (int i = 0; i < NumTries; ++i)
66
146
  {
67
- int expected = _random.Next(int.MinValue, int.MaxValue);
147
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
68
148
  structSetter(testClass, expected);
69
149
  Assert.AreEqual(expected, testClass.intValue);
70
150
  }
71
151
  }
72
152
 
73
- // TODO: Test on static fields
74
153
  [Test]
75
- public void GetFieldSetterStruct()
154
+ public void GetFieldSetterClassStaticField()
155
+ {
156
+ TestClass testClass = new();
157
+ Action<object, object> structSetter = ReflectionHelpers.GetFieldSetter(
158
+ typeof(TestClass).GetField(
159
+ nameof(TestClass.staticIntValue),
160
+ BindingFlags.Static | BindingFlags.Public
161
+ )
162
+ );
163
+ for (int i = 0; i < NumTries; ++i)
164
+ {
165
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
166
+ structSetter(testClass, expected);
167
+ Assert.AreEqual(expected, TestClass.staticIntValue);
168
+ }
169
+ }
170
+
171
+ [Test]
172
+ public void GetStaticFieldSetterThrowsOnNonStaticField()
173
+ {
174
+ Assert.Throws<ArgumentException>(
175
+ () =>
176
+ ReflectionHelpers.GetStaticFieldSetter(
177
+ typeof(TestClass).GetField(nameof(TestClass.intValue))
178
+ )
179
+ );
180
+ }
181
+
182
+ [Test]
183
+ public void GetStaticFieldSetterClassStaticField()
184
+ {
185
+ Action<object> structSetter = ReflectionHelpers.GetStaticFieldSetter(
186
+ typeof(TestClass).GetField(
187
+ nameof(TestClass.staticIntValue),
188
+ BindingFlags.Static | BindingFlags.Public
189
+ )
190
+ );
191
+ for (int i = 0; i < NumTries; ++i)
192
+ {
193
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
194
+ structSetter(expected);
195
+ Assert.AreEqual(expected, TestClass.staticIntValue);
196
+ }
197
+ }
198
+
199
+ [Test]
200
+ public void GetFieldSetterStructMemberField()
76
201
  {
77
202
  // Need boxing
78
203
  object testStruct = new TestStruct();
@@ -81,15 +206,50 @@
81
206
  );
82
207
  for (int i = 0; i < NumTries; ++i)
83
208
  {
84
- int expected = _random.Next(int.MinValue, int.MaxValue);
209
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
85
210
  structSetter(testStruct, expected);
86
211
  Assert.AreEqual(expected, ((TestStruct)testStruct).intValue);
87
212
  }
88
213
  }
89
214
 
90
- // TODO: Test on static fields
91
215
  [Test]
92
- public void GetFieldSetterClassGeneric()
216
+ public void GetFieldSetterStructStaticField()
217
+ {
218
+ // Need boxing
219
+ object testStruct = new TestStruct();
220
+ Action<object, object> structSetter = ReflectionHelpers.GetFieldSetter(
221
+ typeof(TestStruct).GetField(
222
+ nameof(TestStruct.staticIntValue),
223
+ BindingFlags.Static | BindingFlags.Public
224
+ )
225
+ );
226
+ for (int i = 0; i < NumTries; ++i)
227
+ {
228
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
229
+ structSetter(testStruct, expected);
230
+ Assert.AreEqual(expected, TestStruct.staticIntValue);
231
+ }
232
+ }
233
+
234
+ [Test]
235
+ public void GetStaticFieldSetterStructStaticField()
236
+ {
237
+ Action<object> structSetter = ReflectionHelpers.GetStaticFieldSetter(
238
+ typeof(TestStruct).GetField(
239
+ nameof(TestStruct.staticIntValue),
240
+ BindingFlags.Static | BindingFlags.Public
241
+ )
242
+ );
243
+ for (int i = 0; i < NumTries; ++i)
244
+ {
245
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
246
+ structSetter(expected);
247
+ Assert.AreEqual(expected, TestStruct.staticIntValue);
248
+ }
249
+ }
250
+
251
+ [Test]
252
+ public void GetFieldSetterClassGenericMemberField()
93
253
  {
94
254
  TestClass testClass = new();
95
255
  FieldSetter<TestClass, int> classSetter = ReflectionHelpers.GetFieldSetter<
@@ -98,15 +258,63 @@
98
258
  >(typeof(TestClass).GetField(nameof(TestClass.intValue)));
99
259
  for (int i = 0; i < NumTries; ++i)
100
260
  {
101
- int expected = _random.Next(int.MinValue, int.MaxValue);
261
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
102
262
  classSetter(ref testClass, expected);
103
263
  Assert.AreEqual(expected, testClass.intValue);
104
264
  }
105
265
  }
106
266
 
107
- // TODO: Test on static fields
108
267
  [Test]
109
- public void GetFieldSetterStructGeneric()
268
+ public void GetFieldSetterClassGenericStaticField()
269
+ {
270
+ TestClass testClass = new();
271
+ FieldSetter<TestClass, int> classSetter = ReflectionHelpers.GetFieldSetter<
272
+ TestClass,
273
+ int
274
+ >(
275
+ typeof(TestClass).GetField(
276
+ nameof(TestClass.staticIntValue),
277
+ BindingFlags.Static | BindingFlags.Public
278
+ )
279
+ );
280
+ for (int i = 0; i < NumTries; ++i)
281
+ {
282
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
283
+ classSetter(ref testClass, expected);
284
+ Assert.AreEqual(expected, TestClass.staticIntValue);
285
+ }
286
+ }
287
+
288
+ [Test]
289
+ public void GetStaticFieldSetterGenericThrowsOnNonStaticField()
290
+ {
291
+ Assert.Throws<ArgumentException>(
292
+ () =>
293
+ ReflectionHelpers.GetStaticFieldSetter<int>(
294
+ typeof(TestClass).GetField(nameof(TestClass.intValue))
295
+ )
296
+ );
297
+ }
298
+
299
+ [Test]
300
+ public void GetStaticFieldSetterClassGenericStaticField()
301
+ {
302
+ Action<int> classSetter = ReflectionHelpers.GetStaticFieldSetter<int>(
303
+ typeof(TestClass).GetField(
304
+ nameof(TestClass.staticIntValue),
305
+ BindingFlags.Static | BindingFlags.Public
306
+ )
307
+ );
308
+ for (int i = 0; i < NumTries; ++i)
309
+ {
310
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
311
+ classSetter(expected);
312
+ Assert.AreEqual(expected, TestClass.staticIntValue);
313
+ }
314
+ }
315
+
316
+ [Test]
317
+ public void GetFieldSetterStructGenericMemberField()
110
318
  {
111
319
  TestStruct testStruct = new();
112
320
  FieldSetter<TestStruct, int> structSetter = ReflectionHelpers.GetFieldSetter<
@@ -115,15 +323,52 @@
115
323
  >(typeof(TestStruct).GetField(nameof(TestStruct.intValue)));
116
324
  for (int i = 0; i < NumTries; ++i)
117
325
  {
118
- int expected = _random.Next(int.MinValue, int.MaxValue);
326
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
119
327
  structSetter(ref testStruct, expected);
120
328
  Assert.AreEqual(expected, testStruct.intValue);
121
329
  }
122
330
  }
123
331
 
124
- // TODO: Test on static fields
125
332
  [Test]
126
- public void GetFieldGetterClassGeneric()
333
+ public void GetFieldSetterStructGenericStaticField()
334
+ {
335
+ TestStruct testStruct = new();
336
+ FieldSetter<TestStruct, int> structSetter = ReflectionHelpers.GetFieldSetter<
337
+ TestStruct,
338
+ int
339
+ >(
340
+ typeof(TestStruct).GetField(
341
+ nameof(TestStruct.staticIntValue),
342
+ BindingFlags.Static | BindingFlags.Public
343
+ )
344
+ );
345
+ for (int i = 0; i < NumTries; ++i)
346
+ {
347
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
348
+ structSetter(ref testStruct, expected);
349
+ Assert.AreEqual(expected, TestStruct.staticIntValue);
350
+ }
351
+ }
352
+
353
+ [Test]
354
+ public void GetStaticFieldSetterStructGenericStaticField()
355
+ {
356
+ Action<int> structSetter = ReflectionHelpers.GetStaticFieldSetter<int>(
357
+ typeof(TestStruct).GetField(
358
+ nameof(TestStruct.staticIntValue),
359
+ BindingFlags.Static | BindingFlags.Public
360
+ )
361
+ );
362
+ for (int i = 0; i < NumTries; ++i)
363
+ {
364
+ int expected = PRNG.Instance.Next(int.MinValue, int.MaxValue);
365
+ structSetter(expected);
366
+ Assert.AreEqual(expected, TestStruct.staticIntValue);
367
+ }
368
+ }
369
+
370
+ [Test]
371
+ public void GetFieldGetterClassGenericMemberField()
127
372
  {
128
373
  TestClass testClass = new();
129
374
  Func<TestClass, int> classGetter = ReflectionHelpers.GetFieldGetter<TestClass, int>(
@@ -131,14 +376,57 @@
131
376
  );
132
377
  for (int i = 0; i < NumTries; ++i)
133
378
  {
134
- testClass.intValue = _random.Next(int.MinValue, int.MaxValue);
379
+ testClass.intValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
135
380
  Assert.AreEqual(testClass.intValue, classGetter(testClass));
136
381
  }
137
382
  }
138
383
 
139
- // TODO: Test on static fields
140
384
  [Test]
141
- public void GetFieldGetterStructGeneric()
385
+ public void GetFieldGetterClassGenericStaticField()
386
+ {
387
+ TestClass testClass = new();
388
+ Func<TestClass, int> classGetter = ReflectionHelpers.GetFieldGetter<TestClass, int>(
389
+ typeof(TestClass).GetField(
390
+ nameof(TestClass.staticIntValue),
391
+ BindingFlags.Static | BindingFlags.Public
392
+ )
393
+ );
394
+ for (int i = 0; i < NumTries; ++i)
395
+ {
396
+ TestClass.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
397
+ Assert.AreEqual(TestClass.staticIntValue, classGetter(testClass));
398
+ }
399
+ }
400
+
401
+ [Test]
402
+ public void GetStaticFieldGetterGenericThrowsOnNonStaticField()
403
+ {
404
+ Assert.Throws<ArgumentException>(
405
+ () =>
406
+ ReflectionHelpers.GetStaticFieldGetter<int>(
407
+ typeof(TestClass).GetField(nameof(TestClass.intValue))
408
+ )
409
+ );
410
+ }
411
+
412
+ [Test]
413
+ public void GetStaticFieldGetterClassGenericStaticField()
414
+ {
415
+ Func<int> classGetter = ReflectionHelpers.GetStaticFieldGetter<int>(
416
+ typeof(TestClass).GetField(
417
+ nameof(TestClass.staticIntValue),
418
+ BindingFlags.Static | BindingFlags.Public
419
+ )
420
+ );
421
+ for (int i = 0; i < NumTries; ++i)
422
+ {
423
+ TestClass.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
424
+ Assert.AreEqual(TestClass.staticIntValue, classGetter());
425
+ }
426
+ }
427
+
428
+ [Test]
429
+ public void GetFieldGetterStructGenericMemberField()
142
430
  {
143
431
  TestStruct testStruct = new();
144
432
  Func<TestStruct, int> structSetter = ReflectionHelpers.GetFieldGetter<TestStruct, int>(
@@ -146,17 +434,50 @@
146
434
  );
147
435
  for (int i = 0; i < NumTries; ++i)
148
436
  {
149
- testStruct.intValue = _random.Next(int.MinValue, int.MaxValue);
437
+ testStruct.intValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
150
438
  Assert.AreEqual(testStruct.intValue, structSetter(testStruct));
151
439
  }
152
440
  }
153
441
 
442
+ [Test]
443
+ public void GetFieldGetterStructGenericStaticField()
444
+ {
445
+ TestStruct testStruct = new();
446
+ Func<TestStruct, int> structSetter = ReflectionHelpers.GetFieldGetter<TestStruct, int>(
447
+ typeof(TestStruct).GetField(
448
+ nameof(TestStruct.staticIntValue),
449
+ BindingFlags.Static | BindingFlags.Public
450
+ )
451
+ );
452
+ for (int i = 0; i < NumTries; ++i)
453
+ {
454
+ TestStruct.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
455
+ Assert.AreEqual(TestStruct.staticIntValue, structSetter(testStruct));
456
+ }
457
+ }
458
+
459
+ [Test]
460
+ public void GetStaticFieldGetterStructGenericStaticField()
461
+ {
462
+ Func<int> structSetter = ReflectionHelpers.GetStaticFieldGetter<int>(
463
+ typeof(TestStruct).GetField(
464
+ nameof(TestStruct.staticIntValue),
465
+ BindingFlags.Static | BindingFlags.Public
466
+ )
467
+ );
468
+ for (int i = 0; i < NumTries; ++i)
469
+ {
470
+ TestStruct.staticIntValue = PRNG.Instance.Next(int.MinValue, int.MaxValue);
471
+ Assert.AreEqual(TestStruct.staticIntValue, structSetter());
472
+ }
473
+ }
474
+
154
475
  [Test]
155
476
  public void ArrayCreator()
156
477
  {
157
478
  for (int i = 0; i < NumTries; ++i)
158
479
  {
159
- int count = _random.Next(1_000);
480
+ int count = PRNG.Instance.Next(1_000);
160
481
  Array created = ReflectionHelpers.CreateArray(typeof(int), count);
161
482
  Assert.AreEqual(count, created.Length);
162
483
  Assert.IsTrue(created is int[]);
@@ -174,11 +495,11 @@
174
495
  Assert.AreEqual(0, created.Count);
175
496
  Assert.IsTrue(created is List<int>);
176
497
  List<int> typedCreated = (List<int>)created;
177
- int count = _random.Next(50);
498
+ int count = PRNG.Instance.Next(50);
178
499
  List<int> expected = new();
179
500
  for (int j = 0; j < count; ++j)
180
501
  {
181
- int element = _random.Next();
502
+ int element = PRNG.Instance.Next();
182
503
  created.Add(element);
183
504
  expected.Add(element);
184
505
  Assert.AreEqual(j + 1, created.Count);
@@ -192,18 +513,18 @@
192
513
  {
193
514
  for (int i = 0; i < NumTries; ++i)
194
515
  {
195
- int capacity = _random.Next(1_000);
516
+ int capacity = PRNG.Instance.Next(1_000);
196
517
  IList created = ReflectionHelpers.CreateList(typeof(int), capacity);
197
518
  Assert.AreEqual(0, created.Count);
198
519
  Assert.IsTrue(created is List<int>);
199
520
  List<int> typedCreated = (List<int>)created;
200
521
  Assert.AreEqual(capacity, typedCreated.Capacity);
201
522
 
202
- int count = _random.Next(50);
523
+ int count = PRNG.Instance.Next(50);
203
524
  List<int> expected = new();
204
525
  for (int j = 0; j < count; ++j)
205
526
  {
206
- int element = _random.Next();
527
+ int element = PRNG.Instance.Next();
207
528
  created.Add(element);
208
529
  expected.Add(element);
209
530
  Assert.AreEqual(j + 1, created.Count);
@@ -1,10 +1,10 @@
1
- namespace UnityHelpers.Tests.Tests.Runtime.Helper
1
+ namespace UnityHelpers.Tests.Helper
2
2
  {
3
- using Core.Extension;
4
- using Core.Helper;
5
- using Core.Random;
6
3
  using NUnit.Framework;
7
4
  using UnityEngine;
5
+ using UnityHelpers.Core.Extension;
6
+ using UnityHelpers.Core.Helper;
7
+ using UnityHelpers.Core.Random;
8
8
 
9
9
  public sealed class WallMathTests
10
10
  {
@@ -10,13 +10,13 @@
10
10
  [Test]
11
11
  public void Benchmark()
12
12
  {
13
- TimeSpan timeout = TimeSpan.FromSeconds(1.125);
13
+ TimeSpan timeout = TimeSpan.FromSeconds(1);
14
14
 
15
15
  UnityEngine.Debug.Log(
16
- $"| Random | NextBool | Next | NextUInt | NextFloat | NextDouble | NextUint - Range | "
16
+ "| Random | NextBool | Next | NextUInt | NextFloat | NextDouble | NextUint - Range | NextInt - Range |"
17
17
  );
18
18
  UnityEngine.Debug.Log(
19
- $"| ------ | -------- | ---- | -------- | --------- | ---------- | ---------------- |"
19
+ "| ------ | -------- | ---- | -------- | --------- | ---------- | ---------------- | --------------- |"
20
20
  );
21
21
 
22
22
  RunTest(new PcgRandom(), timeout);
@@ -28,6 +28,8 @@
28
28
  RunTest(new SplitMix64(), timeout);
29
29
  RunTest(new RomuDuo(), timeout);
30
30
  RunTest(new XorShiroRandom(), timeout);
31
+ RunTest(new UnityRandom(), timeout);
32
+ RunTest(new LinearCongruentialGenerator(), timeout);
31
33
  }
32
34
 
33
35
  private static void RunTest<T>(T random, TimeSpan timeout)
@@ -39,6 +41,7 @@
39
41
  int nextFloat = RunNextFloat(timeout, random);
40
42
  int nextDouble = RunNextDouble(timeout, random);
41
43
  int nextUintRange = RunNextUintRange(timeout, random);
44
+ int nextIntRange = RunNextIntRange(timeout, random);
42
45
 
43
46
  UnityEngine.Debug.Log(
44
47
  $"| {random.GetType().Name} | "
@@ -48,6 +51,7 @@
48
51
  + $"{(nextFloat / timeout.TotalSeconds):N0} | "
49
52
  + $"{(nextDouble / timeout.TotalSeconds):N0} |"
50
53
  + $"{(nextUintRange / timeout.TotalSeconds):N0} |"
54
+ + $"{(nextIntRange / timeout.TotalSeconds):N0} |"
51
55
  );
52
56
  }
53
57
 
@@ -108,6 +112,20 @@
108
112
  return count;
109
113
  }
110
114
 
115
+ private static int RunNextIntRange<T>(TimeSpan timeout, T random)
116
+ where T : IRandom
117
+ {
118
+ int count = 0;
119
+ Stopwatch timer = Stopwatch.StartNew();
120
+ do
121
+ {
122
+ _ = random.Next(1_000);
123
+ ++count;
124
+ } while (timer.Elapsed < timeout);
125
+
126
+ return count;
127
+ }
128
+
111
129
  private static int RunNextFloat<T>(TimeSpan timeout, T random)
112
130
  where T : IRandom
113
131
  {
@@ -0,0 +1,12 @@
1
+ namespace UnityHelpers.Tests.Random
2
+ {
3
+ using Core.Random;
4
+
5
+ public sealed class LinearCongruentialGeneratorTests : RandomTestBase
6
+ {
7
+ protected override IRandom NewRandom()
8
+ {
9
+ return new LinearCongruentialGenerator();
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 7859c541d79a4af7893bd98abfe7fea8
3
+ timeCreated: 1742702856
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc43",
3
+ "version": "2.0.0-rc45",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},