當前位置: 首頁>>代碼示例>>C#>>正文


C# BinarySearchTree.ToList方法代碼示例

本文整理匯總了C#中BinarySearchTree.ToList方法的典型用法代碼示例。如果您正苦於以下問題:C# BinarySearchTree.ToList方法的具體用法?C# BinarySearchTree.ToList怎麽用?C# BinarySearchTree.ToList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinarySearchTree的用法示例。


在下文中一共展示了BinarySearchTree.ToList方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BinaryTreeMustSortTheSameAsSortedDictionary

        public void BinaryTreeMustSortTheSameAsSortedDictionary()
        {
            // Arrange
            var asm = Assembly.GetExecutingAssembly();
            var importer = new Importer(asm.GetManifestResourceStream("ClientImport.Tests.records.txt"), ',');
            var dictionary = new SortedDictionary<string, IPerson>();
            var tree = new BinarySearchTree<string, IPerson>();

            //Act
            importer.Data
                           .ToList()
                           .ForEach(record =>
                           {
                               var person = new Person
                               {
                                   FirstName = record.FirstName,
                                   Surname = record.Surname,
                                   Age = Convert.ToInt16(record.Age)
                               };
                               var key = PersonRepository.BuildKey(person, SortKey.SurnameFirstNameAge);
                               if (tree.Find(key) == null)
                                   tree.Add(key, person);
                           }
                              );

            tree
                .ToList()
                .Shuffle() //Shuffle result from binary tree, to test sorting
                .ForEach(r => dictionary.Add(PersonRepository.BuildKey(r.KeyValue.Value, SortKey.SurnameFirstNameAge), r.KeyValue.Value));

            var expected = dictionary.Select(r => r.Value).ToList();
            var actual = tree.Select(n => n.KeyValue.Value).ToList();
            // Assert
            CollectionAssert.AreEqual(expected, actual);
        }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:35,代碼來源:BinaryTreeTests.cs

示例2: TreeTraversalIsSortedInAscendingOrder

        public void TreeTraversalIsSortedInAscendingOrder()
        {
            // Arrange
            var tree = new BinarySearchTree<int, int>();

            var keys = Enumerable.Range(1, 50).ToList();
            keys.Shuffle().ForEach(k => tree.Add(k, k));

            var expected = keys.OrderBy(k => k).ToList();

            //Act
            var traversed = tree.ToList();

            //Assert
            CollectionAssert.AreEqual(expected, traversed.Select(r => r.KeyValue.Key).ToList());
        }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:16,代碼來源:BinaryTreeTests.cs

示例3: TreeIsNotDegenerateWhenGivenUnSortedData

        public void TreeIsNotDegenerateWhenGivenUnSortedData()
        {
            // Arrange
            var tree = new BinarySearchTree<int, int>();
            var count = 0;

            var keys = Enumerable.Range(1, 50).ToList();
            keys.Shuffle().ForEach(k => tree.Add(k, k));

            //Act
            var traversed = tree.ToList();

            //Assert
            traversed.ForEach(currentNode =>
            {
                if (currentNode.Parent == null) return;
                if (currentNode.Left != null)
                    count++;
            });

            Assert.IsTrue(count > 0);
        }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:22,代碼來源:BinaryTreeTests.cs

示例4: RighttKeyIsAlwaysGreaterThanParentKey

        public void RighttKeyIsAlwaysGreaterThanParentKey()
        {
            // Arrange
            var tree = new BinarySearchTree<int, int>();

            var keys = Enumerable.Range(1, 50).ToList();
            keys.Shuffle().ForEach(k => tree.Add(k, k));

            //Act
            var traversed = tree.ToList();

            //Assert
            traversed.ForEach(currentNode =>
                                  {
                                      if (currentNode.Parent == null) return;
                                      if (currentNode.Parent.Right == currentNode)
                                          Assert.IsTrue(currentNode.KeyValue.Key > currentNode.Parent.KeyValue.Key);
                                  });
        }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:19,代碼來源:BinaryTreeTests.cs

示例5: DefaultRootNodeIsInitializedEvenWhenEmpty

        public void DefaultRootNodeIsInitializedEvenWhenEmpty()
        {
            // Arrange
            var data = new BinarySearchTree<string, IPerson>();

            //Act
            var result = data.ToList();

            //Assert
            Assert.AreEqual(result.Count, 0);
        }
開發者ID:Romiko,項目名稱:Dev2,代碼行數:11,代碼來源:BinaryTreeTests.cs

示例6: TestGetValues

        public void TestGetValues()
        {
            var tree = new BinarySearchTree<int>();

            var size = 10000;
            var random = new Random();
            var numbers = new int[size];
            for (int i = 0; i < size; i++)
            {
                numbers[i] = random.Next();
                tree.Add(numbers[i]);
            }

            var values = tree.ToList();

            Assert.AreEqual(values.Count, numbers.Length);

            foreach (var n in numbers)
            {
                Assert.IsTrue(values.Contains(n));
                values.Remove(n);
            }

            Assert.AreEqual(values.Count, 0);
        }
開發者ID:deva666,項目名稱:BinarySearchTree,代碼行數:25,代碼來源:BinaryTreeTests.cs


注:本文中的BinarySearchTree.ToList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。