This repository was archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_passphrases.py
55 lines (38 loc) · 1.53 KB
/
test_passphrases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# coding: utf-8
"""Tests for day 4 of the advent of code."""
import io
import passphrases
passwd_file = """correct horse battery shore
correct horse staple horse
"""
def test_valid_passphrase() -> None:
"""Contains no repeated words."""
phrase = "correct horse battery staple"
assert passphrases.valid_passphrase(phrase) is True
def test_invalid_passphrase() -> None:
"""Contains repeated words."""
phrase = "correct horse staple horse"
assert passphrases.valid_passphrase(phrase) is False
def test_valid_passphrases() -> None:
"""Filter our invalid passphrases."""
good = "correct horse battery staple"
bad = "correct horse staple horse"
phrases = [good, bad]
assert passphrases.valid_passphrases(phrases) == [good]
def test_count_valid_passphrases() -> None:
"""Count quantity of good passphrases."""
passwd = io.StringIO(passwd_file)
assert passphrases.count_valid_passphrases(passwd) == 1
def test_extra_valid_passphrase() -> None:
"""Contains no repeated words, or anagrams."""
phrase = "correct horse battery staple"
assert passphrases.extra_valid_passphrase(phrase) is True
def test_extra_invalid_passphrase() -> None:
"""Contains an anagram."""
phrase = "correct horse battery shore"
assert passphrases.extra_valid_passphrase(phrase) is False
def test_count_extra_valid_passphrases() -> None:
"""Count quantity of good passphrases."""
passwd = io.StringIO(passwd_file)
assert passphrases.count_extra_valid_passphrases(passwd) == 0