示例#1
0
def test_scan_not_found():
    source = scan_scm + '(scan (quote z) l )'
    got = run(source)
    assert got == []
示例#2
0
def test_env_build():
    got = run(env_scm)
    assert got == [['+', op.add], ['-', op.sub]]
示例#3
0
def test_scan():
    source = scan_scm + '(scan (quote a) l )'
    got = run(source)
    assert got == 'a'
示例#4
0
def test_gcd():
    got = run(gcd_src)
    assert got == 9
示例#5
0
def test_quicksort():
    got = run(quicksort_src)
    assert got == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
示例#6
0
 def test_nested_add(self):
     self.assertEqual(run(['+', ['+', 1, ['+', 0, 2]], 3]), 6)
示例#7
0
def test_factorial():
    got = run(fact_src)
    assert got == 1405006117752879898543142606244511569936384000000000
    assert got == math.factorial(42)
示例#8
0
 def test_begin(self):
     self.assertEqual(run(['begin', ['+', 1, 2], ['+', 2, 3]]), 5)
示例#9
0
def test_newton():
    got = run(newton_src)
    assert math.isclose(got, 11111)
示例#10
0
 def test_gte_lte_comparison(self):
     prog = ['=', ['<=', 4, 4], ['>=', 3, 2]]
     self.assertEqual(run(prog), True)
示例#11
0
 def test_abs(self):
     self.assertEqual(run(['abs', -3]), 3)
示例#12
0
 def test_gt_lt_comparison(self):
     prog = ['=', ['<', 4, 3], ['>', 3, 2]]
     self.assertEqual(run(prog), False)
示例#13
0
 def test_multiple_operations(self):
     self.assertEqual(run(['-', ['+', 3, 10], ['/', ['*', 4, 5], 5]]), 9)
示例#14
0
 def test_subtract_operation(self):
     self.assertEqual(run(['-', 3, 2]), 1)
示例#15
0
def test_lookup():
    source = lookup_scm + '(lookup (quote +) env)'
    got = run(source)
    assert got == op.add
示例#16
0
def test_newton():
    got = run(closure_src)
    assert got == 100
示例#17
0
def test_lookup_not_found():
    source = lookup_scm + '(lookup (quote z) env )'
    got = run(source)
    assert got == []
示例#18
0
 def test_simple_add(self):
     self.assertEqual(run(['+', 1, 2]), 3)