Add count

This commit is contained in:
Linus Björnstam 2026-02-11 12:56:48 +01:00
parent 79b5ab98aa
commit 280177a9cb
4 changed files with 151 additions and 59 deletions

View file

@ -21,7 +21,8 @@ public class BTreeFuzzTests
// CONFIGURATION
const int Iterations = 100_000; // High enough to trigger all splits/merges
const int KeyRange = 5000; // Small enough to cause frequent collisions
int Seed = Environment.TickCount;
const bool showOps = true;
int Seed = 2135974; // Environment.TickCount;
// ORACLES
var reference = new SortedDictionary<int, int>();
@ -42,6 +43,7 @@ public class BTreeFuzzTests
if (isInsert)
{
// ACTION: INSERT
if (showOps)Console.WriteLine("insert");
reference[key] = val;
subject.Set(key, val);
}
@ -50,6 +52,7 @@ public class BTreeFuzzTests
// ACTION: REMOVE
if (reference.ContainsKey(key))
{
if (showOps)Console.WriteLine("remove");
reference.Remove(key);
subject.Remove(key);
}
@ -63,10 +66,10 @@ public class BTreeFuzzTests
// 2. VERIFY CONSISTENCY (Expensive but necessary)
// We check consistency every 1000 ops or if the tree is small,
// to keep the test fast enough.
if (i % 1000 == 0 || reference.Count < 100)
{
//if (i % 1000 == 0 || reference.Count < 100)
//{
AssertConsistency(reference, subject);
}
//}
}
// Final check
@ -132,10 +135,11 @@ public class BTreeFuzzTests
private void AssertConsistency(SortedDictionary<int, int> expected, TransientMap<int, int, IntStrategy> actual)
{
// 1. Count
// if (expected.Count != actual.Count)
// {
// throw new Exception($"Count Mismatch! Expected {expected.Count}, Got {actual.Count}");
// }
if (expected.Count != actual.Count)
{
Console.WriteLine("BP");
throw new Exception($"Count Mismatch! Expected {expected.Count}, Got {actual.Count}");
}
// 2. Full Scan Verification
using var enumerator = actual.GetEnumerator();
@ -148,6 +152,7 @@ public class BTreeFuzzTests
if (enumerator.Current.Key != kvp.Key || enumerator.Current.Value != kvp.Value)
{
Console.WriteLine("BP");
throw new Exception($"Content Mismatch! Expected [{kvp.Key}:{kvp.Value}], Got [{enumerator.Current.Key}:{enumerator.Current.Value}]");
}
}