Ejemplo n.º 1
0
    def test_invert(self):
        dlg = run_calculator()

        num = (generate_random_number(-10000, 1000) / 100)
        # num = generate_random_number(-1000, 1000)
        num_c = str(num).replace('.', ',')

        # divide to 0
        # num_c = 0

        dlg.type_keys(num_c)
        dlg.child_window(auto_id='negateButton').click()
        send_keys('{ENTER}')

        time.sleep(1)
        dlg.child_window(auto_id='invertButton').click()
        result = dlg.child_window(auto_id='CalculatorResults').window_text()

        if contain_digits(result):
            real_res = get_number(result)
            exp_res = trim_num(1 / (-num), get_numbers_of_symbols(real_res))
        else:
            self.assertEqual('Display is Cannot divide by zero', result)

        time.sleep(1)

        dlg.close()
Ejemplo n.º 2
0
    def test_multiplication(self):
        # run a program
        dlg = run_calculator()

        # enter data
        dlg.child_window(auto_id='num7Button').click()
        dlg.child_window(auto_id='multiplyButton').click()

        num = generate_random_number(0, 200)
        str_num = str(num)
        count = len(str_num)

        for i in range(count):
            dlg.child_window(auto_id='num{a}Button'.format(
                a=str_num[i])).click()
            time.sleep(0.5)

        # get results
        dlg.child_window(auto_id='equalButton').click()
        real_res = get_number(
            dlg.child_window(auto_id='CalculatorResults').window_text())

        # compare results
        self.assertEqual(real_res, 7 * num)
        time.sleep(1)
        dlg.close()
Ejemplo n.º 3
0
    def test_subtraction(self):

        # run a program
        dlg = run_calculator()

        for i in range(4):
            # enter data
            num1 = generate_random_number(10, 29)
            num2 = generate_random_number(1, 9)
            dlg.type_keys(num1)
            dlg.type_keys('-')
            time.sleep(1)
            dlg.type_keys(num2)
            time.sleep(1)

            # get results
            dlg.type_keys('=')
            real_res = get_number(
                dlg.child_window(auto_id='CalculatorResults').window_text())

            # compare results
            self.assertEqual(real_res, num1 - num2)
            send_keys('{ESC}')
            time.sleep(1)

        dlg.close()
Ejemplo n.º 4
0
def addition(num1, num2, res):
    # start timer
    start_time = datetime.now()

    # run a program
    dlg = run_calculator()

    # enter data
    dlg.type_keys(num1)
    c_num1 = get_number(
        dlg.child_window(auto_id='CalculatorResults').window_text())
    dlg.child_window(auto_id='plusButton').click()
    dlg.type_keys(num2)
    c_num2 = get_number(
        dlg.child_window(auto_id='CalculatorResults').window_text())

    # get result
    dlg.child_window(auto_id='equalButton').click()
    real_res = get_number(
        dlg.child_window(auto_id='CalculatorResults').window_text())
    dlg.close()

    # assert results
    try:
        assert real_res == int(res)
        test_res = "Pass"
    except AssertionError:
        test_res = "Fail"
    finally:
        end_time = datetime.now() - start_time
        print("End testing!")

    return c_num1, c_num2, real_res, test_res, end_time
Ejemplo n.º 5
0
    def test_square_root(self):
        dlg = run_calculator()

        # generate int data
        num = generate_random_number(-10000, 10000)

        # generate fractional data
        # num = (generate_random_number(-10000, 10000) / 100)

        str_num = str(num)
        count = len(str_num)
        minus = False

        # enter data
        for i in range(count):
            if str_num[i] == '.':
                dlg.child_window(auto_id='decimalSeparatorButton').click()
            elif str_num[i] == '-':
                minus = True
            else:
                dlg.child_window(auto_id='num{a}Button'.format(
                    a=str_num[i])).click()
            time.sleep(0.25)

        # change to negative/positive
        if minus:
            dlg.child_window(auto_id='negateButton').click()

        # click square root button
        dlg.child_window(auto_id='squareRootButton').click()

        # get result in text form
        result = dlg.child_window(auto_id='CalculatorResults').window_text()

        # check if result contain digits
        if contain_digits(result):
            real_res = get_number(result)
            exp_res = trim_num(get_sqrt_or_error(num),
                               get_numbers_of_symbols(real_res))

            # compare digital result
            self.assertEqual(exp_res, real_res)
        else:
            # checking for error
            self.assertEqual('Display is Invalid input', result)

        time.sleep(1)
        dlg.close()
Ejemplo n.º 6
0
    def test_quadratic_degree(self):
        dlg = run_calculator()

        # num = (generate_random_number(-10000, 1000) / 100)
        num = generate_random_number(-1000, 1000)
        num_c = str(num).replace('.', ',')
        dlg.type_keys(num_c)
        dlg.child_window(auto_id='negateButton').click()
        send_keys('{ENTER}')

        time.sleep(1)
        dlg.child_window(auto_id='xpower2Button').click()
        result = dlg.child_window(auto_id='CalculatorResults').window_text()
        real_res = get_number(result)

        time.sleep(1)
        exp_res = trim_num(math.pow(-num, 2), get_numbers_of_symbols(real_res))
        self.assertEqual(exp_res, real_res)
        dlg.close()
Ejemplo n.º 7
0
    def test_addition(self):
        num = generate_random_number(1, 9)

        # run a program
        dlg = run_calculator()

        # enter data
        dlg.child_window(auto_id='num9Button').click()
        dlg.child_window(auto_id='plusButton').click()
        dlg.type_keys(num)
        dlg.child_window(auto_id='equalButton').click()

        # get results
        real_res = get_number(
            dlg.child_window(auto_id='CalculatorResults').window_text())

        # compare results
        self.assertEqual(real_res, 9 + num)
        dlg.close()
Ejemplo n.º 8
0
    def test_division(self):
        num = generate_random_number(-100, 100)

        # run a program
        dlg = run_calculator()

        # enter data
        dlg.type_keys(num)
        dlg.child_window(auto_id='divideButton').click()
        dlg.child_window(auto_id='num8Button').click()
        time.sleep(1.5)

        # get results
        send_keys('{ENTER}')
        time.sleep(1.5)
        real_res = get_number(
            dlg.child_window(auto_id='CalculatorResults').window_text())

        # compare results
        self.assertEqual(real_res, num / 8)
        dlg.close()