Ejemplo n.º 1
0
        public void Stress_Test()
        {
            const int iterations = 100;
            var       random     = new Random(0);
            var       selection  = new List <IndexRange>();
            var       expected   = new List <int>();

            IndexRange Generate()
            {
                var start = random.Next(100);

                return(new IndexRange(start, start + random.Next(20)));
            }

            for (var i = 0; i < iterations; ++i)
            {
                var toAdd = random.Next(5);

                for (var j = 0; j < toAdd; ++j)
                {
                    var range = Generate();
                    IndexRange.Add(selection, range);

                    for (var k = range.Begin; k <= range.End; ++k)
                    {
                        if (!expected.Contains(k))
                        {
                            expected.Add(k);
                        }
                    }

                    var actual = IndexRange.EnumerateIndices(selection).ToList();
                    expected.Sort();
                    Assert.Equal(expected, actual);
                }

                var toRemove = random.Next(5);

                for (var j = 0; j < toRemove; ++j)
                {
                    var range = Generate();
                    IndexRange.Remove(selection, range);

                    for (var k = range.Begin; k <= range.End; ++k)
                    {
                        expected.Remove(k);
                    }

                    var actual = IndexRange.EnumerateIndices(selection).ToList();
                    Assert.Equal(expected, actual);
                }

                selection.Clear();
                expected.Clear();
            }
        }