Ejemplo n.º 1
0
 def test_first_valid_second_valid_div_calculate(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("12/3")
     viewmodel.set_second_number("2/7")
     viewmodel.set_operation("/")
     viewmodel.calculate()
     self.assertEqual("14", viewmodel.get_result())
Ejemplo n.º 2
0
 def test_number_updated_result_empty(self):
     viewmodel = RationalNumberViewModel()
     viewmodel.set_first_number("12/3")
     viewmodel.set_second_number("2/7")
     viewmodel.set_operation("+")
     viewmodel.calculate()
     viewmodel.set_first_number("12/11")
     self.assertEqual("", viewmodel.get_result())
Ejemplo n.º 3
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())