From: Stefan Behnel Date: Sun, 16 Nov 2008 22:20:15 +0000 (+0100) Subject: test case for iter-dict transform X-Git-Tag: 0.11-beta~243 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=562dbd1f1919ee026d8fa874e143585aed3d09e1;p=cython.git test case for iter-dict transform --- diff --git a/tests/run/iterdict.pyx b/tests/run/iterdict.pyx new file mode 100644 index 00000000..8fb92ae3 --- /dev/null +++ b/tests/run/iterdict.pyx @@ -0,0 +1,50 @@ +__doc__ = u""" +>>> dict_size = 4 +>>> d = dict(zip(range(10,dict_size+10), range(dict_size))) + +>>> items(d) +[(10, 0), (11, 1), (12, 2), (13, 3)] +>>> iteritems(d) +[(10, 0), (11, 1), (12, 2), (13, 3)] +>>> iteritems_tuple(d) +[(10, 0), (11, 1), (12, 2), (13, 3)] +>>> iterkeys(d) +[10, 11, 12, 13] +>>> itervalues(d) +[0, 1, 2, 3] +""" + +def items(dict d): + l = [] + for k,v in d.items(): + l.append((k,v)) + l.sort() + return l + +def iteritems(dict d): + l = [] + for k,v in d.iteritems(): + l.append((k,v)) + l.sort() + return l + +def iteritems_tuple(dict d): + l = [] + for t in d.iteritems(): + l.append(t) + l.sort() + return l + +def iterkeys(dict d): + l = [] + for k in d.iterkeys(): + l.append(k) + l.sort() + return l + +def itervalues(dict d): + l = [] + for v in d.itervalues(): + l.append(v) + l.sort() + return l