コード例 #1
0
        public void TestBoundaryLanguages(int k)
        {
            var lengthsBoundary = Enumerable.Range(1, 10).Select(n => n * 100).ToArray();
            var strategy        = new RemoveBorderStrategy();
            var e              = new RationalNumber(k, k - 1);
            var detector       = new RepetitionDetector(new StringBuilder(), e, false);
            var generator      = new RandomCharGenerator(k);
            var charsGenerated = 0;
            var times          = new List <long>();
            var coefs          = new List <double>();
            var sw             = Stopwatch.StartNew();

            foreach (var length in lengthsBoundary)
            {
                RandomWordGenerator.Generate(detector, length, strategy, generator);
                charsGenerated += RandomWordGenerator.Statistics.CharsGenerated;
                times.Add(sw.ElapsedMilliseconds);
                coefs.Add(charsGenerated * 1.0 / length);
            }
            sw.Stop();
            Console.WriteLine((string)"Alphabet size = {0}, e = {1}+", (object)k, (object)e);
            for (var i = 0; i < lengthsBoundary.Length; ++i)
            {
                Console.WriteLine("\tLength: {0}, Time: {1} ms, Conversion coeff: {2}", lengthsBoundary[i], times[i], coefs[i]);
            }
        }
コード例 #2
0
        private static void GenerateBoundaryUniform()
        {
            const int length    = 100000;
            const int runsCount = 100;

            using (var outputStream = File.Open(string.Format("D:\\statistics\\boundary_uniform_{0}.txt", length), FileMode.Create))
                using (var output = new StreamWriter(outputStream))
                {
                    output.WriteLine("k | coeff");

                    var removeStrategy = new RemoveBorderStrategy();
                    var logger         = new ConsoleTextLengthLogger(length / 100);
                    for (var k = 5; k <= 10; ++k)
                    {
                        Console.WriteLine("Conversion for k = {0}", k);
                        var text = new StringBuilder();

                        var e         = new RationalNumber(k, k - 1);
                        var generator = new RandomCharGenerator(k);
                        var detector  = new RepetitionDetector(text, e, false);

                        Calculate(runsCount, detector, length, removeStrategy, generator, logger, output);
                    }
                }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            RandomCharGenerator  Char  = new RandomCharGenerator();
            RandomBytesGenerator Bytes = new RandomBytesGenerator();

            Char.GenerateFiles(2, 3);
            Bytes.GenerateFiles(2, 3);
        }
コード例 #4
0
        public void Test(int alphabet, int numerator, int denominator, bool detectEqual, Type detectorType, int length)
        {
            var generator = new RandomCharGenerator(alphabet);
            var detector  = GetDetector(detectorType, detectEqual, new RationalNumber(numerator, denominator));

            detector.Reset();
            var sw = Stopwatch.StartNew();

            RandomWordGenerator.Generate(detector, length, new RemoveBorderStrategy(), generator);
            sw.Stop();
            Console.WriteLine("Length: {0}\n\tTime: {1} ms\n\tConversion coeff: {2:0.000000}", length, sw.ElapsedMilliseconds, RandomWordGenerator.Statistics.CharsGenerated * 1.0 / length);
        }
コード例 #5
0
        public void Should_Return_Minimum_Count_Of_Chars()
        {
            IRandomCharGenerator     randomCharGenerator = new RandomCharGenerator();
            Dictionary <char, int[]> lookupTable         = new Dictionary <char, int[]>();

            lookupTable.Add('a', new int[] { 0, 1, 1, 1, 1 });
            lookupTable.Add('b', new int[] { 1, 0, 1, 1, 1 });
            lookupTable.Add('c', new int[] { 1, 1, 0, 1, 1 });
            lookupTable.Add('d', new int[] { 1, 1, 1, 0, 1 });
            lookupTable.Add('e', new int[] { 1, 1, 1, 1, 0 });
            Assert.AreEqual('a', randomCharGenerator.GetRandomCharFromArray(lookupTable, 0));
            Assert.AreEqual('b', randomCharGenerator.GetRandomCharFromArray(lookupTable, 1));
            Assert.AreEqual('c', randomCharGenerator.GetRandomCharFromArray(lookupTable, 2));
            Assert.AreEqual('d', randomCharGenerator.GetRandomCharFromArray(lookupTable, 3));
            Assert.AreEqual('e', randomCharGenerator.GetRandomCharFromArray(lookupTable, 4));
        }
コード例 #6
0
        private string SaveImages(HttpPostedFileBase image, string imagesDir)
        {
            string fileName = string.Empty;

            try
            {
                string uniqueCode             = RandomCharGenerator.RandomString(5, false);
                string preFileName            = uniqueCode + "_";
                bool   isServerImagesDirExist = System.IO.Directory.Exists(imagesDir);

                if (!isServerImagesDirExist)
                {
                    System.IO.Directory.CreateDirectory(imagesDir);
                }

                //string destinationDir = Path.Combine(imagesDir, destinatioFolderName);

                //bool isPathDirectoryExist = System.IO.Directory.Exists(destinationDir);

                //if (!isPathDirectoryExist)
                //{
                //    System.IO.Directory.CreateDirectory(destinationDir);
                //}

                fileName = preFileName + "_" + Path.GetFileName(image.FileName);
                //string path = Path.Combine(destinationDir, fileName);

                string path = Path.Combine(imagesDir, fileName);

                image.SaveAs(path);
            }
            catch (Exception)
            {
                throw;
            }

            return(fileName);;
        }