com.wallstop-studios.unity-helpers 2.0.0-rc44 → 2.0.0-rc46
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.
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +1 -3
- package/Runtime/Core/DataStructure/KDTree.cs +10 -8
- package/Runtime/Core/DataStructure/QuadTree.cs +16 -8
- package/Runtime/Core/DataStructure/RTree.cs +18 -8
- package/Runtime/Core/DataStructure/StringWrapper.cs +4 -4
- package/Runtime/Core/DataStructure/TimedCache.cs +20 -5
- package/Runtime/Core/Extension/IListExtensions.cs +17 -0
- package/Runtime/Core/Helper/FormattingHelpers.cs +5 -5
- package/Runtime/Core/Helper/Objects.cs +2 -2
- package/Runtime/Core/Helper/ReflectionHelpers.cs +156 -1
- package/Runtime/Core/Helper/SpriteHelpers.cs +7 -52
- package/Runtime/Core/Helper/WallMath.cs +5 -5
- package/Runtime/Utils/RuntimeSingleton.cs +13 -5
- package/Tests/Runtime/Extensions/IListExtensionTests.cs +28 -0
- package/Tests/Runtime/Helper/ArrayConverterTests.cs +3 -3
- package/Tests/Runtime/Helper/FormattingHelperTests.cs +129 -0
- package/Tests/Runtime/Helper/FormattingHelperTests.cs.meta +3 -0
- package/Tests/Runtime/Helper/ObjectHelperTests.cs +2 -2
- package/Tests/Runtime/Helper/ReflectionHelperTests.cs +356 -35
- package/Tests/Runtime/Helper/WallMathTests.cs +4 -4
- package/package.json +1 -1
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
namespace UnityHelpers.Tests.
|
|
1
|
+
namespace UnityHelpers.Tests.Helper
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections;
|
|
5
5
|
using System.Collections.Generic;
|
|
6
|
-
using
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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.
|
|
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
|
{
|