本文整理汇总了C#中Range.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Range.Intersect方法的具体用法?C# Range.Intersect怎么用?C# Range.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Range
的用法示例。
在下文中一共展示了Range.Intersect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Intersect_ShouldReturnIntersection_WhenExists
public void Intersect_ShouldReturnIntersection_WhenExists()
{
var range = new Range<int>(0, 3);
var other = new Range<int>(2, 4);
Assert.AreEqual(new Range<int>(2, 3), range.Intersect(other));
}
示例2: ShouldSupportDecimal
public void ShouldSupportDecimal()
{
var range = new Range<decimal>(0.1m, 3.1m);
var other = new Range<decimal>(2.1m, 4);
Assert.AreEqual(new Range<decimal>(2.1m, 3.1m), range.Intersect(other));
}
示例3: IntersectShouldIntersect
public void IntersectShouldIntersect(int s1, int e1, int s2, int e2, int s, int e)
{
var r1 = new Range<int>(s1, e1);
var r2 = new Range<int>(s2, e2);
var r = e >= 0 ? (Range<int>?)new Range<int>(s, e) : null;
Assert.AreEqual(r, r1.Intersect(r2));
Assert.AreEqual(r, r2.Intersect(r1));
}
示例4: Intersection
public void Intersection()
{
var r1 = new Range<int>(10, 20);
var r2 = new Range<int>(15, 25);
var intersection = r1.Intersect(r2);
Assert.AreEqual(15, intersection.Start);
Assert.AreEqual(20, intersection.End);
}
示例5: Intersect_ShouldReturnNull_WhenNoIntersection
public void Intersect_ShouldReturnNull_WhenNoIntersection()
{
var range = new Range<int>(0, 10);
var other = new Range<int>(20, 30);
Assert.IsNull(range.Intersect(other));
}
示例6: IntersectThrowsException
public void IntersectThrowsException(Range nonOverlappingRange)
{
Assert.Throws<ArgumentOutOfRangeException>(() => nonOverlappingRange.Intersect(TargetRange));
Assert.Throws<ArgumentOutOfRangeException>(() => TargetRange.Intersect(nonOverlappingRange));
}
示例7: IntersectReturnsCommonRangeParts
public void IntersectReturnsCommonRangeParts(Range input, Range output)
{
Assert.AreEqual(output, TargetRange.Intersect(input));
Assert.AreEqual(output, input.Intersect(TargetRange));
}
示例8: GetIntersection
public void GetIntersection()
{
var range = new Range<int>(3, 6);
Range<int> intersection = range.Intersect(new Range<int>(5, 8));
Assert.AreEqual(5, intersection.Start);
Assert.AreEqual(6, intersection.End);
}
示例9: GetIntersectionWithNoIntersection
public void GetIntersectionWithNoIntersection()
{
var range = new Range<int>(3, 6);
Assert.IsNull(range.Intersect(new Range<int>(7, 8)));
}