public Day4(string path) : base(4) { passports = new Iter <Passport>(); FileParser parser = new FileParser(path); StringBuilder builder = new StringBuilder(); foreach (var line in parser.Lines) { if (line.Length == 0) { if (builder.Length > 1) { passports.Add(Passport.FromString(builder.ToString())); } builder = new StringBuilder(); } builder.Append(line.Trim() + " "); } if (builder.Length > 1) { passports.Add(Passport.FromString(builder.ToString())); } }
public void TestPassport() { string input = "eid:bla \n iyr:123 hgt:abS cid: 12 hcl:#112233"; Passport pass = Passport.FromString(input); Assert.AreEqual("byr: iyr:123 eyr: hgt:ab hcl:#112233 ecl: pid: cid:", pass.ToString()); Assert.False(pass.IsValid); pass = Passport.FromString("byr:1920 iyr:2012 eyr:2022 hgt:170cm\nhcl:#556677 ecl:gry pid:123456789"); Assert.True(pass.IsValid); }