예제 #1
0
def test_calculator_add_is_begative(answer):

    calt = Calculator()
    num1 = 2
    num2 = 2
    with pytest.raises(Exception):
        assert calt.add_1(num1, num2) == answer()
예제 #2
0
def test_calculator_add_is_zero():

    calt = Calculator()
    num1 = 0
    num2 = 1
    expected = 0

    assert calt.multiply(num1, num2) == expected
예제 #3
0
def test_calculator_add_is_zero():

    calt = Calculator()
    num1 = 1
    num2 = 1
    expected = 0

    assert calt.substract(num1, num2) == expected
예제 #4
0
def test_calculator_power_is():

    calt = Calculator()
    num1 = 5
    num2 = 2
    expected = 25

    assert calt.power(num1, num2) == expected
예제 #5
0
def test_calculator_power_is_one():

    calt = Calculator()
    num1 = 1
    num2 = 2
    expected = 1

    assert calt.power(num1, num2) == expected
예제 #6
0
def test_calculator_multiply_is_zero():

    calt = Calculator()
    num1 = 3
    num2 = 1
    expected = 0
    with pytest.raises(Exception):
        assert calt.multiply(num1, num2)
예제 #7
0
def calc(request):
    value = ''

    if request.method == 'POST':
        calc = Calculator()
        expr = request.POST['expr']
        value = calc.evalString(expr)

    return render(request, 'calculator.html', {'value': value})
예제 #8
0
class TestCalculator:
    def setup(self):
        self.calc = Calculator()

    def test_addition_2_plus_3(self):
        assert self.calc.add(2, 3) == 5

    def test_addition_6_plus_8(self):
        assert self.calc.add(6, 8) == 14

    def test_subtraction_4_minus_3(self):
        assert self.calc.sub(4, 3) == 1

    def test_subtraction_9_minus_2(self):
        assert self.calc.sub(9, 2) == 7

    def test_division_9_divide_by_3(self):
        assert self.calc.div(9, 3) == 3

    def test_division_error_divide_by_zero(self):
        with pytest.raises(ZeroDivisionError):
            self.calc.div(5, 0)

    def test_multiplication_10_multiply_by_4(self):
        assert self.calc.mul(10, 4) == 40

    def test_multiplication_12_multiply_by_6(self):
        assert self.calc.mul(12, 6) == 72
예제 #9
0
파일: tests.py 프로젝트: shihyu/learn-test
    def setUp(self):
        """
        add_dict = {(3,2) : 5, (4,6) : 10, (4,3) : 7, (2,2) : 4}
        sub_dict = {(3,2) : 1, (9,6) : 3, (9,3) : 6}
        mul_dict = {(3,2) : 6, (7,2) : 14, (6,4) : 24}
        div_dict = {(3,2) : 1.5, (2,1) : 2, (24,1) : 24}

        def add(*args):
            return add_dict[args]
        def sub(*args):
            return sub_dict[args]
        def mul(*args):
            return mul_dict[args]
        def div(*args):
            return div_dict[args]

        scalc = SimpleCalculator()
        scalc.add = MagicMock(side_effect = add)
        scalc.sub = MagicMock(side_effect = sub)
        scalc.mul = MagicMock(side_effect = mul)
        scalc.div = MagicMock(side_effect = div)

        self.calc = Calculator(scalc)
        """
        self.calc = Calculator()
예제 #10
0
def div():
    try:
        a = request.args.get('a')
        b = request.args.get('b')
        return str(Calculator.div(float(a), float(b)))
    except:
        return "Usage <a href='div?a=9&b=3'>example</a>".format(
            request.host_url)
예제 #11
0
def mul():
    try:
        a = request.args.get('a')
        b = request.args.get('b')
        return str(Calculator.mul(float(a), float(b)))
    except:
        return "Usage <a href='mul?a=2&b=4'>example</a>".format(
            request.host_url)
예제 #12
0
def sub():
    try:
        a = request.args.get('a')
        b = request.args.get('b')
        return str(Calculator.sub(float(a), float(b)))
    except:
        return "Usage <a href='sub?a=20&b=5'>example</a>".format(
            request.host_url)
예제 #13
0
    def __init__(self):
        self.calculator = Calculator()

        self.methodsList = {
            '+': self.calculator.sum,
            '-': self.calculator.sub,
            '*': self.calculator.multi,
            '/': self.calculator.div
        }
예제 #14
0
    def __init__(self):
        super().__init__()
        self.calculator = Calculator()

        self.complexCalc = ComplexCalc()
        self.methodsComplList = {
            '+': self.complexCalc.sum,
            '-': self.complexCalc.sub,
            '*': self.complexCalc.multi,
            '/': self.complexCalc.div
        }
예제 #15
0
def main():

    calc = Calculator(int(input("첫번째 수")), int(input("두번째 수")))
    print("{} + {} = {}".format(calc.num1, calc.num2, calc.sum()))
    print("{} + {} = {}".format(calc.num1, calc.num2, calc.mul()))
    print("{} + {} = {}".format(calc.num1, calc.num2, calc.sub()))
    print("{} + {} = {}".format(calc.num1, calc.num2, calc.div()))
예제 #16
0
 def setup(self):
     self.calc = Calculator()
예제 #17
0
 def testAdd(self):
     calculator = Calculator()
     result = calculator.add(operanda=2, operandb=3)
     self.assertEqual(result, 5, "Not equal")
예제 #18
0
from calc.calculator import Calculator
import sys
x = float(sys.argv[1])
d = sys.argv[2]
y = float(sys.argv[3])

if d == '+':
    print(Calculator.add(x, y))
if d == '-':
    print(Calculator.sub(x, y))
if d == '*':
    print(Calculator.mul(x, y))
if d == '/':
    print(round(Calculator.div(x, y), 2))
예제 #19
0
파일: calc.py 프로젝트: hugolu/learn-test
def step_impl(context, expr2):
    calc = Calculator()
    context.answer2 = calc.evalString(expr2)
예제 #20
0
def test_divide():
    cal = Calculator()
    assert cal.divide(8.00, 4.00) == 2
예제 #21
0
 def testAdd(self):
     calculator = Calculator()
     result = calculator.add(operanda=2, operandb=3)
     self.assertEqual(result, 5, "Addition failed")
예제 #22
0
def test_add():
    cal = Calculator()
    with pytest.raises(Exception):
        assert cal.add('du', 43) == 66
예제 #23
0
파일: calc.py 프로젝트: hugolu/learn-test
def step_impl(context):
    calc = Calculator()
    context.answer = calc.evalString(context.expr)
예제 #24
0
 def testAdd(self):
     calculator = Calculator()
     result = calculator.Add(2, 3)
     self.assertEquals(result, 5, "Addition failed")
예제 #25
0
def test_multiplay():
    cal = Calculator()
    assert cal.multiplay(2, 4) == 8
 def test_add(self):
     self.assertEqual(Calculator.add(2, 2), 4)
     self.assertNotEqual(Calculator.add(2, 2), -4)
     self.assertEqual(Calculator.add(1, 2.2), 3.2)
     self.assertEqual(Calculator.add(-3, -3), -6)
예제 #27
0
def test_power():
    cal = Calculator()
    assert cal.power(3, 2) == 9
예제 #28
0
파일: calc.py 프로젝트: shihyu/learn-test
def step_impl(context, expr2):
    calc = Calculator()
    context.answer2 = calc.evalString(expr2)
예제 #29
0
def test_subbstractor():
    cal = Calculator()
    assert cal.substractor(43, 23) == 20
 def test_div(self):
     self.assertEqual(Calculator.div(9, 3), 3)
     self.assertEqual(Calculator.div(16, 4), 4)
예제 #31
0
 def test_return_0_on_empty_string(self):
     c = Calculator()
     assert_equal(c.add(""), 0)
예제 #32
0
 def testAdd(self):
     calculator = Calculator()
     result = calculator.add(operanda=2, operandb=3)
     self.assertEqual(result, 5, "Not equal")
예제 #33
0
파일: calc.py 프로젝트: shihyu/learn-test
def step_impl(context):
    calc = Calculator()
    context.answer = calc.evalString(context.expr)
 def test_mul(self):
     self.assertEqual(Calculator.mul(3, 4), 12)
     self.assertEqual(Calculator.mul(3, 0), 0)
     self.assertEqual(Calculator.mul(3, 4.5), 13.5)