예제 #1
0
        public void IntersectsDisjoint()
        {
            // simple overlap
            var a = new IntInterval(7, 42);
            var b = new IntInterval(10, 100);

            Assert.IsTrue(a.IntersectsWith(b));
            Assert.IsTrue(b.IntersectsWith(a));
            Assert.IsTrue(a.IntersectsWith(a));
            Assert.IsFalse(a.IsDisjointFrom(b));
            Assert.IsFalse(b.IsDisjointFrom(a));
            Assert.IsFalse(a.IsDisjointFrom(a));

            // "touching", inclusive
            var c = new IntInterval(42, 100);

            Assert.IsTrue(a.IntersectsWith(c));
            Assert.IsTrue(c.IntersectsWith(a));
            Assert.IsFalse(a.IsDisjointFrom(c));
            Assert.IsFalse(c.IsDisjointFrom(a));

            // "touching", but non-inclusive
            var d = new IntInterval(42, false, 100, true);

            Assert.IsFalse(a.IntersectsWith(d));
            Assert.IsFalse(d.IntersectsWith(a));
            Assert.IsTrue(a.IsDisjointFrom(d));
            Assert.IsTrue(d.IsDisjointFrom(a));
            var e = new IntInterval(0, true, 7, false);

            Assert.IsFalse(a.IntersectsWith(e));
            Assert.IsFalse(e.IntersectsWith(a));
            Assert.IsTrue(a.IsDisjointFrom(e));
            Assert.IsTrue(e.IsDisjointFrom(a));

            // simple disjoint
            var f = new IntInterval(0, 3);

            Assert.IsFalse(a.IntersectsWith(f));
            Assert.IsFalse(f.IntersectsWith(a));
            Assert.IsTrue(a.IsDisjointFrom(f));
            Assert.IsTrue(f.IsDisjointFrom(a));

            // negative interval
            var g = new IntInterval(8, 0);

            Assert.IsTrue(a.IntersectsWith(g));
            Assert.IsTrue(g.IntersectsWith(a));
            Assert.IsFalse(a.IsDisjointFrom(g));
            Assert.IsFalse(g.IsDisjointFrom(a));

            // containment
            var h = new IntInterval(7, 42);
            var i = new IntInterval(10, 40);

            Assert.IsTrue(h.IntersectsWith(i));
            Assert.IsTrue(i.IntersectsWith(h));
            Assert.IsFalse(h.IsDisjointFrom(i));
            Assert.IsFalse(i.IsDisjointFrom(h));
        }