advent-of-code/2017-python/tests/day_04_tests.py

38 lines
1.2 KiB
Python
Raw Normal View History

2021-11-01 16:40:46 +01:00
import unittest
from solutions.day_04 import Solution
class Day4TestCase(unittest.TestCase):
def setUp(self):
self.solution = Solution()
def test_passphrase_has_only_unique_words(self):
passphrases = [
2025-05-06 20:14:58 +02:00
"aa bb cc dd ee",
"aa bb cc dd aa",
"aa bb cc dd aaa",
2021-11-01 16:40:46 +01:00
]
assert self.solution.validate(passphrases[0]) == True
assert self.solution.validate(passphrases[1]) == False
assert self.solution.validate(passphrases[2]) == True
2025-05-06 20:14:58 +02:00
assert self.solution.solve("\n".join(passphrases)) == 2
2021-11-01 16:40:46 +01:00
def test_passphrase_has_no_anagrams(self):
passphrases = [
2025-05-06 20:14:58 +02:00
"abcde fghij",
"abcde xyz ecdab",
"a ab abc abd abf abj",
"iiii oiii ooii oooi oooo",
"oiii ioii iioi iiio",
2021-11-01 16:40:46 +01:00
]
assert self.solution.validate(passphrases[0], True) == True
assert self.solution.validate(passphrases[1], True) == False
assert self.solution.validate(passphrases[2], True) == True
assert self.solution.validate(passphrases[3], True) == True
assert self.solution.validate(passphrases[4], True) == False
2025-05-06 20:14:58 +02:00
if __name__ == "__main__":
2021-11-01 16:40:46 +01:00
unittest.main()