-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_rarefy.py
37 lines (27 loc) · 1.11 KB
/
test_rarefy.py
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
28
29
30
31
32
33
34
35
36
37
import numpy as np
from rarefy import rarefy
def test_basic_rarefaction():
x = np.array([10, 20, 30, 40, 50])
rarefied = rarefy(x, depth=100, iterations=1, seed=42)
assert len(rarefied) == len(x)
assert sum(np.isnan(rarefied)) == 0
def test_rarefaction_depth_greater_than_total_counts():
x = np.array([10, 20, 30, 40, 50])
rarefied = rarefy(x, depth=300, iterations=1, seed=42)
assert len(rarefied) == len(x)
assert np.all(np.isnan(rarefied))
def test_multiple_iterations():
x = np.array([10, 20, 30, 40, 50])
rarefied = rarefy(x, depth=50, iterations=5, seed=42)
assert len(rarefied) == len(x)
assert sum(np.isnan(rarefied)) == 0
def test_zero_counts():
x = np.array([0, 0, 0, 0, 0])
rarefied = rarefy(x, depth=10, iterations=1, seed=42)
assert len(rarefied) == len(x)
assert np.all(np.isnan(rarefied))
def test_seed_reproducibility():
x = np.array([10, 20, 30, 40, 50])
rarefied_1 = rarefy(x, depth=50, iterations=1, seed=42)
rarefied_2 = rarefy(x, depth=50, iterations=1, seed=42)
np.testing.assert_allclose(rarefied_1, rarefied_2, rtol=1e-6)