本文整理汇总了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();
}
示例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);
}
}
}
示例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");
}
示例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");
}
示例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");
}
}
示例6: DisplayMemberList
public static void DisplayMemberList(Iterator.IIterator iterator)
{
while (!iterator.IsDone())
{
Console.WriteLine(iterator.Next());
}
}
示例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);
}
}
}
示例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");
}
}
示例9: createIterator
public override Iterator createIterator()
{
if (iterator == null)
{
iterator = new BankWindowIterator(components);
}
return iterator;
}
示例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));
}
示例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);
}
}
示例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);
}
示例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()));
}
示例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());
}
示例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());
}