Skip to content

Commit 293402a

Browse files
author
LoneWandererProductions
committed
2 parents 425c3e5 + 1841230 commit 293402a

46 files changed

Lines changed: 991 additions & 509 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CommonExtendedObjectsTests/ImmutableLookupMapAllTests.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@ namespace CommonExtendedObjectsTests
2222
public class ImmutableLookupMapAllTests
2323
{
2424
/// <summary>
25-
/// The string map data
25+
/// The float map data
2626
/// </summary>
27-
private Dictionary<int, string> _stringMapData;
27+
private Dictionary<int, float> _floatMapData;
2828

2929
/// <summary>
30-
/// The float map data
30+
/// The read only map
3131
/// </summary>
32-
private Dictionary<int, float> _floatMapData;
32+
private ReadOnlyDictionary<int, string> _readOnlyMap;
3333

3434
/// <summary>
35-
/// The string map
35+
/// The string map
3636
/// </summary>
3737
private ImmutableLookupMap<int, string> _stringMap;
3838

3939
/// <summary>
40-
/// The read only map
40+
/// The string map data
4141
/// </summary>
42-
private ReadOnlyDictionary<int, string> _readOnlyMap;
42+
private Dictionary<int, string> _stringMapData;
4343

4444
/// <summary>
45-
/// The unmanaged map
45+
/// The unmanaged map
4646
/// </summary>
4747
private ImmutableLookupMapUnmanaged<int, float> _unmanagedMap;
4848

4949
/// <summary>
50-
/// Setups this instance.
50+
/// Setups this instance.
5151
/// </summary>
5252
[TestInitialize]
5353
public void Setup()
@@ -67,7 +67,7 @@ public void Setup()
6767
}
6868

6969
/// <summary>
70-
/// Cleanups this instance.
70+
/// Cleanups this instance.
7171
/// </summary>
7272
[TestCleanup]
7373
public void Cleanup()
@@ -78,7 +78,7 @@ public void Cleanup()
7878
// ------------ STRING MAP TESTS ----------------
7979

8080
/// <summary>
81-
/// Tests the string map initialization.
81+
/// Tests the string map initialization.
8282
/// </summary>
8383
[TestMethod]
8484
public void TestStringMapInitialization()
@@ -91,7 +91,7 @@ public void TestStringMapInitialization()
9191
}
9292

9393
/// <summary>
94-
/// Tests the read only dictionary initialization.
94+
/// Tests the read only dictionary initialization.
9595
/// </summary>
9696
[TestMethod]
9797
public void TestReadOnlyDictionaryInitialization()
@@ -104,7 +104,7 @@ public void TestReadOnlyDictionaryInitialization()
104104
}
105105

106106
/// <summary>
107-
/// Tests the string map lookup.
107+
/// Tests the string map lookup.
108108
/// </summary>
109109
[TestMethod]
110110
public void TestStringMapLookup()
@@ -122,7 +122,7 @@ public void TestStringMapLookup()
122122
}
123123

124124
/// <summary>
125-
/// Tests the read only dictionary lookup.
125+
/// Tests the read only dictionary lookup.
126126
/// </summary>
127127
[TestMethod]
128128
public void TestReadOnlyDictionaryLookup()
@@ -142,7 +142,7 @@ public void TestReadOnlyDictionaryLookup()
142142
// ------------ UNMANAGED MAP TESTS ----------------
143143

144144
/// <summary>
145-
/// Tests the unmanaged map initialization.
145+
/// Tests the unmanaged map initialization.
146146
/// </summary>
147147
[TestMethod]
148148
public void TestUnmanagedMapInitialization()
@@ -155,7 +155,7 @@ public void TestUnmanagedMapInitialization()
155155
}
156156

157157
/// <summary>
158-
/// Tests the unmanaged map lookup.
158+
/// Tests the unmanaged map lookup.
159159
/// </summary>
160160
[TestMethod]
161161
public void TestUnmanagedMapLookup()
@@ -173,7 +173,7 @@ public void TestUnmanagedMapLookup()
173173
}
174174

175175
/// <summary>
176-
/// Tests the unmanaged map try get value.
176+
/// Tests the unmanaged map try get value.
177177
/// </summary>
178178
[TestMethod]
179179
public void TestUnmanagedMapTryGetValue()
@@ -185,7 +185,7 @@ public void TestUnmanagedMapTryGetValue()
185185
}
186186

187187
/// <summary>
188-
/// Tests the unmanaged map enumeration.
188+
/// Tests the unmanaged map enumeration.
189189
/// </summary>
190190
[TestMethod]
191191
public void TestUnmanagedMapEnumeration()
@@ -202,7 +202,7 @@ public void TestUnmanagedMapEnumeration()
202202
}
203203

204204
/// <summary>
205-
/// Tests the initialization and lookup performance comparison.
205+
/// Tests the initialization and lookup performance comparison.
206206
/// </summary>
207207
[TestMethod]
208208
public void TestInitializationAndLookupPerformanceComparison()
@@ -238,6 +238,7 @@ public void TestInitializationAndLookupPerformanceComparison()
238238
{
239239
_ = stringMap.Get(i);
240240
}
241+
241242
swLookup1.Stop();
242243

243244
// --- Lookup: ReadOnlyDictionary<string>
@@ -246,6 +247,7 @@ public void TestInitializationAndLookupPerformanceComparison()
246247
{
247248
_ = readOnlyMap[i];
248249
}
250+
249251
swLookup2.Stop();
250252

251253
// --- Lookup: ImmutableLookupMapUnmanaged<float>
@@ -254,6 +256,7 @@ public void TestInitializationAndLookupPerformanceComparison()
254256
{
255257
_ = unmanagedMap.Get(i);
256258
}
259+
257260
swLookup3.Stop();
258261

259262
// Dispose unmanaged
@@ -274,6 +277,5 @@ public void TestInitializationAndLookupPerformanceComparison()
274277
Assert.AreEqual(iterations, stringMap.ToList().Count);
275278
Assert.AreEqual(iterations, readOnlyMap.Count);
276279
}
277-
278280
}
279281
}

CommonExtendedObjectsTests/IntArrayTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class IntArrayTests
2828
[TestMethod]
2929
public void IndexingShouldGetAndSetValuesCorrectly()
3030
{
31-
var arr = new IntArray(5);
31+
var arr = new UnmanagedIntArray(5);
3232
for (var i = 0; i < arr.Length; i++)
3333
{
3434
arr[i] = i * 10;
@@ -48,7 +48,7 @@ public void IndexingShouldGetAndSetValuesCorrectly()
4848
[TestMethod]
4949
public void RemoveAtShouldRemoveElementAndShiftLeft()
5050
{
51-
var arr = new IntArray(5);
51+
var arr = new UnmanagedIntArray(5);
5252
for (var i = 0; i < arr.Length; i++)
5353
{
5454
arr[i] = i;
@@ -68,7 +68,7 @@ public void RemoveAtShouldRemoveElementAndShiftLeft()
6868
[TestMethod]
6969
public void ResizeShouldChangeLengthAndPreserveOldData()
7070
{
71-
var arr = new IntArray(3);
71+
var arr = new UnmanagedIntArray(3);
7272
arr[0] = 1;
7373
arr[1] = 2;
7474
arr[2] = 3;
@@ -89,7 +89,7 @@ public void ResizeShouldChangeLengthAndPreserveOldData()
8989
[TestMethod]
9090
public void ClearShouldZeroOutAllElements()
9191
{
92-
var arr = new IntArray(4);
92+
var arr = new UnmanagedIntArray(4);
9393
for (var i = 0; i < arr.Length; i++)
9494
{
9595
arr[i] = 42;
@@ -114,7 +114,7 @@ public void CompareIntArrayvsIntArrayDotNetPerformance()
114114
var stopwatch = new Stopwatch();
115115

116116
// === IntArray Test ===
117-
var intArray = new IntArray(Size);
117+
var intArray = new UnmanagedIntArray(Size);
118118
stopwatch.Restart();
119119

120120
for (var i = 0; i < Size; i++)
@@ -192,7 +192,7 @@ public void CompareIntArrayvsIntArrayDotNetPerformance()
192192
[TestMethod]
193193
public void IndexingShouldWorkForIntArray()
194194
{
195-
RunIndexingTest(new IntArray(5));
195+
RunIndexingTest(new UnmanagedIntArray(5));
196196
}
197197

198198
/// <summary>
@@ -229,7 +229,7 @@ private static void RunIndexingTest(IUnmanagedArray<int> arr)
229229
[TestMethod]
230230
public void RemoveMultipleShouldRemoveSequentialIndices()
231231
{
232-
var arr = new IntArray(10);
232+
var arr = new UnmanagedIntArray(10);
233233
for (var i = 0; i < arr.Length; i++)
234234
{
235235
arr[i] = i + 1; // [1..10]
@@ -263,7 +263,7 @@ public void RemoveMultipleShouldRemoveSequentialIndices()
263263
[TestMethod]
264264
public void RemoveMultipleShouldRemoveNonSequentialIndices()
265265
{
266-
var arr = new IntArray(10);
266+
var arr = new UnmanagedIntArray(10);
267267
for (var i = 0; i < arr.Length; i++)
268268
{
269269
arr[i] = i + 1; // [1..10]

CommonExtendedObjectsTests/IntListTests.cs

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ public class IntListTests
2323
[TestMethod]
2424
public void AddPopPeekBehavior()
2525
{
26-
using var list = new IntList(4);
26+
using var list = new UnmanagedIntList(4) { 10, 20, 30 };
2727

28-
list.Add(10);
29-
list.Add(20);
30-
list.Add(30);
3128

3229
Assert.AreEqual(3, list.Length);
3330
Assert.AreEqual(30, list.Peek());
@@ -51,7 +48,7 @@ public void AddPopPeekBehavior()
5148
[ExpectedException(typeof(InvalidOperationException))]
5249
public void PopEmptyThrows()
5350
{
54-
using var list = new IntList();
51+
using var list = new UnmanagedIntList();
5552
list.Pop();
5653
}
5754

@@ -62,7 +59,7 @@ public void PopEmptyThrows()
6259
[ExpectedException(typeof(InvalidOperationException))]
6360
public void PeekEmptyThrows()
6461
{
65-
using var list = new IntList();
62+
using var list = new UnmanagedIntList();
6663
list.Peek();
6764
}
6865

@@ -72,7 +69,7 @@ public void PeekEmptyThrows()
7269
[TestMethod]
7370
public void CapacityResizesCorrectly()
7471
{
75-
using var list = new IntList(2);
72+
using var list = new UnmanagedIntList(2);
7673
for (var i = 0; i < 1000; i++)
7774
{
7875
list.Add(i);
@@ -82,6 +79,87 @@ public void CapacityResizesCorrectly()
8279
Assert.AreEqual(999, list[999]);
8380
}
8481

82+
#if DEBUG
83+
/// <summary>
84+
/// Indexes the get out of bounds throws.
85+
/// </summary>
86+
[TestMethod]
87+
[ExpectedException(typeof(IndexOutOfRangeException))]
88+
public void IndexGetOutOfBoundsThrows()
89+
{
90+
using var list = new UnmanagedIntList(1);
91+
var _ = list[5];
92+
}
93+
94+
/// <summary>
95+
/// Indexes the set out of bounds throws.
96+
/// </summary>
97+
[TestMethod]
98+
[ExpectedException(typeof(IndexOutOfRangeException))]
99+
public void IndexSetOutOfBoundsThrows()
100+
{
101+
using var list = new UnmanagedIntList(1) {[3] = 99};
102+
}
103+
#endif
104+
105+
/// <summary>
106+
/// Removes at invalid index throws.
107+
/// </summary>
108+
[TestMethod]
109+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
110+
public void RemoveAtInvalidIndexThrows()
111+
{
112+
using var list = new UnmanagedIntList(1) {1};
113+
list.RemoveAt(2);
114+
}
115+
116+
/// <summary>
117+
/// Inserts at adds elements correctly.
118+
/// </summary>
119+
[TestMethod]
120+
public void InsertAtAddsElementsCorrectly()
121+
{
122+
using var list = new UnmanagedIntList(2) {1, 2};
123+
list.InsertAt(1, 99); // Between 1 and 2
124+
125+
Assert.AreEqual(3, list.Length);
126+
Assert.AreEqual(1, list[0]);
127+
Assert.AreEqual(99, list[1]);
128+
Assert.AreEqual(2, list[2]);
129+
}
130+
131+
/// <summary>
132+
/// Inserts at with count adds multiple.
133+
/// </summary>
134+
[TestMethod]
135+
public void InsertAtWithCountAddsMultiple()
136+
{
137+
using var list = new UnmanagedIntList(2) {1, 2};
138+
list.InsertAt(1, 99, 2); // Insert 99 twice at index 1
139+
140+
Assert.AreEqual(4, list.Length);
141+
Assert.AreEqual(1, list[0]);
142+
Assert.AreEqual(99, list[1]);
143+
Assert.AreEqual(99, list[2]);
144+
Assert.AreEqual(2, list[3]);
145+
}
146+
147+
/// <summary>
148+
/// Disposes the state of the frees memory and invalidates.
149+
/// </summary>
150+
[TestMethod]
151+
public void DisposeFreesMemoryAndInvalidatesState()
152+
{
153+
var list = new UnmanagedIntList(2) { 1 };
154+
list.Dispose();
155+
156+
// Post-condition: buffer is cleared, pointers null, Length and Capacity are zero.
157+
// Behavior is undefined after Dispose. No exception is required.
158+
// Test only verifies internal reset, not enforcement.
159+
Assert.AreEqual(0, list.Length);
160+
Assert.AreEqual(0, list.Capacity);
161+
}
162+
85163
/// <summary>
86164
/// Performances the benchmark.
87165
/// </summary>
@@ -91,7 +169,7 @@ public void PerformanceBenchmark()
91169
const int n = 1_000_000;
92170

93171
// IntList timing
94-
using var intList = new IntList(n);
172+
using var intList = new UnmanagedIntList(n);
95173
var sw = Stopwatch.StartNew();
96174
for (var i = 0; i < n; i++)
97175
{
@@ -103,6 +181,7 @@ public void PerformanceBenchmark()
103181

104182
// List<int> timing
105183
var list = new List<int>(n);
184+
106185
sw.Restart();
107186
for (var i = 0; i < n; i++)
108187
{
@@ -114,6 +193,7 @@ public void PerformanceBenchmark()
114193

115194
// Stack<int> timing
116195
var stack = new Stack<int>(n);
196+
117197
sw.Restart();
118198
for (var i = 0; i < n; i++)
119199
{

0 commit comments

Comments
 (0)