コード例 #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();
        }
コード例 #2
0
        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));
        }
コード例 #3
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]);
        }
コード例 #4
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));
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: DifferFacts.cs プロジェクト: tongtree27/diffplex
            public IEnumerator <object[]> GetEnumerator()
            {
                for (int i = 0; i < count; i++)
                {
                    int[] a, b;
                    int   editLength;
                    generator.Generate(out a, out b, out editLength);

                    yield return(new object[] { a, b, editLength });
                }
            }
コード例 #7
0
ファイル: Tests.cs プロジェクト: unrealdst/TestArray
        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));
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine(string.Join(" ", ArrayGenerator.Generate(10, false, 1, 11)));

            Console.WriteLine();

            var array = ArrayGenerator.Generate(10, true, 1, 151);

            Console.WriteLine(string.Join(" ", array));

            var result = new int[0];
            var ticks  = 0L;

            array = new[] { 5, 4, 3, 2, 1, 6, 6, 7, 2, 8, 9, 3 };

//            var time = PerformanceAnalyzer.GetExecutionTime(() => result = new Bogosort<int>().SortDebug(array, ListSortDirection.Ascending, out ticks));

//            Console.WriteLine($"Random sort:\n{string.Join(" ", result)} for {time.Milliseconds} ms; {ticks} iterations");

//            var time = PerformanceAnalyzer.GetExecutionTime(() => result = new BruteForceSort<int>().SortDebug(array, ListSortDirection.Ascending, out ticks));

//            Console.WriteLine($"Brute force sort:\n{string.Join(" ", result)} for {time.Milliseconds} ms; {ticks} iterations");

            var time = PerformanceAnalyzer.GetExecutionTime(() => result = new PancakeSort <int>().Sort(array, ListSortDirection.Ascending));

            Console.WriteLine($"Brute force sort:\n{string.Join(" ", result)} for {time.Milliseconds} ms; {ticks} iterations");

            /*var busted = new int[array.Length];
             *
             * var count = 0;
             *
             * Bust(busted, array, 0, ref count);*/

//            Console.WriteLine($"Total combinations: {count}");

/*              array.Shuffle();
 *          Console.WriteLine(string.Join(" ", array));
 *
 *          array.Shuffle(1);
 *          Console.WriteLine(string.Join(" ", array));*/

            Console.ReadLine();
        }
コード例 #9
0
 public void generate_int_unique_exception_test()
 {
     Assert.ThrowsException <InvalidOperationException>(() => ArrayGenerator.Generate(3, false, 1, 3));
 }
コード例 #10
0
        /// <summary>
        /// Reads the given amount of characters, and treats
        /// the read characters as a string.  The string should
        /// not be null terminated.
        /// </summary>
        public static string ReadStringOfLength(this BinaryReader reader, int length)
        {
            var data = ArrayGenerator.Generate(length, i => reader.ReadByte());

            return(Encoding.UTF8.GetString(data, 0, data.Length));
        }
コード例 #11
0
        public void TestGenerateEmpty()
        {
            var php = _generator.Generate(new ArrayStatement(new Dictionary <IStatement, IStatement>()));

            Assert.AreEqual("array()", php);
        }
 private Segment <T> CreateSegment()
 {
     return(new Segment <T>(ArrayGenerator.Generate(kBucketSize, i => new Segment <T> .Box <T>()), sentinelEnd));
 }