Author: Armin Rigo <[email protected]>
Branch:
Changeset: r74910:b30951625595
Date: 2014-12-14 13:23 +0000
http://bitbucket.org/pypy/pypy/changeset/b30951625595/
Log: Add stress tests for rordereddict, copied from rdict. Kill an
unused function.
diff --git a/rpython/rtyper/lltypesystem/rordereddict.py
b/rpython/rtyper/lltypesystem/rordereddict.py
--- a/rpython/rtyper/lltypesystem/rordereddict.py
+++ b/rpython/rtyper/lltypesystem/rordereddict.py
@@ -865,23 +865,6 @@
pass
-def rtype_r_dict(hop):
- r_dict = hop.r_result
- if not r_dict.custom_eq_hash:
- raise TyperError("r_dict() call does not return an r_dict instance")
- v_eqfn = hop.inputarg(r_dict.r_rdict_eqfn, arg=0)
- v_hashfn = hop.inputarg(r_dict.r_rdict_hashfn, arg=1)
- cDICT = hop.inputconst(lltype.Void, r_dict.DICT)
- hop.exception_cannot_occur()
- v_result = hop.gendirectcall(ll_newdict, cDICT)
- if r_dict.r_rdict_eqfn.lowleveltype != lltype.Void:
- cname = hop.inputconst(lltype.Void, 'fnkeyeq')
- hop.genop('setfield', [v_result, cname, v_eqfn])
- if r_dict.r_rdict_hashfn.lowleveltype != lltype.Void:
- cname = hop.inputconst(lltype.Void, 'fnkeyhash')
- hop.genop('setfield', [v_result, cname, v_hashfn])
- return v_result
-
# ____________________________________________________________
#
# Iteration.
diff --git a/rpython/rtyper/test/test_rordereddict.py
b/rpython/rtyper/test/test_rordereddict.py
--- a/rpython/rtyper/test/test_rordereddict.py
+++ b/rpython/rtyper/test/test_rordereddict.py
@@ -287,3 +287,126 @@
def test_memoryerror_should_not_insert(self):
py.test.skip("I don't want to edit this file on two branches")
+
+
+class TestStress:
+
+ def test_stress(self):
+ from rpython.annotator.dictdef import DictKey, DictValue
+ from rpython.annotator import model as annmodel
+ from rpython.rtyper import rint
+ from rpython.rtyper.test.test_rdict import not_really_random
+ rodct = rordereddict
+ dictrepr = rodct.OrderedDictRepr(
+ None, rint.signed_repr, rint.signed_repr,
+ DictKey(None, annmodel.SomeInteger()),
+ DictValue(None, annmodel.SomeInteger()))
+ dictrepr.setup()
+ l_dict = rodct.ll_newdict(dictrepr.DICT)
+ referencetable = [None] * 400
+ referencelength = 0
+ value = 0
+
+ def complete_check():
+ for n, refvalue in zip(range(len(referencetable)), referencetable):
+ try:
+ gotvalue = rodct.ll_dict_getitem(l_dict, n)
+ except KeyError:
+ assert refvalue is None
+ else:
+ assert gotvalue == refvalue
+
+ for x in not_really_random():
+ n = int(x*100.0) # 0 <= x < 400
+ op = repr(x)[-1]
+ if op <= '2' and referencetable[n] is not None:
+ rodct.ll_dict_delitem(l_dict, n)
+ referencetable[n] = None
+ referencelength -= 1
+ elif op <= '6':
+ rodct.ll_dict_setitem(l_dict, n, value)
+ if referencetable[n] is None:
+ referencelength += 1
+ referencetable[n] = value
+ value += 1
+ else:
+ try:
+ gotvalue = rodct.ll_dict_getitem(l_dict, n)
+ except KeyError:
+ assert referencetable[n] is None
+ else:
+ assert gotvalue == referencetable[n]
+ if 1.38 <= x <= 1.39:
+ complete_check()
+ print 'current dict length:', referencelength
+ assert l_dict.num_items == referencelength
+ complete_check()
+
+ def test_stress_2(self):
+ yield self.stress_combination, True, False
+ yield self.stress_combination, False, True
+ yield self.stress_combination, False, False
+ yield self.stress_combination, True, True
+
+ def stress_combination(self, key_can_be_none, value_can_be_none):
+ from rpython.rtyper.lltypesystem.rstr import string_repr
+ from rpython.annotator.dictdef import DictKey, DictValue
+ from rpython.annotator import model as annmodel
+ from rpython.rtyper.test.test_rdict import not_really_random
+ rodct = rordereddict
+
+ print
+ print "Testing combination with can_be_None: keys %s, values %s" % (
+ key_can_be_none, value_can_be_none)
+
+ class PseudoRTyper:
+ cache_dummy_values = {}
+ dictrepr = rodct.OrderedDictRepr(
+ PseudoRTyper(), string_repr, string_repr,
+ DictKey(None, annmodel.SomeString(key_can_be_none)),
+ DictValue(None, annmodel.SomeString(value_can_be_none)))
+ dictrepr.setup()
+ print dictrepr.lowleveltype
+ #for key, value in dictrepr.DICTENTRY._adtmeths.items():
+ # print ' %s = %s' % (key, value)
+ l_dict = rodct.ll_newdict(dictrepr.DICT)
+ referencetable = [None] * 400
+ referencelength = 0
+ values = not_really_random()
+ keytable = [string_repr.convert_const("foo%d" % n)
+ for n in range(len(referencetable))]
+
+ def complete_check():
+ for n, refvalue in zip(range(len(referencetable)), referencetable):
+ try:
+ gotvalue = rodct.ll_dict_getitem(l_dict, keytable[n])
+ except KeyError:
+ assert refvalue is None
+ else:
+ assert gotvalue == refvalue
+
+ for x in not_really_random():
+ n = int(x*100.0) # 0 <= x < 400
+ op = repr(x)[-1]
+ if op <= '2' and referencetable[n] is not None:
+ rodct.ll_dict_delitem(l_dict, keytable[n])
+ referencetable[n] = None
+ referencelength -= 1
+ elif op <= '6':
+ ll_value = string_repr.convert_const(str(values.next()))
+ rodct.ll_dict_setitem(l_dict, keytable[n], ll_value)
+ if referencetable[n] is None:
+ referencelength += 1
+ referencetable[n] = ll_value
+ else:
+ try:
+ gotvalue = rodct.ll_dict_getitem(l_dict, keytable[n])
+ except KeyError:
+ assert referencetable[n] is None
+ else:
+ assert gotvalue == referencetable[n]
+ if 1.38 <= x <= 1.39:
+ complete_check()
+ print 'current dict length:', referencelength
+ assert l_dict.num_items == referencelength
+ complete_check()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit