Did some code cleanup,
added some extra thingies. switched to spans. Let google gemini do whatever it wanted..
This commit is contained in:
parent
978d0873dc
commit
7bea233edc
11 changed files with 944 additions and 248 deletions
70
TestProject1/UnitTest1.cs
Normal file
70
TestProject1/UnitTest1.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
namespace TestProject1;
|
||||
|
||||
using Xunit;
|
||||
using PersistentMap;
|
||||
|
||||
public class BasicTests
|
||||
{
|
||||
private readonly UnicodeStrategy _strategy = new UnicodeStrategy();
|
||||
|
||||
[Fact]
|
||||
public void Transient_InsertAndGet_Works()
|
||||
{
|
||||
var map = BaseOrderedMap<string, int, UnicodeStrategy>.CreateTransient(_strategy);
|
||||
|
||||
map.Set("Apple", 1);
|
||||
map.Set("Banana", 2);
|
||||
map.Set("Cherry", 3);
|
||||
|
||||
Assert.True(map.TryGetValue("Apple", out int v1));
|
||||
Assert.Equal(1, v1);
|
||||
|
||||
Assert.True(map.TryGetValue("Banana", out int v2));
|
||||
Assert.Equal(2, v2);
|
||||
|
||||
Assert.False(map.TryGetValue("Date", out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transient_Update_Works()
|
||||
{
|
||||
var map = BaseOrderedMap<string, int, UnicodeStrategy>.CreateTransient(_strategy);
|
||||
map.Set("Key", 100);
|
||||
map.Set("Key", 200); // Overwrite
|
||||
|
||||
map.TryGetValue("Key", out int val);
|
||||
Assert.Equal(200, val);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transient_Remove_Works()
|
||||
{
|
||||
var map = BaseOrderedMap<string, int, UnicodeStrategy>.CreateTransient(_strategy);
|
||||
map.Set("A", 1);
|
||||
map.Set("B", 2);
|
||||
map.Set("C", 3);
|
||||
|
||||
map.Remove("B");
|
||||
|
||||
Assert.True(map.ContainsKey("A"));
|
||||
Assert.False(map.ContainsKey("B"));
|
||||
Assert.True(map.ContainsKey("C"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transient_PrefixCollision_HandlesCollision()
|
||||
{
|
||||
// UnicodeStrategy only packs the first 4 chars.
|
||||
// "Test1" and "Test2" have the same prefix "Test".
|
||||
var map = BaseOrderedMap<string, int, UnicodeStrategy>.CreateTransient(_strategy);
|
||||
|
||||
map.Set("Test1", 1);
|
||||
map.Set("Test2", 2);
|
||||
|
||||
Assert.True(map.TryGetValue("Test1", out var v1));
|
||||
Assert.Equal(1, v1);
|
||||
|
||||
Assert.True(map.TryGetValue("Test2", out var v2));
|
||||
Assert.Equal(2, v2);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue