Esempio n. 1
0
        public HeapsTestSuite()
        {
            _startingValuesSmall        = InputGenerator.GenerateRandomInts(_startingValuesCountSmall);
            _startingKeyValuePairsSmall = _startingValuesSmall
                                          .Select(v => new KeyValuePair <int, int>(++_key, v))
                                          .ToList();
            _key = 0;
            _startingValuesBig        = InputGenerator.GenerateRandomInts(_startingValuesCountBig);
            _startingKeyValuePairsBig = _startingValuesBig
                                        .Select(v => new KeyValuePair <int, int>(++_key, v))
                                        .ToList();
            _randomOperations = InputGenerator.GenerateRandomInts(_randomOperationsCount, 1, 4);
            _randomValues     = InputGenerator.GenerateRandomInts(_randomOperationsCount);

            var randomPrimOperations  = new List <Tuple <int, int> >();
            int extractOperationCount = 0;
            var rand = InputGenerator.Rand;

            while (extractOperationCount != _startingValuesCountBig)
            {
                int operation = rand.Next(1, 6 + 1);
                if (operation == 1)
                {
                    ++extractOperationCount;
                    randomPrimOperations.Add(null);
                }
                else
                {
                    randomPrimOperations.Add(Tuple.Create(rand.Next(1, _startingValuesCountBig + 1), rand.Next()));
                }
            }
            _randomPrimOperations = randomPrimOperations;
        }
        public void MergeSortedArrays()
        {
            CollectionAssert.AreEqual(new int[0],
                                      IEnumerableHelper.MergeSortedArrays(new int[0], new int[0]));

            CollectionAssert.AreEqual(new[] { 1 },
                                      IEnumerableHelper.MergeSortedArrays(new[] { 1 }, new int[0]));
            CollectionAssert.AreEqual(new[] { 1 },
                                      IEnumerableHelper.MergeSortedArrays(new int[0], new[] { 1 }));

            CollectionAssert.AreEqual(new[] { 1, 1 },
                                      IEnumerableHelper.MergeSortedArrays(new int[0], new[] { 1, 1 }));
            CollectionAssert.AreEqual(new[] { 1, 1, 1 },
                                      IEnumerableHelper.MergeSortedArrays(new[] { 1 }, new[] { 1, 1 }));

            CollectionAssert.AreEqual(new[] { 1, 1, 2, 2, 3, 3, 4, 4 },
                                      IEnumerableHelper.MergeSortedArrays(new[] { 1, 1, 2, 3, 4, 4 }, new[] { 2, 3 }));

            for (int i = 0; i < 100; ++i)
            {
                for (int j = 0; j < 100; ++j)
                {
                    var firstArray  = InputGenerator.GenerateRandomInts(i);
                    var secondArray = InputGenerator.GenerateRandomInts(i);
                    Array.Sort(firstArray);
                    Array.Sort(secondArray);

                    CollectionAssert.AreEqual(firstArray.Concat(secondArray).OrderBy(v => v).ToArray(),
                                              IEnumerableHelper.MergeSortedArrays(firstArray, secondArray));
                }
            }
        }
Esempio n. 3
0
        public BinaryIndexedTreesTestSuite()
        {
            _array = InputGenerator.GenerateRandomInts(_arraySize, -1000, 1000);

            var rand         = InputGenerator.Rand;
            var randomRanges = new Tuple <int, int> [_randomRangesCount];

            for (int i = 0; i < _randomRangesCount; ++i)
            {
                int firstIndex  = rand.Next(0, _arraySize);
                int secondIndex = rand.Next(0, _arraySize);

                randomRanges[i] = Tuple.Create(
                    Math.Min(firstIndex, secondIndex),
                    Math.Max(firstIndex, secondIndex));
            }

            _randomRanges = randomRanges;
        }
        public void DoesntGenerateDistinctRandomInts()
        {
            int[] ints = InputGenerator.GenerateRandomInts(1000, 1, 999);

            Assert.IsTrue(!ints.SequenceEqual(ints.Distinct()));
        }