MCPcopy Index your code
hub / github.com/python/cpython / testStressfully

Method testStressfully

Lib/test/test_sort.py:43–129  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

41
42class TestBase(unittest.TestCase):
43 def testStressfully(self):
44 # Try a variety of sizes at and around powers of 2, and at powers of 10.
45 sizes = [0]
46 for power in range(1, 10):
47 n = 2 ** power
48 sizes.extend(range(n-1, n+2))
49 sizes.extend([10, 100, 1000])
50
51 class Complains(object):
52 maybe_complain = True
53
54 def __init__(self, i):
55 self.i = i
56
57 def __lt__(self, other):
58 if Complains.maybe_complain and random.random() < 0.001:
59 if verbose:
60 print(" complaining at", self, other)
61 raise RuntimeError
62 return self.i < other.i
63
64 def __repr__(self):
65 return "Complains(%d)" % self.i
66
67 class Stable(object):
68 def __init__(self, key, i):
69 self.key = key
70 self.index = i
71
72 def __lt__(self, other):
73 return self.key < other.key
74
75 def __repr__(self):
76 return "Stable(%d, %d)" % (self.key, self.index)
77
78 for n in sizes:
79 x = list(range(n))
80 if verbose:
81 print("Testing size", n)
82
83 s = x[:]
84 check("identity", x, s)
85
86 s = x[:]
87 s.reverse()
88 check("reversed", x, s)
89
90 s = x[:]
91 random.shuffle(s)
92 check("random permutation", x, s)
93
94 y = x[:]
95 y.reverse()
96 s = x[:]
97 check("reversed via function", y, s, lambda a, b: (b>a)-(b<a))
98
99 if verbose:
100 print(" Checking against an insane comparison function.")

Callers

nothing calls this directly

Calls 12

cmp_to_keyFunction · 0.90
listClass · 0.85
ComplainsClass · 0.85
StableClass · 0.85
shuffleMethod · 0.80
randrangeMethod · 0.80
checkFunction · 0.70
extendMethod · 0.45
reverseMethod · 0.45
sortMethod · 0.45
randomMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected