[Python-checkins] python/nondist/sandbox/twister _random.c,1.18,1.19 test_random.py,1.5,1.6
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
2002年12月29日 00:57:05 -0800
Update of /cvsroot/python/python/nondist/sandbox/twister
In directory sc8-pr-cvs1:/tmp/cvs-serv8579
Modified Files:
_random.c test_random.py
Log Message:
Do type-checking on jumpahead's argument -- you could get some really
bizarre error messages by hoping PyNumber_Remainder() eventually
complained.
Index: _random.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/_random.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** _random.c 29 Dec 2002 08:47:45 -0000 1.18
--- _random.c 29 Dec 2002 08:57:03 -0000 1.19
***************
*** 386,389 ****
--- 386,396 ----
unsigned long *mt, tmp;
+ if (!PyInt_Check(n) && !PyLong_Check(n)) {
+ PyErr_Format(PyExc_TypeError, "jumpahead requires an "
+ "integer, not '%s'",
+ n->ob_type->tp_name);
+ return NULL;
+ }
+
mt = self->state;
for (i = N-1; i > 1; i--) {
Index: test_random.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/test_random.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** test_random.py 29 Dec 2002 07:07:02 -0000 1.5
--- test_random.py 29 Dec 2002 08:57:03 -0000 1.6
***************
*** 49,52 ****
--- 49,57 ----
self.assertNotEqual(state2, state3)
+ self.assertRaises(TypeError, self.gen.jumpahead) # needs an arg
+ self.assertRaises(TypeError, self.gen.jumpahead, "ick") # wrong type
+ self.assertRaises(TypeError, self.gen.jumpahead, 2.3) # wrong type
+ self.assertRaises(TypeError, self.gen.jumpahead, 2, 3) # too many
+
def test_sample(self):
# For the entire allowable range of 0 <= k <= N, validate that