summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_statistics.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-07-21 07:55:13 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2019-07-21 07:55:13 (GMT)
commitc613c3319ed9bdc8cd74c730ad946169c0776c8a (patch)
tree24216f0ffc2363e117f732459dfd36e307b19193 /Lib/test/test_statistics.py
parent3015191b29c9d69535ea63417c20d89008a73a76 (diff)
downloadcpython-c613c3319ed9bdc8cd74c730ad946169c0776c8a.zip
cpython-c613c3319ed9bdc8cd74c730ad946169c0776c8a.tar.gz
cpython-c613c3319ed9bdc8cd74c730ad946169c0776c8a.tar.bz2
bpo-36324: Make internal attributes for statistics.NormalDist() private. (GH-14871) (GH-14875)
Diffstat (limited to 'Lib/test/test_statistics.py')
-rw-r--r--Lib/test/test_statistics.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index 946c742..ed2f657 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -2326,18 +2326,18 @@ class TestNormalDist(unittest.TestCase):
nd = statistics.NormalDist(300, 23)
with self.assertRaises(TypeError):
vars(nd)
- self.assertEqual(tuple(nd.__slots__), ('mu', 'sigma'))
+ self.assertEqual(tuple(nd.__slots__), ('_mu', '_sigma'))
def test_instantiation_and_attributes(self):
nd = statistics.NormalDist(500, 17)
- self.assertEqual(nd.mu, 500)
- self.assertEqual(nd.sigma, 17)
+ self.assertEqual(nd.mean, 500)
+ self.assertEqual(nd.stdev, 17)
self.assertEqual(nd.variance, 17**2)
# default arguments
nd = statistics.NormalDist()
- self.assertEqual(nd.mu, 0)
- self.assertEqual(nd.sigma, 1)
+ self.assertEqual(nd.mean, 0)
+ self.assertEqual(nd.stdev, 1)
self.assertEqual(nd.variance, 1**2)
# error case: negative sigma
@@ -2520,10 +2520,7 @@ class TestNormalDist(unittest.TestCase):
with self.assertRaises(statistics.StatisticsError):
iq.inv_cdf(1.1) # p over one
with self.assertRaises(statistics.StatisticsError):
- iq.sigma = 0.0 # sigma is zero
- iq.inv_cdf(0.5)
- with self.assertRaises(statistics.StatisticsError):
- iq.sigma = -0.1 # sigma under zero
+ iq = NormalDist(100, 0) # sigma is zero
iq.inv_cdf(0.5)
# Special values
@@ -2544,8 +2541,8 @@ class TestNormalDist(unittest.TestCase):
def overlap_numeric(X, Y, *, steps=8_192, z=5):
'Numerical integration cross-check for overlap() '
fsum = math.fsum
- center = (X.mu + Y.mu) / 2.0
- width = z * max(X.sigma, Y.sigma)
+ center = (X.mean + Y.mean) / 2.0
+ width = z * max(X.stdev, Y.stdev)
start = center - width
dx = 2.0 * width / steps
x_arr = [start + i*dx for i in range(steps)]
@@ -2626,12 +2623,12 @@ class TestNormalDist(unittest.TestCase):
X = NormalDist(100, 12)
Y = +X
self.assertIsNot(X, Y)
- self.assertEqual(X.mu, Y.mu)
- self.assertEqual(X.sigma, Y.sigma)
+ self.assertEqual(X.mean, Y.mean)
+ self.assertEqual(X.stdev, Y.stdev)
Y = -X
self.assertIsNot(X, Y)
- self.assertEqual(X.mu, -Y.mu)
- self.assertEqual(X.sigma, Y.sigma)
+ self.assertEqual(X.mean, -Y.mean)
+ self.assertEqual(X.stdev, Y.stdev)
def test_equality(self):
NormalDist = statistics.NormalDist
@@ -2682,6 +2679,11 @@ class TestNormalDist(unittest.TestCase):
nd3 = pickle.loads(pickle.dumps(nd))
self.assertEqual(nd, nd3)
+ def test_hashability(self):
+ ND = statistics.NormalDist
+ s = {ND(100, 15), ND(100.0, 15.0), ND(100, 10), ND(95, 15), ND(100, 15)}
+ self.assertEqual(len(s), 3)
+
def test_repr(self):
nd = statistics.NormalDist(37.5, 5.625)
self.assertEqual(repr(nd), 'NormalDist(mu=37.5, sigma=5.625)')