Ejemplo n.º 1
0
def test_tokenize():
    source0 = ['(define a 3)']
    tokens0 = tokenize(source0)
    source1 = ['(+ 10 25 0)']
    tokens1 = tokenize(source1)
    assert list(tokens0) == ['(', 'define', 'a', '3', ')']
    assert list(tokens1) == ['(', '+', '10', '25', '0', ')']
Ejemplo n.º 2
0
def test_list():
    source = ['(list 1 2 (+ 1 2) 4)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == [1, 2, 3, 4]
Ejemplo n.º 3
0
def test_cdr():
    source = ['(cdr (cons 1 null))']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == []
Ejemplo n.º 4
0
 def test_tokenise(self):
     self.assertEqual(
         tokenize('(set var 123)'),
         ['(', 'set', 'var', '123', ')']
     )
Ejemplo n.º 5
0
def test_multiply():
    source = ['(* 1 3 5)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == 15
Ejemplo n.º 6
0
def test_or_false():
    source = ['(or (> 2 10) (= 1 2) #f)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == False
Ejemplo n.º 7
0
def test_parse_add():
    source = ['(define a (+ 3 3))']
    tokens = tokenize(source)
    exp = parse_tokens(tokens)
    assert exp == [['define', 'a', ['+', 3, 3]]]
Ejemplo n.º 8
0
def test_nullcheck_3():
    source = ['(null? (cdr (list 1)))']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == True
Ejemplo n.º 9
0
def test_add():
    source = ['(+ 1 3 5)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == 9
Ejemplo n.º 10
0
def test_divide():
    source = ['(/ 10 3)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == 3
Ejemplo n.º 11
0
def test_subtract():
    source = ['(- 10 14)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == -4
Ejemplo n.º 12
0
 def test_begin_statement(self):
     self.assertEqual(tokenize('(begin ())'), ['(', 'begin', '(', ')', ')'])
Ejemplo n.º 13
0
 def test_empty_brackets(self):
     self.assertEqual(tokenize('()'), ['(', ')'])
Ejemplo n.º 14
0
def test_parse_define_lambda():
    source = ['(define add (lambda (x y) (+ x y)))']
    tokens = tokenize(source)
    exp = parse_tokens(tokens)
    assert exp == [['define', 'add', ['lambda', ['x', 'y'], ['+', 'x', 'y']]]]
Ejemplo n.º 15
0
def test_nullcheck():
    source = ['(null? null)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == True
Ejemplo n.º 16
0
def test_gt():
    source0, source1 = ['(> 2 2)'], ['(> 3 2)']
    exp0 = parse_tokens(tokenize(source0))[0]
    exp1 = parse_tokens(tokenize(source1))[0]
    assert eval_in_env(exp0, []) == False
    assert eval_in_env(exp1, []) == True
Ejemplo n.º 17
0
def test_nullcheck_2():
    source = ['(null? (cons 1 null))']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == False
Ejemplo n.º 18
0
def test_and_false():
    source = ['(and (> 2 1) (= 1 2) #t)']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == False
Ejemplo n.º 19
0
def test_cons_2():
    source = ['(cons (+ 1 3 5) (cons (+ 1 3 5) null))']
    exp = parse_tokens(tokenize(source))[0]
    assert eval_in_env(exp, []) == [9, 9]
Ejemplo n.º 20
0
def test_parse_define():
    source = ['(define a 3)']
    tokens = tokenize(source)
    exp = parse_tokens(tokens)
    assert exp == [['define', 'a', 3]]