public void IndexesCacheGeneration()
        {
            RangeCollection range = new RangeCollection();

            int [] index_cache = range.Indexes;

            Assert.AreSame(index_cache, range.Indexes);

            range.Add(0);
            range.Add(5);

            if (index_cache == range.Indexes)
            {
                Assert.Fail("Indexes Cache not regenerated after change");
            }

            index_cache = range.Indexes;
            range.Remove(0);
            range.Add(3);

            if (index_cache == range.Indexes)
            {
                Assert.Fail("Indexes Cache not regenerated after change");
            }
        }
示例#2
0
        public void RemoveEnds()
        {
            RangeCollection range = _SetupTestRemoveMerges();

            Assert.AreEqual(true, range.Contains(5));
            range.Remove(5);
            Assert.AreEqual(false, range.Contains(5));
            Assert.AreEqual(5, range.RangeCount);
            Assert.AreEqual(2, range.Ranges[1].Start);
            Assert.AreEqual(4, range.Ranges[1].End);

            Assert.AreEqual(true, range.Contains(15));
            range.Remove(15);
            Assert.AreEqual(false, range.Contains(15));
            Assert.AreEqual(5, range.RangeCount);
            Assert.AreEqual(14, range.Ranges[3].Start);
            Assert.AreEqual(14, range.Ranges[3].End);
        }
示例#3
0
        public void RemoveStarts()
        {
            RangeCollection range = _SetupTestRemoveMerges();

            Assert.AreEqual(true, range.Contains(0));
            range.Remove(0);
            Assert.AreEqual(false, range.Contains(0));
            Assert.AreEqual(4, range.RangeCount);

            Assert.AreEqual(true, range.Contains(2));
            range.Remove(2);
            Assert.AreEqual(false, range.Contains(2));
            Assert.AreEqual(4, range.RangeCount);
            Assert.AreEqual(3, range.Ranges[0].Start);
            Assert.AreEqual(5, range.Ranges[0].End);

            Assert.AreEqual(true, range.Contains(14));
            range.Remove(14);
            Assert.AreEqual(false, range.Contains(14));
            Assert.AreEqual(4, range.RangeCount);
            Assert.AreEqual(15, range.Ranges[2].Start);
            Assert.AreEqual(15, range.Ranges[2].End);
        }
示例#4
0
        public void RemoveSingles()
        {
            RangeCollection range = new RangeCollection();

            int [] indexes = new int [] { 0, 2, 4, 6, 8, 10, 12, 14 };
            foreach (int index in indexes)
            {
                range.Add(index);
            }

            foreach (int index in indexes)
            {
                Assert.AreEqual(true, range.Remove(index));
            }
        }
        public void RemoveRangeItemTest()
        {
            RangeCollection <MyRangeItem> collection = new RangeCollection <MyRangeItem>();

            collection.Add(new MyRangeItem(1, 10));
            collection.Add(new MyRangeItem(20, 10));

            collection.RemoveNearest(0, 15);

            var result = collection.ToList();

            Assert.IsTrue(result[0].start == 20 && result[0].length == 10);

            collection.Remove(20, 1);
            Assert.IsTrue(collection.Count == 0);
        }
示例#6
0
        public void RemoveMids()
        {
            RangeCollection range = _SetupTestRemoveMerges();

            Assert.AreEqual(5, range.RangeCount);
            Assert.AreEqual(14, range.Ranges[3].Start);
            Assert.AreEqual(15, range.Ranges[3].End);
            Assert.AreEqual(true, range.Contains(9));
            range.Remove(9);
            Assert.AreEqual(false, range.Contains(9));
            Assert.AreEqual(6, range.RangeCount);
            Assert.AreEqual(7, range.Ranges[2].Start);
            Assert.AreEqual(8, range.Ranges[2].End);
            Assert.AreEqual(10, range.Ranges[3].Start);
            Assert.AreEqual(11, range.Ranges[3].End);
            Assert.AreEqual(14, range.Ranges[4].Start);
            Assert.AreEqual(15, range.Ranges[4].End);
        }
        public void RemoveTest()
        {
            RangeCollection c = new RangeCollection();

            c.Add(new AddressRange(0, 100));
            c.Remove(new AddressRange(50, 50));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(0, 49), c.Ranges[0], "#2");
            Assert.AreEqual(new AddressRange(51, 100), c.Ranges[1], "#3");

            c.Remove(new AddressRange(50, 55));
            Assert.AreEqual(2, c.Ranges.Count, "#4");
            Assert.AreEqual(new AddressRange(0, 49), c.Ranges[0], "#5");
            Assert.AreEqual(new AddressRange(56, 100), c.Ranges[1], "#6");

            c.Remove(new AddressRange(45, 60));
            Assert.AreEqual(2, c.Ranges.Count, "#7");
            Assert.AreEqual(new AddressRange(0, 44), c.Ranges[0], "#8");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#9");

            c.Remove(new AddressRange(45, 60));
            Assert.AreEqual(2, c.Ranges.Count, "#10");
            Assert.AreEqual(new AddressRange(0, 44), c.Ranges[0], "#11");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#12");

            c.Remove(new AddressRange(-100, 5));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(6, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#1");

            c.Remove(new AddressRange(6, 15));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(16, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#1");

            c.Remove(new AddressRange(70, 80));
            Assert.AreEqual(3, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(16, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61, 69), c.Ranges[1], "#1");
            Assert.AreEqual(new AddressRange(81, 100), c.Ranges[2], "#1");
        }
        public void RemoveTest()
        {
            RangeCollection c = new RangeCollection();
            c.Add(new AddressRange(0,100));
            c.Remove(new AddressRange(50, 50));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(0, 49), c.Ranges[0], "#2");
            Assert.AreEqual(new AddressRange(51, 100), c.Ranges[1], "#3");

            c.Remove(new AddressRange(50, 55));
            Assert.AreEqual(2, c.Ranges.Count, "#4");
            Assert.AreEqual(new AddressRange(0, 49), c.Ranges[0], "#5");
            Assert.AreEqual(new AddressRange(56, 100), c.Ranges[1], "#6");

            c.Remove(new AddressRange(45, 60));
            Assert.AreEqual(2, c.Ranges.Count, "#7");
            Assert.AreEqual(new AddressRange(0, 44), c.Ranges[0], "#8");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#9");

            c.Remove(new AddressRange(45, 60));
            Assert.AreEqual(2, c.Ranges.Count, "#10");
            Assert.AreEqual(new AddressRange(0, 44), c.Ranges[0], "#11");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#12");

            c.Remove(new AddressRange(-100, 5));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(6, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#1");

            c.Remove(new AddressRange(6, 15));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(16, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#1");

            c.Remove(new AddressRange(70, 80));
            Assert.AreEqual(3, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(16, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61,69), c.Ranges[1], "#1");
            Assert.AreEqual(new AddressRange(81, 100), c.Ranges[2], "#1");
        }
示例#9
0
        public void IndexesCacheGeneration ()
        {
            RangeCollection range = new RangeCollection ();
            int [] index_cache = range.Indexes;

            Assert.AreSame (index_cache, range.Indexes);

            range.Add (0);
            range.Add (5);

            if (index_cache == range.Indexes) {
                Assert.Fail ("Indexes Cache not regenerated after change");
            }

            index_cache = range.Indexes;
            range.Remove (0);
            range.Add (3);

            if (index_cache == range.Indexes) {
                Assert.Fail ("Indexes Cache not regenerated after change");
            }
        }
示例#10
0
        public void RemoveSingles ()
        {
            RangeCollection range = new RangeCollection ();
            int [] indexes = new int [] { 0, 2, 4, 6, 8, 10, 12, 14 };
            foreach (int index in indexes) {
                range.Add (index);
            }

            foreach (int index in indexes) {
                Assert.AreEqual (true, range.Remove (index));
            }
        }
        public void RemoveTest()
        {
            var c = new RangeCollection();
            c.Add(new AddressRange(0, 100));
            c.Remove(new AddressRange(50, 50));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 49), c.Ranges[0]);
            Assert.Equal(new AddressRange(51, 100), c.Ranges[1]);

            c.Remove(new AddressRange(50, 55));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 49), c.Ranges[0]);
            Assert.Equal(new AddressRange(56, 100), c.Ranges[1]);

            c.Remove(new AddressRange(45, 60));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(45, 60));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(-100, 5));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(6, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(6, 15));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(16, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(70, 80));
            Assert.Equal(3, c.Ranges.Count);
            Assert.Equal(new AddressRange(16, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 69), c.Ranges[1]);
            Assert.Equal(new AddressRange(81, 100), c.Ranges[2]);
        }