private bool IsProperlyValidPassport(Passport passport) { if (passport.BirthYear == null) { return(false); } if (passport.BirthYear < 1920) { return(false); } if (passport.BirthYear > 2002) { return(false); } if (passport.IssueYear == null) { return(false); } if (passport.IssueYear < 2010) { return(false); } if (passport.IssueYear > 2020) { return(false); } if (passport.ExpirationYear == null) { return(false); } if (passport.ExpirationYear < 2020) { return(false); } if (passport.ExpirationYear > 2030) { return(false); } if (passport.Height == null) { return(false); } if (!ValidHeight(passport.Height)) { return(false); } if (passport.HairColour == null) { return(false); } if (!ValidHairColour(passport.HairColour)) { return(false); } if (passport.EyeColour == null) { return(false); } if (!_validEyeColours.Contains(passport.EyeColour)) { return(false); } if (passport.PassportId == null) { return(false); } if (passport.PassportId.Length != 9) { return(false); } if (!passport.PassportId.All(c => c >= '0' && c <= '9')) { return(false); } return(true); }
public static bool IsValid(Passport passport) => PassportRules.All(rule => rule.IsValid(passport));
public bool IsValid(Passport passport) => _predicate.Invoke(_fieldSelector.Invoke(passport));
[TestMethod] public void IsValidHairColor_n123abz() => Assert.IsFalse(Passport.IsValidHairColor("#123abz"));
[TestMethod] public void IsValidHairColor_123abc() => Assert.IsFalse(Passport.IsValidHairColor("123abc"));
[TestMethod] public void IsValidHeight_190() => Assert.IsFalse(Passport.IsValidHeight("190"));
[TestMethod] public void IsValidHairColor_n123abc() => Assert.IsTrue(Passport.IsValidHairColor("#123abc"));
[TestMethod] public void IsValidHeight_60in() => Assert.IsTrue(Passport.IsValidHeight("60in"));
[TestMethod] public void IsValidHeight_190cm() => Assert.IsTrue(Passport.IsValidHeight("190cm"));
[TestMethod] public void IsValidBirthYear_2002() => Assert.IsTrue(Passport.IsValidYear("2002", 1920, 2002));
[TestMethod] public void IsValidBirthYear_2003() => Assert.IsFalse(Passport.IsValidYear("2003", 1920, 2002));
public int CountValidPassports(string[] input, bool useExtendedValidation = false) { var passports = Passport.ParseLines(input); return(passports.Count(passport => passport.IsValid(useExtendedValidation))); }
[TestMethod] public void IsValidPassportId_56789() => Assert.IsFalse(Passport.IsValidPassportId("56789"));
[TestMethod] public void IsValidPassportId_000000001() => Assert.IsTrue(Passport.IsValidPassportId("000000001"));
[TestMethod] public void IsValidEyeColor_wat() => Assert.IsFalse(Passport.IsValidEyeColor("wat"));
[TestMethod] public void IsValidEyeColor_brn() => Assert.IsTrue(Passport.IsValidEyeColor("brn"));