示例#1
0
        public void TestEmptyRanges()
        {
            var r1 = IntRange.FromInteger(0);
            var r2 = IntRange.FromInteger(1);
            var r3 = IntRange.FromInteger(-1);

            Assert.AreEqual(1, r1.Length);
            Assert.AreEqual(1, r2.Length);
            Assert.AreEqual(1, r2.Length);
            Assert.AreEqual(1, r2.Length);

            Assert.IsTrue(r1.Touches(r2));
            Assert.IsTrue(r2.Touches(r1));
            Assert.IsTrue(r1.Touches(r3));
            Assert.IsTrue(r3.Touches(r1));
            Assert.IsTrue(!r2.Touches(r3));
            Assert.IsTrue(!r3.Touches(r2));

            Assert.IsFalse(r1.Intersects(r2));
            Assert.IsFalse(r2.Intersects(r3));
            Assert.IsFalse(r1.Intersects(r3));
            Assert.IsFalse(r3.Intersects(r2));
            Assert.IsFalse(r3.Intersects(r1));
            Assert.IsFalse(r2.Intersects(r1));
        }
示例#2
0
        public void TestMethodShrinkingRange()
        {
            var rc = new SparseIntRange();

            rc.AddInclusive(1, 4);
            // rc = [(1,4)] -> [1,2,3,4]
            Assert.AreEqual(1, rc.RangeCount);
            Assert.IsFalse(rc.Contains(0));
            Assert.IsTrue(rc.Contains(1));
            Assert.IsTrue(rc.Contains(2));
            Assert.IsTrue(rc.Contains(3));
            Assert.IsTrue(rc.Contains(4));
            Assert.IsFalse(rc.Contains(5));
            Assert.AreEqual(4, rc.Count);
            Assert.AreEqual(1, rc.Lower);
            Assert.AreEqual(4, rc.Upper);

            rc.Remove(IntRange.FromInteger(-2));
            // rc = [(1,4)] -> [1,2,3,4]
            Assert.AreEqual(1, rc.RangeCount);
            Assert.IsFalse(rc.Contains(0));
            Assert.IsTrue(rc.Contains(1));
            Assert.IsTrue(rc.Contains(2));
            Assert.IsTrue(rc.Contains(3));
            Assert.IsTrue(rc.Contains(4));
            Assert.IsFalse(rc.Contains(5));
            Assert.AreEqual(4, rc.Count);
            Assert.AreEqual(1, rc.Lower);
            Assert.AreEqual(4, rc.Upper);

            rc.Remove(IntRange.FromInteger(2));
            // rc = [(1,1),(3,4)] -> [1,3,4]
            Assert.AreEqual(2, rc.RangeCount);
            Assert.IsFalse(rc.Contains(0));
            Assert.IsTrue(rc.Contains(1));
            Assert.IsFalse(rc.Contains(2));
            Assert.IsTrue(rc.Contains(3));
            Assert.IsTrue(rc.Contains(4));
            Assert.IsFalse(rc.Contains(5));
            Assert.AreEqual(3, rc.Count);
            Assert.AreEqual(1, rc.Lower);
            Assert.AreEqual(4, rc.Upper);

            rc.RemoveInclusive(3, 4);
            // rc = [(1,1)] -> [1]
            Assert.AreEqual(1, rc.RangeCount);
            Assert.IsFalse(rc.Contains(0));
            Assert.IsTrue(rc.Contains(1));
            Assert.IsFalse(rc.Contains(2));
            Assert.AreEqual(1, rc.Count);
            Assert.AreEqual(1, rc.Lower);
            Assert.AreEqual(1, rc.Upper);

            rc.Remove(1);
            // rc = [] -> []

            Assert.AreEqual(0, rc.RangeCount);
            Assert.IsFalse(rc.Contains(0));
            Assert.IsFalse(rc.Contains(1));
            Assert.IsFalse(rc.Contains(2));
            Assert.AreEqual(0, rc.Count);
        }