public void Foreach_AddedManyRandomElements_ShouldReturnSortedAscending() { const int NumCount = 10000; var tree = new AvlTree <int>(); var nums = new HashSet <int>(); var random = new Random(); for (int i = 0; i < NumCount; i++) { var num = random.Next(0, NumCount); nums.Add(num); tree.Add(num); } var sortedNumbers = nums.OrderBy(n => n).ToArray(); var expectedSequence = new Queue <int>(sortedNumbers); int count = 0; tree.ForeachDfs((depth, num) => { Assert.AreEqual(expectedSequence.Dequeue(), num); count++; }); Assert.AreEqual(count, tree.Count); }
static void Main(string[] args) { var tree = new AvlTree<int>(); var random = new Random(); for (int i = 0; i < 20; i++) { var num = random.Next(0, 1000); tree.Add(num); } tree.ForeachDfs((depth, num) => { Console.WriteLine(num); }); }
public void AddingMultipleItems_InBalancedWay_ShouldForeachInOrder() { var numbers = TestUtils.ToIntArray("20 10 30 0 15 25 40"); var tree = new AvlTree <int>(); foreach (int number in numbers) { tree.Add(number); } var sortedNumbers = numbers.OrderBy(n => n).ToArray(); var expectedSequence = new Queue <int>(sortedNumbers); tree.ForeachDfs((depth, num) => { Assert.AreEqual(expectedSequence.Dequeue(), num); }); }
public void AddingMultipleItems_RandomOrder_ShouldForeachInOrder() { var nums = TestUtils.ToIntArray("1 5 3 20 6 13 40 70 100 200 -50"); var tree = new AvlTree <int>(); foreach (var num in nums) { tree.Add(num); } var sortedNumbers = nums.OrderBy(n => n).ToArray(); var expectedSequence = new Queue <int>(sortedNumbers); tree.ForeachDfs((depth, num) => { Assert.AreEqual(expectedSequence.Dequeue(), num); }); }
public void AddingMultipleItems_RandomOrder_ShouldForeachInOrder() { var nums = TestUtils.ToIntArrayUnique("1 5 3 20 6 13 40 70 100 200 -50"); var tree = new AvlTree<int>(); foreach (var num in nums) { tree.Add(num); } var sortedNumbers = nums.OrderBy(n => n).ToArray(); var expectedSequence = new Queue<int>(sortedNumbers); int count = 0; tree.ForeachDfs((depth, num) => { Assert.AreEqual(expectedSequence.Dequeue(), num); count++; }); Assert.AreEqual(count, tree.Count); }
public void AddingMultipleItems_InBalancedWay_ShouldForeachInOrder() { var numbers = TestUtils.ToIntArrayUnique("20 10 30 0 15 25 40"); var tree = new AvlTree<int>(); foreach (int number in numbers) { tree.Add(number); } var sortedNumbers = numbers.OrderBy(n => n).ToArray(); var expectedSequence = new Queue<int>(sortedNumbers); int count = 0; tree.ForeachDfs((depth, num) => { Assert.AreEqual(expectedSequence.Dequeue(), num); count++; }); Assert.AreEqual(count, tree.Count); }
public void Foreach_AddedManyRandomElements_ShouldReturnSortedAscending() { const int NumCount = 10000; var tree = new AvlTree<int>(); var nums = new HashSet<int>(); var random = new Random(); for (int i = 0; i < NumCount; i++) { var num = random.Next(0, NumCount); nums.Add(num); tree.Add(num); } var sortedNumbers = nums.OrderBy(n => n).ToArray(); var expectedSequence = new Queue<int>(sortedNumbers); int count = 0; tree.ForeachDfs((depth, num) => { Assert.AreEqual(expectedSequence.Dequeue(), num); count++; }); Assert.AreEqual(count, tree.Count); }