def problem_18(grades): tests1 = [ ("(merge < '(1 5 7 9) '(4 8 10))", read_line('(1 4 5 7 8 9 10)')), ("(merge > '(9 7 5 1) '(10 8 4 3))", read_line('(10 9 8 7 5 4 3 1)')), ] tests2 = [ ("(merge < '(1 2 3) '(4))", read_line('(1 2 3 4)')), ("(merge < () '(1 2))", read_line('(1 2)')), ] if check_func(check_scheme, tests1, comp=scheme_equal): return True if check_func(check_scheme, tests2, comp=scheme_equal): return True
def problem_20(grades): tests1 = [ ('(tree-sums (make-tree 3 nil))', read_line('(3)')), ('(tree-sums tree)', read_line('(20 19 13 16 11)')), ] tests2 = [ ("(tree-sums '(9 (4 (3 (8)) (2)) (5) (1 (2 (6)) (5))))", read_line('(24 15 14 18 15)')), ("(tree-sums '(-3 (-2) (-4)))", read_line('(-5 -7)')), ] if check_func(check_scheme, tests1, comp=scheme_equal): return True if check_func(check_scheme, tests2, comp=scheme_equal): return True
def problem_10(grades): gf = create_global_frame() formals, vals = read_line('(a b c)'), read_line('(1 2 3)') call_frame = gf.make_call_frame(formals, vals) doctest = [ (set(call_frame.bindings), {'a', 'b', 'c'}), (len(call_frame.bindings), 3), (call_frame.bindings['a'], 1), (call_frame.bindings['b'], 2), (call_frame.bindings['c'], 3), (call_frame.parent, gf), ] if check_func(lambda x: x, doctest, comp=scheme_equal): return True formals = read_line('(a b c)') args = read_line('(2 #t a)') lf = gf.make_call_frame(formals, args) tests1 = [ (lf.bindings['a'], 2), (lf.bindings['b'], True), (lf.bindings['c'], 'a'), (lf.parent, gf), ] if check_func(lambda x: x, tests1, comp=scheme_equal): return True formals = read_line('(a)') args = read_line('(seven)') lf2 = lf.make_call_frame(formals, args) tests2 = [ (lf.bindings['a'], 2), (lf.parent, gf), ] if check_func(lambda x: x, tests2, comp=scheme_equal): return True
def problem_10(grades): gf = create_global_frame() formals, vals = read_line("(a b c)"), read_line("(1 2 3)") call_frame = gf.make_call_frame(formals, vals) doctest = [ (set(call_frame.bindings), {"a", "b", "c"}), (len(call_frame.bindings), 3), (call_frame.bindings["a"], 1), (call_frame.bindings["b"], 2), (call_frame.bindings["c"], 3), (call_frame.parent, gf), ] if check_func(lambda x: x, doctest, comp=scheme_equal): return True formals = read_line("(a b c)") args = read_line("(2 #t a)") lf = gf.make_call_frame(formals, args) tests1 = [ (lf.bindings["a"], 2), (lf.bindings["b"], True), (lf.bindings["c"], "a"), (lf.parent, gf), ] if check_func(lambda x: x, tests1, comp=scheme_equal): return True formals = read_line("(a)") args = read_line("(seven)") lf2 = lf.make_call_frame(formals, args) tests2 = [ (lf.bindings["a"], 2), (lf.parent, gf), ] if check_func(lambda x: x, tests2, comp=scheme_equal): return True