コード例 #1
0
ファイル: AVLTTester.cs プロジェクト: KabatLukas/AVL-Tree
        public void LevelOrderCheck()
        {
            LinkedList <AVLData> levelOrder = avlTree.TraversalLevelOrder();

            foreach (int key in keyList)
            {
                AVLData data = avlTree.Find(new AVLData(key));
                if (!levelOrder.Contains(data))
                {
                    Assert.Fail("Key not found: " + key);
                }
            }
        }
コード例 #2
0
ファイル: AVLTTester.cs プロジェクト: KabatLukas/AVL-Tree
        public void Generate()
        {
            avlTree = new AVLTree <AVLData>();
            int numberOfOperations = keyList.Count;

            keyList = new List <int>(numberOfOperations);
            int collisionCount = 0;

            for (int i = 0; i < NumOFOperations; i++)
            {
                double operationNum = rng.NextDouble();
                if (operationNum < operationsProb[0])
                {
                    int addKey = rng.Next(int.MinValue, int.MaxValue);
                    if (!avlTree.Insert(new AVLData(addKey)))
                    {
                        collisionCount++;
                    }
                    else
                    {
                        keyList.Add(addKey);
                    }

                    if (perOperationCheck)
                    {
                        InOrderCheck();
                        HeightBalanceCheck();
                    }
                }
                else if (operationNum < operationsProb[0] + operationsProb[1])
                {
                    if (keyList.Count > 0)
                    {
                        int deleteKey = keyList[rng.Next(keyList.Count - 1)];
                        if (!avlTree.Delete(new AVLData(deleteKey)))
                        {
                            Assert.Fail("Key to delete not found: " + deleteKey);
                        }
                        keyList.Remove(deleteKey);
                        if (perOperationCheck)
                        {
                            InOrderCheck();
                            HeightBalanceCheck();
                        }
                    }
                }
                else
                {
                    if (keyList.Count > 0)
                    {
                        int     key  = keyList[rng.Next(keyList.Count - 1)];
                        AVLData data = avlTree.Find(new AVLData(key));
                        if (perOperationCheck)
                        {
                            LinkedList <AVLData> inOrder = avlTree.TraversalInOrder();
                            if (!inOrder.Contains(data))
                            {
                                Assert.Fail("Key not found: " + key);
                            }
                        }
                    }
                }
            }
        }