import pytest
import numpy as np
import scirs2
class TestLognormalDistribution:
def test_lognorm_creation(self):
dist = scirs2.lognorm()
assert dist is not None
dist_custom = scirs2.lognorm(mu=0.5, sigma=0.8, loc=0.0)
assert dist_custom is not None
def test_lognorm_pdf(self):
dist = scirs2.lognorm()
assert abs(dist.pdf(0.0)) < 1e-10
assert dist.pdf(1.0) > 0
assert dist.pdf(2.0) > 0
def test_lognorm_cdf(self):
dist = scirs2.lognorm()
assert abs(dist.cdf(0.0)) < 1e-10
assert dist.cdf(0.5) < dist.cdf(1.0) < dist.cdf(2.0)
def test_lognorm_ppf(self):
dist = scirs2.lognorm()
median = dist.ppf(0.5)
assert abs(median - 1.0) < 0.05
assert dist.ppf(0.1) < dist.ppf(0.5) < dist.ppf(0.9)
def test_lognorm_rvs(self):
dist = scirs2.lognorm()
samples = dist.rvs(1000)
assert len(samples) == 1000
assert all(s > 0 for s in samples)
mean = np.mean(samples)
assert 1.0 < mean < 3.0
class TestWeibullDistribution:
def test_weibull_creation(self):
dist = scirs2.weibull_min(2.0)
assert dist is not None
dist_custom = scirs2.weibull_min(shape=1.5, scale=2.0, loc=0.0)
assert dist_custom is not None
def test_weibull_pdf(self):
dist = scirs2.weibull_min(2.0, scale=1.0)
assert abs(dist.pdf(0.0)) < 1e-10
assert dist.pdf(1.0) > 0
assert dist.pdf(2.0) > 0
def test_weibull_cdf(self):
dist = scirs2.weibull_min(2.0)
assert abs(dist.cdf(0.0)) < 1e-10
assert dist.cdf(0.5) < dist.cdf(1.0) < dist.cdf(2.0)
def test_weibull_ppf(self):
dist = scirs2.weibull_min(2.0)
assert abs(dist.ppf(0.0)) < 1e-3
assert dist.ppf(0.1) < dist.ppf(0.5) < dist.ppf(0.9)
def test_weibull_rvs(self):
dist = scirs2.weibull_min(2.0, scale=1.0)
samples = dist.rvs(1000)
assert len(samples) == 1000
assert all(s >= 0 for s in samples)
class TestLaplaceDistribution:
def test_laplace_creation(self):
dist = scirs2.laplace()
assert dist is not None
dist_custom = scirs2.laplace(loc=2.0, scale=3.0)
assert dist_custom is not None
def test_laplace_pdf(self):
dist = scirs2.laplace()
assert abs(dist.pdf(1.0) - dist.pdf(-1.0)) < 1e-6
pdf_at_zero = dist.pdf(0.0)
assert abs(pdf_at_zero - 0.5) < 1e-6
def test_laplace_cdf(self):
dist = scirs2.laplace()
cdf_at_zero = dist.cdf(0.0)
assert abs(cdf_at_zero - 0.5) < 1e-6
assert dist.cdf(-2.0) < dist.cdf(0.0) < dist.cdf(2.0)
def test_laplace_ppf(self):
dist = scirs2.laplace()
median = dist.ppf(0.5)
assert abs(median) < 1e-6
assert dist.ppf(0.1) < dist.ppf(0.5) < dist.ppf(0.9)
def test_laplace_rvs(self):
dist = scirs2.laplace()
samples = dist.rvs(1000)
assert len(samples) == 1000
mean = np.mean(samples)
assert abs(mean) < 0.2
class TestLogisticDistribution:
def test_logistic_creation(self):
dist = scirs2.logistic()
assert dist is not None
dist_custom = scirs2.logistic(loc=1.0, scale=2.0)
assert dist_custom is not None
def test_logistic_pdf(self):
dist = scirs2.logistic()
assert abs(dist.pdf(1.0) - dist.pdf(-1.0)) < 1e-6
pdf_at_zero = dist.pdf(0.0)
assert abs(pdf_at_zero - 0.25) < 1e-6
def test_logistic_cdf(self):
dist = scirs2.logistic()
cdf_at_zero = dist.cdf(0.0)
assert abs(cdf_at_zero - 0.5) < 1e-6
assert dist.cdf(-2.0) < dist.cdf(0.0) < dist.cdf(2.0)
def test_logistic_ppf(self):
dist = scirs2.logistic()
median = dist.ppf(0.5)
assert abs(median) < 1e-6
assert dist.ppf(0.1) < dist.ppf(0.5) < dist.ppf(0.9)
def test_logistic_rvs(self):
dist = scirs2.logistic()
samples = dist.rvs(1000)
assert len(samples) == 1000
mean = np.mean(samples)
assert abs(mean) < 0.2
class TestParetoDistribution:
def test_pareto_creation(self):
dist = scirs2.pareto(3.0)
assert dist is not None
dist_custom = scirs2.pareto(shape=2.0, scale=2.0, loc=0.0)
assert dist_custom is not None
def test_pareto_pdf(self):
dist = scirs2.pareto(3.0, scale=1.0)
assert abs(dist.pdf(0.5)) < 1e-10
assert abs(dist.pdf(1.0)) < 1e-10
assert dist.pdf(1.1) > 0
assert dist.pdf(2.0) > 0
def test_pareto_cdf(self):
dist = scirs2.pareto(3.0, scale=1.0)
assert abs(dist.cdf(1.0)) < 1e-10
assert dist.cdf(1.0) <= dist.cdf(2.0) < dist.cdf(3.0)
def test_pareto_ppf(self):
dist = scirs2.pareto(3.0, scale=1.0)
assert abs(dist.ppf(0.0) - 1.0) < 1e-3
assert dist.ppf(0.1) < dist.ppf(0.5) < dist.ppf(0.9)
def test_pareto_rvs(self):
dist = scirs2.pareto(3.0, scale=1.0)
samples = dist.rvs(1000)
assert len(samples) == 1000
assert all(s >= 1.0 for s in samples)
class TestGeometricDistribution:
def test_geom_creation(self):
dist = scirs2.geom(0.3)
assert dist is not None
dist_custom = scirs2.geom(0.5)
assert dist_custom is not None
def test_geom_pmf(self):
dist = scirs2.geom(0.5)
pmf_0 = dist.pmf(0.0)
assert abs(pmf_0 - 0.5) < 1e-6
assert dist.pmf(0.0) > dist.pmf(1.0) > dist.pmf(2.0)
def test_geom_cdf(self):
dist = scirs2.geom(0.5)
assert dist.cdf(0.0) < dist.cdf(1.0) < dist.cdf(2.0)
assert dist.cdf(20.0) > 0.999
def test_geom_ppf(self):
dist = scirs2.geom(0.5)
median = dist.ppf(0.5)
assert 0.0 <= median <= 2.0
def test_geom_rvs(self):
dist = scirs2.geom(0.3)
samples = dist.rvs(1000)
assert len(samples) == 1000
assert all(s >= 0 for s in samples)
mean = np.mean(samples)
assert 1.5 < mean < 3.5
class TestDistributionConsistency:
def test_lognorm_cdf_ppf_inverse(self):
dist = scirs2.lognorm()
x = 1.5
cdf_val = dist.cdf(x)
ppf_val = dist.ppf(cdf_val)
assert abs(ppf_val - x) < 1e-2
def test_weibull_cdf_ppf_inverse(self):
dist = scirs2.weibull_min(2.0)
x = 1.0
cdf_val = dist.cdf(x)
ppf_val = dist.ppf(cdf_val)
assert abs(ppf_val - x) < 1e-2
def test_laplace_cdf_ppf_inverse(self):
dist = scirs2.laplace()
x = 1.0
cdf_val = dist.cdf(x)
ppf_val = dist.ppf(cdf_val)
assert abs(ppf_val - x) < 1e-2
def test_logistic_cdf_ppf_inverse(self):
dist = scirs2.logistic()
x = 1.0
cdf_val = dist.cdf(x)
ppf_val = dist.ppf(cdf_val)
assert abs(ppf_val - x) < 1e-2
def test_pareto_cdf_ppf_inverse(self):
dist = scirs2.pareto(3.0)
x = 2.0
cdf_val = dist.cdf(x)
ppf_val = dist.ppf(cdf_val)
assert abs(ppf_val - x) < 1e-2
def test_geometric_cdf_ppf_inverse(self):
dist = scirs2.geom(0.3)
k = 2.0
cdf_val = dist.cdf(k)
ppf_val = dist.ppf(cdf_val)
assert abs(ppf_val - k) <= 1.0