[Python-checkins] CVS: python/dist/src/Lib/test test_long.py,1.14,1.15

Tim Peters tim_one@users.sourceforge.net
Tue, 04 Sep 2001 17:53:47 -0700


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

Modified Files:
	test_long.py 
Log Message:
Return reasonable results for math.log(long) and math.log10(long) (we were
getting Infs, NaNs, or nonsense in 2.1 and before; in yesterday's CVS we
were getting OverflowError; but these functions always make good sense
for positive arguments, no matter how large).


Index: test_long.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_long.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test_long.py	2001/09/04 19:48:01	1.14
--- test_long.py	2001/09/05 00:53:44	1.15
***************
*** 1,3 ****
! from test_support import verify, verbose, TestFailed
  from string import join
  from random import random, randint
--- 1,3 ----
! from test_support import verify, verbose, TestFailed, fcmp
  from string import join
  from random import random, randint
***************
*** 354,360 ****
                   "1. ** huge", "huge ** 1.", "1. ** mhuge", "mhuge ** 1.",
                   "math.sin(huge)", "math.sin(mhuge)",
-                  "math.log(huge)", "math.log(mhuge)", # should do better
                   "math.sqrt(huge)", "math.sqrt(mhuge)", # should do better
-                  "math.log10(huge)", "math.log10(mhuge)", # should do better
                   "math.floor(huge)", "math.floor(mhuge)"]:
  
--- 354,358 ----
***************
*** 365,368 ****
--- 363,401 ----
          else:
              raise TestFailed("expected OverflowError from %s" % test)
+ 
+ # ---------------------------------------------- test huge log and log10
+ 
+ def test_logs():
+     import math
+ 
+     if verbose:
+         print "log and log10"
+ 
+     LOG10E = math.log10(math.e)
+ 
+     for exp in range(10) + [100, 1000, 10000]:
+         value = 10 ** exp
+         log10 = math.log10(value)
+         verify(fcmp(log10, exp) == 0)
+ 
+         # log10(value) == exp, so log(value) == log10(value)/log10(e) ==
+         # exp/LOG10E
+         expected = exp / LOG10E
+         log = math.log(value)
+         verify(fcmp(log, expected) == 0)
+ 
+     for bad in -(1L << 10000), -2L, 0L:
+         try:
+             math.log(bad)
+             raise TestFailed("expected ValueError from log(<= 0)")
+         except ValueError:
+             pass
+ 
+         try:
+             math.log10(bad)
+             raise TestFailed("expected ValueError from log10(<= 0)")
+         except ValueError:
+             pass
+ 
  # ---------------------------------------------------------------- do it
  
***************
*** 373,374 ****
--- 406,408 ----
  test_auto_overflow()
  test_float_overflow()
+ test_logs()