Debian Codegraph @

pypy/objspace/std/test/test_userobject.py

raw symbols SCIP
1 from pypy.interpreter import gateway
2
3
4 class AppTestUserObject:
5 spaceconfig = {}
6
7 def setup_class(cls):
8 cls.w_runappdirect = cls.space.wrap(cls.runappdirect)
9 def rand(space):
10 import random
11 return space.wrap(random.randrange(0, 5))
12 cls.w_rand = cls.space.wrap(gateway.interp2app(rand))
13
14 def test_hash(self):
15 if not hasattr(self, 'runappdirect'):
16 skip("disabled")
17 if self.runappdirect:
18 total = 500000
19 def rand():
20 import random
21 return random.randrange(0, 5)
22 else:
23 total = 50
24 rand = self.rand
25 #
26 class A(object):
27 hash = None
28 tail = any = A()
29 tail.next = tail
30 i = 0
31 while i < total:
32 a = A()
33 a.next = tail.next
34 tail.next = a
35 for j in range(rand()):
36 any = any.next
37 if any.hash is None:
38 any.hash = hash(any)
39 else:
40 assert any.hash == hash(any)
41 i += 1
42 i = 0
43 while i < total:
44 if any.hash is not None:
45 assert any.hash == hash(any)
46 any = any.next
47 i += 1