Debian Codegraph @

tests/test_coverup_48.py

raw symbols SCIP
1 # file scalene/runningstats.py:63-65
2 # lines [65]
3 # branches []
4
5 import pytest
6 from scalene.runningstats import RunningStats
7
8
9 def test_running_stats_variance():
10 stats = RunningStats()
11 stats.push(1.0)
12 stats.push(2.0)
13 # Pushing more than one value to ensure n > 1 for variance calculation
14 variance = stats.var()
15 # Variance of [1.0, 2.0] is 0.5
16 assert variance == 0.5, "Variance calculation is incorrect."
17
18
19 def test_running_stats_variance_with_single_value():
20 stats = RunningStats()
21 stats.push(1.0)
22 # Expecting an exception because variance cannot be computed with a single value
23 with pytest.raises(ZeroDivisionError):
24 _ = stats.var()