コード例 #1
0
ファイル: Program.cs プロジェクト: mamasha/tests
        private static void ConvertFile(string rootFolder, string inFile, string outFile)
        {
            var digitCodes = BuildDigitCodes(DigitPatterns);

            var config = new AsciiNumber.Config {
                NoOfDigits = 9,
                ValidChars = ValidChars,
                DigitCodes = digitCodes
            };

            var inPath  = Path.Combine(rootFolder, inFile);
            var outPath = Path.Combine(rootFolder, outFile);

            var lines     = File.ReadAllLines(inPath);  // read them all for now; can be read line line if file is big
            var lineCount = lines.Length;

            Console.WriteLine($"Processing '{inFile}' ({lineCount} lines) into '{outFile}'");

            if (lineCount % 4 != 0)
            {
                throw new ApplicationException($"Wrong line count {lineCount} in '{inFile}'; should be modulo of four");
            }

            var numbers = new List <string>();

            for (int next = 0; next < lineCount;)
            {
                var ascii = AsciiNumber.New(config, next); // number of 9 digits at next line no

                ascii.PushLine(lines[next++]);             // fragment of three line
                ascii.PushLine(lines[next++]);
                ascii.PushLine(lines[next++]);
                next++;                                 // skip empty line

                var number = ascii.Number;

                if (ascii.IsValid == false)
                {
                    number += " ILLEGAL";
                }

                numbers.Add(number);
            }

            Console.WriteLine($"Parsed {numbers.Count} numbers");

            File.WriteAllLines(outPath, numbers);
        }
コード例 #2
0
ファイル: UnitTests.cs プロジェクト: mamasha/tests
        public void parse_line_of_all_digits()
        {
            var patterns   = Program.DigitPatterns;
            var validChars = Program.ValidChars;

            var digitCodes = Program.BuildDigitCodes(patterns);

            var config = new AsciiNumber.Config {
                NoOfDigits = 10,
                ValidChars = validChars,
                DigitCodes = digitCodes
            };

            var ascii = AsciiNumber.New(config, 0);

            ascii.PushLine("    _  _     _  _  _  _  _  _ ");
            ascii.PushLine("  | _| _||_||_ |_   ||_||_|| |");
            ascii.PushLine("  ||_  _|  | _||_|  ||_| _||_|");

            var number = ascii.Number;

            Assert.That(number, Is.EqualTo("1234567890"));
        }