diff options
Diffstat (limited to 'Lib/test/test_statistics.py')
-rw-r--r-- | Lib/test/test_statistics.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index 9971107..4b8686b 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -1599,6 +1599,27 @@ class TestHarmonicMean(NumericTestCase, AverageMixin, UnivariateTypeMixin): actual = self.func(data*2) self.assertApproxEqual(actual, expected) + def test_with_weights(self): + self.assertEqual(self.func([40, 60], [5, 30]), 56.0) # common case + self.assertEqual(self.func([40, 60], + weights=[5, 30]), 56.0) # keyword argument + self.assertEqual(self.func(iter([40, 60]), + iter([5, 30])), 56.0) # iterator inputs + self.assertEqual( + self.func([Fraction(10, 3), Fraction(23, 5), Fraction(7, 2)], [5, 2, 10]), + self.func([Fraction(10, 3)] * 5 + + [Fraction(23, 5)] * 2 + + [Fraction(7, 2)] * 10)) + self.assertEqual(self.func([10], [7]), 10) # n=1 fast path + with self.assertRaises(TypeError): + self.func([1, 2, 3], [1, (), 3]) # non-numeric weight + with self.assertRaises(statistics.StatisticsError): + self.func([1, 2, 3], [1, 2]) # wrong number of weights + with self.assertRaises(statistics.StatisticsError): + self.func([10], [0]) # no non-zero weights + with self.assertRaises(statistics.StatisticsError): + self.func([10, 20], [0, 0]) # no non-zero weights + class TestMedian(NumericTestCase, AverageMixin): # Common tests for median and all median.* functions. |