Esempio n. 1
0
 def test_integration_passport_missing_field(self):
     p = Passport(
         data=
         'iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 hcl:#cfa07d byr:1929'
     )
     actual = p.is_passport_valid()
     self.assertFalse(actual)
Esempio n. 2
0
 def test_integration_passport_invalid_hgt(self):
     p = Passport(
         data=
         'eyr:2029 ecl:blu cid:129 byr:1990 iyr:2014 pid:896056531 hcl:#a97842 hgt:165in'
     )
     actual = p.is_passport_valid()
     self.assertFalse(actual)
Esempio n. 3
0
 def test_integration_passport_with_all_valid_fields(self):
     p = Passport(
         data=
         'eyr:2029 ecl:blu cid:129 byr:1989 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm'
     )
     actual = p.is_passport_valid()
     self.assertTrue(actual)
Esempio n. 4
0
 def test_integration_passport_invalid_ecl(self):
     p = Passport(
         data=
         'eyr:2029 ecl:red cid:129 byr:1989 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm'
     )
     actual = p.is_passport_valid()
     self.assertFalse(actual)
Esempio n. 5
0
 def test_confirm_the_keys_is_true(self):
     p = Passport(
         data=
         'eyr:2029 ecl:blu cid:129 byr:1989 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm'
     )
     actual = p.confirm_the_keys()
     self.assertTrue(actual)
Esempio n. 6
0
def validate_passport_data(passport) -> Passport:
    return Passport(
        byr=passport["byr"],
        iyr=passport["iyr"],
        eyr=passport["eyr"],
        hgt=passport["hgt"],
        hcl=passport["hcl"],
        ecl=passport["ecl"],
        pid=passport["pid"]
    )
Esempio n. 7
0
def GeneratePassports(input_data):
    _passports = []
    pattern = re.compile("([a-z]{3}:[#a-z0-9]+)")
    for line in input_data:
        kvps = pattern.findall(line)
        _passport = Passport()
        for kvp in kvps:
            parts = kvp.split(':')
            setattr(_passport, parts[0], parts[1])
        _passports.append(_passport)
    return _passports
Esempio n. 8
0
def validate(strings, validate_values):
    """
    Implementation of 1st star (validate_values = False) 
    and 2nd star (validate_values = True)
    """
    valid = 0
    for s in strings:
        passport = Passport.passport_from_str(s, passport_type=REGULAR_PASSPORT)

        log(passport.fields)
        if passport.validate(validate_values):
            log("VALID")
            valid += 1
        log()

    return valid
Esempio n. 9
0
 def test_setup_keys(self):
     p = Passport(
         data=
         'eyr:2029 ecl:blu cid:129 byr:1989 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm'
     )
     expected = {
         'eyr': '2029',
         'ecl': 'blu',
         'cid': '129',
         'byr': '1989',
         'iyr': '2014',
         'pid': '896056539',
         'hcl': '#a97842',
         'hgt': '165cm',
     }
     actual = p.details
     self.assertEqual(expected, actual)
Esempio n. 10
0
def getpopulatedPassports(entries):
    passports = []

    for entry in entries:
        separated = entry.split(' ')
        currentEntry = defaultdict(str)
        for field in separated:
            key, value = field.split(':')
            currentEntry[key] = value

        passport = Passport(currentEntry['byr'], currentEntry['iyr'],
                            currentEntry['eyr'], currentEntry['hgt'],
                            currentEntry['hcl'], currentEntry['ecl'],
                            currentEntry['pid'], currentEntry['cid'])

        passports.append(passport)

    return passports
Esempio n. 11
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    logging.info('Started')
    lv = LoadValues()
    lv.strip_lines()
    passports = (lv.passportlist_parse())

    cntstar1 = 0
    cntstar2 = 0

    for passportfields in passports:
        passport = Passport()
        passport.set_fields(passportfields)
        if passport.are_compulsory_keys_present():
            cntstar1 += 1
        if passport.isvalid_passport():
            cntstar2 += 1

    print(cntstar1, cntstar2)
    logging.info('Finished')
Esempio n. 12
0
def create_passports():
    passports = []
    with open('day_04/input.txt') as f:
        line = f.readline()
        passport = Passport()
        while line:
            if line == '\n':
                passports.append(passport)
                passport = Passport()
                line = f.readline()
                continue

            parts = line.split(' ')
            for part in parts:
                passport.add_property(part.strip())

            line = f.readline()
        passports.append(passport)
    print(len(passports), 'total passports loaded')
    return passports
Esempio n. 13
0
 def test_validate_pid_when_missing_is_true(self):
     p = Passport(data='place_holder:1234')
     actual = p.validate_passport_id()
     self.assertTrue(actual)
Esempio n. 14
0
 def test_validate_pid_with_invalid_id(self):
     p = Passport(data='pid:11')
     actual = p.validate_passport_id()
     self.assertFalse(actual)
Esempio n. 15
0
 def test_validate_pid_with_valid_id(self):
     p = Passport(data='pid:000000000')
     actual = p.validate_passport_id()
     self.assertTrue(actual)
Esempio n. 16
0
 def test_validate_eye_color_is_missing_but_valid(self):
     p = Passport(data='place_holder:1234')
     actual = p.validate_eye_color()
     self.assertTrue(actual)
Esempio n. 17
0
 def test_validate_eye_color_is_invalid(self):
     p = Passport(data='ecl:red')
     actual = p.validate_eye_color()
     self.assertFalse(actual)
Esempio n. 18
0
 def test_validate_height_valid_cm(self):
     p = Passport(data='hgt:160cm')
     actual = p.validate_height()
     self.assertTrue(actual)
Esempio n. 19
0
 def test_validate_issue_year_invalid(self):
     p = Passport(data='iyr:2009')
     actual = p.validate_issue_year()
     self.assertFalse(actual)
Esempio n. 20
0
 def test_validate_hair_color_with_invalid_color(self):
     p = Passport(data='hcl:#zzzz')
     actual = p.validate_hair_color()
     self.assertFalse(actual)
Esempio n. 21
0
 def test_validate_hair_color_with_valid_color(self):
     p = Passport(data='hcl:#aaaaaa')
     actual = p.validate_hair_color()
     self.assertTrue(actual)
Esempio n. 22
0
 def test_validate_height_valid_missing_height(self):
     p = Passport(data='place_holder:1234')
     actual = p.validate_height()
     self.assertTrue(actual)
Esempio n. 23
0
 def test_validate_height_valid_in(self):
     p = Passport(data='hgt:59in')
     actual = p.validate_height()
     self.assertTrue(actual)
Esempio n. 24
0
 def test_validate_height_invalid_cm(self):
     p = Passport(data='hgt:140cm')
     actual = p.validate_height()
     self.assertFalse(actual)
Esempio n. 25
0
 def test_validate_expiration_year_invalid(self):
     p = Passport(data='eyr:2019')
     actual = p.validate_expiration_year()
     self.assertFalse(actual)
Esempio n. 26
0
 def test_validate_hair_color_passes_with_no_color(self):
     p = Passport(data='place_holder:1234')
     actual = p.validate_hair_color()
     self.assertTrue(actual)
Esempio n. 27
0
 def test_validate_expiration_year_valid(self):
     p = Passport(data='eyr:2020')
     actual = p.validate_expiration_year()
     self.assertTrue(actual)
Esempio n. 28
0
 def test_validate_eye_color_is_valid(self):
     p = Passport(data='ecl:blu')
     actual = p.validate_eye_color()
     self.assertTrue(actual)
Esempio n. 29
0
 def test_validate_height_invalid_string(self):
     p = Passport(data='hgt:58sin')
     actual = p.validate_height()
     self.assertFalse(actual)
Esempio n. 30
0
 def test_validate_expiration_year_valid_if_missing(self):
     p = Passport(data='place_holder:1234')
     actual = p.validate_expiration_year()
     self.assertTrue(actual)