import unittest

from NumberSystems.ExcelConverter import ExcelConverter


class TestExcelConverter(unittest.TestCase):
    def setUp(self):
        self.converter = ExcelConverter()

    def tearDown(self):
        self.converter.column_number = None
        self.converter.column = None

    def test_converter_is_initialised(self):
        self.assertIsNone(self.converter.column_number)
        self.assertIsNone(self.converter.column)

    def test_to_capital(self):
        self.converter.column = 'Hello world'
        self.converter.to_capital()
        self.assertEqual('HELLO WORLD', self.converter.column)

    def test_is_valid_column(self):
        self.converter.column = 'apple'
        self.assertEqual(True, self.converter.is_valid_column())
        self.converter.column = 'a1pple'
        self.assertEqual(False, self.converter.is_valid_column())
        self.converter.column = 'a pple'
        self.assertEqual(False, self.converter.is_valid_column())
        self.converter.column = 'a-pple'
        self.assertEqual(False, self.converter.is_valid_column())
        self.converter.column = '123'
        self.assertEqual(False, self.converter.is_valid_column())

    def test_converter_converts_single_colums(self):
        self.converter.column = 'A'
        self.converter.to_column_number()
        self.assertEqual(1, self.converter.column_number)
        self.converter.column = 'B'
        self.converter.to_column_number()
        self.assertEqual(2, self.converter.column_number)
        self.converter.column = 'z'
        self.converter.to_column_number()
        self.assertEqual(26, self.converter.column_number)

    def test_converter_converts_double_colums(self):
        self.converter.column = 'AA'
        self.converter.to_column_number()
        self.assertEqual(27, self.converter.column_number)
        self.converter.column = 'AB'
        self.converter.to_column_number()
        self.assertEqual(28, self.converter.column_number)
        self.converter.column = 'BC'
        self.converter.to_column_number()
        self.assertEqual(55, self.converter.column_number)

    def test_converter_converts_multiple_colums(self):
        self.converter.column = 'AAZZ'
        self.converter.to_column_number()
        self.assertEqual(18954, self.converter.column_number)
        self.converter.column = 'ZZAAA'
        self.converter.to_column_number()
        self.assertEqual(12339055, self.converter.column_number)

