Commit ce93bf52 authored by Xavier Thompson's avatar Xavier Thompson

Clarify cypclass builtin dict and list unit tests

parent 659ba3a5
This diff is collapsed.
...@@ -59,7 +59,7 @@ def test_nogil_insert_and_iteration(): ...@@ -59,7 +59,7 @@ def test_nogil_insert_and_iteration():
def test_len(): def test_len():
""" """
>>> test_len() >>> test_len()
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
cdef long unsigned int nb_elements = 0 cdef long unsigned int nb_elements = 0
...@@ -68,15 +68,15 @@ def test_len(): ...@@ -68,15 +68,15 @@ def test_len():
for v in l: for v in l:
nb_elements += 1 nb_elements += 1
if l.__len__() != nb_elements: if l.__len__() != nb_elements:
return 0 return -1
if nb_elements != 10: if nb_elements != 10:
return 0 return -2
return 1 return 0
def test_clear(): def test_clear():
""" """
>>> test_clear() >>> test_clear()
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
for i in range(10): for i in range(10):
...@@ -85,23 +85,23 @@ def test_clear(): ...@@ -85,23 +85,23 @@ def test_clear():
return -1 return -1
l.clear() l.clear()
if l.__len__() != 0: if l.__len__() != 0:
return 0 return -2
return 1 return 0
def test_contains(): def test_contains():
""" """
>>> test_clear() >>> test_clear()
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
for i in range(10): for i in range(10):
value = Value(i) value = Value(i)
if value in l: if value in l:
return 0 return -1
l.append(value) l.append(value)
if value not in l: if value not in l:
return 0 return -2
return 1 return 0
def test_add(): def test_add():
""" """
...@@ -157,55 +157,55 @@ def test_getitem_out_of_range(): ...@@ -157,55 +157,55 @@ def test_getitem_out_of_range():
""" """
>>> test_getitem_out_of_range() >>> test_getitem_out_of_range()
Getting list index out of range Getting list index out of range
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
try: try:
with nogil: with nogil:
v = l[0] v = l[0]
with gil: with gil:
return 0 return -1
except IndexError as e: except IndexError as e:
print(e) print(e)
return 1 return 0
def test_setitem_out_of_range(): def test_setitem_out_of_range():
""" """
>>> test_setitem_out_of_range() >>> test_setitem_out_of_range()
Setting list index out of range Setting list index out of range
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
try: try:
with nogil: with nogil:
l[0] = Value(0) l[0] = Value(0)
with gil: with gil:
return 0 return -1
except IndexError as e: except IndexError as e:
print(e) print(e)
return 1 return 0
def test_delitem_out_of_range(): def test_delitem_out_of_range():
""" """
>>> test_delitem_out_of_range() >>> test_delitem_out_of_range()
Deleting list index out of range Deleting list index out of range
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
try: try:
with nogil: with nogil:
del l[0] del l[0]
with gil: with gil:
return 0 return -1
except IndexError as e: except IndexError as e:
print(e) print(e)
return 1 return 0
def test_append_iterator_invalidation(): def test_append_iterator_invalidation():
""" """
>>> test_append_iterator_invalidation() >>> test_append_iterator_invalidation()
Modifying a list with active iterators Modifying a list with active iterators
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
iterator = l.begin() iterator = l.begin()
...@@ -213,16 +213,16 @@ def test_append_iterator_invalidation(): ...@@ -213,16 +213,16 @@ def test_append_iterator_invalidation():
with nogil: with nogil:
l.append(Value(1)) l.append(Value(1))
with gil: with gil:
return 0 return -1
except RuntimeError as e: except RuntimeError as e:
print(e) print(e)
return 1 return 0
def test_insert_iterator_invalidation(): def test_insert_iterator_invalidation():
""" """
>>> test_insert_iterator_invalidation() >>> test_insert_iterator_invalidation()
Modifying a list with active iterators Modifying a list with active iterators
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
iterator = l.begin() iterator = l.begin()
...@@ -230,16 +230,16 @@ def test_insert_iterator_invalidation(): ...@@ -230,16 +230,16 @@ def test_insert_iterator_invalidation():
with nogil: with nogil:
l.insert(0, Value(1)) l.insert(0, Value(1))
with gil: with gil:
return 0 return -1
except RuntimeError as e: except RuntimeError as e:
print(e) print(e)
return 1 return 0
def test_del_iterator_invalidation(): def test_del_iterator_invalidation():
""" """
>>> test_del_iterator_invalidation() >>> test_del_iterator_invalidation()
Modifying a list with active iterators Modifying a list with active iterators
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
l.append(Value(0)) l.append(Value(0))
...@@ -248,16 +248,16 @@ def test_del_iterator_invalidation(): ...@@ -248,16 +248,16 @@ def test_del_iterator_invalidation():
with nogil: with nogil:
del l[0] del l[0]
with gil: with gil:
return 0 return -1
except RuntimeError as e: except RuntimeError as e:
print(e) print(e)
return 1 return 0
def test_clear_iterator_invalidation(): def test_clear_iterator_invalidation():
""" """
>>> test_clear_iterator_invalidation() >>> test_clear_iterator_invalidation()
Modifying a list with active iterators Modifying a list with active iterators
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
iterator = l.begin() iterator = l.begin()
...@@ -265,15 +265,15 @@ def test_clear_iterator_invalidation(): ...@@ -265,15 +265,15 @@ def test_clear_iterator_invalidation():
with nogil: with nogil:
l.clear() l.clear()
with gil: with gil:
return 0 return -1
except RuntimeError as e: except RuntimeError as e:
print(e) print(e)
return 1 return 0
def test_modification_after_iteration(): def test_modification_after_iteration():
""" """
>>> test_modification_after_iteration() >>> test_modification_after_iteration()
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
for value in l: for value in l:
...@@ -285,10 +285,10 @@ def test_modification_after_iteration(): ...@@ -285,10 +285,10 @@ def test_modification_after_iteration():
del l[0] del l[0]
l.clear() l.clear()
with gil: with gil:
return 1 return 0
except RuntimeError as e: except RuntimeError as e:
print(e) print(e)
return 0 return -1
def test_scalar_types_list(): def test_scalar_types_list():
""" """
...@@ -327,101 +327,101 @@ def test_values_destroyed(): ...@@ -327,101 +327,101 @@ def test_values_destroyed():
def test_values_refcount(): def test_values_refcount():
""" """
>>> test_values_refcount() >>> test_values_refcount()
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
value = Value() value = Value()
if Cy_GETREF(value) != 2: if Cy_GETREF(value) != 2:
return 0 return -1
l.append(value) l.append(value)
if Cy_GETREF(value) != 3: if Cy_GETREF(value) != 3:
return 0 return -2
l.insert(0, value) l.insert(0, value)
if Cy_GETREF(value) != 4: if Cy_GETREF(value) != 4:
return 0 return -3
del l[0] del l[0]
if Cy_GETREF(value) != 3: if Cy_GETREF(value) != 3:
return 0 return -4
l.clear() l.clear()
if Cy_GETREF(value) != 2: if Cy_GETREF(value) != 2:
return 0 return -5
l.append(value) l.append(value)
if Cy_GETREF(value) != 3: if Cy_GETREF(value) != 3:
return 0 return -6
del l del l
if Cy_GETREF(value) != 2: if Cy_GETREF(value) != 2:
return 0 return -7
return 1 return 0
def test_iterator_refcount(): def test_iterator_refcount():
""" """
>>> test_iterator_refcount() >>> test_iterator_refcount()
1 0
""" """
l = cyplist[Value]() l = cyplist[Value]()
if Cy_GETREF(l) != 2: if Cy_GETREF(l) != 2:
return 0 return -1
def begin_iterator(): def begin_iterator():
it = l.begin() it = l.begin()
if Cy_GETREF(l) != 3: if Cy_GETREF(l) != 3:
return 0 return -1
return 1
if not begin_iterator():
return 0 return 0
if begin_iterator():
return -2
if Cy_GETREF(l) != 2: if Cy_GETREF(l) != 2:
return 0 return -3
def end_iterator(): def end_iterator():
it = l.end() it = l.end()
if Cy_GETREF(l) != 2: if Cy_GETREF(l) != 2:
return 0 return -1
return 1
if not end_iterator():
return 0 return 0
if end_iterator():
return -4
if Cy_GETREF(l) != 2: if Cy_GETREF(l) != 2:
return 0 return -5
return 1 return 0
def test_concatenation_refcount(): def test_concatenation_refcount():
""" """
>>> test_concatenation_refcount() >>> test_concatenation_refcount()
1 0
""" """
value = Value(1) value = Value(1)
l1 = cyplist[Value]() l1 = cyplist[Value]()
if Cy_GETREF(value) != 2: if Cy_GETREF(value) != 2:
return 0 return -1
l1.append(value) l1.append(value)
if Cy_GETREF(value) != 3: if Cy_GETREF(value) != 3:
return 0 return -2
l2 = cyplist[Value]() l2 = cyplist[Value]()
l2.append(value) l2.append(value)
if Cy_GETREF(value) != 4: if Cy_GETREF(value) != 4:
return 0 return -3
l3 = l1 + l2 l3 = l1 + l2
if Cy_GETREF(value) != 6: if Cy_GETREF(value) != 6:
return 0 return -4
l3 += l1 l3 += l1
if Cy_GETREF(value) != 7: if Cy_GETREF(value) != 7:
return 0 return -5
l4 = l3 * 3 l4 = l3 * 3
if Cy_GETREF(value) != 16: if Cy_GETREF(value) != 16:
return 0 return -6
l4 *= 2 l4 *= 2
if Cy_GETREF(value) != 25: if Cy_GETREF(value) != 25:
return 0 return -7
return 1 return 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment