Beispiel #1
0
def test_eval_no_operator_detail():
    with raises(InvalidOperator) as excinfo:
        evaluate(parse('(2 3)'))

    assert str(excinfo.value) == 'invalid operator: 2'
Beispiel #2
0
def test_eval_sub():
    assert evaluate(parse('(- 2 3)')) == -1
Beispiel #3
0
def test_eval_numexp_inner():
    assert evaluate(parse('(+ 2 (* 3 4))')) == 14
Beispiel #4
0
def test_eval_no_operator2():
    with raises(InvalidOperator):
        evaluate(parse('(2 3)'))
Beispiel #5
0
def test_eval_lt_true():
    assert evaluate(parse('(< 2 3)')) == 1
Beispiel #6
0
def test_eval_numexp():
    assert evaluate(parse('(+ 2 3)')) == 5
Beispiel #7
0
def test_eval_too_many_args():
    with raises(TooManyArguments):
        evaluate(parse('(* 1 2 3)'))
Beispiel #8
0
def test_eval_div_by_zero():
    with raises(ZeroDivisionError):
        evaluate(parse('(/ 6 0)'))
Beispiel #9
0
def test_plus_number():
    with raises(InvalidOperator):
        evaluate(parse('+1'))
Beispiel #10
0
def test_eval_too_few_args():
    with raises(MissingArguments):
        evaluate(parse('(* 1)'))
Beispiel #11
0
def test_eval_gt_false_2():
    assert evaluate(parse('(> 3 4)')) == 0
Beispiel #12
0
def test_eval_gt_true():
    assert evaluate(parse('(> 4 3)')) == 1
Beispiel #13
0
def test_eval_lt_false_2():
    assert evaluate(parse('(< 3 2)')) == 0
Beispiel #14
0
def test_eval_div():
    assert evaluate(parse('(/ 6 2)')) == 3
Beispiel #15
0
def test_eval_int():
    assert evaluate(parse('3')) == 3
Beispiel #16
0
def test_eval_div_returns_int():
    assert evaluate(parse('(/ 6 4)')) == 1
Beispiel #17
0
def test_eval_op():
    import operator
    assert evaluate(parse('+')) == operator.add
Beispiel #18
0
def test_eval_eq_true():
    assert evaluate(parse('(= 2 2)')) == 1
Beispiel #19
0
def test_eval_eq_false():
    assert evaluate(parse('(= 2 3)')) == 0