Ejemplo n.º 1
0
        public void Give_passeports_separate_by_blank_lines()
        {
            //Given
            const string batchFileDescription   = BatchFileDescription.PartOneExampleDescription;
            const int    expectedPassportsCount = 4;

            //When
            var passportsCount = PassportParser.ParseBatchFile(batchFileDescription).Count();

            //Then
            Assert.Equal(expectedPassportsCount, passportsCount);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var input = ReadFromFile("input.txt");
            //var input = TestInput();
            var passportTokens = InputTokenizer.Tokenize(input);
            Console.WriteLine("passports found: " + passportTokens.Count);

            var passports = passportTokens.Select(x => PassportParser.Parse(x)).ToList();

            Console.WriteLine("Passports with all fields: " + passports.Count(x => x.ValidateFieldsExist()));
            Console.WriteLine("Passports with valid fields: " + passports.Count(x => x.ValidateFieldsValid()));
        }
Ejemplo n.º 3
0
        public void Give_passeport_field_informations_separate_by_colon(
            string passportFieldDescription,
            string expectedPassportFieldName,
            string expectedPassportFieldValue)
        {
            // Given
            var expectedPassportFieldInformation = new PassportFieldInformation(
                expectedPassportFieldName,
                expectedPassportFieldValue);

            //When
            var actualPassportFieldInformation = PassportParser.ParsePassportFieldDescription(passportFieldDescription);

            //Then
            Assert.Equal(expectedPassportFieldInformation, actualPassportFieldInformation);
        }
Ejemplo n.º 4
0
        public void Give_passeport_fields_separate_by_spaces_or_newlines(
            int passportNumber,
            int expectedPassportFieldsCount)
        {
            //Given
            const string batchFileDescription = BatchFileDescription.PartOneExampleDescription;

            //When
            var passportFieldsCount = PassportParser.ParsePassportDescription(
                PassportParser
                .ParseBatchFile(batchFileDescription)
                .ElementAt(passportNumber))
                                      .Count();

            //Then
            Assert.Equal(expectedPassportFieldsCount, passportFieldsCount);
        }
 public static int CountValidPassports(string batchFileDescription)
 => PassportParser
 .ParseBatchFile(batchFileDescription)
 .Select(PassportFactory.Create)
 .Count(passport => passport.ContainsAllRequiredFields());