当前位置: 首页>>代码示例>>C#>>正文


C# Iterator类代码示例

本文整理汇总了C#中Iterator的典型用法代码示例。如果您正苦于以下问题:C# Iterator类的具体用法?C# Iterator怎么用?C# Iterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Iterator类属于命名空间,在下文中一共展示了Iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrintMenu

        public string PrintMenu(Iterator iterator)

        {

            StringBuilder sb = new StringBuilder();

            while(iterator.HasNext())

            {

                MenuItem menuItem = (MenuItem)iterator.Next();



                sb.Append(menuItem.Name + ", ");

                sb.Append(menuItem.Price + " -- ");

                sb.Append(menuItem.Description + "\n");

            }



            return sb.ToString();

        }
开发者ID:Gittre,项目名称:HeadFirstDesignPatterns,代码行数:27,代码来源:Waitress.cs

示例2: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix([Values(4, 8, 10)] int order)
        {
            var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
            var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);

            var monitor = new Iterator(new IIterationStopCriterium[]
                                       {
                                           new IterationCountStopCriterium(1000),
                                           new ResidualStopCriterium(1e-10)
                                       });
            var solver = new TFQMR(monitor);
            var matrixX = solver.Solve(matrixA, matrixB);

            // The solution X row dimension is equal to the column dimension of A
            Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

            // The solution X has the same number of columns as B
            Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);

            var matrixBReconstruct = matrixA * matrixX;
            // Check the reconstruction.
            for (var i = 0; i < matrixB.RowCount; i++)
            {
                for (var j = 0; j < matrixB.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixB[i, j], matrixBReconstruct[i, j], 1.0e-7);
                }
            }
        }
开发者ID:KeithVanderzanden,项目名称:mmbot,代码行数:29,代码来源:TFQMRTest.cs

示例3: DetermineStatus

        public void DetermineStatus()
        {
            var criteria = new List<IIterationStopCriterium<float>>
                {
                    new FailureStopCriterium(),
                    new DivergenceStopCriterium(),
                    new IterationCountStopCriterium<float>(1)
                };

            var iterator = new Iterator<float>(criteria);

            // First step, nothing should happen.
            iterator.DetermineStatus(
                0,
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4));
            Assert.AreEqual(IterationStatus.Running, iterator.Status, "Incorrect status");

            // Second step, should run out of iterations.
            iterator.DetermineStatus(
                1,
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4));
            Assert.AreEqual(IterationStatus.StoppedWithoutConvergence, iterator.Status, "Incorrect status");
        }
开发者ID:primebing,项目名称:mathnet-numerics,代码行数:27,代码来源:IteratorTest.cs

示例4: DetermineStatus

        public void DetermineStatus()
        {
            var criteria = new List<IIterationStopCriterium<Complex32>>
            {
                new FailureStopCriterium<Complex32>(),
                new DivergenceStopCriterium<Complex32>(),
                new IterationCountStopCriterium<Complex32>(1)
            };

            var iterator = new Iterator<Complex32>(criteria);

            // First step, nothing should happen.
            iterator.DetermineStatus(
                0,
                Vector<Complex32>.Build.Dense(3, 4),
                Vector<Complex32>.Build.Dense(3, 4),
                Vector<Complex32>.Build.Dense(3, 4));
            Assert.AreEqual(IterationStatus.Continue, iterator.Status, "Incorrect status");

            // Second step, should run out of iterations.
            iterator.DetermineStatus(
                1,
                Vector<Complex32>.Build.Dense(3, 4),
                Vector<Complex32>.Build.Dense(3, 4),
                Vector<Complex32>.Build.Dense(3, 4));
            Assert.AreEqual(IterationStatus.StoppedWithoutConvergence, iterator.Status, "Incorrect status");
        }
开发者ID:kityandhero,项目名称:mathnet-numerics,代码行数:27,代码来源:IteratorTest.cs

示例5: Clone

        public void Clone()
        {
            var criteria = new List<IIterationStopCriterium<Complex32>>
                           {
                               new FailureStopCriterium(),
                               new DivergenceStopCriterium(),
                               new IterationCountStopCriterium(),
                               new ResidualStopCriterium()
                           };

            var iterator = new Iterator(criteria);

            var clonedIterator = iterator.Clone();
            Assert.IsInstanceOfType(typeof(Iterator), clonedIterator, "Incorrect type");

            var clone = clonedIterator as Iterator;
            Assert.IsNotNull(clone);
            // ReSharper disable PossibleNullReferenceException
            Assert.AreEqual(iterator.NumberOfCriteria, clone.NumberOfCriteria, "Incorrect criterium count");
            // ReSharper restore PossibleNullReferenceException

            var enumerator = clone.StoredStopCriteria;
            while (enumerator.MoveNext())
            {
                var criterium = enumerator.Current;
                Assert.IsTrue(criteria.Exists(c => c.GetType().Equals(criterium.GetType())), "Criterium missing");
            }
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:28,代码来源:IteratorTest.cs

示例6: DisplayMemberList

 public static void DisplayMemberList(Iterator.IIterator iterator)
 {
     while (!iterator.IsDone())
     {
         Console.WriteLine(iterator.Next());
     }
 }
开发者ID:dmoelgaard,项目名称:design-patterns-simple,代码行数:7,代码来源:Program.cs

示例7: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix(int order)
        {
            var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
            var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);

            var monitor = new Iterator(new IIterationStopCriterium<Complex>[]
                                       {
                                           new IterationCountStopCriterium(1000),
                                           new ResidualStopCriterium(1e-10),
                                       });
            var solver = new MlkBiCgStab(monitor);
            var matrixX = solver.Solve(matrixA, matrixB);

            // The solution X row dimension is equal to the column dimension of A
            Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);
            // The solution X has the same number of columns as B
            Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);

            var matrixBReconstruct = matrixA * matrixX;

            // Check the reconstruction.
            for (var i = 0; i < matrixB.RowCount; i++)
            {
                for (var j = 0; j < matrixB.ColumnCount; j++)
                {
                    Assert.AreApproximatelyEqual(matrixB[i, j].Real, matrixBReconstruct[i, j].Real, 1.0e-5);
                    Assert.AreApproximatelyEqual(matrixB[i, j].Imaginary, matrixBReconstruct[i, j].Imaginary, 1.0e-5);
                }
            }
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:30,代码来源:MlkBiCgStabTest.cs

示例8: Add

        public void Add()
        {
            var criteria = new List<IIterationStopCriterium>
                           {
                               new FailureStopCriterium(),
                               new DivergenceStopCriterium(),
                               new IterationCountStopCriterium(),
                               new ResidualStopCriterium()
                           };
            var iterator = new Iterator();
            Assert.AreEqual(0, iterator.NumberOfCriteria, "Incorrect criterium count");

            foreach (var criterium in criteria)
            {
                iterator.Add(criterium);
                Assert.IsTrue(iterator.Contains(criterium), "Missing criterium");
            }

            // Check that we have all the criteria
            Assert.AreEqual(criteria.Count, iterator.NumberOfCriteria, "Incorrect criterium count");
            var enumerator = iterator.StoredStopCriteria;
            while (enumerator.MoveNext())
            {
                var criterium = enumerator.Current;
                Assert.IsTrue(criteria.Exists(c => ReferenceEquals(c, criterium)), "Criterium missing");
            }
        }
开发者ID:jvangael,项目名称:mathnet-numerics,代码行数:27,代码来源:IteratorTest.cs

示例9: createIterator

 public override Iterator createIterator()
 {
     if (iterator == null)
     {
         iterator = new BankWindowIterator(components);
     }
     return iterator;
 }
开发者ID:SergeyStaroletov,项目名称:Patterns15,代码行数:8,代码来源:BankWindowComposite.cs

示例10: TheSumOfAllMultiplesOf3Or5Below10Equals23

        public void TheSumOfAllMultiplesOf3Or5Below10Equals23()
        {
            var iterator = new Iterator<int>(0, 10, isMultipleOf3Or5, i => i + 1);
            var aggregator = new Aggregator(iterator);

            int result = aggregator.GetSum();
            Assert.That(result, Is.EqualTo(23));
        }
开发者ID:ronanmoriarty,项目名称:CodeKatas,代码行数:8,代码来源:AggregatorTests.cs

示例11: add_to_player_iterator

 private void add_to_player_iterator(Iterator iterator,BrandPlayer player)
 {
     while (iterator.hasNext())
     {
         Brand brand = (Brand)iterator.next();
         player.add(brand);
     }
 }
开发者ID:billteng,项目名称:mahjong,代码行数:8,代码来源:DealTest.cs

示例12: IteratorThrowsExceptionIfNextValueIsLessThanCurrentValue

        public void IteratorThrowsExceptionIfNextValueIsLessThanCurrentValue()
        {
            var isMatch = MockRepository.GenerateStub<Predicate<int>>();
            var iterator = new Iterator<int>(0, 2, isMatch, i => i - 1);

            var total = 0;
            iterator.Visit(i => total += i);
        }
开发者ID:ronanmoriarty,项目名称:CodeKatas,代码行数:8,代码来源:IteratorTests.cs

示例13: AddWithExistingStopCriteriumThrowsArgumentException

        public void AddWithExistingStopCriteriumThrowsArgumentException()
        {
            var iterator = new Iterator();
            iterator.Add(new FailureStopCriterium());
            Assert.AreEqual(1, iterator.NumberOfCriteria, "Incorrect criterium count");

            Assert.Throws<ArgumentException>(() => iterator.Add(new FailureStopCriterium()));
        }
开发者ID:jvangael,项目名称:mathnet-numerics,代码行数:8,代码来源:IteratorTest.cs

示例14: AddWithExistingStopCriterium

        public void AddWithExistingStopCriterium()
        {
            var iterator = new Iterator();
            iterator.Add(new FailureStopCriterium());
            Assert.AreEqual(1, iterator.NumberOfCriteria, "Incorrect criterium count");

            iterator.Add(new FailureStopCriterium());
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:8,代码来源:IteratorTest.cs

示例15: TestNext

 public void TestNext()
 {
     IEnumerable<DayOfWeek> collection = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Friday };
     var iterator = new Iterator<DayOfWeek>(collection.GetEnumerator());
     Assert.AreEqual(DayOfWeek.Monday, iterator.Next());
     Assert.AreEqual(DayOfWeek.Friday, iterator.Next());
     ExceptionAssert.Throws<InvalidOperationException>(() => iterator.Next());
 }
开发者ID:tssoft,项目名称:TsSoft.Commons,代码行数:8,代码来源:IteratorTest.cs


注:本文中的Iterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。