Exemplo n.º 1
0
        public void TestSmallestRangeUsingListWithduplicates()
        {
            // Arrange
            var rangeFinder = new SmallestRangeWithList();

            var input = new List <int[]>()
            {
                new int[] { 4, 7, 10, 12, 12, 12, 15 },
                new int[] { 0, 8, 9, 14, 14, 14, 20 },
                new int[] { 5, 11, 14, 15, 16, 30, 50 }
            };

            // Act
            var result = rangeFinder.SmallestRange(input, input[0].Length, input.Count);

            // Assert
            Assert.Equal(new int[] { 9, 11 }, result);
        }
Exemplo n.º 2
0
        static void Main(string [] args)
        {
            var largeCollection = new List <int[]>();
            var n = 50;
            var k = 1000;

            Random rnd = new Random();

            for (int i = 0; i < k; i++)
            {
                var next = new List <int>();

                for (int j = 0; j < n; j++)
                {
                    next.Add(rnd.Next());
                }

                next.Sort();

                largeCollection.Add(next.ToArray());
            }

            var smallestRangeFinderWithList = new SmallestRangeWithList();
            var smallestRangeFinderWithHeap = new SmallestRangeWithHeap();

            var watch = new Stopwatch();

            watch.Start();
            smallestRangeFinderWithList.SmallestRange(largeCollection, n, k);
            watch.Stop();

            Console.Out.WriteLine($"Completed list search in {watch.Elapsed}");

            watch.Reset();

            watch.Start();
            smallestRangeFinderWithHeap.SmallestRange(largeCollection, n, k);
            watch.Stop();

            Console.Out.WriteLine($"Completed heap search in {watch.Elapsed}");
        }