/// <summary> /// Returns the remainder of <see cref="range"/> after subtracting <see cref="compare"/> /// </summary> /// <typeparam name="TRange"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="range"></param> /// <param name="compare"></param> /// <returns></returns> public static IEnumerable <TRange> Subtract <TRange, TValue>( this TRange range, IRange <TValue> compare) where TRange : IRangeWith <TRange, TValue> where TValue : IComparable <TValue> { if (!range.OverLaps(compare)) { return(new[] { range }); } if (compare.Ecapsulates(range)) { return(new TRange[] { }); } if (compare.EcapsulatesFrom(range)) { return(new TRange[] { range.With(compare.Till, range.Till) }); } if (compare.EcapsulatesTill(range)) { return(new TRange[] { range.With(range.From, compare.From) }); } return(new TRange[] { range.With(range.From, compare.From), range.With(compare.Till, range.Till) }); }
[InlineData(11, 13, false)] // out of range public void EcapsulatesTill(int from, int till, bool expected) { Assert.Equal(expected, _range.EcapsulatesTill(new RangeModel <int>(from, till))); }