Ejemplo n.º 1
0
 public bool EndsBefore(T value) =>
 IsNotEmpty && RangeBoundaryTo <T> .IsValid(value) && To < Range.BoundaryTo(value);
Ejemplo n.º 2
0
 /// <summary>Creates instance of <seealso cref="Range{T}"/></summary>
 /// <param name="from">Boundary From.</param>
 /// <param name="to">Boundary To.</param>
 /// <param name="key">The value of the range key.</param>
 public Range(T from, T to, TKey key) :
     this(Range.BoundaryFrom(from), Range.BoundaryTo(to), key)
 {
 }
Ejemplo n.º 3
0
 public bool Contains(T value) =>
 RangeBoundaryFrom <T> .IsValid(value)
                         ? Contains(Range.BoundaryFrom(value))
                         : Contains(Range.BoundaryTo(value));
Ejemplo n.º 4
0
        public static void TestRangeStartsAfter()
        {
            double?empty     = null;
            double?value1    = 1;
            double?value2    = 2;
            var    emptyFrom = RangeBoundaryFrom <double?> .Empty;
            var    emptyTo   = RangeBoundaryTo <double?> .Empty;

            var range = Range.Create(value1, value2);

            IsTrue(range.StartsAfter(null));
            IsTrue(range.StartsAfter(double.NegativeInfinity));
            IsFalse(range.StartsAfter(double.PositiveInfinity));
            IsFalse(range.StartsAfter(RangeBoundaryFrom <double?> .Empty));
            IsFalse(range.StartsAfter(RangeBoundaryTo <double?> .Empty));
            IsTrue(range.StartsAfter(0));
            IsFalse(range.StartsAfter(1));
            IsFalse(range.StartsAfter(1.5));
            IsFalse(range.StartsAfter(2));
            IsFalse(range.StartsAfter(3));

            IsTrue(range.StartsAfter(Range.Create(empty, 0, RangeKey2)));
            IsTrue(range.StartsAfter(Range.CreateExclusiveTo(empty, 1, RangeKey2)));
            IsFalse(range.StartsAfter(Range.Create(empty, 1, RangeKey2)));

            range = Range.Create(emptyFrom, emptyTo);
            IsFalse(range.StartsAfter(null));
            IsFalse(range.StartsAfter(double.NegativeInfinity));
            IsFalse(range.StartsAfter(double.PositiveInfinity));
            IsFalse(range.StartsAfter(RangeBoundaryFrom <double?> .Empty));
            IsFalse(range.StartsAfter(RangeBoundaryTo <double?> .Empty));
            IsFalse(range.StartsAfter(0));

            range = Range.CreateExclusive(empty, empty);
            IsFalse(range.StartsAfter(null));
            IsFalse(range.StartsAfter(double.NegativeInfinity));
            IsFalse(range.StartsAfter(double.PositiveInfinity));
            IsFalse(range.StartsAfter(RangeBoundaryFrom <double?> .Empty));
            IsFalse(range.StartsAfter(RangeBoundaryTo <double?> .Empty));
            IsFalse(range.StartsAfter(0));

            range = Range.CreateExclusive(value1, value2);
            IsTrue(range.StartsAfter(1));
            IsFalse(range.StartsAfter(1.5));
            IsFalse(range.StartsAfter(2));

            range = Range.CreateExclusive(value1, value2);
            IsTrue(range.StartsAfter(Range.BoundaryFrom <double?>(1)));
            IsFalse(range.StartsAfter(Range.BoundaryTo <double?>(2)));
            IsFalse(range.StartsAfter(Range.BoundaryFromExclusive <double?>(1)));
            IsFalse(range.StartsAfter(Range.BoundaryFromExclusive <double?>(1.5)));
            IsFalse(range.StartsAfter(Range.BoundaryFromExclusive <double?>(2)));
            IsTrue(range.StartsAfter(Range.BoundaryToExclusive <double?>(1)));
            IsFalse(range.StartsAfter(Range.BoundaryToExclusive <double?>(1.5)));
            IsFalse(range.StartsAfter(Range.BoundaryToExclusive <double?>(2)));

            Throws <ArgumentException>(
                () => range.StartsAfter(Range.BoundaryFrom <double?>(double.PositiveInfinity)));
            Throws <ArgumentException>(
                () => range.StartsAfter(Range.BoundaryTo <double?>(double.NegativeInfinity)));
        }
Ejemplo n.º 5
0
        public static void TestRangeEndsBefore()
        {
            double?empty     = null;
            double?value1    = 1;
            double?value2    = 2;
            var    emptyFrom = RangeBoundaryFrom <double?> .Empty;
            var    emptyTo   = RangeBoundaryTo <double?> .Empty;

            var range = Range.Create(value1, value2);

            IsTrue(range.EndsBefore(null));
            IsFalse(range.EndsBefore(double.NegativeInfinity));
            IsTrue(range.EndsBefore(double.PositiveInfinity));
            IsFalse(range.EndsBefore(RangeBoundaryFrom <double?> .Empty));
            IsFalse(range.EndsBefore(RangeBoundaryTo <double?> .Empty));
            IsFalse(range.EndsBefore(0));
            IsFalse(range.EndsBefore(1));
            IsFalse(range.EndsBefore(1.5));
            IsFalse(range.EndsBefore(2));
            IsTrue(range.EndsBefore(3));

            IsFalse(range.EndsBefore(Range.Create(2, empty, RangeKey2)));
            IsTrue(range.EndsBefore(Range.CreateExclusiveFrom(2, empty, RangeKey2)));
            IsTrue(range.EndsBefore(Range.Create(3, empty, RangeKey2)));

            range = Range.Create(emptyFrom, emptyTo);
            IsFalse(range.EndsBefore(null));
            IsFalse(range.EndsBefore(double.NegativeInfinity));
            IsFalse(range.EndsBefore(double.PositiveInfinity));
            IsFalse(range.EndsBefore(RangeBoundaryFrom <double?> .Empty));
            IsFalse(range.EndsBefore(RangeBoundaryTo <double?> .Empty));
            IsFalse(range.EndsBefore(0));

            range = Range.CreateExclusive(empty, empty);
            IsFalse(range.EndsBefore(null));
            IsFalse(range.EndsBefore(double.NegativeInfinity));
            IsFalse(range.EndsBefore(double.PositiveInfinity));
            IsFalse(range.EndsBefore(RangeBoundaryFrom <double?> .Empty));
            IsFalse(range.EndsBefore(RangeBoundaryTo <double?> .Empty));
            IsFalse(range.EndsBefore(0));

            range = Range.CreateExclusive(value1, value2);
            IsFalse(range.EndsBefore(1));
            IsFalse(range.EndsBefore(1.5));
            IsTrue(range.EndsBefore(2));

            range = Range.CreateExclusive(value1, value2);
            IsFalse(range.EndsBefore(Range.BoundaryFrom <double?>(1)));
            IsTrue(range.EndsBefore(Range.BoundaryTo <double?>(2)));
            IsFalse(range.EndsBefore(Range.BoundaryFromExclusive <double?>(1)));
            IsFalse(range.EndsBefore(Range.BoundaryFromExclusive <double?>(1.5)));
            IsTrue(range.EndsBefore(Range.BoundaryFromExclusive <double?>(2)));
            IsFalse(range.EndsBefore(Range.BoundaryToExclusive <double?>(1)));
            IsFalse(range.EndsBefore(Range.BoundaryToExclusive <double?>(1.5)));
            IsFalse(range.EndsBefore(Range.BoundaryToExclusive <double?>(2)));

            Throws <ArgumentException>(
                () => range.EndsBefore(Range.BoundaryFrom <double?>(double.PositiveInfinity)));
            Throws <ArgumentException>(
                () => range.EndsBefore(Range.BoundaryTo <double?>(double.NegativeInfinity)));
        }
Ejemplo n.º 6
0
 public static Range <T> TrimTo <T>(this Range <T> range, T to) =>
 TrimTo(range, Range.BoundaryTo(to));
Ejemplo n.º 7
0
        public static void TestRangeCreate()
        {
            int?value1 = 1;
            int?value2 = 2;
            int?empty  = null;
            var key    = "Hello!";

            DoesNotThrow(() => Range.Create(value1, value2));
            DoesNotThrow(() => Range.Create(value1, value1));
            DoesNotThrow(() => Range.Create(empty, value2));
            DoesNotThrow(() => Range.Create(empty, empty));

            DoesNotThrow(() => Range.CreateExclusiveFrom(value1, value2));
            Throws <ArgumentException>(() => Range.CreateExclusiveFrom(value1, value1));
            DoesNotThrow(() => Range.CreateExclusiveFrom(empty, value2));
            DoesNotThrow(() => Range.CreateExclusiveFrom(empty, empty));

            DoesNotThrow(() => Range.CreateExclusiveTo(value1, value2, key));
            Throws <ArgumentException>(() => Range.CreateExclusiveTo(value2, value2, key));
            DoesNotThrow(() => Range.CreateExclusiveTo(empty, value2, key));
            DoesNotThrow(() => Range.CreateExclusiveTo(empty, empty, key));

            DoesNotThrow(() => Range.CreateExclusive(value1, value2, key));
            Throws <ArgumentException>(() => Range.CreateExclusive(value2, value2, key));
            DoesNotThrow(() => Range.CreateExclusive(empty, value2, key));
            DoesNotThrow(() => Range.CreateExclusive(empty, empty, key));

            Throws <ArgumentException>(() => Range.Create(value2, value1, key));
            Throws <ArgumentException>(() => Range.CreateExclusiveFrom(value2, value1));
            Throws <ArgumentException>(() => Range.CreateExclusiveTo(value2, value1, key));
            Throws <ArgumentException>(() => Range.CreateExclusive(value2, value1, key));
            Throws <ArgumentException>(() => Range.Create(RangeBoundaryFrom <int?> .Empty, Range.BoundaryTo(value2), key));
            Throws <ArgumentException>(() => Range.Create(Range.BoundaryFrom(empty), RangeBoundaryTo <int?> .Empty, key));
            Throws <ArgumentException>(() => Range.Create(double.NaN, 1, key));
            Throws <ArgumentException>(() => Range.Create(1, double.NaN, key));
            Throws <ArgumentException>(() => Range.Create(double.NegativeInfinity, double.NegativeInfinity, key));
            Throws <ArgumentException>(() => Range.Create(double.PositiveInfinity, double.PositiveInfinity, key));
            Throws <ArgumentException>(() => Range.Create(double.PositiveInfinity, double.NegativeInfinity, key));
            Throws <ArgumentException>(() => Range.Create(double.PositiveInfinity, 2, key));
            Throws <ArgumentException>(() => Range.Create(1, double.NegativeInfinity, key));

            AreEqual(
                Range <int?> .Empty,
                new Range <int?>(RangeBoundaryFrom <int?> .Empty, RangeBoundaryTo <int?> .Empty));
            AreEqual(
                Range <int?> .Infinite,
                Range.Create(empty, empty));
            AreEqual(
                Range <double> .Infinite,
                Range.Create(double.NegativeInfinity, double.PositiveInfinity));
            AreEqual(
                Range.TryCreate(value2, value1),
                Range <int?> .Empty);
            AreEqual(
                Range <int?, string> .Empty,
                Range.TryCreate(value2, value1, (string)null));
            AreEqual(
                Range <int?, string> .Infinite,
                Range.Create(empty, empty, (string)null));
            AreNotEqual(
                Range <int?, string> .Empty,
                Range.TryCreate(value2, value1, key));
            AreNotEqual(
                Range <int?, string> .Infinite,
                Range.Create(empty, empty, key));

            IsTrue(Range.TryCreate(value2, value1, key).IsEmpty);
            IsFalse(Range.TryCreate(value1, value2, key).IsEmpty);
            IsTrue(Range.TryCreate(double.NegativeInfinity, double.NegativeInfinity, key).IsEmpty);
            IsTrue(Range.TryCreate(double.NaN, 1, key).IsEmpty);
            IsTrue(Range.TryCreate(double.NaN, double.NaN, key).IsEmpty);
        }
Ejemplo n.º 8
0
 public static bool EndsBefore <T>(this Range <T> range, T value) =>
 range.IsNotEmpty && RangeBoundaryTo <T> .IsValid(value) && range.To < Range.BoundaryTo(value);
Ejemplo n.º 9
0
 public static Range <T> ExtendTo <T>(this Range <T> range, T to) =>
 ExtendTo(range, Range.BoundaryTo(to));
Ejemplo n.º 10
0
		/// <summary>Creates instance of <seealso cref="Range{T}"/></summary>
		/// <param name="from">Boundary From.</param>
		/// <param name="to">Boundary To.</param>
		public Range(T from, T to) :
			this(Range.BoundaryFrom(from), Range.BoundaryTo(to))
		{ }
Ejemplo n.º 11
0
 public static bool Contains <T>(this Range <T> range, T value) =>
 RangeBoundaryFrom <T> .IsValid(value)
                         ? Contains(range, Range.BoundaryFrom(value))
                         : Contains(range, Range.BoundaryTo(value));
Ejemplo n.º 12
0
 public Range <T> TrimTo(T to) =>
 TrimTo(Range.BoundaryTo(to));
Ejemplo n.º 13
0
 public Range <T> ExtendTo(T to) =>
 ExtendTo(Range.BoundaryTo(to));
Ejemplo n.º 14
0
 public CompositeRange <T, TKey> TrimTo(T to) => TrimTo(Range.BoundaryTo(to));
Ejemplo n.º 15
0
 public CompositeRange <T, TKey> ExtendTo(T to) =>
 ExtendTo(Range.BoundaryTo(to));
 public static CompositeRange <T> TrimTo <T>(this CompositeRange <T> compositeRange, T to) =>
 TrimTo(compositeRange, Range.BoundaryTo(to));