示例#1
0
def test_cons():
    run_fix ("(car (cons 1 2))", 1)
    run_fix ("(cdr (cons 1 2))", 2)
    with pytest.raises(Exception):
        run("(car 1)", None, expect_to_fail=True)
    with pytest.raises(Exception):
        run("(car 1 2)", None, expect_to_fail=True)
示例#2
0
def test_cons():
    run_fix("(car (cons 1 2))", 1)
    run_fix("(cdr (cons 1 2))", 2)
    with pytest.raises(SchemeException):
        run("(car 1)", None)
    with pytest.raises(SchemeException):
        run("(car 1 2)", None)
示例#3
0
def test_vec_strategies_dehomogenize():
    vec = run('(let ([vec (vector 1 2 3)]) (vector-set! vec 1 "Anna") vec)')
    assert isinstance(vec.strategy, ObjectVectorStrategy)
    vec = run('(let ([vec (make-vector 3 1)]) (vector-set! vec 1 "Anna") vec)')
    assert isinstance(vec.strategy, ObjectVectorStrategy)
    vec = run('(let ([vec (make-vector 3 1)]) (vector-set! vec 1 2) vec)')
    assert isinstance(vec.strategy, FixnumVectorStrategy)
示例#4
0
文件: test_vector.py 项目: 8l/pycket
def test_vec_strategies_empty():
    vec = run("(vector)")
    print "First size: %s" % vec.length()
    assert isinstance(vec.strategy, ObjectVectorStrategy)
    vec = run("(make-vector 0)")
    print "Second size: %s" % vec.length()
    assert isinstance(vec.strategy, ObjectVectorStrategy)
示例#5
0
def test_cons():
    run_fix("(car (cons 1 2))", 1)
    run_fix("(cdr (cons 1 2))", 2)
    with pytest.raises(Exception):
        run("(car 1)", None, expect_to_fail=True)
    with pytest.raises(Exception):
        run("(car 1 2)", None, expect_to_fail=True)
示例#6
0
def test_cons():
    run_fix ("(car (cons 1 2))", 1)
    run_fix ("(cdr (cons 1 2))", 2)
    with pytest.raises(SchemeException):
        run("(car 1)", None)
    with pytest.raises(SchemeException):
        run("(car 1 2)", None)
示例#7
0
def test_quotient():
    run_fix("(quotient 0 1)", 0)
    run_fix("(quotient 0 -1)", 0)
    run_fix("(quotient 0 2)", 0)
    run_fix("(quotient 0 -2)", 0)
    run_fix("(quotient 0 3)", 0)
    run_fix("(quotient 1 1)", 1)
    run_fix("(quotient -1 1)", -1)
    run_fix("(quotient 1 -1)", -1)
    run_fix("(quotient -1 -1)", 1)
    run_fix("(quotient 1 2)", 0)
    run_fix("(quotient -1 2)", 0)
    run_fix("(quotient 1 -2)", 0)
    run_fix("(quotient -1 -2)", 0)
    run_fix("(quotient -1234 -10)", 123)
    run_fix("(quotient 1234 1234)", 1)
    big = 2**70
    run_fix("(quotient %s %s)" % (big, big), 1)
    run_fix("(quotient %s %s)" % (-big, big), -1)
    run_fix("(quotient %s %s)" % (big, -big), -1)
    run_fix("(quotient %s %s)" % (-big, -big), 1)
    run_fix("(quotient %s %s)" % (big + 1, big), 1)
    run_fix("(quotient %s %s)" % (-(big + 1), big), -1)
    res = run(str(big / 2))
    run("(quotient %s 2)" % (big, ), res)

    res = run("(quotient 8.0 2.0)")
    assert isinstance(res, W_Flonum) and res.value == 4.0
    res = run("(quotient 1.0 2.0)")
    assert isinstance(res, W_Flonum) and res.value == 0.0
示例#8
0
def test_quotient():
    run_fix("(quotient 0 1)", 0)
    run_fix("(quotient 0 -1)", 0)
    run_fix("(quotient 0 2)", 0)
    run_fix("(quotient 0 -2)", 0)
    run_fix("(quotient 0 3)", 0)
    run_fix("(quotient 1 1)", 1)
    run_fix("(quotient -1 1)", -1)
    run_fix("(quotient 1 -1)", -1)
    run_fix("(quotient -1 -1)", 1)
    run_fix("(quotient 1 2)", 0)
    run_fix("(quotient -1 2)", 0)
    run_fix("(quotient 1 -2)", 0)
    run_fix("(quotient -1 -2)", 0)
    run_fix("(quotient -1234 -10)", 123)
    run_fix("(quotient 1234 1234)", 1)
    big = 2 ** 70
    run_fix("(quotient %s %s)" % (big, big), 1)
    run_fix("(quotient %s %s)" % (-big, big), -1)
    run_fix("(quotient %s %s)" % (big, -big), -1)
    run_fix("(quotient %s %s)" % (-big, -big), 1)
    run_fix("(quotient %s %s)" % (big+1, big), 1)
    run_fix("(quotient %s %s)" % (-(big+1), big), -1)
    res = run(str(big / 2))
    run("(quotient %s 2)" % (big, ), res)

    res = run("(quotient 8.0 2.0)")
    assert isinstance(res, W_Flonum) and res.value == 4.0
    res = run("(quotient 1.0 2.0)")
    assert isinstance(res, W_Flonum) and res.value == 0.5
示例#9
0
def test_box():
    run("(unbox (box #t))", w_true)
    run("(unbox (box-immutable #f))", w_false)
    run("(unsafe-unbox (box #t))", w_true)
    run("(let ([b (box 5)]) (begin (set-box! b #f) (unbox b)))", w_false)
    run("(let* ([b (box 5)] [r (box-cas! b 5 6)]) (and r (eqv? (unbox b) 6)))",
        w_true)
示例#10
0
def test_quotient():
    run_fix("(quotient 0 1)", 0)
    run_fix("(quotient 0 -1)", 0)
    run_fix("(quotient 0 2)", 0)
    run_fix("(quotient 0 -2)", 0)
    run_fix("(quotient 0 3)", 0)
    run_fix("(quotient 1 1)", 1)
    run_fix("(quotient -1 1)", -1)
    run_fix("(quotient 1 -1)", -1)
    run_fix("(quotient -1 -1)", 1)
    run_fix("(quotient 1 2)", 0)
    run_fix("(quotient -1 2)", 0)
    run_fix("(quotient 1 -2)", 0)
    run_fix("(quotient -1 -2)", 0)
    run_fix("(quotient -1234 -10)", 123)
    run_fix("(quotient 1234 1234)", 1)
    big = 2 ** 70
    run_fix("(quotient %s %s)" % (big, big), 1)
    run_fix("(quotient %s %s)" % (-big, big), -1)
    run_fix("(quotient %s %s)" % (big, -big), -1)
    run_fix("(quotient %s %s)" % (-big, -big), 1)
    run_fix("(quotient %s %s)" % (big+1, big), 1)
    run_fix("(quotient %s %s)" % (-(big+1), big), -1)
    res = run(str(big / 2))
    run("(quotient %s 2)" % (big, ), res)
示例#11
0
def test_vec_imp():
    assert isinstance(run('(impersonate-vector (vector 1) values values)'), W_ImpVector)
    run('(vector? (chaperone-vector \'#(0 (2 2 2 2) "Anna") values values))', w_true)
    run_fix("(let ([v (impersonate-vector (vector 1 2 3) values values)]) (vector-length v))", 3)
    run("(let ([v (impersonate-vector (vector 1 2 3) (lambda (x y z) z) (lambda (x y z) z))]) (vector-set! v 0 0))", w_void)
    run_fix("(let ([v (impersonate-vector (vector 1 2 3) (lambda (x y z) z) (lambda (x y z) z))]) (vector-set! v 0 0) (vector-length v))", 3)
    run_fix("(let ([v (impersonate-vector (vector 1 2 3) (lambda (x y z) z) (lambda (x y z) z))]) (vector-set! v 0 0) (vector-ref v 0))", 0)
示例#12
0
def test_vec():
    assert isinstance(run('(vector 1)'), W_Vector)
    #run('(vector? (quote #(0 (2 2 2 2)) "Anna"))', w_true)
    #run("(vector? (quote #())", w_true)
    run_fix("(let-values ([(v) (vector 1 2 3)]) (vector-length v))", 3)
    run("(let-values ([(v) (vector 1 2 3)]) (vector-set! v 0 0))", w_void)
    run_fix("(let-values ([(v) (vector 1 2 3)]) (vector-set! v 0 0) (vector-length v))", 3)
    run_fix("(let-values ([(v) (vector 1 2 3)]) (vector-set! v 0 0) (vector-ref v 0))", 0)
示例#13
0
def test_mcons():
    run_fix("(mcar (mcons 1 2))", 1)
    run_fix("(mcdr (mcons 1 2))", 2)
    run_fix("(unsafe-mcar (mcons 1 2))", 1)
    run_fix("(unsafe-mcdr (mcons 1 2))", 2)
    with pytest.raises(SchemeException):
        run("(mcar 1)", None)
    with pytest.raises(SchemeException):
        run("(mcar 1 2)", None)
示例#14
0
def test_mcons():
    run_fix ("(mcar (mcons 1 2))", 1)
    run_fix ("(mcdr (mcons 1 2))", 2)
    run_fix ("(unsafe-mcar (mcons 1 2))", 1)
    run_fix ("(unsafe-mcdr (mcons 1 2))", 2)
    with pytest.raises(SchemeException):
        run("(mcar 1)", None)
    with pytest.raises(SchemeException):
        run("(mcar 1 2)", None)
示例#15
0
def test_copy_vector_strategy_preserve():
    vec = run("(vector->immutable-vector (vector 1.0 2.0 3.0))")
    assert vec.strategy is FlonumImmutableVectorStrategy.singleton
    vec = run("(vector->immutable-vector (vector 1 2 3))")
    assert vec.strategy is FixnumImmutableVectorStrategy.singleton
    vec = run(r"(vector->immutable-vector (vector #\a #\b #\c))")
    assert vec.strategy is CharacterImmutableVectorStrategy.singleton
    vec = run(r"(vector->immutable-vector (vector #\a #\b #\c 1 1.0))")
    assert vec.strategy is ObjectImmutableVectorStrategy.singleton
示例#16
0
def test_varref():
    run("(#%variable-reference)")
    run("(#%variable-reference add1)")
    run("(let ([x 0]) (#%variable-reference x))")
    run(
        "(let ([x 0]) (variable-reference-constant? (#%variable-reference x)))",
        w_true)
    run(
        "(let ([x 0]) (set! x 1) (variable-reference-constant? (#%variable-reference x)))",
        w_false)
示例#17
0
def test_mcons():
    run_fix ("(mcar (mcons 1 2))", 1)
    run_fix ("(mcdr (mcons 1 2))", 2)
    if pytest.config.load_expander:
        run_fix ("(begin (#%require (quote #%unsafe)) (unsafe-mcar (mcons 1 2)))", 1)
        run_fix ("(begin (#%require (quote #%unsafe)) (unsafe-mcdr (mcons 1 2)))", 2)
    else:
        run_fix ("(unsafe-mcar (mcons 1 2))", 1)
        run_fix ("(unsafe-mcdr (mcons 1 2))", 2)
    with pytest.raises(Exception):
        run("(mcar 1)", None, expect_to_fail=True)
    with pytest.raises(Exception):
        run("(mcar 1 2)", None, expect_to_fail=True)
示例#18
0
def test_lt():
    run("(< 0 1)", w_true)
    run("(< 0 1000000000000000000000000000)", w_true)
    run("(< 10000000000000000000000000001000000000000000000000000000 0 )",
        w_false)
    run(
        "(> 35074662110434038747627587960280857993524015880330828824075798024790963850563322203657080886584969261653150406795437517399294548941469959754171038918004700847889956485329097264486802711583462946536682184340138629451355458264946342525383619389314960644665052551751442335509249173361130355796109709885580674313954210217657847432626760733004753275317192133674703563372783297041993227052663333668509952000175053355529058880434182538386715523683713208549376 0.0)",
        w_true)
示例#19
0
def test_vec():
    assert isinstance(run('(vector 1)'), W_Vector)
    run('(vector? \'#(0 (2 2 2 2) "Anna"))', w_true)
    run("(vector? '#())", w_true)
    run_fix("(let ([v (vector 1 2 3)]) (vector-length v))", 3)
    run("(let ([v (vector 1 2 3)]) (vector-set! v 0 0))", w_void)
    run_fix("(let ([v (vector 1 2 3)]) (vector-set! v 0 0) (vector-length v))", 3)
    run_fix("(let ([v (vector 1 2 3)]) (vector-set! v 0 0) (vector-ref v 0))", 0)
示例#20
0
def test_vec_strategies_stays_flonum():
    vec = run("(let ([vec (vector 1.2 1.2 1.2)]) (vector-set! vec 1 5.5) vec)")
    assert isinstance(vec.strategy, FlonumVectorStrategy)
    vec = run("(let ([vec (vector 1.2 1.2 1.2)]) (vector-set! vec 1 0) vec)")

    # Test that we can encode the full range of signed 32-bit values in the tagged
    # flonum strategy
    assert isinstance(vec.strategy, FlonumTaggedVectorStrategy)
    vec = run("(let ([vec (vector 1.2 1.2 1.2)]) (vector-set! vec 1 %d) vec)" % (2 ** 31 - 1))
    assert isinstance(vec.strategy, FlonumTaggedVectorStrategy)
    vec = run("(let ([vec (vector 1.2 1.2 1.2)]) (vector-set! vec 1 %d) vec)" % (-(2 ** 31)))
    assert isinstance(vec.strategy, FlonumTaggedVectorStrategy)

    # Test transitions from the constant vector strategy to the tagged flonum strategy
    vec = run("(let ([vec (make-vector 10 0)]) (vector-set! vec 1 1.1) vec)")
    assert isinstance(vec.strategy, FlonumTaggedVectorStrategy)
    vec = run("(let ([vec (make-vector 10 %d)]) (vector-set! vec 1 1.1) vec)" % (2 ** 31 - 1))
    assert isinstance(vec.strategy, FlonumTaggedVectorStrategy)
    vec = run("(let ([vec (make-vector 10 %d)]) (vector-set! vec 1 1.1) vec)" % (-(2 ** 31)))
    assert isinstance(vec.strategy, FlonumTaggedVectorStrategy)
示例#21
0
def test_vec_equal_imp():
    run("(equal? (impersonate-vector (vector 1 2 3) (lambda (x y z) z) (lambda (x y z) z)) (vector 1 2 3))", w_true)
    run("(equal? (impersonate-vector (vector 1 2 3) (lambda (x y z) z) (lambda (x y z) z)) (vector 1 2))", w_false)
    run("(equal? (impersonate-vector (vector 1 2 3) (lambda (x y z) z) (lambda (x y z) z)) (vector 1 2 5))", w_false)
示例#22
0
def test_constant():
    ov = run("1", stdlib=False)
    assert isinstance(ov, W_Fixnum)
    assert ov.value == 1
示例#23
0
def test_void():
    run ("(void)", w_void)
    run ("(void 1)", w_void)
    run ("(void 2 3 #true)", w_void)
示例#24
0
def test_eq():
    run("(eq? 'yes 'yes)", w_true)
    run("(eq? 'yes 'no)", w_false)
    run("(let ([v (mcons 1 2)]) (eq? v v))", w_true)
    run("(eq? (mcons 1 2) (mcons 1 2))", w_false)
    #run_top("(eq? (make-string 3 #\z) (make-string 3 #\z))", w_false, stdlib=True)

    run("(eq? 'a 'a)", w_true)
    run("(eq? '(a) '(a))", w_false) #racket
    run("(eq? (list 'a) (list 'a))", w_false)
    # run('(eq? "a" "a")', w_true) #racket
    # run('(eq? "" "")', w_true) #racket
    run("(eq? '() '())", w_true)
    run("(eq? 2 2)",  w_true) #racket
    run("(eq? #\A #\A)", w_true) #racket
    run("(eq? car car)", w_true)
    run("(let ((n (+ 2 3)))(eq? n n))", w_true) #racket
    run("(let ((x '(a)))(eq? x x))", w_true)
    run("(let ((x '#()))(eq? x x))", w_true)
    run("(let ((p (lambda (x) x))) (eq? p p))", w_true)
示例#25
0
def test_vec_equal():
    run("(equal? (vector 1 2 3) (vector 1 2 3))", w_true)
    run("(equal? (vector 1 2 3) (vector 1 2))", w_false)
    run("(equal? (vector 1 2 3) (vector 1 2 5))", w_false)
示例#26
0
def test_lists():
    run ("null", w_null)
    run ("(list)", w_null)
    run ("(list #t)", to_list([w_true]))
    run ("(list-tail (list #f #f #t #t) 2)", to_list([w_true, w_true]))
示例#27
0
def test_vararg():
    run_fix ("((lambda x (car x)) 1)", 1)
    run_fix ("((lambda (a . x) a) 1)", 1)
    run ("((lambda (a . x) x) 1)", w_null)
示例#28
0
def test_vec_strategies_fixnum_singleton():
    vec1 = run("(vector 1 2 3)")
    vec2 = run("(vector 3 2 1)")
    assert vec1.strategy is vec2.strategy
示例#29
0
def test_vec_strategies_object():
    vec = run("(vector (cons 1 2) 2 3)")
    assert isinstance(vec.strategy, ObjectVectorStrategy)
    vec = run("(vector-immutable (cons 1 2) 2 3)")
    assert isinstance(vec.strategy, ObjectImmutableVectorStrategy)
示例#30
0
def test_vec_strategies_stays_character():
    vec = run(r"(let ([vec (vector #\A #\A #\A)]) (vector-set! vec 1 #\D) vec)")
    assert isinstance(vec.strategy, CharacterVectorStrategy)
示例#31
0
def test_vec_strategies_flonum():
    vec = run("(vector 1.0 2.1 3.2)")
    assert isinstance(vec.strategy, FlonumVectorStrategy)
    vec = run("(make-vector 2 1.2)")
    assert isinstance(vec.strategy, ConstantVectorStrategy)
示例#32
0
 def test_basic_hl(self):
     run_fix("(car (cons 1 2))", 1)
     run_fix("(cdr (cons 1 2))", 2)
     run_fix("(car (list 1))", 1)
     run_fix("(car (cdr (list 1 2)))", 2)
     run("(equal? (cons 1 2) (cons 1 2))", w_true)
     run("(equal? (cons 1 2) (cons 2 2))", w_false)
     run("(equal? (cons 1 2) (quote barf))", w_false)
     run("(let-values (((x) (cons 1 2))) (equal? x x))", w_true)
     run("(equal? (cons 1 (cons 2 3)) (cons 1 (cons 2 3)))", w_true)
     run("(equal? (cons 1 (cons 2 3)) (cons 1 (cons 3 3)))", w_false)
     run("(equal? (cons 1 (cons 2 3)) (cons 1 (cons 2 4)))", w_false)
示例#33
0
def test_varref():
    run("(#%variable-reference)")
    run("(#%variable-reference add1)")
    run("(let ([x 0]) (#%variable-reference x))")
    run("(let ([x 0]) (variable-reference-constant? (#%variable-reference x)))", w_true)
    run("(let ([x 0]) (set! x 1) (variable-reference-constant? (#%variable-reference x)))", w_false)
示例#34
0
def test_make_vector():
    run_fix("(let ([v (vector)]) (vector-length v))", 0)
    run_fix("(let ([v (make-vector 5)]) (vector-length v))", 5)
    vec = run('(make-vector 5)')
    for i in range(vec.length()):
        assert vec.ref(i).value == 0
示例#35
0
def test_set_bang():
    run("((lambda (x) (set! x #t) x) 1)", w_true)
    run("(letrec([x 0]) ((lambda (x) (set! x #t) x) 1))", w_true)
示例#36
0
def test_vec_strategies_stays_fixnum():
    vec = run("(let ([vec (vector 0 0 0)]) (vector-set! vec 1 5) vec)")
    assert isinstance(vec.strategy, FixnumVectorStrategy)
示例#37
0
def test_bools():
    run ("#t", w_true)
    run ("#true", w_true)
    run ("#T", w_true)
    run ("#f", w_false)
    run ("#false", w_false)
    run ("#F", w_false)
    run ("(not #t)", w_false)
    run ("(not #f)", w_true)
    run ("(not 5)", w_false)
    run ("true", w_true, stdlib=True)
    run ("false", w_false, stdlib=True)
示例#38
0
def test_eqv():
    check_equal(
        "(eqv? 'yes 'yes)", "#t",
        "(eqv? 'yes 'no)", "#f",
        "(eqv? (expt 2 100) (expt 2 100))", "#t",
        "(eqv? 2 2.0)", "#f",
        "(eqv? (integer->char 955) (integer->char 955))", "#t",
    #run_top("(eqv? (make-string 3 #\z) (make-string 3 #\z))", "#f", stdlib=True)
        "(eqv? +nan.0 +nan.0)", "#t",

        "(eqv? 'a 'a)", "#t",
        "(eqv? 'a 'b)", "#f",
        "(eqv? 2 2)", "#t",
        "(eqv? '() '())", "#t",
        "(eqv? 100000000 100000000)", "#t",
        "(eqv? (cons 1 2) (cons 1 2))", "#f",
        """(eqv? (lambda () 1)
                 (lambda () 2))""", "#f",
        "(eqv? #f 'nil)", "#f",
        """(let ((p (lambda (x) x)))
           (eqv? p p))""", "#t",
    # run('(eqv? "" "")', "#t") #racket
        "(eqv? '#() '#())", "#f", #racket
        """(eqv? (lambda (x) x)
                 (lambda (x) x))""", "#f", #racket
        """(eqv? (lambda (x) x)
                 (lambda (y) y))""", "#f", #racket
    )
    run_top("""(define gen-counter
             (lambda ()
               (let ((n 0))
                 (lambda () (set! n (+ n 1)) n))))
           (let ((g (gen-counter)))
             (eqv? g g))""",
        w_true)
    run_top("""(define gen-counter
             (lambda ()
               (let ((n 0))
                 (lambda () (set! n (+ n 1)) n))))
           (eqv? (gen-counter) (gen-counter))""",
        w_false)
    run_top("""(define gen-loser
             (lambda ()
               (let ((n 0))
                 (lambda () (set! n (+ n 1)) 27))))
           (let ((g (gen-loser)))
             (eqv? g g))""",
        w_true)
    run_top("""(define gen-loser
             (lambda ()
               (let ((n 0))
                 (lambda () (set! n (+ n 1)) 27))))
           (eqv? (gen-loser) (gen-loser))""",
        w_false) #racket

    run("""(letrec ((f (lambda () (if (eqv? f g) 'both 'f)))
                    (g (lambda () (if (eqv? f g) 'both 'g))))
             (eqv? f g))""",
        w_false) #racket

    run("""(letrec ((f (lambda () (if (eqv? f g) 'f 'both)))
                    (g (lambda () (if (eqv? f g) 'g 'both))))
             (eqv? f g))""",
        w_false)
    run("(eqv? '(a) '(a))", w_false) #racket
    # run('(eqv? "a" "a")', w_true) #racket
    run("(eqv? '(b) (cdr '(a b)))", w_false) #racket
    run("""(let ((x '(a)))
           (eqv? x x))""", w_true)
示例#39
0
def test_box():
    run("(unbox (box #t))", w_true)
    run("(unbox (box-immutable #f))", w_false)
    run("(let ([b (box 5)]) (begin (set-box! b #f) (unbox b)))", w_false)
示例#40
0
def test_vec_strategies_character_singleton():
    vec1 = run(r"(vector #\A #\A #\A)")
    vec2 = run(r"(vector #\B #\B)")
    assert vec1.strategy is vec2.strategy
示例#41
0
def test_keyword():
    run("'#:foo", W_Keyword.make("foo"))
示例#42
0
def test_vec_strategies_character():
    vec1 = run(r"(vector #\A #\B #\C)")
    assert isinstance(vec1.strategy, CharacterVectorStrategy)
    vec2 = run(r"(vector #\a)")
    assert isinstance(vec2.strategy, CharacterVectorStrategy)
示例#43
0
def test_equal():
    run("(equal? 'a 'a)", w_true)
    run("(equal? '(a) '(a))", w_true)
    run("(equal? '(a (b) c) '(a (b) c))", w_true)
    run('(equal? "abc" "abc")', w_true)
    run("(equal? 2 2)", w_true)
    run("(equal? (make-vector 5 'a) (make-vector 5 'a))", w_true)
    run("(equal? (lambda (x) x) (lambda (y) y))", w_false) #racket
示例#44
0
def test_bug_symbol_in_vector():
    # FIXME somebody who knows expand
    run("#('a)")
示例#45
0
def test_caselambda():
    run("(case-lambda [(x) 1])")
    run("(case-lambda [(x) x])")
    run("(case-lambda [() 0])")
    run("(case-lambda [() 0] [(x) x])")
    run("(case-lambda [x 0])")
    run("((case-lambda [() #f]))", w_false)
    run("((case-lambda [(x) #f]) 0)", w_false)
    run("((case-lambda [() 0] [(x) x]) #f)", w_false)
    run("((case-lambda [x #t] [(x) x]) #f)", w_true)
    run("((case-lambda [x (car x)] [(x) x]) #f #t 17)", w_false)
    run("((case-lambda [(x) x] [x (car x)]) #f #t 17)", w_false)
示例#46
0
def run_unsafe(e,v):
    run(e,v,extra="")
示例#47
0
def test_arity():
    run("(procedure-arity-includes? add1 1)", w_true)
    run("(procedure-arity-includes? add1 2)", w_false)
    run("(procedure-arity-includes? make-vector 1)", w_true)
    run("(procedure-arity-includes? make-vector 2)", w_true)
    run("(procedure-arity-includes? (lambda (x) 0) 1)", w_true)
    run("(procedure-arity-includes? (lambda (x) 0) 2)", w_false)
    run("(procedure-arity-includes? (lambda (x y) 0) 2)", w_true)
    run("(procedure-arity-includes? (lambda (x . y) 0) 1)", w_true)
    run("(procedure-arity-includes? (lambda (x . y) 0) 2)", w_true)
    run("(procedure-arity-includes? (lambda (x . y) 0) 200000)", w_true)
    run("(procedure-arity-includes? (lambda x 1) 1)", w_true)
    run("(procedure-arity-includes? (lambda x 1) 0)", w_true)
示例#48
0
def test_constant_strategy():
    vec = run("(make-vector 10 #f)")
    assert vec.strategy is ConstantVectorStrategy.singleton
    vec = run("(vector->immutable-vector (make-vector 10 #t))")
    assert vec.strategy is ConstantImmutableVectorStrategy.singleton
示例#49
0
def test_random_seed():
    run("(begin (random-seed 142) (let ((x (random))) (random-seed 142) (= (random) x)))", w_true)
示例#50
0
def test_vec_strategies_fixnum():
    vec = run("(vector 1 2 3)")
    assert isinstance(vec.strategy, FixnumVectorStrategy)
    vec = run("(make-vector 2)")
    assert isinstance(vec.strategy, ConstantVectorStrategy)