本文整理汇总了C#中IntRange.Count方法的典型用法代码示例。如果您正苦于以下问题:C# IntRange.Count方法的具体用法?C# IntRange.Count怎么用?C# IntRange.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntRange
的用法示例。
在下文中一共展示了IntRange.Count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated
public void IntRange_LengthNotDivisibleByStep_IterationCountMatchesCalculated()
{
int length = Random.Next(1, int.MaxValue);
int start = Random.Next(int.MinValue, int.MaxValue - length);
int end = start + length;
// note that the number of steps is limited to 1000 or fewer
int step = length / Random.Next(4, Math.Max(4, Math.Min(length / 2, 1000)));
// In case range length is under 4, ensure the step is at least 2
if (step < 2) step = 2;
//ensure that step size is not a factor of the length of the range
if (length % step == 0)
{
start += Random.Next(1, step - 1);
length = end - start;
}
IntRange intRange = new IntRange(start, end, step);
Assert.AreEqual(length / step + 1, intRange.Count(), "Iteration count should be (start-end)/step +1");
}
示例2: IntRange_LengthDivisibleByStep_IterationCountMatchesCalculated
public void IntRange_LengthDivisibleByStep_IterationCountMatchesCalculated()
{
int length = Random.Next(1, int.MaxValue);
int start = Random.Next(int.MinValue, int.MaxValue - length);
int end = start + length;
// note that the number of steps is limited to 1000 or fewer
int step = length / Random.Next(4, Math.Max(4, Math.Min(length / 2, 1000)));
// In case range length is under 4, ensure the step is at least 1
if (step < 1) step = 1;
//ensure that step size is a factor of the length of the range
start += length % step;
IntRange intRange = new IntRange(start, end, step);
// Range endpoint is inclusive, so must take into account this extra iteration
Assert.AreEqual(
length / step + 1,
intRange.Count(),
"Iteration count should be (end-start)/step + 1 where endpoint is included");
}