Skip to content

Commit 32f3dbd

Browse files
author
LoneWandererProductions
committed
Some more tests
1 parent 37b2fc1 commit 32f3dbd

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

CommonExtendedObjectsTests/IntListTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,57 @@ public void PerformanceBenchmark()
210210

211211
// Assert nothing here — just print results
212212
}
213+
214+
/// <summary>
215+
/// Pushes the pop should work with positive and negative values.
216+
/// </summary>
217+
[TestMethod]
218+
public void PushPopShouldWorkWithPositiveAndNegativeValues()
219+
{
220+
using var list = new UnmanagedIntList();
221+
222+
// Push positive values
223+
list.Push(10);
224+
list.Push(20);
225+
list.Push(30);
226+
227+
// Push negative values
228+
list.Push(-1);
229+
list.Push(-50);
230+
231+
Assert.AreEqual(5, list.Length);
232+
233+
// Pop values and verify LIFO order
234+
Assert.AreEqual(-50, list.Pop());
235+
Assert.AreEqual(-1, list.Pop());
236+
Assert.AreEqual(30, list.Pop());
237+
Assert.AreEqual(20, list.Pop());
238+
Assert.AreEqual(10, list.Pop());
239+
240+
Assert.AreEqual(0, list.Length);
241+
242+
// Pop from empty list should throw
243+
Assert.ThrowsException<InvalidOperationException>(() => list.Pop());
244+
}
245+
246+
/// <summary>
247+
/// Peeks the should return last element without removing.
248+
/// </summary>
249+
[TestMethod]
250+
public void PeekShouldReturnLastElementWithoutRemoving()
251+
{
252+
using var list = new UnmanagedIntList();
253+
list.Push(42);
254+
list.Push(-42);
255+
256+
Assert.AreEqual(-42, list.Peek());
257+
Assert.AreEqual(2, list.Length);
258+
259+
var popped = list.Pop();
260+
Assert.AreEqual(-42, popped);
261+
Assert.AreEqual(1, list.Length);
262+
263+
Assert.AreEqual(42, list.Peek());
264+
}
213265
}
214266
}

CommonExtendedObjectsTests/SortedKvStoreTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
77
*/
88

9+
using System;
10+
using System.Buffers;
11+
using System.Collections.Generic;
912
using System.Diagnostics;
1013
using System.Linq;
14+
using System.Windows.Documents;
1115
using ExtendedSystemObjects;
1216
using Microsoft.VisualStudio.TestTools.UnitTesting;
1317

@@ -24,6 +28,10 @@ public class SortedKvStoreTests
2428
/// </summary>
2529
private const int ItemCount = 100_000;
2630

31+
private SortedKvStore _store;
32+
33+
private int _entryCount;
34+
2735
/// <summary>
2836
/// Adds the and try get works.
2937
/// </summary>
@@ -469,5 +477,32 @@ public void RemoveAndCompactTest()
469477
Assert.IsTrue(store.ContainsKey(9));
470478
}
471479

480+
public void TestCase()
481+
{
482+
const int size = 1024;
483+
var count = 10;
484+
485+
486+
_store = new SortedKvStore(128);
487+
488+
for (var cycle = 0; cycle < 5; cycle++)
489+
{
490+
var handles = new List<int>(count);
491+
for (var i = 0; i < count; i++)
492+
handles[i] = Allocate(size);
493+
for (var i = 0; i < count; i++)
494+
Free(handles[i]);
495+
}
496+
}
497+
498+
private void Free(int memoryHandle)
499+
{
500+
//_store[id] = _entryCount;
501+
}
502+
503+
private int Allocate(int size)
504+
{
505+
return 1;
506+
}
472507
}
473508
}

0 commit comments

Comments
 (0)