Skip to content

Commit

Permalink
More unit tests and black
Browse files Browse the repository at this point in the history
  • Loading branch information
j1c committed Jan 11, 2024
1 parent 957b0d6 commit 161e436
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
8 changes: 6 additions & 2 deletions hyppo/conditional/tests/test_pcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ def test_linear_oned(self, n, obs_stat):
@pytest.mark.parametrize("n", [100, 200])
def test_rep(self, n):
x, y, z = indep_normal(n, 1)
stat1, pvalue1 = PartialCorr().test(x, y, z, random_state=2, auto=False, reps=1000)
stat2, pvalue2 = PartialCorr().test(x, y, z, random_state=2, auto=False, reps=1000)
stat1, pvalue1 = PartialCorr().test(
x, y, z, random_state=2, auto=False, reps=1000
)
stat2, pvalue2 = PartialCorr().test(
x, y, z, random_state=2, auto=False, reps=1000
)

assert stat1 == stat2
assert pvalue1 == pvalue2
Expand Down
11 changes: 11 additions & 0 deletions hyppo/conditional/tests/test_pdcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def test_rep(self, n):
assert stat1 == stat2
assert pvalue1 == pvalue2

@pytest.mark.parametrize("n", [100])
@pytest.mark.parametrize("obs_stat", [0.0143057])
@pytest.mark.parametrize("obs_pvalue", [0.12])
def test_indep_normal_corr(self, n, obs_stat, obs_pvalue):
np.random.seed(123456789)
x, y, z = indep_normal(n, 1)
stat1, pvalue1 = PartialDcorr(use_cov=False).test(x, y, z)

assert_almost_equal(stat1, obs_stat, decimal=2)
assert_almost_equal(pvalue1, obs_pvalue, decimal=2)


class TestPDcorrTypeIError:
def test_oned(self):
Expand Down
13 changes: 13 additions & 0 deletions hyppo/tools/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ def test_error_distkern(self):
assert_raises(ValueError, _check_distmat, x, y)
assert_raises(ValueError, _check_kernmat, x, y)

def test_error_threedist(self):
x = np.arange(10).reshape(-1, 1)
y = np.arange(10).reshape(1, -1)
z = np.arange(10).reshape(1, -1)
assert_raises(ValueError, _check_distmat, x, y, z)

def test_error_nonzerodiag(self):
x = np.eye(10, dtype=int) ^ 1 # 0 on diag, 1 elsewhere
y = np.eye(10, dtype=int) ^ 1 # 0 on diag, 1 elsewhere
z = np.eye(10, dtype=int)

assert_raises(ValueError, _check_distmat, x, y, z)

def test_error_multidistkern(self):
# raises error if samples are low (< 3)
x = np.arange(10).reshape(-1, 1)
Expand Down
5 changes: 3 additions & 2 deletions hyppo/tools/tests/test_conditional_indep_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class TestCondiIndepSimErrorWarn:

def test_np_inctype(self):
assert_raises(ValueError, condi_indep_sim, n="a", p=1, sim="independent_normal")
assert_raises(ValueError, condi_indep_sim, n=10, p=7.0, sim="independent_normal")
assert_raises(
ValueError, condi_indep_sim, n=10, p=7.0, sim="independent_normal"
)

def test_low_n(self):
assert_raises(ValueError, condi_indep_sim, n=3, p=1, sim="independent_normal")
Expand All @@ -71,4 +73,3 @@ def test_low_p(self):

def test_wrong_sim(self):
assert_raises(ValueError, condi_indep_sim, n=100, p=1, sim="abcd")

12 changes: 12 additions & 0 deletions hyppo/tools/tests/test_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def test_multi(self):
)
assert_almost_equal(est_power, 0.05, decimal=1)

def test_condi_power_perm(self):
np.random.seed(123456789)
est_power = power(
"conditionaldcorr",
sim_type="condi",
sim="independent_normal",
n=50,
p=1,
auto=False,
)
assert_almost_equal(est_power, 0.05, decimal=2)


class TestPowerErrorWarn:
def test_power_nosim(self):
Expand Down

0 comments on commit 161e436

Please sign in to comment.