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,12 +1,21 @@
|
|
|
1
1
|
namespace UnityHelpers.Tests.Extensions
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
4
5
|
using System.Linq;
|
|
5
6
|
using Core.Extension;
|
|
7
|
+
using Core.Random;
|
|
6
8
|
using NUnit.Framework;
|
|
7
9
|
|
|
8
10
|
public sealed class IListExtensionTests
|
|
9
11
|
{
|
|
12
|
+
private const int NumTries = 1_000;
|
|
13
|
+
|
|
14
|
+
private readonly struct IntComparer : IComparer<int>
|
|
15
|
+
{
|
|
16
|
+
public int Compare(int x, int y) => x.CompareTo(y);
|
|
17
|
+
}
|
|
18
|
+
|
|
10
19
|
[Test]
|
|
11
20
|
public void ShiftLeft()
|
|
12
21
|
{
|
|
@@ -72,5 +81,24 @@
|
|
|
72
81
|
Assert.Throws<ArgumentException>(() => input.Reverse(1, int.MaxValue));
|
|
73
82
|
Assert.Throws<ArgumentException>(() => input.Reverse(1, int.MinValue));
|
|
74
83
|
}
|
|
84
|
+
|
|
85
|
+
[Test]
|
|
86
|
+
public void InsertionSort()
|
|
87
|
+
{
|
|
88
|
+
for (int i = 0; i < NumTries; ++i)
|
|
89
|
+
{
|
|
90
|
+
int[] input = Enumerable
|
|
91
|
+
.Range(0, 100)
|
|
92
|
+
.Select(_ => PRNG.Instance.Next(int.MinValue, int.MaxValue))
|
|
93
|
+
.ToArray();
|
|
94
|
+
int[] conventionalSorted = input.ToArray();
|
|
95
|
+
Array.Sort(conventionalSorted);
|
|
96
|
+
|
|
97
|
+
int[] insertionSorted = input.ToArray();
|
|
98
|
+
insertionSorted.InsertionSort(new IntComparer());
|
|
99
|
+
Assert.That(conventionalSorted, Is.EqualTo(insertionSorted));
|
|
100
|
+
Assert.That(input.OrderBy(x => x), Is.EqualTo(insertionSorted));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
75
103
|
}
|
|
76
104
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
namespace UnityHelpers.Tests.
|
|
1
|
+
namespace UnityHelpers.Tests.Helper
|
|
2
2
|
{
|
|
3
3
|
using System.Linq;
|
|
4
|
-
using Core.Helper;
|
|
5
|
-
using Core.Random;
|
|
6
4
|
using NUnit.Framework;
|
|
5
|
+
using UnityHelpers.Core.Helper;
|
|
6
|
+
using UnityHelpers.Core.Random;
|
|
7
7
|
|
|
8
8
|
public sealed class ArrayConverterTests
|
|
9
9
|
{
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
namespace UnityHelpers.Tests.Helper
|
|
2
|
+
{
|
|
3
|
+
using NUnit.Framework;
|
|
4
|
+
using UnityHelpers.Core.Helper;
|
|
5
|
+
using UnityHelpers.Core.Random;
|
|
6
|
+
|
|
7
|
+
public sealed class FormattingHelperTests
|
|
8
|
+
{
|
|
9
|
+
private const int NumTries = 1_000;
|
|
10
|
+
|
|
11
|
+
[Test]
|
|
12
|
+
public void FormatNegative()
|
|
13
|
+
{
|
|
14
|
+
for (int i = 0; i < NumTries; ++i)
|
|
15
|
+
{
|
|
16
|
+
long bytes = PRNG.Instance.NextLong(long.MinValue, 0);
|
|
17
|
+
const string expected = "0 B";
|
|
18
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
19
|
+
Assert.AreEqual(expected, found, $"{bytes} failed to convert");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
[Test]
|
|
24
|
+
public void FormatZeroBytes()
|
|
25
|
+
{
|
|
26
|
+
long bytes = 0L;
|
|
27
|
+
const string expected = "0 B";
|
|
28
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
29
|
+
Assert.AreEqual(expected, found);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[Test]
|
|
33
|
+
public void FormatBytes()
|
|
34
|
+
{
|
|
35
|
+
for (int i = 0; i < NumTries; ++i)
|
|
36
|
+
{
|
|
37
|
+
long bytes = PRNG.Instance.NextLong(1024L);
|
|
38
|
+
string expected = $"{bytes} B";
|
|
39
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
40
|
+
Assert.AreEqual(expected, found);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
[Test]
|
|
45
|
+
public void FormatKiloBytes()
|
|
46
|
+
{
|
|
47
|
+
for (int i = 0; i < NumTries; ++i)
|
|
48
|
+
{
|
|
49
|
+
long bytes = PRNG.Instance.NextLong(1024L, 1024L * 1024L);
|
|
50
|
+
string expected = $"{(bytes / 1024.0):0.##} KB";
|
|
51
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
52
|
+
Assert.AreEqual(expected, found);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[Test]
|
|
57
|
+
public void FormatMegaBytes()
|
|
58
|
+
{
|
|
59
|
+
for (int i = 0; i < NumTries; ++i)
|
|
60
|
+
{
|
|
61
|
+
long bytes = PRNG.Instance.NextLong(1024L * 1024L, 1024L * 1024L * 1024L);
|
|
62
|
+
string expected = $"{(bytes / 1024.0 / 1024.0):0.##} MB";
|
|
63
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
64
|
+
Assert.AreEqual(expected, found);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[Test]
|
|
69
|
+
public void FormatGigaBytes()
|
|
70
|
+
{
|
|
71
|
+
for (int i = 0; i < NumTries; ++i)
|
|
72
|
+
{
|
|
73
|
+
long bytes = PRNG.Instance.NextLong(
|
|
74
|
+
1024L * 1024L * 1024L,
|
|
75
|
+
1024L * 1024L * 1024L * 1024L
|
|
76
|
+
);
|
|
77
|
+
string expected = $"{(bytes / 1024.0 / 1024.0 / 1024.0):0.##} GB";
|
|
78
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
79
|
+
Assert.AreEqual(expected, found);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[Test]
|
|
84
|
+
public void FormatTeraBytes()
|
|
85
|
+
{
|
|
86
|
+
for (int i = 0; i < NumTries; ++i)
|
|
87
|
+
{
|
|
88
|
+
long bytes = PRNG.Instance.NextLong(
|
|
89
|
+
1024L * 1024L * 1024L * 1024L,
|
|
90
|
+
1024L * 1024L * 1024L * 1024L * 1024L
|
|
91
|
+
);
|
|
92
|
+
string expected = $"{(bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0):0.##} TB";
|
|
93
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
94
|
+
Assert.AreEqual(expected, found);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
[Test]
|
|
99
|
+
public void FormatPetaBytes()
|
|
100
|
+
{
|
|
101
|
+
for (int i = 0; i < NumTries; ++i)
|
|
102
|
+
{
|
|
103
|
+
long bytes = PRNG.Instance.NextLong(
|
|
104
|
+
1024L * 1024L * 1024L * 1024L * 1024L,
|
|
105
|
+
1024L * 1024L * 1024L * 1024L * 1024L * 1024L
|
|
106
|
+
);
|
|
107
|
+
string expected = $"{(bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0):0.##} PB";
|
|
108
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
109
|
+
Assert.AreEqual(expected, found);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
[Test]
|
|
114
|
+
public void FormatExaBytes()
|
|
115
|
+
{
|
|
116
|
+
for (int i = 0; i < NumTries; ++i)
|
|
117
|
+
{
|
|
118
|
+
long bytes = PRNG.Instance.NextLong(
|
|
119
|
+
1024L * 1024L * 1024L * 1024L * 1024L * 1024L,
|
|
120
|
+
long.MaxValue
|
|
121
|
+
);
|
|
122
|
+
string expected =
|
|
123
|
+
$"{(bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0):0.##} EB";
|
|
124
|
+
string found = FormattingHelpers.FormatBytes(bytes);
|
|
125
|
+
Assert.AreEqual(expected, found);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
namespace UnityHelpers.Tests.
|
|
1
|
+
namespace UnityHelpers.Tests.Helper
|
|
2
2
|
{
|
|
3
3
|
using System.Collections;
|
|
4
|
-
using Core.Helper;
|
|
5
4
|
using JetBrains.Annotations;
|
|
6
5
|
using NUnit.Framework;
|
|
7
6
|
using UnityEngine;
|
|
8
7
|
using UnityEngine.TestTools;
|
|
8
|
+
using UnityHelpers.Core.Helper;
|
|
9
9
|
|
|
10
10
|
[UsedImplicitly]
|
|
11
11
|
public sealed class ObjectHelperComponent : MonoBehaviour { }
|