Commit 225da25f authored by cjgibson's avatar cjgibson

Fixing test cases for Python3, added unicode.

parent 3a810f55
......@@ -208,31 +208,35 @@ ctypedef fused slicable:
list
tuple
bytes
unicode
def slice_fused_type_start(slicable seq, start):
"""
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
... for s in (0, 4, 5, -5, None):
... slice_fused_type_start(o, s)
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for s in (0, 4, 5, -5):
... print(p(slice_fused_type_start(o, s)))
...
[1, 2, 3, 4, 5]
[5]
[]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
(5,)
()
(1, 2, 3, 4, 5)
(1, 2, 3, 4, 5)
'12345'
'5'
''
'12345'
'12345'
12345
5
<BLANKLINE>
12345
12345
5
<BLANKLINE>
12345
"""
obj = seq[start:]
return obj
......@@ -242,9 +246,11 @@ def slice_fused_type_stop(slicable seq, stop):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for s in (0, 4, 5, -5, None):
... slice_fused_type_stop(o, s)
... print(p(slice_fused_type_stop(o, s)))
...
[]
[1, 2, 3, 4]
......@@ -256,11 +262,16 @@ def slice_fused_type_stop(slicable seq, stop):
(1, 2, 3, 4, 5)
()
(1, 2, 3, 4, 5)
''
'1234'
'12345'
''
'12345'
<BLANKLINE>
1234
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
<BLANKLINE>
12345
"""
obj = seq[:stop]
return obj
......@@ -270,10 +281,12 @@ def slice_fused_type_start_and_stop(slicable seq, start, stop):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for start in (0, 1, 4, 5, -5, None):
... for stop in (0, 4, 5, 10, -10, None):
... slice_fused_type_start_and_stop(o, start, stop)
... for stop in (0, 4, 5, 10, -10, None):
... print(p(slice_fused_type_start_and_stop(o, start, stop)))
...
[]
[1, 2, 3, 4]
......@@ -347,42 +360,78 @@ def slice_fused_type_start_and_stop(slicable seq, start, stop):
(1, 2, 3, 4, 5)
()
(1, 2, 3, 4, 5)
''
'1234'
'12345'
'12345'
''
'12345'
''
'234'
'2345'
'2345'
''
'2345'
''
''
'5'
'5'
''
'5'
''
''
''
''
''
''
''
'1234'
'12345'
'12345'
''
'12345'
''
'1234'
'12345'
'12345'
''
'12345'
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
234
2345
2345
<BLANKLINE>
2345
<BLANKLINE>
<BLANKLINE>
5
5
<BLANKLINE>
5
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
234
2345
2345
<BLANKLINE>
2345
<BLANKLINE>
<BLANKLINE>
5
5
<BLANKLINE>
5
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
<BLANKLINE>
1234
12345
12345
<BLANKLINE>
12345
"""
obj = seq[start:stop]
return obj
......@@ -392,9 +441,11 @@ def slice_fused_type_step(slicable seq, step):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for s in (1, -1, 2, -3, 10, -10, None):
... slice_fused_type_step(o, s)
... print(p(slice_fused_type_step(o, s)))
...
[1, 2, 3, 4, 5]
[5, 4, 3, 2, 1]
......@@ -410,13 +461,20 @@ def slice_fused_type_step(slicable seq, step):
(1,)
(5,)
(1, 2, 3, 4, 5)
'12345'
'54321'
'135'
'52'
'1'
'5'
'12345'
12345
54321
135
52
1
5
12345
12345
54321
135
52
1
5
12345
>>> for o in (l, t, b):
... try: slice_fused_type_step(o, 0)
... except ValueError: pass
......@@ -429,10 +487,12 @@ def slice_fused_type_start_and_step(slicable seq, start, step):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for start in (0, 2, 5, -5, None):
... for step in (1, -1, 2, -3, None):
... slice_fused_type_start_and_step(o, start, step)
... for step in (1, -1, 2, -3, None):
... print(p(slice_fused_type_start_and_step(o, start, step)))
...
[1, 2, 3, 4, 5]
[1]
......@@ -484,31 +544,56 @@ def slice_fused_type_start_and_step(slicable seq, start, step):
(1, 3, 5)
(5, 2)
(1, 2, 3, 4, 5)
'12345'
'1'
'135'
'1'
'12345'
'345'
'321'
'35'
'3'
'345'
''
'54321'
''
'52'
''
'12345'
'1'
'135'
'1'
'12345'
'12345'
'54321'
'135'
'52'
'12345'
12345
1
135
1
12345
345
321
35
3
345
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
1
135
1
12345
12345
54321
135
52
12345
12345
1
135
1
12345
345
321
35
3
345
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
1
135
1
12345
12345
54321
135
52
12345
>>> for o in (l, t, b):
... try: slice_fused_type_start_and_step(o, 0, 0)
... except ValueError: pass
......@@ -521,10 +606,12 @@ def slice_fused_type_stop_and_step(slicable seq, stop, step):
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, b):
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for stop in (5, 10, 3, -10, None):
... for step in (1, -1, 2, -3, None):
... slice_fused_type_stop_and_step(o, stop, step)
... for step in (1, -1, 2, -3, None):
... print(p(slice_fused_type_stop_and_step(o, stop, step)))
...
[1, 2, 3, 4, 5]
[]
......@@ -576,31 +663,56 @@ def slice_fused_type_stop_and_step(slicable seq, stop, step):
(1, 3, 5)
(5, 2)
(1, 2, 3, 4, 5)
'12345'
''
'135'
''
'12345'
'12345'
''
'135'
''
'12345'
'123'
'5'
'13'
'5'
'123'
''
'54321'
''
'52'
''
'12345'
'54321'
'135'
'52'
'12345'
12345
<BLANKLINE>
135
<BLANKLINE>
12345
12345
<BLANKLINE>
135
<BLANKLINE>
12345
123
5
13
5
123
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
54321
135
52
12345
12345
<BLANKLINE>
135
<BLANKLINE>
12345
12345
<BLANKLINE>
135
<BLANKLINE>
12345
123
5
13
5
123
<BLANKLINE>
54321
<BLANKLINE>
52
<BLANKLINE>
12345
54321
135
52
12345
>>> for o in (l, t, b):
... try: slice_fused_type_stop_and_step(o, 5, 0)
... except ValueError: pass
......@@ -612,55 +724,46 @@ def slice_fused_type_all(slicable seq, start, stop, step):
"""
>>> l = [1,2,3,4,5]
>>> t = tuple(l)
>>> s = ''.join(map(str, l)).encode('ASCII')
>>> for o in (l, t, s):
... slice_fused_type_all(o, 0, 5, 1)
...
>>> b = ''.join(map(str, l)).encode('ASCII')
>>> u = b.decode('ASCII')
>>> p = lambda o: o.decode() if isinstance(o, type(b)) else str(o)
>>> for o in (l, t, b, u):
... for args in ((0, 5, 1), (5, 0, -1), (None, 5, 1), (5, None, -1),
... (-100, 100, None), (None, None, None), (1, 3, 2), (5, 1, -3)):
... print(p(slice_fused_type_all(o, *args)))
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 5, 0, -1)
...
[5, 4, 3, 2]
(5, 4, 3, 2)
'5432'
>>> for o in (l, t, s):
... slice_fused_type_all(o, None, 5, 1)
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 5, None, -1)
...
[5, 4, 3, 2, 1]
(5, 4, 3, 2, 1)
'54321'
>>> for o in (l, t, s):
... slice_fused_type_all(o, -100, 100, None)
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, None, None, None)
...
[1, 2, 3, 4, 5]
(1, 2, 3, 4, 5)
'12345'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 1, 3, 2)
...
[2]
(2,)
'2'
>>> for o in (l, t, s):
... slice_fused_type_all(o, 5, 1, -3)
...
[5]
(1, 2, 3, 4, 5)
(5, 4, 3, 2)
(1, 2, 3, 4, 5)
(5, 4, 3, 2, 1)
(1, 2, 3, 4, 5)
(1, 2, 3, 4, 5)
(2,)
(5,)
'5'
12345
5432
12345
54321
12345
12345
2
5
12345
5432
12345
54321
12345
12345
2
5
"""
obj = seq[start:stop:step]
return obj
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