[Python-checkins] python/dist/src/Lib/test test_random.py, 1.16, 1.17

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Fri Jul 9 16:26:20 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9193

Modified Files:
	test_random.py 
Log Message:
Add some tests for corner cases.

Index: test_random.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_random.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** test_random.py	16 Nov 2003 16:17:48 -0000	1.16
--- test_random.py	9 Jul 2004 14:26:18 -0000	1.17
***************
*** 40,43 ****
--- 40,45 ----
          for arg in [range(3), dict(one=1)]:
              self.assertRaises(TypeError, self.gen.seed, arg)
+         self.assertRaises(TypeError, self.gen.seed, 1, 2)
+         self.assertRaises(TypeError, type(self.gen), [])
  
      def test_jumpahead(self):
***************
*** 123,126 ****
--- 125,131 ----
      gen = random.WichmannHill()
  
+     def test_setstate_first_arg(self):
+         self.assertRaises(ValueError, self.gen.setstate, (2, None, None))
+ 
      def test_strong_jumpahead(self):
          # tests that jumpahead(n) semantics correspond to n calls to random()
***************
*** 163,166 ****
--- 168,184 ----
      gen = random.Random()
  
+     def test_setstate_first_arg(self):
+         self.assertRaises(ValueError, self.gen.setstate, (1, None, None))
+ 
+     def test_setstate_middle_arg(self):
+         # Wrong type, s/b tuple
+         self.assertRaises(TypeError, self.gen.setstate, (2, None, None))
+         # Wrong length, s/b 625
+         self.assertRaises(ValueError, self.gen.setstate, (2, (1,2,3), None))
+         # Wrong type, s/b tuple of 625 ints
+         self.assertRaises(TypeError, self.gen.setstate, (2, ('a',)*625, None))
+         # Last element s/b an int also
+         self.assertRaises(TypeError, self.gen.setstate, (2, (0,)*624+('a',), None))
+ 
      def test_referenceImplementation(self):
          # Compare the python implementation with results from the original
***************
*** 211,215 ****
                      0x02dad977c9e1feL,
                      0x191d96d4d334c6L]
- 
          self.gen.seed(61731L + (24903L<<32) + (614L<<64) + (42143L<<96))
          actual = self.randomlist(2000)[-10:]
--- 229,232 ----
***************
*** 275,278 ****
--- 292,302 ----
              self.assertEqual(cum, 2**span-1)
  
+         # Verify argument checking
+         self.assertRaises(TypeError, self.gen.getrandbits)
+         self.assertRaises(TypeError, self.gen.getrandbits, 'a')
+         self.assertRaises(TypeError, self.gen.getrandbits, 1, 2)
+         self.assertRaises(ValueError, self.gen.getrandbits, 0)
+         self.assertRaises(ValueError, self.gen.getrandbits, -1)
+ 
      def test_randbelow_logic(self, _log=log, int=int):
          # check bitcount transition points:  2**i and 2**(i+1)-1



More information about the Python-checkins mailing list