예제 #1
0
def test_create_int():
    a = wrap_int(0)
    b = wrap_int(1)
    c = wrap_int(1)

    assert RT._equiv.invoke2(a, b) is false
    assert RT._equiv.invoke2(b, c) is true
예제 #2
0
def test_create_int():
    a = wrap_int(0)
    b = wrap_int(1)
    c = wrap_int(1)

    assert RT._equiv.invoke2(a, b) is false
    assert RT._equiv.invoke2(b, c) is true
예제 #3
0
def test_large_vector():
    r = EMPTY_VEC
    for x in range(1024 * 2):
        r = RT.conj.invoke2(r, wrap_int(x))
        c = RT.count.invoke1(r)
        assert c._int_value == x + 1

    assert r

    for x in range(1024 * 2):
        v = RT.nth.invoke2(r, wrap_int(x))
        assert RT._equiv.invoke2(v, wrap_int(x)) is true
예제 #4
0
def test_binop_overflow():
    v1 = wrap_int(maxint - 1)
    v2 = wrap_int(2)

    def assert_overflows(f):
        try:
            f.invoke2(v1, v2)
            assert False, "Should overflow"
        except OverflowError:
            pass

    def assert_converts_to_bigint(f, v):
        expected = wrap_bigint(rbigint.fromlong(v))
        result = f.invoke2(v1, v2)
        assert type(result) == WBigInt
        assert result._bigint_value.eq(expected._bigint_value)

    assert_overflows(RT._add)
    assert_overflows(RT._multiply)
    assert_converts_to_bigint(RT._addP, maxint+1)
    assert_converts_to_bigint(RT._multiplyP, (maxint-1)*2)
예제 #5
0
def test_unary_overflow():
    pos = wrap_int(maxint)
    neg = wrap_int(-maxint-1)

    def assert_overflows(f, x):
        try:
            f.invoke1(x)
            assert False, "Should overflow"
        except OverflowError:
            pass

    def assert_converts_to_bigint(f, x, n):
        expected = wrap_bigint(rbigint.fromlong(n))
        result = f.invoke1(x)
        assert type(result) == WBigInt
        assert result._bigint_value.eq(expected._bigint_value)

    assert_overflows(RT._negate, neg)
    assert_overflows(RT._inc, pos)
    assert_overflows(RT._dec, neg)
    assert_converts_to_bigint(RT._negateP, neg, maxint+1)
    assert_converts_to_bigint(RT._incP, pos, maxint+1)
    assert_converts_to_bigint(RT._decP, neg, -maxint-2)
예제 #6
0
def wrap_num(n, type):
    if type == WInt:
        return wrap_int(n)
    elif type == WBigInt:
        return wrap_bigint(rbigint.fromint(n))
예제 #7
0
 def rt_hash(self):
     return wrap_int(42)
예제 #8
0
 def rt_hash(self):
     return wrap_int(42)