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

Method test_basics

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

Source from the content-addressed store, hash-verified

2241class TestGeometricMean(unittest.TestCase):
2242
2243 def test_basics(self):
2244 geometric_mean = statistics.geometric_mean
2245 self.assertAlmostEqual(geometric_mean([54, 24, 36]), 36.0)
2246 self.assertAlmostEqual(geometric_mean([4.0, 9.0]), 6.0)
2247 self.assertAlmostEqual(geometric_mean([17.625]), 17.625)
2248
2249 random.seed(86753095551212)
2250 for rng in [
2251 range(1, 100),
2252 range(1, 1_000),
2253 range(1, 10_000),
2254 range(500, 10_000, 3),
2255 range(10_000, 500, -3),
2256 [12, 17, 13, 5, 120, 7],
2257 [random.expovariate(50.0) for i in range(1_000)],
2258 [random.lognormvariate(20.0, 3.0) for i in range(2_000)],
2259 [random.triangular(2000, 3000, 2200) for i in range(3_000)],
2260 ]:
2261 gm_decimal = math.prod(map(Decimal, rng)) ** (Decimal(1) / len(rng))
2262 gm_float = geometric_mean(rng)
2263 self.assertTrue(math.isclose(gm_float, float(gm_decimal)))
2264
2265 def test_various_input_types(self):
2266 geometric_mean = statistics.geometric_mean

Callers

nothing calls this directly

Calls 8

DecimalClass · 0.90
geometric_meanFunction · 0.85
expovariateMethod · 0.80
lognormvariateMethod · 0.80
triangularMethod · 0.80
assertTrueMethod · 0.80
assertAlmostEqualMethod · 0.45
seedMethod · 0.45

Tested by

no test coverage detected