@@ -324,6 +324,7 @@ def testAtan2(self):
324
324
self.ftest('atan2(0, 1)', math.atan2(0, 1), 0)
325
325
self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
326
326
self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
327
+ self.ftest('atan2(1, -1)', math.atan2(1, -1), 3*math.pi/4)
327
328
328
329
# math.atan2(0, x)
329
330
self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
@@ -598,6 +599,7 @@ def testFmod(self):
598
599
self.assertEqual(math.fmod(-3.0, NINF), -3.0)
599
600
self.assertEqual(math.fmod(0.0, 3.0), 0.0)
600
601
self.assertEqual(math.fmod(0.0, NINF), 0.0)
602
+ self.assertRaises(ValueError, math.fmod, INF, INF)
601
603
602
604
def testFrexp(self):
603
605
self.assertRaises(TypeError, math.frexp)
@@ -714,6 +716,11 @@ def msum(iterable):
714
716
s = msum(vals)
715
717
self.assertEqual(msum(vals), math.fsum(vals))
716
718
719
+ self.assertEqual(math.fsum([1.0, math.inf]), math.inf)
720
+ self.assertRaises(OverflowError, math.fsum, [1e+308, 1e+308])
721
+ self.assertRaises(ValueError, math.fsum, [math.inf, -math.inf])
722
+ self.assertRaises(TypeError, math.fsum, ['spam'])
723
+
717
724
def testGcd(self):
718
725
gcd = math.gcd
719
726
self.assertEqual(gcd(0, 0), 0)
@@ -831,6 +838,8 @@ def testHypot(self):
831
838
scale = FLOAT_MIN / 2.0 ** exp
832
839
self.assertEqual(math.hypot(4*scale, 3*scale), 5*scale)
833
840
841
+ self.assertRaises(TypeError, math.hypot, *([1.0]*18), 'spam')
842
+
834
843
@requires_IEEE_754
835
844
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
836
845
"hypot() loses accuracy on machines with double rounding")
@@ -966,13 +975,19 @@ class T(tuple):
966
975
dist((1, 2, 3, 4), (5, 6, 7))
967
976
with self.assertRaises(ValueError): # Check dimension agree
968
977
dist((1, 2, 3), (4, 5, 6, 7))
978
+ with self.assertRaises(TypeError):
979
+ dist((1,)*17 + ("spam",), (1,)*18)
969
980
with self.assertRaises(TypeError): # Rejects invalid types
970
981
dist("abc", "xyz")
971
982
int_too_big_for_float = 10 ** (sys.float_info.max_10_exp + 5)
972
983
with self.assertRaises((ValueError, OverflowError)):
973
984
dist((1, int_too_big_for_float), (2, 3))
974
985
with self.assertRaises((ValueError, OverflowError)):
975
986
dist((2, 3), (1, int_too_big_for_float))
987
+ with self.assertRaises(TypeError):
988
+ dist((1,), 2)
989
+ with self.assertRaises(TypeError):
990
+ dist([1], 2)
976
991
977
992
# Verify that the one dimensional case is equivalent to abs()
978
993
for i in range(20):
@@ -1111,6 +1126,7 @@ def test_lcm(self):
1111
1126
1112
1127
def testLdexp(self):
1113
1128
self.assertRaises(TypeError, math.ldexp)
1129
+ self.assertRaises(TypeError, math.ldexp, 2.0, 1.1)
1114
1130
self.ftest('ldexp(0,1)', math.ldexp(0,1), 0)
1115
1131
self.ftest('ldexp(1,1)', math.ldexp(1,1), 2)
1116
1132
self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5)
@@ -1153,6 +1169,7 @@ def testLog(self):
1153
1169
2302.5850929940457)
1154
1170
self.assertRaises(ValueError, math.log, -1.5)
1155
1171
self.assertRaises(ValueError, math.log, -10**1000)
1172
+ self.assertRaises(ValueError, math.log, 10, -10)
1156
1173
self.assertRaises(ValueError, math.log, NINF)
1157
1174
self.assertEqual(math.log(INF), INF)
1158
1175
self.assertTrue(math.isnan(math.log(NAN)))
@@ -2364,6 +2381,14 @@ def __float__(self):
2364
2381
# argument to a float.
2365
2382
self.assertFalse(getattr(y, "converted", False))
2366
2383
2384
+ def test_input_exceptions(self):
2385
+ self.assertRaises(TypeError, math.exp, "spam")
2386
+ self.assertRaises(TypeError, math.erf, "spam")
2387
+ self.assertRaises(TypeError, math.atan2, "spam", 1.0)
2388
+ self.assertRaises(TypeError, math.atan2, 1.0, "spam")
2389
+ self.assertRaises(TypeError, math.atan2, 1.0)
2390
+ self.assertRaises(TypeError, math.atan2, 1.0, 2.0, 3.0)
2391
+
2367
2392
# Custom assertions.
2368
2393
2369
2394
def assertIsNaN(self, value):
0 commit comments