From b02c0b099d92086dd0e0ff1f6164fbfef8a832e6 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 11 Mar 2009 04:46:33 -0700 Subject: [PATCH] More indexing tests --- tests/run/dictintindex.pyx | 4 ++-- tests/run/index.pyx | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/run/dictintindex.pyx b/tests/run/dictintindex.pyx index df739065..1aca230d 100644 --- a/tests/run/dictintindex.pyx +++ b/tests/run/dictintindex.pyx @@ -42,9 +42,9 @@ KeyError: 0 >>> test_del_int() Traceback (most recent call last): KeyError: 0 ->>> test_del_uint() +>>> test_del_uint() #doctest: +ELLIPSIS Traceback (most recent call last): -KeyError: 0 +KeyError: 0... >>> test_del_longlong() #doctest: +ELLIPSIS Traceback (most recent call last): KeyError: 0... diff --git a/tests/run/index.pyx b/tests/run/index.pyx index 492598db..58bcf441 100644 --- a/tests/run/index.pyx +++ b/tests/run/index.pyx @@ -42,6 +42,10 @@ IndexError: string index out of range Traceback (most recent call last): ... TypeError: 'int' object is unsubscriptable + +>>> test_unsigned_long() +>>> test_unsigned_short() +>>> test_long_long() """ @@ -53,3 +57,45 @@ def index_list(list L, int i): def index_object(object o, int i): return o[i] + + +# These make sure that our fast indexing works with large and unsigned types. + +def test_unsigned_long(): + cdef int i + cdef unsigned long ix + cdef D = {} + for i from 0 <= i < sizeof(unsigned long) * 8: + ix = (1) << i + D[ix] = True + for i from 0 <= i < sizeof(unsigned long) * 8: + ix = (1) << i + assert D[ix] is True + del D[ix] + assert len(D) == 0 + +def test_unsigned_short(): + cdef int i + cdef unsigned short ix + cdef D = {} + for i from 0 <= i < sizeof(unsigned short) * 8: + ix = (1) << i + D[ix] = True + for i from 0 <= i < sizeof(unsigned short) * 8: + ix = (1) << i + assert D[ix] is True + del D[ix] + assert len(D) == 0 + +def test_long_long(): + cdef int i + cdef long long ix + cdef D = {} + for i from 0 <= i < sizeof(long long) * 8: + ix = (1) << i + D[ix] = True + for i from 0 <= i < sizeof(long long) * 8: + ix = (1) << i + assert D[ix] is True + del D[ix] + assert len(D) == 0 -- 2.26.2