#!/usr/bin/env python

import unittest
from day07 import has_abba, get_abba_allowed_strings, get_abba_disallowed_strings
from day07 import supports_tls, count_tls_addresses
from day07 import find_abas, supports_ssl, count_ssl_addresses


class TestFindingABBASequences(unittest.TestCase):
    cases = (
        ('abba', True),
        ('oxyyxo', True),
        ('aaaa', False),
        ('abcd', False),
    )

    def test_finds_abba_sequences(self):
        for text, expected in self.cases:
            self.assertEqual(has_abba(text), expected)


class TestGettingAllowedChunks(unittest.TestCase):
    cases = (
        ('abba[mnop]qrst[abcd]defg', ['abba', 'qrst', 'defg']),
    )

    def test_finds_allowed_substrings(self):
        for text, expected in self.cases:
            self.assertEqual(get_abba_allowed_strings(text), expected)


class TestGettingDisallowedChunks(unittest.TestCase):
    cases = (
        ('abba[mnop]qrst[abcd]defg', ['mnop', 'abcd']),
    )

    def test_finds_disallowed_substrings(self):
        for text, expected in self.cases:
            self.assertEqual(get_abba_disallowed_strings(text), expected)


class TestCheckingTLSAddresses(unittest.TestCase):
    cases = (
        ('abba[mnop]qrst', True),
        ('abcd[bddb]xyyx', False),
        ('aaaa[qwer]tyui', False),
        ('ioxxoj[asdfgh]zxcvbn', True),
    )

    def test_finds_tls_addresses(self):
        for text, expected in self.cases:
            self.assertEqual(supports_tls(text), expected)

    def test_counts_tls_addresses(self):
        data = [x[0] for x in self.cases]
        self.assertEqual(count_tls_addresses(data), 2)


class TestFindingABASequences(unittest.TestCase):
    cases = (
        ('aba', ['aba']),
        ('xyxxyx', ['xyx']),
        ('aaakekeke', ['eke', 'kek']),
        ('zazbzbzbcdb', ['bzb', 'zaz', 'zbz']),
    )

    def test_finds_aba_sequences(self):
        for text, expected in self.cases:
            self.assertEqual(find_abas(text), expected)


class TestCheckingSSLAddresses(unittest.TestCase):
    cases = (
        ('aba[bab]xyz', True),
        ('xyx[xyx]xyx', False),
        ('aaa[kek]eke', True),
        ('zazbz[bzb]cdb', True),
    )

    def test_finds_ssl_addresses(self):
        for text, expected in self.cases:
            self.assertEqual(supports_ssl(text), expected)

    def test_counts_ssl_addresses(self):
        data = [x[0] for x in self.cases]
        self.assertEqual(count_ssl_addresses(data), 3)


if __name__ == '__main__':
    unittest.main()

[((90, 4, 90, 19), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((56, 25, 56, 50), 'day07.count_tls_addresses', 'count_tls_addresses', ({(56, 45, 56, 49): 'data'}, {}), '(data)', False, 'from day07 import supports_tls, count_tls_addresses\n'), ((86, 25, 86, 50), 'day07.count_ssl_addresses', 'count_ssl_addresses', ({(86, 45, 86, 49): 'data'}, {}), '(data)', False, 'from day07 import find_abas, supports_ssl, count_ssl_addresses\n'), ((19, 29, 19, 43), 'day07.has_abba', 'has_abba', ({(19, 38, 19, 42): 'text'}, {}), '(text)', False, 'from day07 import has_abba, get_abba_allowed_strings, get_abba_disallowed_strings\n'), ((29, 29, 29, 59), 'day07.get_abba_allowed_strings', 'get_abba_allowed_strings', ({(29, 54, 29, 58): 'text'}, {}), '(text)', False, 'from day07 import has_abba, get_abba_allowed_strings, get_abba_disallowed_strings\n'), ((39, 29, 39, 62), 'day07.get_abba_disallowed_strings', 'get_abba_disallowed_strings', ({(39, 57, 39, 61): 'text'}, {}), '(text)', False, 'from day07 import has_abba, get_abba_allowed_strings, get_abba_disallowed_strings\n'), ((52, 29, 52, 47), 'day07.supports_tls', 'supports_tls', ({(52, 42, 52, 46): 'text'}, {}), '(text)', False, 'from day07 import supports_tls, count_tls_addresses\n'), ((69, 29, 69, 44), 'day07.find_abas', 'find_abas', ({(69, 39, 69, 43): 'text'}, {}), '(text)', False, 'from day07 import find_abas, supports_ssl, count_ssl_addresses\n'), ((82, 29, 82, 47), 'day07.supports_ssl', 'supports_ssl', ({(82, 42, 82, 46): 'text'}, {}), '(text)', False, 'from day07 import find_abas, supports_ssl, count_ssl_addresses\n')]