Ejemplo n.º 1
0
def test_operate():
    assert specs.operate(4, 5, '+') == 9, "failed for '+' operator"
    assert specs.operate(3, 6, '-') == -3, "failed for '-' operator"
    assert specs.operate(6, -7, '*') == -42, "failed for '*' operator"
    assert specs.operate(15, 3, '/') == 5, "failed for '/' operator"
    with pytest.raises(TypeError) as excinfo_1:
        specs.operate(14, 2, 5)
    assert excinfo_1.value.args[0] == "oper must be a string"
    with pytest.raises(ZeroDivisionError) as excinfo_2:
        specs.operate(4, 0, '/')
    assert excinfo_2.value.args[0] == "division by zero is undefined"
    with pytest.raises(ValueError) as excinfo_3:
        specs.operate(3, 2, '=')
    assert excinfo_3.value.args[0] == "oper must be one of '+', '/', '-', or '*'"
Ejemplo n.º 2
0
def test_operate():
    with pytest.raises(TypeError) as excinfo:
        specs.operate(1, 2, 4)
    assert excinfo.value.args[0] == "oper must be a string"
    assert specs.operate(4, 10, '+') == 14, "failed on '+'"
    assert specs.operate(10, 4, '-') == 6, "failed on '-'"
    assert specs.operate(4, 10, '*') == 40, "failed on '*'"
    assert specs.operate(12, 4, '/') == 3, "failed on '/'"
    with pytest.raises(ZeroDivisionError) as excinfo:
        specs.operate(4, 0, '/')
    assert excinfo.value.args[0] == "division by zero is undefined"
    with pytest.raises(ValueError) as excinfo:
        specs.operate(10, 4, '%')
    assert excinfo.value.args[0] == "oper must be one of '+', '/', '-', or '*'"
def test_operate():
    #test cases for all conditions
    assert specs.operate(1, 2, "+") == 3
    assert specs.operate(3, 5, "-") == -2
    assert specs.operate(2, 3, "*") == 6
    assert specs.operate(6, 3, "/") == 2
    with pytest.raises(ZeroDivisionError) as excinfo:
        specs.operate(4, 0, "/")
    assert excinfo.value.args[0] == "division by zero is undefined"

    with pytest.raises(TypeError) as excinfo:
        specs.operate(4, 0, 2)
    assert excinfo.value.args[0] == "oper must be a string"

    with pytest.raises(ValueError) as excinfo:
        specs.operate(4, 0, "^")
    assert excinfo.value.args[0] == "oper must be one of '+', '/', '-', or '*'"
Ejemplo n.º 4
0
def test_operate():
    assert specs.operate(3, 4, "+") == 7, "addition operation failed"
    assert specs.operate(5, 4, "-") == 1, "subtraction operation failed"
    assert specs.operate(3, 4, "*") == 12, "multiplication operation failed"
    assert specs.operate(12, 3, "/") == 4, "Division failed"
    pytest.raises(TypeError, specs.operate, a=3, b=3, oper=3)
    pytest.raises(ValueError, specs.operate, a=3, b=3, oper="^")
    with pytest.raises(ZeroDivisionError) as excinfo:
        specs.operate(4, 0, "/")
    #FOR SOME REASON THE MESSAGE THAT IS RETURNED with the error in the assert must match
    #the error that is given by the raise in spec.py - INTERESTING. My hypothesis was correct.
    assert excinfo.value.args[0] == "division by zero is undefined"
Ejemplo n.º 5
0
def test_operate():
    """tests operations on two numbers"""
    assert specs.operate(1, 2, '+') == 3, "Failed on positive + positive"
    assert specs.operate(1, 0, '+') == 1, "Failed on positive + zero"
    assert specs.operate(1, -2, '+') == -1, "Failed on positive + negative"
    assert specs.operate(0, 0, '+') == 0, "Failed on zero + zero"
    assert specs.operate(1, 2, '-') == -1, "Failed on positive + positive"
    assert specs.operate(1, 0, '-') == 1, "Failed on positive + positive"
    assert specs.operate(1, -2, '-') == 3, "Failed on positive + positive"
    assert specs.operate(0, 0, '-') == 0, "Failed on positive + positive"
    assert specs.operate(1, 2, '*') == 2, "Failed on positive + positive"
    assert specs.operate(1, 0, '*') == 0, "Failed on positive + positive"
    assert specs.operate(1, -2, '*') == -2, "Failed on positive + positive"
    assert specs.operate(0, 0, '*') == 0, "Failed on positive + positive"
    assert specs.operate(1, 2, '/') == 0.5, "Failed on positive + positive"
    assert specs.operate(1, -2, '/') == -0.5, "Failed on positive + positive"
    assert specs.operate(-1, 2, '/') == -0.5, "Failed on positive + positive"
    assert specs.operate(0, 2, '/') == 0, "Failed on positive + positive"
    pytest.raises(ZeroDivisionError, specs.operate, a=1, b=0, oper='/')
    pytest.raises(ZeroDivisionError, specs.operate, a=0, b=0, oper='/')
    pytest.raises(TypeError, specs.operate, a=1, b=2,
                  oper=9)  #tests non-operator
    pytest.raises(ValueError, specs.operate, a=1, b=2, oper='test')