summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2021-05-21 03:22:26 (GMT)
committerGitHub <noreply@github.com>2021-05-21 03:22:26 (GMT)
commitbe4dd7fcd93ed29d362c4bbcc48151bc619d6595 (patch)
treefca75e6315657f7d7fc8ad1355a31e774e1ee4bf /Lib/test
parent18f41c04ff4161531f4d08631059fd3ed37c0218 (diff)
downloadcpython-be4dd7fcd93ed29d362c4bbcc48151bc619d6595.zip
cpython-be4dd7fcd93ed29d362c4bbcc48151bc619d6595.tar.gz
cpython-be4dd7fcd93ed29d362c4bbcc48151bc619d6595.tar.bz2
bpo-44150: Support optional weights parameter for fmean() (GH-26175)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_statistics.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index 70d269d..3e6e17a 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -1972,6 +1972,27 @@ class TestFMean(unittest.TestCase):
with self.assertRaises(ValueError):
fmean([Inf, -Inf])
+ def test_weights(self):
+ fmean = statistics.fmean
+ StatisticsError = statistics.StatisticsError
+ self.assertEqual(
+ fmean([10, 10, 10, 50], [0.25] * 4),
+ fmean([10, 10, 10, 50]))
+ self.assertEqual(
+ fmean([10, 10, 20], [0.25, 0.25, 0.50]),
+ fmean([10, 10, 20, 20]))
+ self.assertEqual( # inputs are iterators
+ fmean(iter([10, 10, 20]), iter([0.25, 0.25, 0.50])),
+ fmean([10, 10, 20, 20]))
+ with self.assertRaises(StatisticsError):
+ fmean([10, 20, 30], [1, 2]) # unequal lengths
+ with self.assertRaises(StatisticsError):
+ fmean(iter([10, 20, 30]), iter([1, 2])) # unequal lengths
+ with self.assertRaises(StatisticsError):
+ fmean([10, 20], [-1, 1]) # sum of weights is zero
+ with self.assertRaises(StatisticsError):
+ fmean(iter([10, 20]), iter([-1, 1])) # sum of weights is zero
+
# === Tests for variances and standard deviations ===