Ejemplo n.º 1
0
        public void RunBenchmark <T>(Func <T> get, Action <T> put)
        {
            const int threadCount = 8;
            const int putGetCount = 200000;

            var readyEvent = new CountdownEvent(threadCount);
            var beginEvent = new CountdownEvent(1);
            var doneEvent  = new CountdownEvent(threadCount);
            var threads    = ArrayGenerator.Generate(threadCount,
                                                     threadNumber => new Thread(() => {
                readyEvent.Signal();
                beginEvent.Wait();
                for (var i = 0; i < putGetCount; i++)
                {
                    put(get());
                }
                doneEvent.Signal();
            }));

            threads.ForEach(t => t.Start());

            readyEvent.Wait();
            beginEvent.Signal();
            doneEvent.Wait();
        }
Ejemplo n.º 2
0
 public void Setup()
 {
     this.binarySearch   = new BinarySearch();
     this.arrayGenerator = new ArrayGenerator();
     this.arrayGenerator.AscendGenerator(this.Length);
     this.testArray = this.arrayGenerator.output;
 }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     ConsoleHelper.WriteText($"Greetings!\nThis programm generates the random one-dimensional array and calculates sum of its non-negative values.\n");
     int[] array = ArrayGenerator.GenerateOneDimensional();
     ArrayProcessor.CalculateNonNegativeSumm(array);
     ConsoleHelper.PressAnyKey();
 }
        private void GenerateArray(SourceGeneratorContext context, INamedTypeSymbol type)
        {
            var structure = new JsonArray(type);
            var code      = ArrayGenerator.Generate(structure);

            context.AddSource($"{type.Name}.Generated.cs", SourceText.From(code, Encoding.UTF8));
        }
Ejemplo n.º 5
0
 public static int CountCompareOperations(int arraySize, int maxValue, int key, CommonSearching searching)
 {
     int[] array = ArrayGenerator.GenerateArray(arraySize, maxValue);
     Array.Sort(array);
     searching(array, key);
     return(Searching.Comparings);
 }
        public void MergeSort_RandomArray_ArrayIsSorted(int amountOfGeneratedValues)
        {
            var array = ArrayGenerator.GetRandomSequence(amountOfGeneratedValues, -1000, 1000);

            array.MergeSort();
            Assert.That(array, Is.Ordered);
        }
Ejemplo n.º 7
0
        public static int[] GetRandomNumbers(int length)
        {
            var generator = new ArrayGenerator(length);

            generator.generate();
            return(generator.GetArray());
        }
 public void Setup()
 {
     this.interpolationSearch = new InterpolationSearch();
     this.arrayGenerator      = new ArrayGenerator();
     this.arrayGenerator.AscendGenerator(this.Length);
     this.testArray = this.arrayGenerator.output;
 }
Ejemplo n.º 9
0
        public void QuickSort_RandomArray_ArrayIsSorted(int amountOfElements)
        {
            var array = ArrayGenerator.GetRandomSequence(amountOfElements, -10000, 10000);

            array.QuickSort();
            Assert.IsTrue(array.IsOrdered());
        }
Ejemplo n.º 10
0
        public void MergeSort_RandomArray_ArrayIsSorted(int amountOfElements)
        {
            var array = ArrayGenerator.GetRandomSequence(amountOfElements, int.MinValue, int.MaxValue);

            array.MergeSort();
            Assert.IsTrue(array.IsOrdered());
        }
Ejemplo n.º 11
0
 static void Main(string[] args)
 {
     ConsoleHelper.WriteText($"Greetings!\nThis programm generates the random two-dimensional array and finds summ of even values.\n");
     int[,] array = ArrayGenerator.GenerateTwoDimensional();
     ArrayProcessor.CalculateSummOfEven(array);
     ConsoleHelper.PressAnyKey();
 }
Ejemplo n.º 12
0
 public void Setup()
 {
     this.sequentialSearch = new SequentialSearch();
     this.arrayGenerator   = new ArrayGenerator();
     this.arrayGenerator.AscendGenerator(this.Length);
     this.testArray = this.arrayGenerator.output;
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            ArrayGenerator generator  = new ArrayGenerator();
            List <int>     randomList = generator.GenerateArray(10000);

            Out(randomList);
            Console.ReadKey();
        }
        public void GetMaxElement_RandomArray_ReturnMaxValue(int amountOfGeneratedValues)
        {
            var randomizedArray = ArrayGenerator.GetRandomSequence(amountOfGeneratedValues, -10000, 10000);
            int expected        = randomizedArray.Max();
            int actual          = randomizedArray.GetMaxElement();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public void generate_int_not_unique_test()
        {
            var arr = ArrayGenerator.Generate(3, true, 2, 2);

            Assert.AreEqual(2, arr[0]);
            Assert.AreEqual(2, arr[1]);
            Assert.AreEqual(2, arr[2]);
        }
Ejemplo n.º 16
0
        public void generate_int_unique_test()
        {
            var arr = ArrayGenerator.Generate(3, false, 1, 4);

            Assert.IsTrue(arr.Contains(1));
            Assert.IsTrue(arr.Contains(2));
            Assert.IsTrue(arr.Contains(3));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Generate next path.
        /// </summary>
        /// <returns>
        /// An array containing a single <see cref="Path"/>,
        /// wrapped in a (possibly weighted) <see cref="Sample"/>.
        /// </returns>
        public override Sample Next()
        {
            var paths  = new Path[1];
            var sample = ArrayGenerator.NextSample();  // get a weighted SparseVector

            paths[0] = new Path(Times, Drift[0], (SparseVector)sample.Value);
            return(new Sample(paths, sample.Weight));
        }
Ejemplo n.º 18
0
 static void Main(string[] args)
 {
     ConsoleHelper.WriteText($"Greetings!\nThis programm generates and sorts the random three-dimensional array and replaces all positive values with 0\n");
     int[, ,] array = ArrayGenerator.GenerateThreeDimensional();
     ConsoleHelper.WriteText($"Press any key to replace...");
     ConsoleHelper.PressAnyKey();
     ArrayProcessor.ReplaceAllPositive(array);
     ConsoleHelper.PressAnyKey();
 }
Ejemplo n.º 19
0
 static void Main(string[] args)
 {
     ConsoleHelper.WriteText($"Greetings!\nThis programm generates and sorts the random one-dimensional array and finds it min/max values.\n");
     int [] array = ArrayGenerator.GenerateOneDimensional();
     ArrayProcessor.FindMax(array);
     ArrayProcessor.FindMin(array);
     ArrayProcessor.BubbleSort(array);
     ConsoleHelper.PressAnyKey();
 }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            int[,] numbers = ArrayGenerator.GetRandomArray(10, 10);
            BubbleSorter sorter = new BubbleSorter();

            ArrayWriter.WriteArray(numbers, "Original Array");
            ArrayWriter.WriteArray(sorter.Sort(numbers, out double timer), "Sorted Array with time " + timer);
            Console.ReadLine();
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            var array     = new ArrayGenerator(1024, 1024, 1, 0, 10).GenerateTestArrays().First();
            var inputRdd  = new FromMemoryRdd <int>(array);
            var mapRdd    = inputRdd.MapToPair(i => new Tuple <int, int>(i, 1));
            var reduceRdd = mapRdd.ReduceByKey((i1, i2) => i1 + i2);

            var result = new RDDProcessor <int, Tuple <int, int> >().Process(reduceRdd).ToArray();
        }
        public void GenerateRandomArrayTests(int count, double maxValue)
        {
            var generator = new ArrayGenerator();
            var array     = generator.GenerateRandomArray(count, maxValue);

            Assert.AreEqual(count, array.Length);
            Assert.That(array, Is.All.InRange(0d, maxValue));
            Assert.AreEqual(1d, array.Sum(), Delta);
        }
Ejemplo n.º 23
0
        public void generate_generics_test()
        {
            var moq = new Mock <IArrayItemGenerator <IComparable <object> > >();

            moq.Setup(m => m.GenerateNext()).Returns(It.IsAny <IComparable <object> >());

            var arr = ArrayGenerator.Generate(10, moq.Object);

            Assert.AreEqual(10, arr.Length);
        }
Ejemplo n.º 24
0
        static void SortingTest()
        {
            var arrayLength = 100;

            int[] arrayForBubleSort     = null;
            int[] arrayForSelectionSort = null;
            int[] arrayForInsertionSort = null;

            Console.WriteLine($"Sorting test for {arrayLength} numbers:");
            var arrayBase = new ArrayGenerator().Generate(arrayLength, 0, 100);
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            var arrayForBeingSort = ArrayGenerator.GetRandomNumberList(100, 0, 1000);

            Console.WriteLine($"Before Sort:{string.Join(",", arrayForBeingSort)}");

            Sort(arrayForBeingSort, 0, arrayForBeingSort.Count - 1);

            Console.WriteLine($"After Sort:{string.Join(",", arrayForBeingSort)}");

            Console.ReadKey();
        }
Ejemplo n.º 26
0
        public void GeneratedTest()
        {
            var arrays = new ArrayGenerator(10000, 500, 1).GenerateTestArrays();

            foreach (var array in arrays)
            {
                var arrayCopy = (int[])array.Clone();

                var arrayResult = mScan.Scan(array);
                var arrayTest   = mScanCheck.Scan(arrayCopy);
                Assert.AreEqual(arrayTest, arrayResult);
            }
        }
    private void OnArraySizeChanged(float value)
    {
        m_ArraySizeSlider.value = (int)value;

        if ((int)value != m_ArraySize)
        {
            m_ArraySize             = (int)value;
            m_ArraySizeGUIText.text = m_ArraySize.ToString();

            // size of this array will be set from given slider
            BarsManager.Instance.SetValues(
                ArrayGenerator.CreateRandomArray(m_ArraySize, m_MinimumRange, m_MaximumRange), this);
        }
    }
Ejemplo n.º 28
0
        public void GeneratedTest()
        {
            var arrays = new ArrayGenerator(100, 1000, 1).GenerateTestArrays();
            var sort   = new NaiveTplParallelMergeMergeSort();

            foreach (var array in arrays)
            {
                var result = sort.Sort(array);
                var ls     = result.ToList();
                ls.Sort();
                var expectedResult = ls.ToArray();
                Assert.AreEqual(expectedResult, result);
            }
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            int arraysNum = 30;
            int arraySize = 5000;
            int maxValue  = 500;
            int tableSize = 2000;

            int[][]  arrays   = ArrayGenerator.GenerateArrays(arraysNum, arraySize, maxValue);
            double[] constans = new[]
            {
                0.6180339887,
                0.33333333,
                0.5,
                0.125,
                0.9131654,
                1
            };

            Console.WriteLine(
                $"Arrays number = {arraysNum}, each array size = {arraySize},\n"
                + $"maximal value = {maxValue}, table size = {tableSize}.\n"
                );
            for (int i = 0; i < constans.Length; i++)
            {
                if (i == 0)
                {
                    Console.WriteLine("--------------\n\nStandart constant is ((Math.Sqrt(5) - 1) / 2)");
                }
                Console.WriteLine(
                    $"Test for A = {constans[i]}\n" +
                    $"   In average chains have maximum length of " +
                    $"{GetAverageMaxChainLength(constans[i], tableSize, arrays)}\n"
                    );
                if (i == 0)
                {
                    Console.WriteLine("--------------\n\nSelecting better constant:\n");
                }
            }

            Console.WriteLine("--------------\n");
            double calculatedA = GetTheBestConst(tableSize, arrays, 10);

            Console.WriteLine(
                $"Calculated constant is {calculatedA}\n" +
                $"In average chains with that A have maximum length " +
                $"of {GetAverageMaxChainLength(calculatedA, tableSize, arrays)}"
                );
            Console.WriteLine("\n--------------");
            Console.ReadKey();
        }
Ejemplo n.º 30
0
        public void TestArray()
        {
            int testFrom = 1, testTo = 1000;
            var testResults = new List <TestResult>();
            var generator   = new ArrayGenerator();

            for (int i = testFrom; i < testTo; i++)
            {
                int[] result = generator.Generate(i);

                testResults.Add(CheckResult(result, i));
            }

            Assert.IsTrue(testResults.All(x => x.ArraySize == x.ExpectedSize), CreateFailMessage(testResults, "ExpectedSize", x => x.ArraySize != x.ExpectedSize));
            Assert.IsTrue(testResults.All(x => x.SumToZero), CreateFailMessage(testResults, "SumToZero", x => !x.SumToZero));
            Assert.IsTrue(testResults.All(x => x.AllDifferent), CreateFailMessage(testResults, "AllDifferent", x => !x.AllDifferent));
        }