Skip to content

Commit 69e85e2

Browse files
author
LoneWandererProductions
committed
Improve Documentation.
Fix naming of Tests Add some more Tests.
1 parent 0d7b703 commit 69e85e2

21 files changed

Lines changed: 390 additions & 42 deletions

CommonExtendedObjectsTests/IntArrayTests.cs renamed to CommonExtendedObjectsTests/UnmanagedIntArray.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: CommonExtendedObjectsTests
4-
* FILE: IntArrayTests.cs
4+
* FILE: UnmanagedIntArray.cs
55
* PURPOSE: Tests for my custom array
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
77
*/
@@ -15,7 +15,7 @@
1515
namespace CommonExtendedObjectsTests
1616
{
1717
[TestClass]
18-
public class IntArrayTests
18+
public class UnmanagedIntArray
1919
{
2020
/// <summary>
2121
/// The size
@@ -28,7 +28,7 @@ public class IntArrayTests
2828
[TestMethod]
2929
public void IndexingShouldGetAndSetValuesCorrectly()
3030
{
31-
var arr = new UnmanagedIntArray(5);
31+
var arr = new global::ExtendedSystemObjects.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 UnmanagedIntArray(5);
51+
var arr = new global::ExtendedSystemObjects.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 UnmanagedIntArray(3);
71+
var arr = new global::ExtendedSystemObjects.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 UnmanagedIntArray(4);
92+
var arr = new global::ExtendedSystemObjects.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 UnmanagedIntArray(Size);
117+
var intArray = new global::ExtendedSystemObjects.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 UnmanagedIntArray(5));
195+
RunIndexingTest(new global::ExtendedSystemObjects.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 UnmanagedIntArray(10);
232+
var arr = new global::ExtendedSystemObjects.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 UnmanagedIntArray(10);
266+
var arr = new global::ExtendedSystemObjects.UnmanagedIntArray(10);
267267
for (var i = 0; i < arr.Length; i++)
268268
{
269269
arr[i] = i + 1; // [1..10]

CommonExtendedObjectsTests/IntListTests.cs renamed to CommonExtendedObjectsTests/UnmanagedIntListTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: CommonExtendedObjectsTests
4-
* FILE: IntListUnitTests.cs
4+
* FILE: UnmanagedIntListTests.cs
55
* PURPOSE: Tests for my custom list
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
77
*/
@@ -18,7 +18,7 @@ namespace CommonExtendedObjectsTests
1818
/// Some basic sanity tests for my list
1919
/// </summary>
2020
[TestClass]
21-
public class IntListTests
21+
public class UnmanagedIntListTests
2222
{
2323
/// <summary>
2424
/// The item count
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CommonExtendedObjectsTests
4+
* FILE: UnmanagedListTests.cs
5+
* PURPOSE: Tests for our UnmanagedList class, ensuring correct behavior of all operations including edge cases.
6+
* PROGRAMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
using System;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
using ExtendedSystemObjects;
12+
13+
namespace CommonExtendedObjectsTests
14+
{
15+
/// <summary>
16+
/// General tests for the UnmanagedList class, covering construction, basic list operations (add, remove, insert),
17+
/// stack operations (push, pop, peek), and edge cases such as out-of-range access and disposal behavior.
18+
/// </summary>
19+
[TestClass]
20+
public class UnmanagedListTests
21+
{
22+
/// <summary>
23+
/// A simple unmanaged struct to test generic capabilities
24+
/// </summary>
25+
private struct PointD
26+
{
27+
public double X;
28+
public double Y;
29+
}
30+
31+
/// <summary>
32+
/// Constructors the initializes correctly.
33+
/// </summary>
34+
[TestMethod]
35+
public void Constructor_InitializesCorrectly()
36+
{
37+
// Arrange & Act
38+
using var list = new UnmanagedList<int>(10);
39+
40+
// Assert
41+
Assert.AreEqual(0, list.Length);
42+
Assert.AreEqual(10, list.Capacity);
43+
}
44+
45+
/// <summary>
46+
/// Adds the increases length and expands capacity.
47+
/// </summary>
48+
[TestMethod]
49+
public void Add_IncreasesLengthAndExpandsCapacity()
50+
{
51+
// Arrange
52+
using var list = new UnmanagedList<int>(2);
53+
54+
// Act
55+
list.Add(10);
56+
list.Add(20);
57+
list.Add(30); // Should trigger EnsureCapacity
58+
59+
// Assert
60+
Assert.AreEqual(3, list.Length);
61+
Assert.IsTrue(list.Capacity >= 3);
62+
Assert.AreEqual(10, list[0]);
63+
Assert.AreEqual(20, list[1]);
64+
Assert.AreEqual(30, list[2]);
65+
}
66+
67+
/// <summary>
68+
/// Removes at shifts elements correctly.
69+
/// </summary>
70+
[TestMethod]
71+
public void RemoveAt_ShiftsElementsCorrectly()
72+
{
73+
// Arrange
74+
using var list = new UnmanagedList<int>(5);
75+
list.Add(1);
76+
list.Add(2);
77+
list.Add(3);
78+
list.Add(4);
79+
80+
// Act
81+
list.RemoveAt(1, 2); // Remove '2' and '3'
82+
83+
// Assert
84+
Assert.AreEqual(2, list.Length);
85+
Assert.AreEqual(1, list[0]);
86+
Assert.AreEqual(4, list[1]);
87+
}
88+
89+
/// <summary>
90+
/// Inserts at shifts elements and fills correctly.
91+
/// </summary>
92+
[TestMethod]
93+
public void InsertAt_ShiftsElementsAndFillsCorrectly()
94+
{
95+
// Arrange
96+
using var list = new UnmanagedList<int>(5);
97+
list.Add(10);
98+
list.Add(40);
99+
100+
// Act
101+
list.InsertAt(1, 20, 2); // Insert two '20's at index 1
102+
103+
// Assert
104+
Assert.AreEqual(4, list.Length);
105+
Assert.AreEqual(10, list[0]);
106+
Assert.AreEqual(20, list[1]);
107+
Assert.AreEqual(20, list[2]);
108+
Assert.AreEqual(40, list[3]);
109+
}
110+
111+
/// <summary>
112+
/// Stacks the operations push pop peek work as expected.
113+
/// </summary>
114+
[TestMethod]
115+
public void StackOperations_PushPopPeek_WorkAsExpected()
116+
{
117+
// Arrange
118+
using var list = new UnmanagedList<int>(5);
119+
120+
// Act & Assert
121+
list.Push(100);
122+
list.Push(200);
123+
124+
Assert.AreEqual(200, list.Peek());
125+
Assert.AreEqual(2, list.Length);
126+
127+
var popped = list.Pop();
128+
Assert.AreEqual(200, popped);
129+
Assert.AreEqual(1, list.Length);
130+
Assert.AreEqual(100, list.Peek());
131+
}
132+
133+
/// <summary>
134+
/// Pops the on empty list throws invalid operation exception.
135+
/// </summary>
136+
[TestMethod]
137+
public void Pop_OnEmptyList_ThrowsInvalidOperationException()
138+
{
139+
using var list = new UnmanagedList<int>();
140+
Assert.ThrowsException<InvalidOperationException>(() => list.Pop());
141+
}
142+
143+
/// <summary>
144+
/// Structures the support works with custom unmanaged types.
145+
/// </summary>
146+
[TestMethod]
147+
public void StructSupport_WorksWithCustomUnmanagedTypes()
148+
{
149+
// Arrange
150+
using var list = new UnmanagedList<PointD>(2);
151+
var p1 = new PointD { X = 1.5, Y = 2.5 };
152+
var p2 = new PointD { X = 3.0, Y = 4.0 };
153+
154+
// Act
155+
list.Add(p1);
156+
list.Add(p2);
157+
158+
// Assert
159+
Assert.AreEqual(2, list.Length);
160+
Assert.AreEqual(1.5, list[0].X);
161+
Assert.AreEqual(4.0, list[1].Y);
162+
}
163+
164+
/// <summary>
165+
/// Tries the get returns true for valid index false for invalid.
166+
/// </summary>
167+
[TestMethod]
168+
public void TryGet_ReturnsTrueForValidIndex_FalseForInvalid()
169+
{
170+
using var list = new UnmanagedList<int>(5);
171+
list.Add(42);
172+
173+
Assert.IsTrue(list.TryGet(0, out var val));
174+
Assert.AreEqual(42, val);
175+
176+
Assert.IsFalse(list.TryGet(1, out _));
177+
Assert.IsFalse(list.TryGet(-1, out _));
178+
}
179+
180+
/// <summary>
181+
/// Ranges the indexer returns correct span.
182+
/// </summary>
183+
[TestMethod]
184+
public void RangeIndexer_ReturnsCorrectSpan()
185+
{
186+
// Arrange
187+
using var list = new UnmanagedList<int>(5);
188+
for (var i = 0; i < 5; i++) list.Add(i * 10); // 0, 10, 20, 30, 40
189+
190+
// Act
191+
var span = list[1..4]; // Should be 10, 20, 30
192+
193+
// Assert
194+
Assert.AreEqual(3, span.Length);
195+
Assert.AreEqual(10, span[0]);
196+
Assert.AreEqual(30, span[2]);
197+
}
198+
199+
/// <summary>
200+
/// Disposes the prevents further access.
201+
/// </summary>
202+
[TestMethod]
203+
public void Dispose_PreventsFurtherAccess()
204+
{
205+
// Arrange
206+
var list = new UnmanagedList<int>(5);
207+
list.Add(1);
208+
209+
// Act
210+
list.Dispose();
211+
212+
// Assert
213+
Assert.ThrowsException<ObjectDisposedException>(() => list.Add(2));
214+
Assert.ThrowsException<ObjectDisposedException>(() => { var x = list[0]; });
215+
Assert.ThrowsException<ObjectDisposedException>(() => list.Clear());
216+
}
217+
218+
/// <summary>
219+
/// Clears the resets length but keeps capacity.
220+
/// </summary>
221+
[TestMethod]
222+
public void Clear_ResetsLengthButKeepsCapacity()
223+
{
224+
// Arrange
225+
using var list = new UnmanagedList<int>(10);
226+
list.Add(1);
227+
list.Add(2);
228+
var initialCapacity = list.Capacity;
229+
230+
// Act
231+
list.Clear();
232+
233+
// Assert
234+
Assert.AreEqual(0, list.Length);
235+
Assert.AreEqual(initialCapacity, list.Capacity);
236+
}
237+
}
238+
}

ExtendedSystemObjects/CategorizedDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: ExtendedSystemObjects
4-
* FILE: ExtendedSystemObjects/CategorizedDictionary.cs
4+
* FILE: CategorizedDictionary.cs
55
* PURPOSE: Extended Dictionary with a Category.
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/

ExtendedSystemObjects/ExtendedDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: ExtendedSystemObjects
4-
* FILE: ExtendedSystemObjects/DictionaryExtensions.cs
4+
* FILE: DictionaryExtensions.cs
55
* PURPOSE: Helper class that extends the already versatile Dictionary, most operations are not thread safe, so beware.
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/

ExtendedSystemObjects/ExtendedDouble.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: ExtendedSystemObjects
4-
* FILE: ExtendedSystemObjects/ExtendedDouble.cs
4+
* FILE: ExtendedDouble.cs
55
* PURPOSE: Some Extensions for double
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/

ExtendedSystemObjects/ExtendedInt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: ExtendedSystemObjects
4-
* FILE: ExtendedSystemObjects/ExtendedInt.cs
4+
* FILE: ExtendedInt.cs
55
* PURPOSE: Some Extensions for int
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/

ExtendedSystemObjects/ExtendedList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: ExtendedSystemObjects
4-
* FILE: ExtendedSystemObjects/ExtendedList.cs
4+
* FILE: ExtendedList.cs
55
* PURPOSE: Generic System Functions for Lists, most operations are not thread safe, so beware.
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/

0 commit comments

Comments
 (0)