Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c02fec

Browse files
committed
Make test_mutants stronger by also adding random keys during comparisons.
A Mystery: test_mutants ran amazingly slowly even before dictobject.c "got fixed". I don't have a clue as to why. dict comparison was and remains linear-time in the size of the dicts, and test_mutants only tries 100 dict pairs, of size averaging just 50. So "it should" run in less than an eyeblink; but it takes at least a second on this 800MHz box.
1 parent fd69208 commit 4c02fec

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/test/test_mutants.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,33 @@
4141
# If global mutate is true, consider mutating a dict. May or may not
4242
# mutate a dict even if mutate is true. If it does decide to mutate a
4343
# dict, it picks one of {dict1, dict2} at random, and deletes a random
44-
# entry from it.
44+
# entry from it; or, more rarely, adds a random element.
4545

4646
def maybe_mutate():
47+
global mutate
4748
if not mutate:
4849
return
4950
if random.random() < 0.5:
5051
return
52+
5153
if random.random() < 0.5:
5254
target, keys = dict1, dict1keys
5355
else:
5456
target, keys = dict2, dict2keys
55-
if keys:
57+
58+
if random.random() < 0.2:
59+
# Insert a new key.
60+
mutate = 0 # disable mutation until key inserted
61+
while 1:
62+
newkey = Horrid(random.randrange(100))
63+
if newkey not in target:
64+
break
65+
target[newkey] = Horrid(random.randrange(100))
66+
keys.append(newkey)
67+
mutate = 1
68+
69+
elif keys:
70+
# Delete a key at random.
5671
i = random.randrange(len(keys))
5772
key = keys[i]
5873
del target[key]

0 commit comments

Comments
 (0)