Exemple #1
0
 def test_begin(self):
     set_var = e.eval([
         p._begin, [p._define, p.Symbol('x'), 3],
         [p._set, p.Symbol('x'), 5], [p.Symbol('+'),
                                      p.Symbol('x'), 1]
     ])
     assert set_var == 6
Exemple #2
0
 def test_lambda(self):
     lambda_list = [
         p._lambda,
         p.Symbol('x'), [p.Symbol('+'),
                         p.Symbol('x'),
                         p.Symbol('x')]
     ]
     lambda_func = e.eval(lambda_list)
     assert type(lambda_func) == type(e.Procedure('blah', 'blah', 'blah'))
     assert lambda_func(3) == 6
Exemple #3
0
def test_to_string():
    assert u.to_string(True) == '#t'
    assert u.to_string(False) == '#f'
    assert u.to_string(p.Symbol('x')) == 'x'
    assert u.to_string([1, 2, 3, 4]) == '(1 2 3 4)'
    assert u.to_string(complex(4, -3)) == '(4-3i)'
Exemple #4
0
 def test_set(self):
     e.eval([p._set, p.Symbol('x'), 3])
     assert e.eval(p.Symbol('x')) == 3
Exemple #5
0
 def test_define(self):
     e.eval([p._define, p.Symbol('x'), 3])
     assert e.eval(p.Symbol('x')) == 3
Exemple #6
0
 def test_if(self):
     true_if_statement = [p._if, [p.Symbol('='), 1, 1], 5, 'blah']
     false_if_statement = [p._if, [p.Symbol('='), 1, 2], 5, 'blah']
     assert e.eval(true_if_statement) == 5
     assert e.eval(false_if_statement) == 'blah'