Example #1
0
        public void Default()
        {
            var range = new MultiRange();

            Assert.Equal(0, range.Count);
            Assert.Equal(new Range[0], range.GetRanges());
            Assert.False(range.Contains(42));
        }
Example #2
0
        public void AddRange_Empty()
        {
            var range = new MultiRange();

            range.Add(new Range(10, 20));

            Assert.Equal(10, range.Count);
            Assert.Equal(new[] { R(10, 20) }, range.GetRanges());
        }
Example #3
0
        public void Copy_Empty()
        {
            var range = new MultiRange();

            var copy = new MultiRange(range);

            Assert.Equal(0, copy.Count);
            Assert.Equal(new Range[0], copy.GetRanges());
            Assert.False(copy.Contains(42));
        }
Example #4
0
        public void Add()
        {
            var range = new MultiRange();

            range.Add(42);

            Assert.Equal(1, range.Count);
            Assert.Equal(new[] { R(42) }, range.GetRanges());
            Assert.True(range.Contains(42));
        }
Example #5
0
        public void RemoveRange_Mid()
        {
            var range = new MultiRange {
                10, 11, 12, 13, 14
            };

            range.Remove(new Range(11, 14));

            Assert.Equal(2, range.Count);
            Assert.Equal(new[] { R(10), R(14) }, range.GetRanges());
        }
Example #6
0
        public void Remove_End()
        {
            var range = new MultiRange {
                10, 11, 12
            };

            range.Remove(12);

            Assert.Equal(2, range.Count);
            Assert.Equal(new[] { R(10, 12) }, range.GetRanges());
        }
Example #7
0
        public void Remove_Mid()
        {
            var range = new MultiRange {
                10, 11, 12, 13, 14
            };

            range.Remove(12);

            Assert.Equal(4, range.Count);
            Assert.Equal(new[] { R(10, 12), R(13, 15) }, range.GetRanges());
        }
Example #8
0
        public void Remove_NotContained()
        {
            var range = new MultiRange {
                10, 11, 12
            };

            range.Remove(42);

            Assert.Equal(3, range.Count);
            Assert.Equal(new[] { R(10, 13) }, range.GetRanges());
        }
Example #9
0
        public void AddRange_OverlappedEnd()
        {
            var range = new MultiRange {
                10, 11, 12
            };

            range.Add(new Range(11, 15));

            Assert.Equal(5, range.Count);
            Assert.Equal(new[] { R(10, 15) }, range.GetRanges());
        }
Example #10
0
        public void AddRange_OverlappedBegin()
        {
            var range = new MultiRange {
                7, 8, 9
            };

            range.Add(new Range(5, 8));

            Assert.Equal(5, range.Count);
            Assert.Equal(new[] { R(5, 10) }, range.GetRanges());
        }
Example #11
0
        public void AddRange_Super()
        {
            var range = new MultiRange {
                10, 11
            };

            range.Add(new Range(5, 15));

            Assert.Equal(10, range.Count);
            Assert.Equal(new[] { R(5, 15) }, range.GetRanges());
        }
Example #12
0
        public void RemoveRange_Super()
        {
            var range = new MultiRange {
                10, 11, 12, 13, 14
            };

            range.Remove(new Range(8, 16));

            Assert.Equal(0, range.Count);
            Assert.Equal(new Range[0], range.GetRanges());
        }
Example #13
0
        public void RemoveRange_End()
        {
            var range = new MultiRange {
                10, 11, 12, 13, 14
            };

            range.Remove(new Range(13, 15));

            Assert.Equal(3, range.Count);
            Assert.Equal(new[] { R(10, 13) }, range.GetRanges());
        }
Example #14
0
        public void Add_Mid()
        {
            var range = new MultiRange();

            range.Add(10);
            range.Add(12);
            range.Add(11);

            Assert.Equal(3, range.Count);
            Assert.Equal(new[] { R(10, 13) }, range.GetRanges());
        }
Example #15
0
        public void Clear()
        {
            var range = new MultiRange {
                10, 11, 12, 23, 24, 25
            };

            range.Clear();

            Assert.Equal(0, range.Count);
            Assert.Equal(new Range[0], range.GetRanges());
        }
Example #16
0
        public void Add_End()
        {
            var range = new MultiRange {
                11
            };

            range.Add(12);

            Assert.Equal(2, range.Count);
            Assert.Equal(new[] { R(11, 13) }, range.GetRanges());
            Assert.True(range.Contains(12));
        }
Example #17
0
        public void Add_Begin()
        {
            var range = new MultiRange {
                11
            };

            range.Add(10);

            Assert.Equal(2, range.Count);
            Assert.Equal(new[] { R(10, 12) }, range.GetRanges());
            Assert.True(range.Contains(10));
        }
Example #18
0
        public void Copy()
        {
            var range = new MultiRange();

            range.Add(23);
            range.Add(42);

            var copy = new MultiRange(range);

            Assert.Equal(2, copy.Count);
            Assert.Equal(new[] { R(23), R(42) }, range.GetRanges());
        }
Example #19
0
        public void UnionWith_Empty2()
        {
            var range1 = new MultiRange {
                10, 11, 12
            };
            var range2 = new MultiRange();

            range1.UnionWith(range2);

            Assert.Equal(3, range1.Count);
            Assert.Equal(0, range2.Count);
            Assert.Equal(new[] { R(10, 13) }, range1.GetRanges());
            Assert.Empty(range2.GetRanges());
        }
Example #20
0
        public void AddRange_Multiple()
        {
            var range = new MultiRange();

            range.Add(new Range(20, 30));
            range.Add(new Range(15, 25));
            range.Add(new Range(25, 35));
            range.Add(new Range(10, 40));
            range.Add(new Range(40, 45));
            range.Add(new Range(50, 55));
            range.Add(new Range(5, 6));

            Assert.Equal(41, range.Count);
            Assert.Equal(new[] { R(5, 6), R(10, 45), R(50, 55) }, range.GetRanges());
        }
Example #21
0
        public void UnionWith_Overlapping()
        {
            var range1 = new MultiRange {
                10, 11, 12
            };
            var range2 = new MultiRange {
                11, 12, 13
            };

            range1.UnionWith(range2);

            Assert.Equal(4, range1.Count);
            Assert.Equal(3, range2.Count);
            Assert.Equal(new[] { R(10, 14) }, range1.GetRanges());
        }
Example #22
0
        public void UnionWith_Adjacent()
        {
            var range1 = new MultiRange {
                10, 11, 12
            };
            var range2 = new MultiRange {
                13, 14, 15
            };

            range1.UnionWith(range2);

            Assert.Equal(6, range1.Count);
            Assert.Equal(3, range2.Count);
            Assert.Equal(new[] { R(10, 16) }, range1.GetRanges());
        }
Example #23
0
        public void UnionWith_NonOverlapping()
        {
            var range1 = new MultiRange {
                23, 24, 25
            };
            var range2 = new MultiRange {
                10, 11, 12
            };

            range1.UnionWith(range2);

            Assert.Equal(6, range1.Count);
            Assert.Equal(3, range2.Count);
            Assert.Equal(new[] { R(10, 13), R(23, 26) }, range1.GetRanges());
        }
Example #24
0
        public void Add_OutOfOrder()
        {
            var range = new MultiRange();

            range.Add(23);
            range.Add(42);
            range.Add(10);

            Assert.Equal(3, range.Count);
            Assert.Equal(new[] { R(10), R(23), R(42) }, range.GetRanges());
            Assert.True(range.Contains(10));
            Assert.True(range.Contains(23));
            Assert.True(range.Contains(42));
            Assert.False(range.Contains(22));
            Assert.False(range.Contains(24));
        }
Example #25
0
        public void RemoveRange_Multiple(int begin, int end)
        {
            var range = new MultiRange {
                10, 11, 13, 14, 16, 17
            };
            var expected = new MultiRange(range);

            for (int i = begin; i < end; ++i)
            {
                expected.Remove(i);
            }

            range.Remove(new Range(begin, end));

            Assert.Equal(expected.Count, range.Count);
            Assert.Equal(expected.GetRanges(), range.GetRanges());
        }