public void Should_ThrowException_WhenContainsEmptyLine(string newLine) { var passportWithEmptyLine = _validPassportAsString + newLine; Assert.Throws <ArgumentOutOfRangeException>(() => PassportParser.Parse(passportWithEmptyLine)); }
public void Should_ThrowException_When_UnexpectedKey(string keyValue) { var passportWithInvalidKey = _validPassportAsString + " " + keyValue; Assert.Throws <ArgumentOutOfRangeException>(() => PassportParser.Parse(passportWithInvalidKey)); }
public void Should_ReturnEmptyCollection_When_PassportEntryEmpty() { var actualPassportCollection = PassportParser.Parse(Enumerable.Empty <string>().ToArray()); Assert.That(!actualPassportCollection.Any()); }
public static int Run(string input) { var passports = new PassportParser().Parse(input); var validator = new PassportValidator(); return(passports.Count(p => validator.Validate(p).IsValid)); }
internal static void Part1() { var input = Input.Text(4); var passports = PassportParser.Parse(input).ToList(); var numValid = passports.Count(PassportValidator.HasRequiredFields); Console.WriteLine(numValid); }
public void ValidValueValidationTest(bool expectedResult, string input) { // Arrange var passportParser = new PassportParser(); // Act var validity = new ValidValueValidation().IsValid(passportParser.ParsePassport(input)); // Assert Assert.That(validity, Is.EqualTo(expectedResult)); }
public void Should_ReturnOnePassports_When_OneOfTwoValidPassportStringProvided() { var validPassports = new [] { "ecl:aaa pid:aaa eyr:aaa hcl:aaa" + "byr:aaa iyr:aaa cid:aaa hgt:aaa", "AAA:aaa pid:aaa eyr:aaa hcl:aaa" + "byr:aaa iyr:aaa cid:aaa hgt:aaa" }; var sut = PassportParser.Parse(validPassports); Assert.That(sut.Count() == 1); }
private PassportModel GetResultFromTextLines(string text) { var mrz = PassportParser.ParsePassport(text); if (mrz != null && mrz.Valid) { return(mrz); } return(null); }
public static PassportField Create(string passportFieldDescription) { var passportFieldInformations = PassportParser.ParsePassportFieldDescription(passportFieldDescription); return(passportFieldInformations switch { ("byr", _) => new BirthYearPassportField(passportFieldInformations.Value), ("iyr", _) => new IssueYearPassportField(passportFieldInformations.Value), ("eyr", _) => new ExpirationYearPassportField(passportFieldInformations.Value), ("hgt", _) when passportFieldInformations.Value.EndsWith("cm") => new HeightInCentimetrePassportField(passportFieldInformations.Value), ("hgt", _) when passportFieldInformations.Value.EndsWith("in") => new HeightInInchPassportField(passportFieldInformations.Value), ("hgt", _) => new HeightPassportField(passportFieldInformations.Value), ("hcl", _) => new HairColorPassportField(passportFieldInformations.Value), ("ecl", _) => new EyeColorPassportField(passportFieldInformations.Value), ("pid", _) => new PassportIdPassportField(passportFieldInformations.Value), ("cid", _) => new CountryIdPassportField(passportFieldInformations.Value), _ => new UnknownPassportField(passportFieldInformations.Value) });
public void Should_CreatePassport() { var expected = "aaa"; var validPassport = $"ecl:{expected} pid:{expected} eyr:{expected} hcl:{expected} byr:{expected} iyr:{expected} cid:{expected} hgt:{expected}"; var result = PassportParser.Parse(validPassport); Assert.That(result.BirthYear == expected, $"Birth Year was {result.BirthYear} but expected {expected}"); Assert.That(result.CountryId == expected, $"Country Id was {result.CountryId} but expected {expected}"); Assert.That(result.ExpirationYear == expected, $"Expiration Year was {result.ExpirationYear} but expected {expected}"); Assert.That(result.EyeColor == expected, $"EyeColor was {result.EyeColor} but expected {expected}"); Assert.That(result.HairColor == expected, $"HairColor was {result.HairColor} but expected {expected}"); Assert.That(result.Height == expected, $"Height was {result.Height} but expected {expected}"); Assert.That(result.IssueYear == expected, $"IssueYear was {result.IssueYear} but expected {expected}"); Assert.That(result.PassportId == expected, $"Passport Id was {result.PassportId} but expected {expected}"); }
public void TestPart2Valid() { var input = @"pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980 hcl:#623a2f eyr:2029 ecl:blu cid:129 byr:1989 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm hcl:#888785 hgt:164cm byr:2001 iyr:2015 cid:88 pid:545766238 ecl:hzl eyr:2022 iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719"; var passports = PassportParser.Parse(input).ToList(); Assert.True(passports.All(PassportValidator.IsValid)); }
public void TestPart2Invalid() { var input = @"eyr:1972 cid:100 hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926 iyr:2019 hcl:#602927 eyr:1967 hgt:170cm ecl:grn pid:012533040 byr:1946 hcl:dab227 iyr:2012 ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277 hgt:59cm ecl:zzz eyr:2038 hcl:74454a iyr:2023 pid:3556412378 byr:2007"; var passports = PassportParser.Parse(input).ToList(); Assert.DoesNotContain(passports, PassportValidator.IsValid); }
public void IntegrationTest_Where_All_valid() { var rawPassports = "pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980" + "\n" + "hcl:#623a2f" + "\n" + "\n" + "\n" + "eyr:2029 ecl:blu cid:129 byr:1989" + "\n" + "iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm" + "\n" + "\n" + "\n" + "hcl:#888785" + "\n" + "hgt:164cm byr:2001 iyr:2015 cid:88" + "\n" + "pid:545766238 ecl:hzl" + "\n" + "eyr:2022" + "\n" + "\n" + "\n" + "iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719"; var passports = PassportParser.Parse(rawPassports.Split("\n\n")); var validPassports = passports.Where(p => p.Validate()); Assert.That(validPassports.Count() == passports.Count()); }
public void TestPart1() { var input = @"ecl:gry pid:860033327 eyr:2020 hcl:#fffffd byr:1937 iyr:2017 cid:147 hgt:183cm iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 hcl:#cfa07d byr:1929 hcl:#ae17e1 iyr:2013 eyr:2024 ecl:brn pid:760753108 byr:1931 hgt:179cm hcl:#cfa07d eyr:2025 pid:166559648 iyr:2011 ecl:brn hgt:59in"; var passports = PassportParser.Parse(input).ToList(); var numValid = passports.Count(PassportValidator.HasRequiredFields); Assert.Equal(2, numValid); }
public void IntegrationTest_Where_All_Invalid() { var rawPassports = "eyr:1972 cid:100" + "hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926" + "\n" + "iyr:2019" + "hcl:#602927 eyr:1967 hgt:170cm" + "ecl:grn pid:012533040 byr:1946" + "\n" + "hcl:dab227 iyr:2012" + "ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277" + "\n" + "hgt:59cm ecl:zzz" + "eyr:2038 hcl:74454a iyr:2023" + "pid:3556412378 byr:2007"; var passports = PassportParser.Parse(rawPassports.Split("\n")); var validPassports = passports.Where(p => p.Validate()); Assert.That(validPassports.Any() == false); }
public void Should_ThrowException_When_PassportEntryNull() { Assert.Throws <ArgumentNullException>(() => PassportParser.Parse((string[])null)); }
public void Should_ThrowException_WhenNullOrWhitespace(string passportAsString) { Assert.Throws <ArgumentOutOfRangeException>(() => PassportParser.Parse(passportAsString)); }
public Day04() : base(04, 2020, "") { Passports = PassportParser.Parse(Input); }
private static bool IsPassport(string fieldsDescriptions) => PassportParser .ParsePassportDescription(fieldsDescriptions) .Any(fieldDescription => fieldDescription.StartsWith(CredentialMissingFieldDiscriminator));
private static void Run(string part, string input, Func <Passport, bool> isValid) { var passports = PassportParser.Parse(input); System.Console.WriteLine($"{part} {passports.Count(isValid)}"); }