Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added beta mode tests #323

Merged
merged 11 commits into from
Feb 21, 2024
30 changes: 30 additions & 0 deletions preliz/tests/test_beta_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
import numpy as np
from preliz import beta_mode


def test_beta_mode():

_, dist = beta_mode(0.25, 0.75, 0.5, 0.9)

assert np.isclose(dist.alpha, 4.94, atol=0.01)
assert np.isclose(dist.beta, 4.94, atol=0.01)


def test_invalid_mass():
with pytest.raises(ValueError):
beta_mode(0.25, 0.75, 0.5, mass=1.1)


def test_invalid_mode():
with pytest.raises(ValueError):
beta_mode(0.25, 0.75, 1.5)


def test_invalid_bounds():
with pytest.raises(ValueError):
beta_mode(0.75, 0.25, 0.5)


def test_plot_beta_mode():
_, _ = beta_mode(0.25, 0.75, 0.5, 0.9, plot=True, plot_kwargs={"pointinterval": True})
5 changes: 2 additions & 3 deletions preliz/unidimensional/beta_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
_log = logging.getLogger("preliz")


def beta_mode(lower, upper, mode, mass=0.94, plot=False, plot_kwargs=None, ax=None):

def beta_mode(lower, upper, mode, mass=0.94, plot=True, plot_kwargs=None, ax=None):
"""Fits Parameters to a Beta Distribution based on the mode, confidence intervals
and mass of the distribution.

Expand Down Expand Up @@ -44,7 +43,7 @@ def beta_mode(lower, upper, mode, mass=0.94, plot=False, plot_kwargs=None, ax=No
if not 0 < mass <= 1:
raise ValueError("mass should be larger than 0 and smaller or equal to 1")

if mode < lower or mode > upper:
if mode <= lower or mode >= upper:
raise ValueError("mode should be between lower and upper")

if upper <= lower:
Expand Down
Loading