Example #1
0
        public void Parse_ValidRange()
        {
            var r = Range.Parse("4-6");

            Assert.That(r.From, Is.EqualTo(4));
            Assert.That(r.To, Is.EqualTo(6));
        }
Example #2
0
        public void IsInRange_InRange_ReturnsTrue()
        {
            var r1 = new Range <double>(5, 10);
            var r2 = new Range <double>(6, 10);

            Assert.True(r1.IsInRange(r2));
        }
Example #3
0
        public void IsInRange_NotInRange_ReturnsFalse()
        {
            var r1 = new Range <double>(5, 10);
            var r2 = new Range <double>(6, 10);

            Assert.False(r2.IsInRange(r1));
        }
Example #4
0
        public void ParseRanges()
        {
            var ranges = Range.ParseRanges("1-2,5,10-11").ToList();

            CollectionAssert.Contains(ranges, Range.Parse("1-2"));
            CollectionAssert.Contains(ranges, Range.Parse("5"));
            CollectionAssert.Contains(ranges, Range.Parse("10-11"));
        }
Example #5
0
        public void Range_Minus_ClassImplementingMinus()
        {
            var r = Range.FromPoint(new ClassWithMinusOperatorOverloading());

            Assert.DoesNotThrow(() =>
            {
                var i = r.Length;
            });
        }
Example #6
0
        public void Range_Equals()
        {
            var r1 = new Range <double>(5, 10);
            var r2 = new Range <double>(5, 10);

            Assert.That(r1, Is.EqualTo(r2));
            Assert.True(r1 == r2);
            Assert.True(Equals(r1, r2));
            Assert.That(r1.GetHashCode(), Is.EqualTo(r2.GetHashCode()));
        }
Example #7
0
        public void Parse_Invalid()
        {
            Assert.Throws <ArgumentNullException>(() => Range.Parse(null));
            var input = string.Empty;

            Assert.Throws <ArgumentException>(() => Range.Parse(input));
            Assert.Throws <ArgumentException>(() => Range.Parse("-"));
            Assert.Throws <FormatException>(() => Range.Parse("InvalidNumber-6"));
            Assert.Throws <FormatException>(() => Range.Parse("6-InvalidNumber"));

            Assert.Throws <ArgumentOutOfRangeException>(() => Range.Parse("6-4"));

            Assert.Throws <ArgumentException>(() => Range.Parse("4,6"));
        }
Example #8
0
        public void Range_NotEquals()
        {
            var r1 = new Range <double>(5, 10);
            var r2 = new Range <double>(6, 10);

            Assert.That(r1, Is.Not.EqualTo(r2));

            Assert.True(r1 != r2);

            Assert.False(Equals(r1, r2));
            Assert.False(r1.Equals(null));
            Assert.That(r1, Is.Not.EqualTo(null));
            Assert.False(r1.Equals(5));
            Assert.That(r1.GetHashCode(), Is.Not.EqualTo(r2.GetHashCode()));
        }
Example #9
0
        public void Length([Values(1, 2, 3, 4, 5)] double length)
        {
            var r = new Range <double>(0, length);

            Assert.AreEqual(r.Length, length);
        }
Example #10
0
        public void IsInRange_SameRange_ReturnsTrue()
        {
            var r1 = new Range <double>(5, 10);

            Assert.True(r1.IsInRange(r1));
        }
Example #11
0
        public void IsInRange_OutOfRange_False([Values(1, 2, 3, 4, 5)] double value)
        {
            var r = new Range <double>(6, 10);

            Assert.IsFalse(r.IsInRange(value));
        }
Example #12
0
        public void IsInRange_InRange_True([Values(1, 2, 3, 4, 5)] double value)
        {
            var r = new Range <double>(1, 100);

            Assert.IsTrue(r.IsInRange(value));
        }
Example #13
0
        public void Range_ToString()
        {
            var r = new Range <double>(7, 11);

            Assert.That(r.ToString(), Is.EqualTo("7-11"));
        }
Example #14
0
        public void Range_SinglePoint()
        {
            var r = Range.FromPoint(5);

            Assert.That(r.From, Is.EqualTo(r.To));
        }
Example #15
0
        public void Range_Minus_ClassNotImplementingMinus_ThrowsRuntimeBinderException()
        {
            var r = Range.FromPoint(new ClassWithoutMinusOperatorOverloading());

            Assert.That(() => r.Length, Throws.TypeOf <RuntimeBinderException>());
        }
Example #16
0
        public void Range_FromPoint_ToString()
        {
            var r = Range.FromPoint <double>(5);

            Assert.That(r.ToString(), Is.EqualTo("5-5"));
        }