File: test_profiles.py

package info (click to toggle)
python-boost-histogram 1.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,236 kB
  • sloc: python: 7,940; cpp: 3,243; makefile: 22; sh: 1
file content (27 lines) | stat: -rw-r--r-- 767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from __future__ import annotations

from pytest import approx

import boost_histogram as bh


def test_mean_hist():
    h = bh.Histogram(bh.axis.Regular(3, 0, 1), storage=bh.storage.Mean())

    h.fill(0.10, sample=[2.5])
    h.fill(0.25, sample=[3.5])
    h.fill(0.45, sample=[1.2])
    h.fill(0.51, sample=[3.4])
    h.fill(0.81, sample=[1.3])
    h.fill(0.86, sample=[1.9])

    results = (
        {"count": 2, "value": 3.0, "variance": 0.5},
        {"count": 2, "value": 2.3, "variance": 2.42},
        {"count": 2, "value": 1.6, "variance": 0.18},
    )

    for i in range(len(h.axes[0])):
        assert results[i]["count"] == h[i].count
        assert results[i]["value"] == approx(h[i].value)
        assert results[i]["variance"] == approx(h[i].variance)