Exemple #1
0
 def test_cons(self, numbers, capsys):
     # generate cons expression
     s = "".join(["(cons %s" % x for x in numbers])
     # close with (cons 1 ()) and add closing parens
     s = "%s (cons 1 ()) %s" % (s, ")" * len(numbers))
     eval_and_print(s)
     assert_stripped_output_is(capsys,
                               "(%s 1)" % " ".join(str(n) for n in numbers))
Exemple #2
0
 def test_define_recursive_nary_function(self, capsys):
     eval_and_print("""
         (define (max x . z)
             (if (null? z) x
                 (apply max
                     (cons
                         (if (b< x (car z)) (car z) x)
                         (cdr z)))))
                    """)
     capsys.readouterr()
     eval_and_print("(max 10 2 3 4 5 15 100 2)")
     assert_stripped_output_is(capsys, "100")
Exemple #3
0
 def test_binary_addition(self, v1, v2, capsys):
     eval_and_print("(b+ %s %s)" % (v1, v2))
     assert_stripped_output_is(capsys, str(v1 + v2))
Exemple #4
0
 def test_define_functions(self, v1, v2, capsys):
     eval_and_print("(define (a x) (b+ %s x))" % v1)
     capsys.readouterr()
     eval_and_print("(a %s)" % v2)
     assert_stripped_output_is(capsys, str(v1 + v2))
Exemple #5
0
 def test_define_variables(self, v, capsys):
     eval_and_print("(define x %s)" % v)
     capsys.readouterr()
     eval_and_print("x")
     assert_stripped_output_is(capsys, str(v))
Exemple #6
0
 def test_set_cdr(self, numbers, capsys):
     nums = " ".join(str(n) for n in numbers)
     eval_and_print("(set-cdr! '(11 2 3 4) '(%s))" % nums)
     assert_stripped_output_is(capsys, "(11 %s)" % nums)
Exemple #7
0
 def test_set_car(self, number, capsys):
     eval_and_print("(set-car! '(11 2 3 4) %s)" % number)
     assert_stripped_output_is(capsys, "(%s 2 3 4)" % number)
Exemple #8
0
 def test_cdr(self, numbers, capsys):
     eval_and_print("(cdr '(%s))" % " ".join(str(n) for n in numbers))
     assert_stripped_output_is(
         capsys, "(%s)" % " ".join(str(n) for n in numbers[1:]))
Exemple #9
0
 def test_cons_dot(self, capsys):
     eval_and_print("(cons 1 2)")
     assert_stripped_output_is(capsys, "(1 . 2)")
Exemple #10
0
 def test_binary_subtraction(self, v1, v2, capsys):
     eval_and_print("(b- %s %s)" % (v1, v2))
     assert_stripped_output_is(capsys, str(v1 - v2))