コード例 #1
0
        public static void TestBoundaryValueComparison()
        {
            int?value1 = 1;
            int?value2 = 2;

            var eFrom = RangeBoundaryFrom <int?> .Empty;
            var nInf  = Range.BoundaryFromInfinity <int?>();
            var pInf  = Range.BoundaryToInfinity <int?>();

            var fromInc1 = Range.BoundaryFrom(value1);
            var fromEx1  = Range.BoundaryFromExclusive(value1);
            var toInc1   = Range.BoundaryTo(value1);
            var toEx1    = Range.BoundaryToExclusive(value1);

            var fromInc2 = Range.BoundaryFrom(value2);
            var fromEx2  = Range.BoundaryFromExclusive(value2);
            var toInc2   = Range.BoundaryTo(value2);
            var toEx2    = Range.BoundaryToExclusive(value2);

            IsTrue(eFrom < nInf);
            IsTrue(nInf < toEx1);
            IsTrue(toEx1 < fromInc1);
            IsTrue(fromInc1 <= toInc1);
            IsTrue(toInc1 < fromEx1);
            IsTrue(fromEx1 < toEx2);
            IsTrue(toEx2 < fromInc2);
            IsTrue(fromInc2 <= toInc2);
            IsTrue(toInc2 < fromEx2);
            IsTrue(fromEx2 < pInf);
        }
コード例 #2
0
        public static void TestBoundaryRawValueComparison()
        {
            int?value1 = 1;
            int?value2 = 2;
            int?empty  = null;

            var eFrom = RangeBoundaryFrom <int?> .Empty;
            var nInf  = Range.BoundaryFromInfinity <int?>();
            var pInf  = Range.BoundaryToInfinity <int?>();

            var fromInc1 = Range.BoundaryFrom(value1);
            var fromEx1  = Range.BoundaryFromExclusive(value1);
            var toInc1   = Range.BoundaryTo(value1);
            var toEx1    = Range.BoundaryToExclusive(value1);

            var fromInc2 = Range.BoundaryFrom(value2);
            var fromEx2  = Range.BoundaryFromExclusive(value2);
            var toInc2   = Range.BoundaryTo(value2);
            var toEx2    = Range.BoundaryToExclusive(value2);

            IsTrue(eFrom < empty);
            IsTrue(nInf <= empty);
            IsTrue(nInf >= empty);
            IsTrue(pInf > empty);

            IsTrue(toEx1 > empty);
            IsTrue(toInc1 > empty);
            IsTrue(fromEx2 > empty);
            IsTrue(fromInc2 > empty);

            IsTrue(empty < toEx2);
            IsTrue(empty < toInc2);
            IsTrue(empty < fromEx1);
            IsTrue(empty < fromInc1);

            IsTrue(nInf < value1);
            IsTrue(toEx1 < value1);
            IsTrue(fromEx1 > value1);
            IsTrue(toInc1 <= value1);
            IsTrue(fromInc1 >= value1);

            IsTrue(toEx1 < value2);
            IsTrue(fromEx1 < value2);
            IsTrue(toInc1 < value2);
            IsTrue(fromInc1 < value2);

            IsTrue(value2 < pInf);
            IsTrue(value2 > toEx2);
            IsTrue(value2 < fromEx2);
            IsTrue(value2 >= toInc2);
            IsTrue(value2 <= fromInc2);

            IsTrue(value1 < toEx2);
            IsTrue(value1 < fromEx2);
            IsTrue(value1 < toInc2);
            IsTrue(value1 < fromInc2);
        }
コード例 #3
0
        public static void TestBoundaryToProperties()
        {
            int?value1 = 1;
            int?value2 = 2;
            int?empty  = null;

            var a = new RangeBoundaryTo <int?>();

            AreEqual(a.Kind, RangeBoundaryToKind.Empty);
            AreEqual(a.GetValueOrDefault(), empty);
            Throws <InvalidOperationException>(() => a.Value.ToString());

            IsTrue(a.IsEmpty);
            IsFalse(a.IsNotEmpty);
            IsFalse(a.HasValue);
            IsFalse(a.IsPositiveInfinity);
            IsFalse(a.IsInclusiveBoundary);
            IsFalse(a.IsExclusiveBoundary);

            a = Range.BoundaryToInfinity <int?>();
            AreEqual(a.Kind, RangeBoundaryToKind.Infinite);
            AreEqual(a.GetValueOrDefault(), empty);
            Throws <InvalidOperationException>(() => a.Value.ToString());

            IsFalse(a.IsEmpty);
            IsTrue(a.IsNotEmpty);
            IsFalse(a.HasValue);
            IsTrue(a.IsPositiveInfinity);
            IsFalse(a.IsInclusiveBoundary);
            IsFalse(a.IsExclusiveBoundary);

            a = Range.BoundaryTo(value1);
            AreEqual(a.Kind, RangeBoundaryToKind.Inclusive);
            AreEqual(a.Value, value1);
            AreNotEqual(a.Value, value2);

            IsFalse(a.IsEmpty);
            IsTrue(a.IsNotEmpty);
            IsTrue(a.HasValue);
            IsFalse(a.IsPositiveInfinity);
            IsTrue(a.IsInclusiveBoundary);
            IsFalse(a.IsExclusiveBoundary);

            a = Range.BoundaryToExclusive(value1);
            AreEqual(a.Kind, RangeBoundaryToKind.Exclusive);
            AreEqual(a.Value, value1);
            AreNotEqual(a.Value, value2);

            IsFalse(a.IsEmpty);
            IsTrue(a.IsNotEmpty);
            IsTrue(a.HasValue);
            IsFalse(a.IsPositiveInfinity);
            IsFalse(a.IsInclusiveBoundary);
            IsTrue(a.IsExclusiveBoundary);
        }
コード例 #4
0
        public static void TestBoundaryKindComparison()
        {
            int?value1 = 1;

            var eFrom   = RangeBoundaryFrom <int?> .Empty;
            var eTo     = RangeBoundaryTo <int?> .Empty;
            var nInf    = Range.BoundaryFromInfinity <int?>();
            var pInf    = Range.BoundaryToInfinity <int?>();
            var fromInc = Range.BoundaryFrom(value1);
            var fromEx  = Range.BoundaryFromExclusive(value1);
            var toInc   = Range.BoundaryTo(value1);
            var toEx    = Range.BoundaryToExclusive(value1);

            AreNotEqual(fromInc, fromEx);
            AreNotEqual(fromInc, toInc);
            AreNotEqual(toInc, toEx);
            AreEqual(fromInc.Value, fromEx.Value);
            AreEqual(fromInc.Value, toInc.Value);
            AreEqual(toInc.Value, toEx.Value);

            // priority:
            // '∅' < '-∞' < 'a)' < '[a' == 'a]' < '(a' < '+∞'
            AreEqual(eFrom.CompareTo(eTo), 0);
            AreEqual(eTo.CompareTo(eFrom), 0);
            Less(eFrom, nInf);
            Less(nInf, toEx);
            Less(toEx, fromInc);
            AreEqual(fromInc.CompareTo(toInc), 0);
            AreEqual(toInc.CompareTo(fromInc), 0);
            Less(toInc, fromEx);
            Less(fromEx, pInf);

            IsTrue(eTo <= eFrom);
            IsTrue(eFrom < nInf);
            IsTrue(nInf < toEx);
            IsTrue(toEx < fromInc);
            IsTrue(toInc <= fromInc && toInc >= fromInc);
            IsTrue(fromInc < fromEx);
            IsTrue(fromEx < pInf);

            IsTrue(pInf >= fromEx);
            IsTrue(fromEx >= fromInc);
            IsTrue(fromInc >= toInc);
            IsTrue(fromInc >= toEx);
            IsTrue(toEx >= nInf);
            IsTrue(nInf >= eFrom);
            IsTrue(eFrom >= eTo);
        }
コード例 #5
0
        public static void TestBoundaryToCreation()
        {
            int?value1 = 1;
            int?value2 = 2;
            int?empty  = null;

            DoesNotThrow(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Empty));
            DoesNotThrow(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Infinite));
            DoesNotThrow(() => new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive));
            DoesNotThrow(() => new RangeBoundaryTo <int?>(value2, RangeBoundaryToKind.Inclusive));
            DoesNotThrow(() => new RangeBoundaryTo <double?>(double.NaN, RangeBoundaryToKind.Empty));

            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Empty));
            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(value2, RangeBoundaryToKind.Infinite));
            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Inclusive));
            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Exclusive));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(double.NaN, RangeBoundaryToKind.Exclusive));

            AreEqual(
                RangeBoundaryTo <int?> .PositiveInfinity,
                Range.BoundaryToInfinity <int?>());
            AreEqual(
                RangeBoundaryTo <int?> .PositiveInfinity,
                Range.BoundaryTo(empty));
            AreEqual(
                RangeBoundaryTo <int?> .PositiveInfinity,
                Range.BoundaryToExclusive(empty));
            AreEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Inclusive),
                Range.BoundaryTo(value1));
            AreEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive),
                Range.BoundaryToExclusive(value1));
            AreNotEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive),
                Range.BoundaryToExclusive(value2));
            AreNotEqual(
                RangeBoundaryTo <int> .PositiveInfinity,
                Range.BoundaryTo(0));
            AreEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive),
                Range.BoundaryToExclusive(value1));
        }