Example #1
0
 def test_operation_division_second_numerator_zero_info_message_correct(
         self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("12/3")
     viewmodel.set_second_number("0/1")
     viewmodel.set_operation("/")
     self.assertEqual(
         "Numerator of second number is zero. Division by zero is not allowed.",
         viewmodel.get_info_message())
Example #2
0
 def test_first_invalid_second_invalid_info_correct(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("aaa")
     viewmodel.set_second_number("bbbb")
     self.assertEqual("First number is invalid.Second number is invalid.",
                      viewmodel.get_info_message())
Example #3
0
 def test_first_valid_second_empty_info_correct(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("3/4")
     viewmodel.set_second_number("")
     self.assertEqual("Second number is empty.",
                      viewmodel.get_info_message())
Example #4
0
 def test_first_valid_second_valid_info_empty(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("12/3")
     viewmodel.set_second_number("2/7")
     self.assertEqual("", viewmodel.get_info_message())
Example #5
0
 def test_numbers_invalid_calculate_button_disabled(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("a")
     viewmodel.set_second_number("2/7")
     self.assertEqual("disabled", viewmodel.get_calculate_button_state())
Example #6
0
class TestViewModelFakeLogging(unittest.TestCase):
    def setUp(self):
        self.view_model = RationalNumberViewModel(FakeLogger())

    def test_logging_init(self):
        self.assertEqual("Start view",
                         self.view_model.logger.get_last_message())

    def test_logging_first_number_is_empty(self):
        self.view_model.set_second_number("3/5")
        self.view_model.validate_input_numbers()
        self.assertEqual("First number is empty",
                         self.view_model.logger.get_last_message())

    def test_logging_first_number_is_invalid(self):
        self.view_model.set_first_number(r"3\5")
        self.view_model.set_second_number("3/5")
        self.view_model.validate_input_numbers()
        self.assertEqual("First number is invalid",
                         self.view_model.logger.get_last_message())

    def test_logging_first_numbers_denominator_is_null(self):
        self.view_model.set_first_number("3/0")
        self.view_model.set_second_number("3/5")
        self.view_model.validate_input_numbers()
        self.assertEqual("Denominator of first number is zero",
                         self.view_model.logger.get_last_message())

    def test_logging_second_number_is_empty(self):
        self.view_model.set_first_number("3/5")
        self.view_model.validate_input_numbers()
        self.assertEqual("Second number is empty",
                         self.view_model.logger.get_last_message())

    def test_logging_second_number_is_invalid(self):
        self.view_model.set_first_number("3/5")
        self.view_model.set_second_number(r"3\5")
        self.view_model.validate_input_numbers()
        self.assertEqual("Second number is invalid",
                         self.view_model.logger.get_last_message())

    def test_logging_second_numbers_denominator_is_null(self):
        self.view_model.set_first_number("3/5")
        self.view_model.set_second_number("3/0")
        self.view_model.validate_input_numbers()
        self.assertEqual("Denominator of second number is zero",
                         self.view_model.logger.get_last_message())

    def test_logging_operation_is_invalid(self):
        self.view_model.set_operation("//")
        self.view_model.validate_operation()
        self.assertEqual("Operation // is invalid",
                         self.view_model.logger.get_last_message())

    def test_division_by_zero(self):
        self.view_model.set_first_number("3/4")
        self.view_model.set_second_number("0/5")
        self.view_model.set_operation("/")
        self.view_model.validate_input()
        self.assertEqual("Division by zero",
                         self.view_model.logger.get_last_message())

    def test_numbers_and_operation_are_correct(self):
        self.view_model.set_first_number("3/4")
        self.view_model.set_second_number("3/5")
        self.view_model.set_operation("*")
        self.view_model.validate_input()
        self.assertEqual("Operation and input numbers are correct",
                         self.view_model.logger.get_last_message())

    def test_logger_calculate(self):
        self.view_model.set_first_number("3/4")
        self.view_model.set_second_number("3/5")
        self.view_model.set_operation("*")
        self.view_model.calculate()
        self.assertEqual(
            "Calculating was finished successfully. Result: 3/4 * 3/5 = 9/20",
            self.view_model.logger.get_last_message())
Example #7
0
 def test_numbers_filled_calculate_button_enabled(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("1/2")
     viewmodel.set_second_number("2/7")
     self.assertEqual("normal", viewmodel.get_calculate_button_state())
Example #8
0
 def test_denominator_of_number_zero_calculate_button_disabled(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("12/0")
     viewmodel.set_second_number("2/7")
     viewmodel.set_operation("+")
     self.assertEqual("disabled", viewmodel.get_calculate_button_state())