import unittest
from set_1.challenge_1 import hex_to_base64, bytes_to_hex, bytes_to_base64


class TestChallenge1(unittest.TestCase):

    def test_bytes_to_hex(self):
        self.assertEqual('', bytes_to_hex(b''))
        self.assertEqual('000fff', bytes_to_hex(b'\x00\x0f\xff'))

    def test_bytes_to_base64(self):
        self.assertEqual('', bytes_to_base64(b''))
        self.assertEqual('AA//', bytes_to_base64(b'\x00\x0f\xff'))

    def test_bytes_to_base64_padding(self):
        self.assertEqual('AA//', bytes_to_base64(b'\x0f\xff'))

    def test_hex_to_base64(self):
        self.assertEqual('', hex_to_base64(''))
        self.assertEqual('AA', hex_to_base64('000'))

    def test_hex_to_base64_mixed_case(self):
        self.assertEqual('//', hex_to_base64('fff'))
        self.assertEqual('//', hex_to_base64('FfF'))
        self.assertEqual('//', hex_to_base64('FFF'))

    def test_hex_to_base64_padding(self):
        self.assertEqual('AA', hex_to_base64('0'))
        self.assertEqual('AA', hex_to_base64('00'))
        self.assertEqual(hex_to_base64('00f'), hex_to_base64('f'))
        self.assertEqual(hex_to_base64('0f0'), hex_to_base64('f0'))
        self.assertEqual(hex_to_base64('00afff'), hex_to_base64('afff'))

    def test_hex_to_base64_sample_input(self):
        self.assertEqual('SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t',
                         hex_to_base64('49276d206b696c6c696e6720796f757220627261696e206c'
                                       '696b65206120706f69736f6e6f7573206d757368726f6f6d'))

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