Ejemplo n.º 1
0
        public void AllCharsSpaces()
        {
            ParseT9 parseT9 = new ParseT9();
            string  res     = parseT9.Process("a b c d e f g h i j k l m n o p q r s t u v w x y z ");

            Assert.That(res, Is.EqualTo("2022022203033033304044044405055055506066066607077077707777080880888090990999099990"));
        }
Ejemplo n.º 2
0
        public void LongRunning()
        {
            ParseT9 parseT9 = new ParseT9();
            string  res     = parseT9.Process("abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz ");

            Assert.That(res, Is.EqualTo("2 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 99990"));
        }
Ejemplo n.º 3
0
        public void ManyChars()
        {
            ParseT9 parseT9 = new ParseT9();
            string  res     = parseT9.Process("hello world");

            Assert.That(res, Is.EqualTo("4433555 555666096667775553"));
        }
Ejemplo n.º 4
0
        public void WithPrefix()
        {
            ParseT9 parseT9 = new ParseT9();
            string  res     = parseT9.Process("abc", 1);

            Assert.That(res, Is.EqualTo(StaticData.StartString + "1" + StaticData.MiddleString + "2 22 222"));
        }
Ejemplo n.º 5
0
        public void OneBadChar()
        {
            ParseT9 parseT9 = new ParseT9();
            string  res     = parseT9.Process("1");

            Assert.That(res, Is.EqualTo(""));
        }
Ejemplo n.º 6
0
        public void GoodAndBadChars()
        {
            ParseT9 parseT9 = new ParseT9();
            string  res     = parseT9.ProcessAsync("abc:-123").Result;

            Assert.That(res, Is.EqualTo("2 22 222"));
        }
Ejemplo n.º 7
0
        public void BadChar()
        {
            ParseT9 parseT9 = new ParseT9();

            string code = parseT9.GetCode('$');

            Assert.That(code, Is.EqualTo(""));
        }
Ejemplo n.º 8
0
        public void BadChar()
        {
            ParseT9 parseT9 = new ParseT9();

            CharStruct s = parseT9.GetCharStruct('%');

            Assert.That(s.Code, Is.EqualTo(""));
        }
Ejemplo n.º 9
0
        public void ManyChars()
        {
            ParseT9 parseT9 = new ParseT9();

            string res = parseT9.ProcessAsync("abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz ").Result;

            Assert.That(res, Is.EqualTo("2 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 999902 22 2223 33 3334 44 4445 55 5556 66 6667 77 777 77778 88 8889 99 999 99990"));
        }
Ejemplo n.º 10
0
        public void ParseT9_NeedSaveToFile()
        {
            ParseT9 parseT9 = new ParseT9();

            parseT9.NeedSaveToFile = true;

            Assert.That(parseT9.NeedSaveToFile, Is.EqualTo(true));
        }
Ejemplo n.º 11
0
        public void BadFilePathFile()
        {
            ParseT9 parseT9 = new ParseT9();

            bool res = parseT9.ProcessFile("");

            Assert.That(res, Is.EqualTo(false));
        }
Ejemplo n.º 12
0
        public void OneChar()
        {
            ParseT9 parseT9 = new ParseT9();

            string res = parseT9.ProcessAsync("a").Result;

            Assert.That(res, Is.EqualTo("2"));
        }
Ejemplo n.º 13
0
        public void ParseT9Constructor_OutFilePath()
        {
            string path = "1";

            ParseT9 parseT9 = new ParseT9(null, path);

            Assert.That(parseT9.OutFilePath, Is.EqualTo(path));
        }
Ejemplo n.º 14
0
        public void EmptyFile()
        {
            string  filePath = Test_StaticData.CreateAndFillFile("");
            ParseT9 parseT9  = new ParseT9();

            bool res = parseT9.ProcessFile(filePath);

            Assert.That(res, Is.EqualTo(true));
        }
Ejemplo n.º 15
0
        public void FileWithoutStringNumbers()
        {
            string  filePath = Test_StaticData.CreateAndFillFile("abc");
            ParseT9 parseT9  = new ParseT9();

            bool res = parseT9.ProcessFile(filePath);

            Assert.That(res, Is.EqualTo(false));
        }
Ejemplo n.º 16
0
        public void BadFormatFile()
        {
            ParseT9 parseT9 = new ParseT9();

            string filePath = Test_StaticData.CreateAndFillFile("abc");

            bool res = parseT9.ProcessFileAsync(filePath).Result;

            Assert.That(res, Is.EqualTo(false));
        }
Ejemplo n.º 17
0
        public void BigFile()
        {
            string filePath    = Test_StaticData.CreateAndFillFile(Test_StaticData.BigFileContent);
            string outFilePath = Test_StaticData.CreateAndFillFile();

            ParseT9 parseT9 = new ParseT9(filePath, outFilePath);
            bool    res     = parseT9.ProcessFile();

            //Сравниваем с эталонным хэшем файла - означает что конвертировали правильно
            string resultHash = Test_StaticData.GetFileHash(outFilePath);

            File.Delete(filePath);
            File.Delete(outFilePath);

            Assert.That(resultHash, Is.EqualTo(Test_StaticData.BigFileHash));
        }
Ejemplo n.º 18
0
        public void SmallFile()
        {
            string  fileContent = "2" + '\n' + "abc" + '\n' + "";
            string  filePath    = Test_StaticData.CreateAndFillFile(fileContent);
            ParseT9 parseT9     = new ParseT9();

            bool res = parseT9.ProcessFile(filePath);

            string retStr;

            parseT9.ResultConcurrentDictionary.TryGetValue(1, out retStr);

            File.Delete(filePath);

            Assert.That(retStr, Is.EqualTo(StaticData.StartString + "1" + StaticData.MiddleString + "2 22 222"));
        }
Ejemplo n.º 19
0
        public void SmallFile()
        {
            string fileContent = "2" + '\n' + "abc" + '\n' + "";
            string filePath    = Test_StaticData.CreateAndFillFile(fileContent);

            ParseT9 parseT9 = new ParseT9()
            {
                NeedSaveToFile = false
            };
            bool res = parseT9.ProcessFileAsync(filePath).Result;

            parseT9.OutFilePath = Path.GetTempFileName();
            parseT9.SaveToFile();

            Assert.That(File.Exists(parseT9.OutFilePath), Is.EqualTo(true));

            File.Delete(filePath);
            File.Delete(parseT9.OutFilePath);
        }
Ejemplo n.º 20
0
        public void BigFile()
        {
            string fileContent = Test_StaticData.BigFileContent;
            string filePath    = Test_StaticData.CreateAndFillFile(fileContent);

            ParseT9 parseT9 = new ParseT9()
            {
                NeedSaveToFile = false
            };
            bool res = parseT9.ProcessFileAsync(filePath).Result;

            parseT9.OutFilePath = Path.GetTempFileName();
            parseT9.SaveToFile();

            string resultHash = Test_StaticData.GetFileHash(parseT9.OutFilePath);

            File.Delete(filePath);
            File.Delete(parseT9.OutFilePath);

            Assert.That(resultHash, Is.EqualTo(Test_StaticData.BigFileHash));
        }
Ejemplo n.º 21
0
        private async void bStartProcess_Click(object sender, EventArgs e)
        {
            if (File.Exists(tbFilePath.Text))
            {
                ParseT9 parseT9 = new ParseT9(tbFilePath.Text, tbFilePath2.Text);

                bool res = await parseT9.ProcessFileAsync();

                if (res)
                {
                    MessageBox.Show("Готово");

                    Process.Start("notepad.exe", parseT9.OutFilePath);
                }
                else
                {
                    MessageBox.Show("Что-то не так");
                }
            }
            else
            {
                MessageBox.Show("Файл не найден");
            }
        }
Ejemplo n.º 22
0
Archivo: Program.cs Proyecto: iOgre/T9
        public static async Task Main(string[] args)
        {
            if (args == null)
            {
                Help();
                return;
            }


            var inputFileIndex  = Array.IndexOf(args, "-i") + 1;
            var outputFileIndex = Array.IndexOf(args, "-o") + 1;

            if (inputFileIndex == 0 || outputFileIndex == 0)
            {
                Help();
                return;
            }
            var inputFile = new FileInfo(args[inputFileIndex]);

            if (!inputFile.Exists)
            {
                Console.WriteLine($"Input file not found on path {inputFile.FullName}");
                return;
            }
            var  outputFile = new FileInfo(args[outputFileIndex]);
            bool overwrite  = Array.IndexOf(args, "/overwrite") != -1;

            if (outputFile.Exists && !overwrite)
            {
                Console.WriteLine($"Output file already exists on path {outputFile.FullName}");
                Console.WriteLine("Use /overwrite switch if you want to overwrite existing file");
                return;
            }
            ConversionSettings cs = ConversionSettings.Default;

            if (args.Any(t => t == "/lowercase"))
            {
                cs = cs | ConversionSettings.LowercaseAll;
            }

            if (args.Any(t => t == "/strict"))
            {
                cs = cs | ConversionSettings.FailOnUnconvertable;
            }
            var  parser  = new ParseT9(cs);
            bool success = true;

            try
            {
                using (var stream = inputFile.OpenText())
                {
                    Console.WriteLine($"Conversion started at {DateTime.Now.ToLongTimeString()}");
                    using (var writer = new StreamWriter(outputFile.FullName))
                    {
                        string currentString;
                        int    step = 0;
                        while ((currentString = await stream.ReadLineAsync()) != null)
                        {
                            // first line (step == 0) is number of test cases
                            if (step > 0)
                            {
                                var parsed = parser.Parse(currentString);
                                var output = $"Case #{step}: {parsed}";

                                await writer.WriteLineAsync(output);
                            }

                            step++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                _log.Error($"Exception occured during conversion");
                _log.Error($"{ex.Message}");
                _log.Error($"{ex.StackTrace}");
            }
            finally
            {
                if (success)
                {
                    Console.WriteLine($"Conversion ended at {DateTime.Now.ToLongTimeString()}");
                }
                else
                {
                    Console.WriteLine($"Conversion failed at {DateTime.Now.ToLongTimeString()}");
                    Console.WriteLine("Check logfile for detailed information");
                }
            }
        }
Ejemplo n.º 23
0
 public void Setup()
 {
     parser = new ParseT9();
 }
Ejemplo n.º 24
0
        public void ParseT9_Dictionary()
        {
            ParseT9 parseT9 = new ParseT9();

            Assert.IsNotNull(parseT9.ResultConcurrentDictionary);
        }
Ejemplo n.º 25
0
        public void ParseT9Constructor_WithoutPars()
        {
            ParseT9 parseT9 = new ParseT9();

            Assert.IsNotNull(parseT9);
        }