]> granicus.if.org Git - python/commitdiff
Speed up test_dict by about 10x by only checking selected dict literal sizes,
authorJeffrey Yasskin <jyasskin@gmail.com>
Tue, 18 Mar 2008 05:12:41 +0000 (05:12 +0000)
committerJeffrey Yasskin <jyasskin@gmail.com>
Tue, 18 Mar 2008 05:12:41 +0000 (05:12 +0000)
instead of every integer from 0 to 400. Exhaustive testing wastes time without
providing enough more assurance that the code is correct.

Lib/test/test_dict.py

index 7dd5f06868679e6088858cf621a082c6075de358..b62237d9d6f10f968b249f01f47e9c9222cce01c 100644 (file)
@@ -12,12 +12,14 @@ class DictTest(unittest.TestCase):
 
     def test_literal_constructor(self):
         # check literal constructor for different sized dicts (to exercise the BUILD_MAP oparg
-        items = []
-        for n in range(400):
+        for n in (0, 1, 6, 256, 400):
+            items = [(''.join([random.choice(string.letters)
+                               for j in range(8)]),
+                      i)
+                     for i in range(n)]
+            random.shuffle(items)
             dictliteral = '{' + ', '.join('%r: %d' % item for item in items) + '}'
             self.assertEqual(eval(dictliteral), dict(items))
-            items.append((''.join([random.choice(string.letters) for j in range(8)]), n))
-            random.shuffle(items)
 
     def test_bool(self):
         self.assert_(not {})