void TestRandomAddRemove(int repeat, int nodesz, int size) { List <int> keysAdded = new List <int>(250000); BPlusTreeOptions <int, string> options = Options; options.LockingFactory = new IgnoreLockFactory(); Dictionary <int, string> keys = new Dictionary <int, string>(); for (; repeat > 0; repeat--) { keys.Clear(); options.BTreeOrder = nodesz; using (BPlusTree <int, string> data = Create(options)) { data.EnableCount(); AddRandomKeys(size, keys, data); IsSameList(keys, data); keysAdded.Clear(); for (int tc = 0; tc < 1; tc++) { int del = keys.Count / 3 + Random.Next(keys.Count / 3); RemoveRandomKeys(del, keys, data); IsSameList(keys, data); data.Validate(); AddRandomKeys(del, keys, data); IsSameList(keys, data); data.Validate(); } keysAdded.Clear(); foreach (KeyValuePair <int, string> kv in data) { keysAdded.Add(kv.Key); } foreach (int k in keysAdded) { Assert.IsTrue(data.Remove(k)); data.Add(k, k.ToString()); Assert.IsTrue(data.Remove(k)); string test; Assert.IsFalse(data.TryGetValue(k, out test)); Assert.IsNull(test); } } } }
private static void VerifyDictionary(Dictionary <int, string> expected, BPlusTree <int, string> tree) { tree.Validate(); tree.EnableCount(); Dictionary <int, string> test = new Dictionary <int, string>(expected); List <KeyValuePair <int, string> > pairs = new List <KeyValuePair <int, string> >(test); string val; foreach (KeyValuePair <int, string> pair in tree) { Assert.IsTrue(test.TryGetValue(pair.Key, out val)); Assert.AreEqual(pair.Value, val); Assert.IsTrue(test.Remove(pair.Key)); } Assert.AreEqual(0, test.Count); test = null; Assert.IsNull(test); Assert.AreEqual(pairs.Count, tree.Count); foreach (KeyValuePair <int, string> pair in pairs) { Assert.IsTrue(tree.TryGetValue(pair.Key, out val)); Assert.AreEqual(pair.Value, val); } }
private static void VerifyDictionary(Dictionary<int, string> expected, BPlusTree<int, string> tree) { tree.Validate(); tree.EnableCount(); Dictionary<int, string> test = new Dictionary<int, string>(expected); List<KeyValuePair<int, string>> pairs = new List<KeyValuePair<int, string>>(test); string val; foreach (KeyValuePair<int, string> pair in tree) { Assert.IsTrue(test.TryGetValue(pair.Key, out val)); Assert.AreEqual(pair.Value, val); Assert.IsTrue(test.Remove(pair.Key)); } Assert.AreEqual(0, test.Count); test = null; Assert.IsNull(test); Assert.AreEqual(pairs.Count, tree.Count); foreach (KeyValuePair<int, string> pair in pairs) { Assert.IsTrue(tree.TryGetValue(pair.Key, out val)); Assert.AreEqual(pair.Value, val); } }