You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: this is an excerpt from the `PyPy`_ documentation. On Nov. 19, 2014 I ran this test on PyPy 2.4.0 and PyPy3 2.4.0 and the result was not as described, but was the same as with CPython: 'foo'.
Copy file name to clipboardExpand all lines: interfaces/tombola_tests.rst
+47-40Lines changed: 47 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,64 +7,71 @@ Every concrete subclass of Tombola should pass these tests.
7
7
8
8
Create and load instance from iterable::
9
9
10
-
>>> balls = list(range(3))
11
-
>>> globe = TombolaUnderTest(balls)
12
-
>>> globe.loaded()
13
-
True
10
+
>>> balls = list(range(3))
11
+
>>> globe = TombolaUnderTest(balls)
12
+
>>> globe.loaded()
13
+
True
14
14
15
15
16
-
Pop and collect balls::
16
+
Pick and collect balls::
17
17
18
-
>>> picks = []
19
-
>>> picks.append(globe.pop())
20
-
>>> picks.append(globe.pop())
21
-
>>> picks.append(globe.pop())
18
+
>>> picks = []
19
+
>>> picks.append(globe.pick())
20
+
>>> picks.append(globe.pick())
21
+
>>> picks.append(globe.pick())
22
22
23
23
24
24
Check state and results::
25
25
26
-
>>> globe.loaded()
27
-
False
28
-
>>> sorted(picks) == balls
29
-
True
26
+
>>> globe.loaded()
27
+
False
28
+
>>> sorted(picks) == balls
29
+
True
30
30
31
31
32
32
Reload::
33
33
34
-
>>> globe.load(balls)
35
-
>>> globe.loaded()
36
-
True
37
-
>>> picks = [globe.pop() for i in balls]
38
-
>>> globe.loaded()
39
-
False
34
+
>>> globe.load(balls)
35
+
>>> globe.loaded()
36
+
True
37
+
>>> picks = [globe.pick() for i in balls]
38
+
>>> globe.loaded()
39
+
False
40
40
41
41
42
-
Load and pop 20 balls to verify that the order has changed::
42
+
Check that `LookupError` (or a subclass) is the exception
43
+
thrown when the device is empty::
43
44
44
-
>>> balls = list(range(20))
45
-
>>> globe = TombolaUnderTest(balls)
46
-
>>> picks = []
47
-
>>> while globe.loaded():
48
-
... picks.append(globe.pop())
49
-
>>> len(picks) == len(balls)
50
-
True
51
-
>>> picks != balls
52
-
True
45
+
>>> globe = TombolaUnderTest([])
46
+
>>> try:
47
+
... globe.pick()
48
+
... except LookupError as exc:
49
+
... print('OK')
50
+
OK
53
51
54
52
55
-
Also check that the order is not simply reversed either::
53
+
Load and pick 100 balls to verify that they are all come out::
56
54
57
-
>>> picks[::-1] != balls
58
-
True
55
+
>>> balls = list(range(100))
56
+
>>> globe = TombolaUnderTest(balls)
57
+
>>> picks = []
58
+
>>> while globe.loaded():
59
+
... picks.append(globe.pick())
60
+
>>> len(picks) == len(balls)
61
+
True
62
+
>>> set(picks) == set(balls)
63
+
True
59
64
60
-
Note: last 2 tests each have 1 chance in 20! (factorial) of failing even if the implementation is OK. 1/20!, or approximately 4.11e-19, is the probability of the 20 balls coming out, by chance, in the exact order the were loaded.
61
65
62
-
Check that `LookupError` (or a subclass) is the exception thrown when the device is empty::
66
+
Check that the order has changed is not simply reversed either::
63
67
64
-
>>> globe = TombolaUnderTest([])
65
-
>>> try:
66
-
... globe.pop()
67
-
... except LookupError as exc:
68
-
... print('OK')
69
-
OK
68
+
>>> picks != balls
69
+
True
70
+
>>> picks[::-1] != balls
71
+
True
70
72
73
+
Note: the previous 2 tests have a *very* small chance of failing
74
+
even if the implementation is OK. The probability of the 100
75
+
balls coming out, by chance, in the order they were loaded is
76
+
1/100!, or approximately 1.07e-158. It's much easier to win the
77
+
Lotto or to become a billionaire working as a programmer.
0 commit comments