[Python-checkins] CVS: python/dist/src/Lib/test test_mutants.py,1.2,1.3

Tim Peters tim_one@users.sourceforge.net
Thu, 10 May 2001 13:18:32 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv13427/python/dist/src/Lib/test

Modified Files:
	test_mutants.py 
Log Message:
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.


Index: test_mutants.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_mutants.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** test_mutants.py	2001/05/10 19:40:30	1.2
--- test_mutants.py	2001/05/10 20:18:30	1.3
***************
*** 42,57 ****
  # mutate a dict even if mutate is true.  If it does decide to mutate a
  # dict, it picks one of {dict1, dict2} at random, and deletes a random
! # entry from it.
  
  def maybe_mutate():
      if not mutate:
          return
      if random.random() < 0.5:
          return
      if random.random() < 0.5:
          target, keys = dict1, dict1keys
      else:
          target, keys = dict2, dict2keys
!     if keys:
          i = random.randrange(len(keys))
          key = keys[i]
--- 42,72 ----
  # mutate a dict even if mutate is true.  If it does decide to mutate a
  # dict, it picks one of {dict1, dict2} at random, and deletes a random
! # entry from it; or, more rarely, adds a random element.
  
  def maybe_mutate():
+     global mutate
      if not mutate:
          return
      if random.random() < 0.5:
          return
+ 
      if random.random() < 0.5:
          target, keys = dict1, dict1keys
      else:
          target, keys = dict2, dict2keys
! 
!     if random.random() < 0.2:
!         # Insert a new key.
!         mutate = 0   # disable mutation until key inserted
!         while 1:
!             newkey = Horrid(random.randrange(100))
!             if newkey not in target:
!                 break
!         target[newkey] = Horrid(random.randrange(100))
!         keys.append(newkey)
!         mutate = 1
! 
!     elif keys:
!         # Delete a key at random.
          i = random.randrange(len(keys))
          key = keys[i]