本文整理汇总了Python中pycket.test.testhelper.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cons
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)
示例2: test_vec_imp
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)
示例3: test_vec_strategies_empty
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)
示例4: test_quotient
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
示例5: test_quotient
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)
示例6: test_cons
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)
示例7: test_vec_strategies_dehomogenize
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)
示例8: test_vec
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)
示例9: test_copy_vector_strategy_preserve
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
示例10: test_mcons
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)
示例11: test_mcons
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)
示例12: test_vec
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)
示例13: test_vec_strategies_stays_flonum
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)
示例14: test_eq
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)
示例15: test_keyword
def test_keyword():
run("'#:foo", W_Keyword.make("foo"))