private void TestRemove(AllocTest tree) { int count = (int)tree.Count; for (int j = 0; j < count; j++) { IncrementIteration(); TestNoThrow("remove", delegate() { tree.Remove(); }); TestNoThrow("validate", delegate() { tree.Validate(); }); } TestNoThrow("validate", delegate() { tree.Validate(); }); TestTrue("count", delegate() { return(tree.Count == 0); }); }
private void DoTest(MakeTreeUnbound makeTreeUnbound, bool permitDiscardMode) { Tuple <AllocationMode, uint, int>[] tests = new Tuple <AllocationMode, uint, int>[] { new Tuple <AllocationMode, uint, int>(AllocationMode.DynamicDiscard, 0, Int32.MaxValue), new Tuple <AllocationMode, uint, int>(AllocationMode.DynamicDiscard, 3, Int32.MaxValue), new Tuple <AllocationMode, uint, int>(AllocationMode.DynamicDiscard, 8, Int32.MaxValue), new Tuple <AllocationMode, uint, int>(AllocationMode.DynamicRetainFreelist, 0, Int32.MaxValue), new Tuple <AllocationMode, uint, int>(AllocationMode.DynamicRetainFreelist, 3, Int32.MaxValue), new Tuple <AllocationMode, uint, int>(AllocationMode.DynamicRetainFreelist, 8, Int32.MaxValue), new Tuple <AllocationMode, uint, int>(AllocationMode.PreallocatedFixed, 0, 0), new Tuple <AllocationMode, uint, int>(AllocationMode.PreallocatedFixed, 3, 3), new Tuple <AllocationMode, uint, int>(AllocationMode.PreallocatedFixed, 8, 8), }; foreach (Tuple <AllocationMode, uint, int> test in tests) { MakeTreeBound makeTree = delegate() { return(makeTreeUnbound(test.Item1, test.Item2)); }; if (permitDiscardMode) { TestNoThrow("new", delegate() { makeTree(); }); } else { if (test.Item1 != AllocationMode.DynamicDiscard) { TestNoThrow("new", delegate() { makeTree(); }); } else { TestThrow("new", typeof(ArgumentException), delegate() { makeTree(); }); continue; } } TestNoThrow("validate", delegate() { makeTree().Validate(); }); TestTrue("initial", delegate() { AllocTest tree = makeTree(); return(tree.Count == 0); }); for (int i = 0; i <= 7; i++) { AllocTest tree = makeTree(); TestAdd(tree, i, test.Item3); TestRemove(tree); TestAdd(tree, i, test.Item3); } } }
private void TestAdd(AllocTest tree, int count, int capacity) { int c = 0; for (int j = 0; j < count; j++) { IncrementIteration(); if (j < capacity) { TestNoThrow("add", delegate() { tree.Add(); }); c++; } else { TestThrow("add-fail", typeof(OutOfMemoryException), delegate() { tree.Add(); }); } TestNoThrow("validate", delegate() { tree.Validate(); }); } TestNoThrow("validate", delegate() { tree.Validate(); }); TestTrue("count", delegate() { return(tree.Count == c); }); }