Exemple #1
0
        public static List <PassportInfo> ReadPassportsFromFile(string filename)
        {
            List <PassportInfo> passportList = new List <PassportInfo>();
            PassportInfo        passport     = new PassportInfo();

            foreach (string line in FileReader.ReadFileOfStrings(filename))
            {
                if (line == "")
                {
                    passportList.Add(passport);
                    passport = new PassportInfo();
                }
                else
                {
                    foreach (string keyvalue in line.Split(' '))
                    {
                        string[] kv = keyvalue.Split(':');
                        switch (kv[0])
                        {
                        case "byr":
                            passport.byr = int.Parse(kv[1]);
                            break;

                        case "iyr":
                            passport.iyr = int.Parse(kv[1]);
                            break;

                        case "eyr":
                            passport.eyr = int.Parse(kv[1]);
                            break;

                        case "hgt":
                            passport.hgt = kv[1];
                            break;

                        case "hcl":
                            passport.hcl = kv[1];
                            break;

                        case "ecl":
                            passport.ecl = kv[1];
                            break;

                        case "pid":
                            passport.pid = kv[1];
                            break;

                        case "cid":
                            passport.cid = int.Parse(kv[1]);
                            break;
                        }
                    }
                }
            }
            passportList.Add(passport);
            return(passportList);
        }
Exemple #2
0
        public void TestCheckPassport()
        {
            PassportInfo passport = new PassportInfo();

            passport.ecl = "gry";
            passport.pid = "860033327";
            passport.eyr = 2020;
            passport.hcl = "#fffffd";
            passport.byr = 1937;
            passport.iyr = 2017;
            passport.cid = 147;
            passport.hgt = "183cm";
            Assert.True(passport.ValuesPresent());
        }
Exemple #3
0
        public void TestCheckEmptyPassport()
        {
            PassportInfo passport = new PassportInfo();

            Assert.False(passport.ValuesPresent());
        }