示例#1
0
        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));
示例#4
0
 [TestMethod] public void IsValidHairColor_n123abz() => Assert.IsFalse(Passport.IsValidHairColor("#123abz"));
示例#5
0
 [TestMethod] public void IsValidHairColor_123abc() => Assert.IsFalse(Passport.IsValidHairColor("123abc"));
示例#6
0
 [TestMethod] public void IsValidHeight_190() => Assert.IsFalse(Passport.IsValidHeight("190"));
示例#7
0
 [TestMethod] public void IsValidHairColor_n123abc() => Assert.IsTrue(Passport.IsValidHairColor("#123abc"));
示例#8
0
 [TestMethod] public void IsValidHeight_60in() => Assert.IsTrue(Passport.IsValidHeight("60in"));
示例#9
0
 [TestMethod] public void IsValidHeight_190cm() => Assert.IsTrue(Passport.IsValidHeight("190cm"));
示例#10
0
 [TestMethod] public void IsValidBirthYear_2002() => Assert.IsTrue(Passport.IsValidYear("2002", 1920, 2002));
示例#11
0
 [TestMethod] public void IsValidBirthYear_2003() => Assert.IsFalse(Passport.IsValidYear("2003", 1920, 2002));
示例#12
0
        public int CountValidPassports(string[] input, bool useExtendedValidation = false)
        {
            var passports = Passport.ParseLines(input);

            return(passports.Count(passport => passport.IsValid(useExtendedValidation)));
        }
示例#13
0
 [TestMethod] public void IsValidPassportId_56789() => Assert.IsFalse(Passport.IsValidPassportId("56789"));
示例#14
0
 [TestMethod] public void IsValidPassportId_000000001() => Assert.IsTrue(Passport.IsValidPassportId("000000001"));
示例#15
0
 [TestMethod] public void IsValidEyeColor_wat() => Assert.IsFalse(Passport.IsValidEyeColor("wat"));
示例#16
0
 [TestMethod] public void IsValidEyeColor_brn() => Assert.IsTrue(Passport.IsValidEyeColor("brn"));