当前位置: 首页>>代码示例>>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;未经允许,请勿转载。