示例#1
0
        public static void TestKeyedRangeTrimFrom()
        {
            double?empty      = null;
            double?value1     = 1;
            double?value2     = 2;
            var    emptyFrom  = RangeBoundaryFrom <double?> .Empty;
            var    emptyTo    = RangeBoundaryTo <double?> .Empty;
            var    emptyRange = Range.Create(emptyFrom, emptyTo, RangeKey);

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

            AreEqual(range.TrimFrom(null), range);
            AreEqual(range.TrimFrom(double.NegativeInfinity), range);
            Throws <ArgumentException>(() => range.TrimFrom(double.PositiveInfinity));
            AreEqual(range.TrimFrom(RangeBoundaryFrom <double?> .Empty), emptyRange);
            AreEqual(range.TrimFrom(0), range);
            AreEqual(range.TrimFrom(1), range);
            AreEqual(range.TrimFrom(1.5), Range.Create(1.5, value2, RangeKey));
            AreEqual(range.TrimFrom(2), Range.Create(2, value2, RangeKey));
            AreEqual(range.TrimFrom(3), emptyRange);

            range = Range.Create(emptyFrom, emptyTo, RangeKey);
            AreEqual(range.TrimFrom(null), range);
            AreEqual(range.TrimFrom(double.NegativeInfinity), range);
            Throws <ArgumentException>(() => range.TrimFrom(double.PositiveInfinity));
            AreEqual(range.TrimFrom(RangeBoundaryFrom <double?> .Empty), range);
            AreEqual(range.TrimFrom(0), range);

            range = Range.CreateExclusive(empty, empty, RangeKey);
            AreEqual(range.TrimFrom(null), range);
            AreEqual(range.TrimFrom(double.NegativeInfinity), range);
            Throws <ArgumentException>(() => range.TrimFrom(double.PositiveInfinity));
            AreEqual(range.TrimFrom(RangeBoundaryFrom <double?> .Empty), emptyRange);
            AreEqual(range.TrimFrom(0), Range.Create(0, empty, RangeKey));

            range = Range.CreateExclusive(value1, value2, RangeKey);
            AreEqual(range.TrimFrom(1), range);
            AreEqual(range.TrimFrom(1.5), Range.CreateExclusiveTo(1.5, value2, RangeKey));
            AreEqual(range.TrimFrom(2), emptyRange);

            range = Range.CreateExclusive(value1, value2, RangeKey);
            AreEqual(range.TrimFrom(Range.BoundaryFrom <double?>(1)), range);
            AreEqual(range.TrimFrom(Range.BoundaryFrom <double?>(1.5)), Range.CreateExclusiveTo(1.5, value2, RangeKey));
            AreEqual(range.TrimFrom(Range.BoundaryFrom <double?>(2)), emptyRange);
        }
示例#2
0
        public static void TestRangeExtendTo()
        {
            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);

            AreEqual(range.ExtendTo(null), Range.Create(value1, empty));
            AreEqual(range.ExtendTo(double.PositiveInfinity), Range.Create(value1, empty));
            Throws <ArgumentException>(() => range.ExtendTo(double.NegativeInfinity));
            AreEqual(range.ExtendTo(RangeBoundaryTo <double?> .Empty), range);
            AreEqual(range.ExtendTo(0), range);
            AreEqual(range.ExtendTo(1), range);
            AreEqual(range.ExtendTo(1.5), range);
            AreEqual(range.ExtendTo(2), range);
            AreEqual(range.ExtendTo(3), Range.Create(value1, 3));

            range = Range.Create(emptyFrom, emptyTo);
            AreEqual(range.ExtendTo(null), range);
            AreEqual(range.ExtendTo(double.PositiveInfinity), range);
            Throws <ArgumentException>(() => range.ExtendTo(double.NegativeInfinity));
            AreEqual(range.ExtendTo(RangeBoundaryTo <double?> .Empty), range);
            AreEqual(range.ExtendTo(0), range);

            range = Range.CreateExclusive(empty, empty);
            AreEqual(range.ExtendTo(null), range);
            AreEqual(range.ExtendTo(double.PositiveInfinity), range);
            Throws <ArgumentException>(() => range.ExtendTo(double.NegativeInfinity));
            AreEqual(range.ExtendTo(RangeBoundaryTo <double?> .Empty), range);
            AreEqual(range.ExtendTo(0), range);

            range = Range.CreateExclusive(value1, value2);
            AreEqual(range.ExtendTo(1), range);
            AreEqual(range.ExtendTo(1.5), range);
            AreEqual(range.ExtendTo(2), Range.CreateExclusiveFrom(value1, 2));

            range = Range.CreateExclusive(value1, value2);
            AreEqual(range.ExtendTo(Range.BoundaryTo <double?>(2)), Range.CreateExclusiveFrom(value1, 2));
            AreEqual(range.ExtendTo(Range.BoundaryToExclusive <double?>(2)), range);
            AreEqual(range.ExtendTo(Range.BoundaryToExclusive <double?>(3)), Range.CreateExclusive(value1, 3));
        }
示例#3
0
        public static void TestRangeWithValue()
        {
            var range = Range.Create(1, 2);

            AreEqual(Range.Create(0, 3), range.WithValues(i => i - 1, i => i + 1));

            range = Range.CreateExclusiveFrom(1, 2);
            AreEqual(Range.CreateExclusiveFrom(0, 3), range.WithValues(i => i - 1, i => i + 1));

            range = Range.CreateExclusive(1, 2);
            AreEqual(Range.CreateExclusive(2, 3), range.WithValues(i => i + 1));

            var toInf  = (double?)double.PositiveInfinity;
            var range2 = Range.CreateExclusive(1, toInf);

            IsTrue(range2.WithValues(i => (double?)null).IsInfinite);
            range2 = Range.Create(double.NegativeInfinity, toInf);
            AreEqual(range2, range2.WithValues(i => i - 1, i => i + 1));
        }
示例#4
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)));
        }
示例#5
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)));
        }
示例#6
0
        public static void TestRangeHasIntersection()
        {
            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.HasIntersection(range));
            IsTrue(range.HasIntersection(1, 2));
            IsTrue(range.HasIntersection(Range.CreateExclusive(value1, value2, _rangeKey2)));
            IsTrue(range.HasIntersection(1, null));
            IsFalse(range.HasIntersection(Range <double?> .Empty));
            IsTrue(range.HasIntersection(Range <double?> .Infinite));
            IsTrue(range.HasIntersection(null, null));
            IsTrue(range.HasIntersection(double.NegativeInfinity, double.PositiveInfinity));
            Throws <ArgumentException>(
                () => range.HasIntersection(2, 1));
            Throws <ArgumentException>(
                () => range.HasIntersection(double.PositiveInfinity, double.NegativeInfinity));
            IsTrue(range.HasIntersection(1.5, 1.5));
            IsTrue(range.HasIntersection(1.5, 2));
            IsTrue(range.HasIntersection(0, 3));
            IsTrue(range.HasIntersection(0, 1.5));
            IsTrue(range.HasIntersection(1.5, 3));
            IsFalse(range.HasIntersection(3, 4));

            range = Range.Create(emptyFrom, emptyTo);
            IsTrue(range.HasIntersection(range));
            IsFalse(range.HasIntersection(1, 2));
            IsTrue(range.HasIntersection(Range.Create(emptyFrom, emptyTo, _rangeKey2)));
            IsFalse(range.HasIntersection(1, null));
            IsTrue(range.HasIntersection(Range <double?> .Empty));
            IsFalse(range.HasIntersection(Range <double?> .Infinite));
            IsFalse(range.HasIntersection(null, null));
            IsFalse(range.HasIntersection(double.NegativeInfinity, double.PositiveInfinity));
            Throws <ArgumentException>(
                () => range.HasIntersection(2, 1));
            Throws <ArgumentException>(
                () => range.HasIntersection(double.PositiveInfinity, double.NegativeInfinity));

            range = Range.CreateExclusive(empty, empty);
            IsTrue(range.HasIntersection(range));
            IsTrue(range.HasIntersection(Range.CreateExclusive(empty, empty, _rangeKey2)));
            IsTrue(range.HasIntersection(1, 2));
            IsTrue(range.HasIntersection(1, null));
            IsFalse(range.HasIntersection(Range <double?> .Empty));
            IsTrue(range.HasIntersection(Range <double?> .Infinite));
            IsTrue(range.HasIntersection(null, null));
            IsTrue(range.HasIntersection(double.NegativeInfinity, double.PositiveInfinity));
            Throws <ArgumentException>(
                () => range.HasIntersection(2, 1));
            Throws <ArgumentException>(
                () => range.HasIntersection(double.PositiveInfinity, double.NegativeInfinity));

            range = Range.CreateExclusive(value1, value2);
            IsTrue(range.HasIntersection(Range.CreateExclusive(value1, value2, _rangeKey2)));
            IsTrue(range.HasIntersection(1, 2));
            IsTrue(range.HasIntersection(1.5, 1.5));
            IsTrue(range.HasIntersection(1.5, 2));
            IsFalse(range.HasIntersection(3, 4));
        }
示例#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);
        }
        public static void TestCompositeRangeArgsOrderWithKeys()
        {
            var seek = new Random().Next();

            Console.WriteLine(
                $"{MethodBase.GetCurrentMethod().Name}: Rnd seek: {seek} (use the seek to reproduce test results).");
            var rnd = new Random(seek);

            var emtpy    = Range.Create(RangeBoundaryFrom <int> .Empty, RangeBoundaryTo <int> .Empty, "E");
            var infinite = Range.Create(
                RangeBoundaryFrom <int> .NegativeInfinity,
                RangeBoundaryTo <int> .PositiveInfinity, "I");
            // Equal ranges should use same keys to provide repeatable results after
            // ranges array will be shuffled.
            var ranges = new[]
            {
                emtpy,
                Range.Create(1, 2, "A"),
                Range.Create(1, 2, "A"),
                Range.Create(3, 4, "B"),
                Range.Create(3, 5, "C"),
                emtpy,
                emtpy,
                emtpy,
                Range.CreateExclusive(4, 6, "D"),
                Range.CreateExclusiveTo(7, 8, "F"),
                Range.CreateExclusiveTo(3, 5, "G"),
                Range.CreateExclusive(3, 5, "H"),
                Range.CreateExclusiveFrom(3, 5, "K"),
                Range.Create(0, 6, (string)null),
                emtpy,
                emtpy,
                infinite
            };

            var compositeRange = new CompositeRange <int, string>(ranges);

            AreEqual(
                compositeRange.ToString(),
                "(-∞..+∞): { 'I':(-∞..+∞); '':[0..6]; 'A':[1..2]; 'A':[1..2]; 'B':[3..4]; " +
                "'G':[3..5); 'C':[3..5]; 'H':(3..5); 'K':(3..5]; 'D':(4..6); 'F':[7..8) }");

            compositeRange = new CompositeRange <int, string>(ranges.OrderBy(r => rnd.Next()));
            AreEqual(
                compositeRange.ToString(),
                "(-∞..+∞): { 'I':(-∞..+∞); '':[0..6]; 'A':[1..2]; 'A':[1..2]; 'B':[3..4]; " +
                "'G':[3..5); 'C':[3..5]; 'H':(3..5); 'K':(3..5]; 'D':(4..6); 'F':[7..8) }");

            compositeRange = new CompositeRange <int, string>(ranges.Take(ranges.Length - 1));
            AreEqual(
                compositeRange.ToString(),
                "[0..8): { '':[0..6]; 'A':[1..2]; 'A':[1..2]; 'B':[3..4]; " +
                "'G':[3..5); 'C':[3..5]; 'H':(3..5); 'K':(3..5]; 'D':(4..6); 'F':[7..8) }");

            compositeRange = new CompositeRange <int, string>(ranges.Take(ranges.Length - 1).OrderBy(r => rnd.Next()));
            AreEqual(
                compositeRange.ToString(),
                "[0..8): { '':[0..6]; 'A':[1..2]; 'A':[1..2]; 'B':[3..4]; " +
                "'G':[3..5); 'C':[3..5]; 'H':(3..5); 'K':(3..5]; 'D':(4..6); 'F':[7..8) }");

            compositeRange = new CompositeRange <int, string>(ranges.Last());
            AreEqual(compositeRange.ToString(), "(-∞..+∞): { 'I':(-∞..+∞) }");

            compositeRange = new CompositeRange <int, string>(ranges.First());
            AreEqual(compositeRange.ToString(), "∅");

            compositeRange = new CompositeRange <int, string>(ranges.Take(0));
            AreEqual(compositeRange.ToString(), "∅");

            compositeRange = new CompositeRange <int, string>();
            AreEqual(compositeRange.ToString(), "∅");
        }
        public static void TestCompositeRangeArgsOrder()
        {
            var seek = new Random().Next();

            Console.WriteLine(
                $"{MethodBase.GetCurrentMethod().Name}: Rnd seek: {seek} (use the seek to reproduce test results).");
            var rnd = new Random(seek);

            var ranges = new[]
            {
                Range <int> .Empty,
                Range.Create(1, 2),
                Range.Create(1, 2),
                Range.Create(3, 4),
                Range.Create(3, 5),
                Range <int> .Empty,
                Range <int> .Empty,
                Range <int> .Empty,
                Range.CreateExclusive(4, 6),
                Range.CreateExclusiveTo(7, 8),
                Range.CreateExclusiveTo(3, 5),
                Range.CreateExclusive(3, 5),
                Range.CreateExclusiveFrom(3, 5),
                Range.Create(0, 6),
                Range <int> .Empty,
                Range <int> .Empty,
                Range <int> .Infinite
            };

            var compositeRange = new CompositeRange <int>(ranges);

            AreEqual(
                compositeRange.ToString(),
                "(-∞..+∞): { (-∞..+∞); [0..6]; [1..2]; [1..2]; [3..4]; [3..5); [3..5]; (3..5); (3..5]; (4..6); [7..8) }");

            compositeRange = ranges.OrderBy(r => rnd.Next()).ToCompositeRange();
            AreEqual(
                compositeRange.ToString(),
                "(-∞..+∞): { (-∞..+∞); [0..6]; [1..2]; [1..2]; [3..4]; [3..5); [3..5]; (3..5); (3..5]; (4..6); [7..8) }");

            compositeRange = ranges.Take(ranges.Length - 1).ToCompositeRange();
            AreEqual(
                compositeRange.ToString(),
                "[0..8): { [0..6]; [1..2]; [1..2]; [3..4]; [3..5); [3..5]; (3..5); (3..5]; (4..6); [7..8) }");

            compositeRange = ranges.Take(ranges.Length - 1).OrderBy(r => rnd.Next()).ToCompositeRange();
            AreEqual(
                compositeRange.ToString(),
                "[0..8): { [0..6]; [1..2]; [1..2]; [3..4]; [3..5); [3..5]; (3..5); (3..5]; (4..6); [7..8) }");

            compositeRange = new CompositeRange <int>(ranges.Last());
            AreEqual(compositeRange.ToString(), "(-∞..+∞): { (-∞..+∞) }");

            compositeRange = new CompositeRange <int>(ranges.First());
            AreEqual(compositeRange.ToString(), "∅");

            compositeRange = new CompositeRange <int>(ranges.Take(0));
            AreEqual(compositeRange.ToString(), "∅");

            compositeRange = new CompositeRange <int>();
            AreEqual(compositeRange.ToString(), "∅");
        }
        public static void TestKeyedRangeContainsRange()
        {
            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, RangeKey);

            IsTrue(range.Contains(range));
            IsTrue(range.Contains(1, 2));
            IsTrue(range.Contains(Range.CreateExclusive(value1, value2, RangeKey2)));
            IsFalse(range.Contains(1, null));
            IsFalse(range.Contains(Range <double?> .Empty));
            IsFalse(range.Contains(Range <double?> .Infinite));
            IsFalse(range.Contains(null, null));
            IsFalse(range.Contains(double.NegativeInfinity, double.PositiveInfinity));
            Throws <ArgumentException>(
                () => range.Contains(2, 1));
            Throws <ArgumentException>(
                () => range.Contains(double.PositiveInfinity, double.NegativeInfinity));
            IsTrue(range.Contains(1.5, 1.5));
            IsTrue(range.Contains(1.5, 2));
            IsFalse(range.Contains(0, 3));
            IsFalse(range.Contains(0, 1.5));
            IsFalse(range.Contains(1.5, 3));
            IsFalse(range.Contains(3, 4));

            range = Range.Create(emptyFrom, emptyTo, RangeKey);
            IsTrue(range.Contains(range));
            IsFalse(range.Contains(1, 2));
            IsTrue(range.Contains(Range.Create(emptyFrom, emptyTo, RangeKey2)));
            IsFalse(range.Contains(1, null));
            IsTrue(range.Contains(Range <double?> .Empty));
            IsFalse(range.Contains(Range <double?> .Infinite));
            IsFalse(range.Contains(null, null));
            IsFalse(range.Contains(double.NegativeInfinity, double.PositiveInfinity));
            Throws <ArgumentException>(
                () => range.Contains(2, 1));
            Throws <ArgumentException>(
                () => range.Contains(double.PositiveInfinity, double.NegativeInfinity));

            range = Range.CreateExclusive(empty, empty, RangeKey);
            IsTrue(range.Contains(range));
            IsTrue(range.Contains(Range.CreateExclusive(empty, empty, RangeKey2)));
            IsTrue(range.Contains(1, 2));
            IsTrue(range.Contains(1, null));
            IsFalse(range.Contains(Range <double?> .Empty));
            IsTrue(range.Contains(Range <double?> .Infinite));
            IsTrue(range.Contains(null, null));
            IsTrue(range.Contains(double.NegativeInfinity, double.PositiveInfinity));
            Throws <ArgumentException>(
                () => range.Contains(2, 1));
            Throws <ArgumentException>(
                () => range.Contains(double.PositiveInfinity, double.NegativeInfinity));

            range = Range.CreateExclusive(value1, value2, RangeKey);
            IsTrue(range.Contains(Range.CreateExclusive(value1, value2, RangeKey2)));
            IsFalse(range.Contains(1, 2));
            IsTrue(range.Contains(1.5, 1.5));
            IsFalse(range.Contains(1.5, 2));
            IsFalse(range.Contains(3, 4));
        }