class TestCreateRandomBisymmetricMatrix(unittest.TestCase): def setUp(self): self.view_model = BisymmetricMatrixViewModel() def test_by_default_create_random_matrix_is_disabled(self): self.assertEqual('disabled', self.view_model.get_button_convert_state()) def test_when_choose_size_of_matrix_create_random_matrix_button_enabled(self): self.view_model.set_matrix_size('2') self.assertEqual('normal', self.view_model.get_button_convert_state()) def test_when_select_size_2_create_matrix_size_is_correct(self): self.view_model.set_matrix_size('2') self.view_model.create_random_matrix() result = len(self.view_model.get_str_created_random_matrix()) self.assertEqual((2+2)*2+2, result) def test_when_enter_size_clear_enter_invalid_size_button_is_disabled(self): self.view_model.set_matrix_size('2') self.view_model.set_matrix_size('e3') self.assertEqual('disabled', self.view_model.get_button_convert_state()) def test_when_delete_vector_create_matrix_from_vector_button_is_disabled(self): self.view_model.set_matrix_size('3') self.view_model.set_matrix_size('') self.assertEqual('disabled', self.view_model.get_button_convert_state())
class TestViewModelFakeLogging(unittest.TestCase): def setUp(self): self.view_model = BisymmetricMatrixViewModel(FakeLogger()) def test_logging_init(self): self.assertEqual('Welcome', self.view_model.logger.get_last_message()) def test_logging_set_matrix_size(self): self.view_model.set_matrix_size('3') result = ['Welcome', 'trying to set the matrix size', 'matrix size is set: 3'] self.assertEqual(result, self.view_model.logger.get_log_messages()) def test_logging_set_matrix_size_empty(self): self.view_model.set_matrix_size('') result = ['Welcome', 'trying to set the matrix size', 'matrix size empty'] self.assertEqual(result, self.view_model.logger.get_log_messages()) def test_logging_set_matrix_size_empty_is_not_correct(self): self.view_model.set_matrix_size('z') result = ['Welcome', 'trying to set the matrix size', 'matrix size is not correct'] self.assertEqual(result, self.view_model.logger.get_log_messages()) def test_logging_set_vector(self): self.view_model.set_vector('1234') result = ['Welcome', 'trying to set vector', 'vector set: 1234'] self.assertEqual(result, self.view_model.logger.get_log_messages()) def test_logging_set_vector_empty(self): self.view_model.set_vector('') result = ['Welcome', 'trying to set vector', 'vector empty'] self.assertEqual(result, self.view_model.logger.get_log_messages()) def test_logging_set_vector_is_not_correct(self): self.view_model.set_vector('123z') result = ['Welcome', 'trying to set vector', 'vector is not correct'] self.assertEqual(result, self.view_model.logger.get_log_messages()) def test_logging_set_vector_size_is_not_correct(self): self.view_model.set_vector('123') result = ['Welcome', 'trying to set vector', 'vector size is not correct'] self.assertEqual(result, self.view_model.logger.get_log_messages()) def test_logging_click_created_matrix_by_vector(self): self.view_model.set_vector('123') self.view_model.create_matrix_by_vector() result = 'Button create_matrix_by_vector clicked' self.assertEqual(result, self.view_model.logger.get_last_message()) def test_logging_click_created_random_matrix(self): self.view_model.create_random_matrix() result = 'Button create_random_matrix clicked' self.assertEqual(result, self.view_model.logger.get_last_message()) def test_logging_created_random_matrix(self): matrix = [[1, 2, 3], [2, 3, 4], [5, 6, 7]] self.view_model.set_created_random_matrix(matrix) result = 'result_random_matrix: \n' + self.view_model.convert_matrix_to_str(matrix) self.assertEqual(result, self.view_model.logger.get_last_message()) def test_logging_created_matrix_by_vector(self): matrix = [[1, 2, 3], [2, 3, 4], [5, 6, 7]] self.view_model.set_created_matrix_by_vector(matrix) result = 'result_matrix_by_vector: \n' + self.view_model.convert_matrix_to_str(matrix) self.assertEqual(result, self.view_model.logger.get_last_message()) def test_logging_all(self): matrix = [[1, 2, 3], [2, 3, 4], [5, 6, 7]] self.view_model.set_created_matrix_by_vector(matrix) result1 = 'result_matrix_by_vector: \n' + self.view_model.convert_matrix_to_str(matrix) matrix2 = [[12, 2, 3], [2, 3, 4], [5, 6, 7]] self.view_model.set_created_random_matrix(matrix2) result2 = 'result_random_matrix: \n' + self.view_model.convert_matrix_to_str(matrix2) all_res = ['Welcome', result1, result2] self.assertEqual(all_res, self.view_model.logger.get_log_messages())