예제 #1
0
 def test_division(self):
     self.assertEqual(calculator.division(10, 1), 10)
     self.assertEqual(calculator.division(-10, 1), -10)
     self.assertEqual(calculator.division(0, 1), 0)
     self.assertRaises(ZeroDivisionError, calculator.division, 1, 0)
     self.assertEqual(calculator.division(1.5, 1), 1.5)
     self.assertEqual(calculator.division(3, 2), 1.5)
예제 #2
0
    def test_three_operands_values(self):
        from calculator import division

        operands = "/-34/2/-1"
        expected_values = "Operands provided: [-34, 2, -1]"
        actual = division(operands)
        self.assertTrue(expected_values in actual)
예제 #3
0
    def test_one_operand_result(self):
        from calculator import division

        operands = "-16"
        expected_result = "-16"
        actual = division(operands)
        self.assertTrue(expected_result in actual)
예제 #4
0
    def test_no_operand_values(self):
        from calculator import division

        operands = ""
        expected_values = "Operands provided: []"
        actual = division(operands)
        self.assertTrue(expected_values in actual)
예제 #5
0
    def test_one_operand_divide_by_zero(self):
        from calculator import division

        operands = "0"
        expected_values = "Operands provided: [0]"
        actual = division(operands)
        self.assertTrue(expected_values in actual)
예제 #6
0
    def test_three_operands_divide_by_zero_first_value(self):
        from calculator import division

        operands = "/0/2/-1"
        expected_values = "Operands provided: [0, 2, -1]"
        actual = division(operands)
        self.assertTrue(expected_values in actual)
예제 #7
0
    def test_three_operands_result(self):
        from calculator import division

        operands = "/-34/2/-1"
        expected_result = "Result of operand division: 17"
        actual = division(operands)
        self.assertTrue(expected_result in actual)
예제 #8
0
 def test_division(self):
     # Floats
     result = calculator.division(1, 8)
     self.assertEqual(result, .125)
     # Zero
     result = calculator.division(5, 0)
     self.assertEqual(result, None)
     result = calculator.division(0, 986)
     self.assertEqual(result, 0)
     # Negative
     result = calculator.division(-8, -2)
     self.assertEqual(result, 4)
     result = calculator.division(9, -3)
     self.assertEqual(result, -3)
     # Non-numeric
     result = calculator.multiplication("divide", 7)
     self.assertEqual(result, None)
예제 #9
0
 def test_three_operands_divide_by_zero_third_value(self):
     from calculator import division
     operands = "/2/12/0"
     try:
         actual = division(operands)
     except (ZeroDivisionError, Exception) as e:
         exception = 'yes'
     self.assertTrue(exception == 'yes')
예제 #10
0
    def test_three_operands_divide_by_zero_third_value(self):
        from calculator import division

        operands = "/2/12/0"
        try:
            actual = division(operands)
        except (ZeroDivisionError, Exception) as e:
            exception = "yes"
        self.assertTrue(exception == "yes")
예제 #11
0
def test_division():
    assert calculator.division(-3, 4) == -.75
    assert calculator.division(-2, 1) == -2
    assert calculator.division(1, 0) == "error: divide by zero"
    assert calculator.division(25, 5) == 5
    assert calculator.division(-3, -3) == 1
    assert calculator.division(1, -2) == -.5
    assert calculator.division(0, 4) == 0
예제 #12
0
 def test_division(self):
     self.assertEqual(calculator.division(-3, 4), -.75)
     self.assertEqual(calculator.division(-2, 1), -2)
     self.assertEqual(calculator.division(1, 0), "error: divide by zero")
     self.assertEqual(calculator.division(25, 5), 5)
     self.assertEqual(calculator.division(-3, -3), 1)
     self.assertEqual(calculator.division(1, -2), -.5)
     self.assertEqual(calculator.division(0, 4), 0)
def test_division():
    assert calculator.division(10, 2) == 5
    assert calculator.division(10, 1) == 10
    assert calculator.division(-10, 1) == -10
    assert calculator.division(0, 1) == 0
    assert calculator.division(1.5, 1) == 1.5
    assert calculator.division(3, 2) == 1.5
예제 #14
0
def result():
    var_1 = request.form.get("var_1", type=int)
    var_2 = request.form.get("var_2", type=int)
    operation = request.form.get("operation")
    if (operation == 'Addition'):
        result = add(var_1, var_2)
    elif (operation == 'Subtraction'):
        result = subtract(var_1, var_2)
    elif (operation == 'Multiplication'):
        result = multiply(var_1, var_2)
    elif (operation == 'Division'):
        result = division(var_1, var_2)
    else:
        result = 'INVALID CHOICE'
    entry = result
    return render_template('result.html', entry=entry)
예제 #15
0
    def handle(self, handler_input):
        numbers = extract_numbers(handler_input)
        n1 = numbers["n1"]
        n2 = numbers["n2"]
        result = speakable(calc.division(n1, n2))

        speak_output = f"The result of {n1} by {n2} is {result} {continue_msg} "
        card = SimpleCard("My Calculator", str(result))

        return (
            handler_input.response_builder
                .speak(speak_output)
                .set_card(card)
                .set_should_end_session(False)
                .response
        )
예제 #16
0
 def test_division(self):
     assert 5 == calculator.division(25, 5)
예제 #17
0
 def test_divisionFloat(self):
     self.assertAlmostEqual(division(3, -2), -1.5)
예제 #18
0
 def test_three_operands_divide_by_zero_first_value(self):
     from calculator import division
     operands = "/0/2/-1"
     expected_values = "Operands provided: [0, 2, -1]"
     actual = division(operands)
     self.assertTrue(expected_values in actual)
예제 #19
0
 def test_one_operand_divide_by_zero(self):
     from calculator import division
     operands = "0"
     expected_values = "Operands provided: [0]"
     actual = division(operands)
     self.assertTrue(expected_values in actual)
예제 #20
0
 def test_three_operands_result(self):
     from calculator import division
     operands = '/-34/2/-1'
     expected_result = "Result of operand division: 17"
     actual = division(operands)
     self.assertTrue(expected_result in actual)
예제 #21
0
 def test_three_operands_values(self):
     from calculator import division
     operands = '/-34/2/-1'
     expected_values = "Operands provided: [-34, 2, -1]"
     actual = division(operands)
     self.assertTrue(expected_values in actual)
예제 #22
0
 def test_one_operand_result(self):
     from calculator import division
     operands = "-16"
     expected_result = "-16"
     actual = division(operands)
     self.assertTrue(expected_result in actual)
예제 #23
0
 def test_no_operand_values(self):
     from calculator import division
     operands = ""
     expected_values = "Operands provided: []"
     actual = division(operands)
     self.assertTrue(expected_values in actual)
예제 #24
0
 def test_invalidDivision(self):
     self.assertEqual(division(5, "bad input"), None)
예제 #25
0
 def test_diviision(self):
     self.assertEqual(calculator.division(2, 1), 2)
     self.assertEqual(calculator.division(8, 4), 2)
     self.assertEqual(calculator.division(-10, -2), 5)
     self.assertEqual(calculator.division(9, 2.5), 3.6)
예제 #26
0
def test_ten_divided_by_two():
    """
    If given 10 and 2 as parameters, 5 should
    be returned
    """
    assert division(10, 2) == 5
예제 #27
0
 def post(self):
     return division(request.get_json())
예제 #28
0
 def test_division(self):
     assert 2 == calculator.division(4, 2)
예제 #29
0
 def test_divideByZeroDivision(self):
     self.assertEqual(division(5, 0), None)
예제 #30
0
 def test_divbyzero(self):
     with self.assertRaises(ZeroDivisionError):
         calculator.division(2, 0)
예제 #31
0
from calculator import addition, subtraction, multipication, division

while True:
    try:
        first = int(input("First Number: "))
        operand = input("Would you like to +, -, * or / ? ")
        second = int(input("Second Number: "))

        if operand == "+":
            addition(first, second)
            break
        elif operand == "-":
            subtraction(first, second)
            break
        elif operand == "*":
            multipication(first, second)
            break
        elif operand == "/":
            division(first, second)
            break
        else:
            print("Please enter a valid operand.")
    except ValueError:
        print("Please enter numbers only!")

quit = input("To quit the program, please press q then hit enter.").lower()
if quit == "q":
    import sys
    sys.exit(0)
예제 #32
0
print(math.ceil(1.2))
print(math.fabs(-1.2))


# math 전체를 가지고 오지 않고
# 필요한 ceil, fsum만 가지고 옴
# fsum을 연산할 때는 [] list를 이용해서!
from math import ceil, fsum

print(ceil(1.2))
print(fsum([3, 5 ,6 ,7 ,8]))


# as로 fsum함수를 다른 이름 '리스트사용'으로
# 바꿔줄 수 있음, 함수 = 리스트사용
from math import fsum as 리스트사용

print(리스트사용([3, 5 ,6 ,7 ,8]))


# 내가 만든 calculator 폴더에 있는 것들을
# import(수입)해올 수 가 있음!
from  calculator import plus, minus, times, division, remainder, negation, power

print(plus(1, 2))
print(minus(6, 3))
print(times(2, 3))
print(division(8, 2))
print(remainder(10,3))
print(negation(3, 2))
print(power(2, 6))
예제 #33
0
 def test_division(self):
     assert 4 == calculator.division(16, 4)
예제 #34
0
def test_nine_divided_by_three():
    assert division(9, 3) == 3
    """
 def test_division(self):
     self.assertEqual(calculator.division(1,1),1.0)
     self.assertEqual(calculator.division(1,2),0.5)
예제 #36
0
                    break

                number1 = float(input('\nInsert the first number: '))
                number2 = float(input('Insert the second number: '))
                break
            except:
                print("Insert only numeric")

        if option_selected <= 0 or option_selected > 4:
            exit(0)

        elif option_selected == 1:
            print('\n----------SUM----------')
            result = sum(number1, number2)
            print(f'{number1} + {number2} = {result: .2f}')

        elif option_selected == 2:
            print('\n----------Subtraction----------')
            result = subtracion(number1, number2)
            print(f'{number1} - {number2} = {result: .2f}')

        elif option_selected == 3:
            print('\n----------Division----------')
            result = division(number1, number2)
            print(f'{number1} / {number2} = {result: .2f}')

        elif option_selected == 4:
            print('\n----------Multiplication----------')
            result = multiplication(number1, number2)
            print(f'{number1} * {number2} = {result: .2f}')
 def test_division(self):
     assert 200 == calculator.division(400, 2)