Esempio n. 1
0
        public void TestMethod_GetValues()
        {
            var r = DoubleRange.FromEndpoints(1.5, 3.0);

            var ax = r.GetValues(2).ToList();

            Assert.AreEqual(1, ax.Count);
            Assert.AreEqual(1.5, ax[0]);

            var a0 = r.GetValues(1.5).ToList();

            Assert.AreEqual(2, a0.Count);
            Assert.AreEqual(1.5, a0[0]);
            Assert.AreEqual(3.0, a0[1]);

            var a1 = r.GetValues(1.0).ToList();

            Assert.AreEqual(2, a1.Count);
            Assert.AreEqual(1.5, a1[0]);
            Assert.AreEqual(2.5, a1[1]);

            var a2 = r.GetValues(0.5).ToList();

            Assert.AreEqual(4, a2.Count);
            Assert.AreEqual(1.5, a2[0]);
            Assert.AreEqual(2.0, a2[1]);
            Assert.AreEqual(2.5, a2[2]);
            Assert.AreEqual(3.0, a2[3]);
        }
Esempio n. 2
0
        public void TestEmptyRangesTouches()
        {
            var r1 = DoubleRange.FromEndpoints(3, 4);
            var r2 = DoubleRange.FromEndpoints(2, 2);

            Assert.IsFalse(r1.IntersectsExclusive(r2));
            Assert.IsFalse(r2.IntersectsExclusive(r1));
            Assert.IsFalse(r2.Touches(r1));
            Assert.IsFalse(r1.Touches(r2));
        }
Esempio n. 3
0
        public void TestMethod_GetValues2x()
        {
            var r = DoubleRange.FromEndpoints(1.0, 2.3);

            var a0 = r.GetValues(0.5).ToList();

            Assert.AreEqual(3, a0.Count);
            Assert.AreEqual(1, a0[0]);
            Assert.AreEqual(1.5, a0[1]);
            Assert.AreEqual(2.0, a0[2]);
        }
Esempio n. 4
0
        public void TestEmptyRanges()
        {
            var r1 = DoubleRange.FromEndpoints(0, 1);
            var r2 = DoubleRange.FromEndpoints(1, 2);
            var r3 = DoubleRange.FromEndpoints(-1, 0);

            Assert.AreEqual(1, r1.Length);
            Assert.AreEqual(1, r2.Length);
            Assert.AreEqual(1, r3.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.IntersectsExclusive(r2));
            Assert.IsFalse(r2.IntersectsExclusive(r3));
            Assert.IsFalse(r1.IntersectsExclusive(r3));
            Assert.IsFalse(r3.IntersectsExclusive(r2));
            Assert.IsFalse(r3.IntersectsExclusive(r1));
            Assert.IsFalse(r2.IntersectsExclusive(r1));
        }
Esempio n. 5
0
        public void TestMethodShrinkingRange()
        {
            var rc = new SparseDoubleRange();

            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(3, rc.Count);
            Assert.AreEqual(1, rc.Lower);
            Assert.AreEqual(4, rc.Upper);

            rc.RemoveInclusive(DoubleRange.FromEndpoints(-2, -1));
            // 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(3, rc.Count);
            Assert.AreEqual(1, rc.Lower);
            Assert.AreEqual(4, rc.Upper);

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

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

            rc.RemoveInclusive(1, 2);
            // rc = [] -> []

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