コード例 #1
0
        public override string Second()
        {
            string fileName = GetFilename();
            var    scanner  = new PassportScanner(fileName);

            scanner.Scan();
            int validPassports = scanner.NrOfValidPassports();

            return(validPassports.ToString());
        }
コード例 #2
0
        public override string First()
        {
            string fileName = GetFilename();
            var    scanner  = new PassportScanner(fileName);

            scanner.Scan();
            int validPassports = scanner.NrOfPassportsWithRequiredFields();

            return(validPassports.ToString());
        }
コード例 #3
0
        public override bool Test2()
        {
            string fileName = GetTestFilename();

            fileName.Replace("input_test.txt", "input_test2_1.txt");
            var scanner = new PassportScanner(fileName);

            scanner.Scan();
            int validPassports = scanner.NrOfValidPassports();

            string fileName2 = GetTestFilename();

            fileName2.Replace("input_test.txt", "input_test2_2.txt");
            var scanner2 = new PassportScanner(fileName2);

            scanner2.Scan();
            int validPassports2 = scanner2.NrOfValidPassports();

            var testResults = new List <bool>();

            testResults.Add(scanner2.FieldIsValid("byr", "2002") == true);
            testResults.Add(scanner2.FieldIsValid("byr", "2003") == false);
            testResults.Add(scanner2.FieldIsValid("hgt", "60in") == true);
            testResults.Add(scanner2.FieldIsValid("hgt", "190cm") == true);
            testResults.Add(scanner2.FieldIsValid("hgt", "190in") == false);
            testResults.Add(scanner2.FieldIsValid("hgt", "190") == false);
            testResults.Add(scanner2.FieldIsValid("hcl", "#123abc") == true);
            testResults.Add(scanner2.FieldIsValid("hcl", "#123abz") == false);
            testResults.Add(scanner2.FieldIsValid("hcl", "123abc") == false);
            testResults.Add(scanner2.FieldIsValid("ecl", "brn") == true);
            testResults.Add(scanner2.FieldIsValid("ecl", "wat") == false);
            testResults.Add(scanner2.FieldIsValid("pid", "000000001") == true);
            testResults.Add(scanner2.FieldIsValid("pid", "0123456789") == false);

            return(validPassports == 0 && validPassports2 == 4 && testResults.All(v => v == true));
        }