示例#1
0
        public void SpanSetContainedGetIntersecting1()
        {
            var set   = new SpanSet <int>(deleteZeroLengthSpans: false);
            var spans = new List <Span>();

            ValidateAddSpan(Span.FromBounds(10, 13), spans, ref set);
            ValidateAddSpan(Span.FromBounds(10, 13), spans, ref set);

            int iteration = 0;

            for (int i = 9; (i <= 14); ++i)
            {
                for (int j = i; (j <= 14); ++j)
                {
                    ValidateGetIntersecting(Span.FromBounds(i, j), spans, set, ++iteration);
                }
            }
        }
示例#2
0
        private void ValidateAddSpan(Span span, List <Span> spans, ref SpanSet <int> set)
        {
            int iteration = spans.Count;

            set = set.Add(span, spans.Count);
            spans.Add(span);

            Assert.IsTrue(set.IsValid(int.MaxValue), "DTI failed iteration {0}", iteration);

            var returned = new HashSet <int>();

            foreach (var s in set.GetAllSpans())
            {
                Assert.IsTrue(returned.Add(s.Data), "Duplicate span {0} {1}", s, iteration);
                Assert.AreEqual(spans[s.Data], s.Span, "Incorrect span {0} {1}", s, iteration);
            }

            Assert.AreEqual(spans.Count, returned.Count, "Incorrect count {0}", iteration);
        }
示例#3
0
        private void BuildAndValidateRandom(Random r,
                                            bool deleteZeroLengthSpans,
                                            int numberOfSpans, int maxSpanLength, int maxLength,
                                            out SpanSet <int> set, out List <Span> spans)
        {
            set   = new SpanSet <int>(deleteZeroLengthSpans);
            spans = new List <Span>();

            for (int i = 0; (i < numberOfSpans); ++i)
            {
                // generate spans with the following constraints
                //      start  in [1, maxLength]
                //      end    in [1, maxLength]
                //      length in [deleteZeroLengthSpans ? 1 : 0, maxSpanLength]
                int l = deleteZeroLengthSpans ? (r.Next(maxSpanLength) + 1) : r.Next(maxSpanLength + 1);
                var s = r.Next(maxLength - l - 1) + 1;

                var span = new Span(s, l);
                ValidateAddSpan(span, spans, ref set);
            }
        }
示例#4
0
        private void ValidateGetIntersecting(Span span, List <Span> spans, SpanSet <int> set, int iteration)
        {
            var intersecting = new HashSet <int>();

            for (int i = 0; (i < spans.Count); ++i)
            {
                var s = spans[i];
                if (span.IntersectsWith(s))
                {
                    intersecting.Add(i);
                }
            }

            foreach (var s in set.GetSpansIntersecting(span))
            {
                Assert.IsTrue(intersecting.Remove(s.Data), "Unexpected span {0} {1}", s, iteration);
                Assert.AreEqual(spans[s.Data], s.Span, "Incorrect span {0} {1}", s, iteration);
            }

            Assert.AreEqual(0, intersecting.Count, "Incorrect count {0}", iteration);
        }
示例#5
0
        public void SpanSetNestedGetIntersecting()
        {
            var set   = new SpanSet <int>(deleteZeroLengthSpans: false);
            var spans = new List <Span>();

            ValidateAddSpan(Span.FromBounds(10, 20), spans, ref set);
            for (int d = 1; (d < 5); ++d)
            {
                ValidateAddSpan(Span.FromBounds(10 + d, 20 - d), spans, ref set);
            }

            int iteration = 0;

            for (int i = 9; (i <= 21); ++i)
            {
                for (int j = i; (j <= 21); ++j)
                {
                    ValidateGetIntersecting(Span.FromBounds(i, j), spans, set, ++iteration);
                }
            }
        }