mirror of https://github.com/python/cpython
bpo-36018: Make __pos__ return a distinct instance of NormDist (GH-12009)
https://bugs.python.org/issue36018
This commit is contained in:
parent
e895de3e7f
commit
79fbcc597d
|
@ -762,7 +762,7 @@ class NormalDist:
|
||||||
return NormalDist(x1.mu / x2, x1.sigma / fabs(x2))
|
return NormalDist(x1.mu / x2, x1.sigma / fabs(x2))
|
||||||
|
|
||||||
def __pos__(x1):
|
def __pos__(x1):
|
||||||
return x1
|
return NormalDist(x1.mu, x1.sigma)
|
||||||
|
|
||||||
def __neg__(x1):
|
def __neg__(x1):
|
||||||
return NormalDist(-x1.mu, x1.sigma)
|
return NormalDist(-x1.mu, x1.sigma)
|
||||||
|
|
|
@ -2128,6 +2128,18 @@ class TestNormalDist(unittest.TestCase):
|
||||||
with self.assertRaises(statistics.StatisticsError):
|
with self.assertRaises(statistics.StatisticsError):
|
||||||
Y.cdf(90)
|
Y.cdf(90)
|
||||||
|
|
||||||
|
def test_unary_operations(self):
|
||||||
|
NormalDist = statistics.NormalDist
|
||||||
|
X = NormalDist(100, 12)
|
||||||
|
Y = +X
|
||||||
|
self.assertIsNot(X, Y)
|
||||||
|
self.assertEqual(X.mu, Y.mu)
|
||||||
|
self.assertEqual(X.sigma, Y.sigma)
|
||||||
|
Y = -X
|
||||||
|
self.assertIsNot(X, Y)
|
||||||
|
self.assertEqual(X.mu, -Y.mu)
|
||||||
|
self.assertEqual(X.sigma, Y.sigma)
|
||||||
|
|
||||||
def test_same_type_addition_and_subtraction(self):
|
def test_same_type_addition_and_subtraction(self):
|
||||||
NormalDist = statistics.NormalDist
|
NormalDist = statistics.NormalDist
|
||||||
X = NormalDist(100, 12)
|
X = NormalDist(100, 12)
|
||||||
|
|
Loading…
Reference in New Issue