示例#1
0
        public void GetDigits_ReturnsSingleDigit()
        {
            var lines = separator.GetDigitsByLine(
                " _ " + "\n" +
                "I I" + "\n" +
                "I_I"
                ).ToList();

            lines.Should().HaveCount(1, "there's only a single line of digits in the string");

            var digits = lines[0].ToList();

            digits.Should().HaveCount(1, "There's only a single 3x3 cluster");
            digits.Single().Should().Be(" _ I II_I");
        }
示例#2
0
        /// <inheritdoc />
        public List <string> Scan(string input)
        => digitSeparator.GetDigitsByLine(input)
        // Transform each line by...
        .Select(
            line => {
            // Parsing every 3x3 chunk into digits
            var digitsInLine = line.Select(digit => digitScanner.Parse(digit)).ToList();

            // If all digits are valid, concatenate them into a string, otherwise => null
            return(digitsInLine.All(digit => digit != null)
                            ? digitsInLine.Cast <char>().JoinToString()
                            : null);
        })
        .ToList();