MCPcopy Index your code
hub / github.com/python/cpython / test_special_values

Method test_special_values

Lib/test/test_statistics.py:2320–2335  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2318 geometric_mean([10, 20, 60], 70) # too many arguments
2319
2320 def test_special_values(self):
2321 # Rules for special values are inherited from math.fsum()
2322 geometric_mean = statistics.geometric_mean
2323 NaN = float('Nan')
2324 Inf = float('Inf')
2325 self.assertTrue(math.isnan(geometric_mean([10, NaN])), 'nan')
2326 self.assertTrue(math.isnan(geometric_mean([NaN, Inf])), 'nan and infinity')
2327 self.assertTrue(math.isinf(geometric_mean([10, Inf])), 'infinity')
2328 with self.assertRaises(ValueError):
2329 geometric_mean([Inf, -Inf])
2330
2331 # Cases with zero
2332 self.assertEqual(geometric_mean([3, 0.0, 5]), 0.0) # Any zero gives a zero
2333 self.assertEqual(geometric_mean([3, -0.0, 5]), 0.0) # Negative zero allowed
2334 self.assertTrue(math.isnan(geometric_mean([0, NaN]))) # NaN beats zero
2335 self.assertTrue(math.isnan(geometric_mean([0, Inf]))) # Because 0.0 * Inf -> NaN
2336
2337 def test_mixed_int_and_float(self):
2338 # Regression test for b.p.o. issue #28327

Callers

nothing calls this directly

Calls 4

geometric_meanFunction · 0.85
assertTrueMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected