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

[ENH] Consolidate stats unit tests and fix linting errors in tests #421

Merged
merged 11 commits into from
Nov 11, 2019
Original file line number Diff line number Diff line change
@@ -1,13 +1,80 @@
"""
Tests for tedana.stats.get_coeffs
Tests for the tedana stats module
"""

import numpy as np
import pytest
import random

from tedana.stats import computefeats2
from tedana.stats import get_coeffs
from tedana.stats import getfbounds


"""
jbteves marked this conversation as resolved.
Show resolved Hide resolved
Tests for computefeats2
"""
def test_break_computefeats2():
"""
Ensure that computefeats2 fails when input data do not have the right
shapes.
"""
n_samples, n_vols, n_comps = 10000, 100, 50
data = np.empty((n_samples, n_vols))
mmix = np.empty((n_vols, n_comps))
mask = np.empty((n_samples))

data = np.empty((n_samples))
with pytest.raises(ValueError) as e_info:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just have this as a straight assertion ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computefeats2(data, mmix, mask, normalize=True)
assert str(e_info.value) == ('Parameter data should be 2d, not {0}d'.format(data.ndim))

data = np.empty((n_samples, n_vols))
mmix = np.empty((n_vols))
with pytest.raises(ValueError) as e_info:
computefeats2(data, mmix, mask, normalize=True)
assert str(e_info.value) == ('Parameter mmix should be 2d, not {0}d'.format(mmix.ndim))

mmix = np.empty((n_vols, n_comps))
mask = np.empty((n_samples, n_vols))
with pytest.raises(ValueError) as e_info:
computefeats2(data, mmix, mask, normalize=True)
assert str(e_info.value) == ('Parameter mask should be 1d, not {0}d'.format(mask.ndim))

mask = np.empty((n_samples+1))
with pytest.raises(ValueError) as e_info:
computefeats2(data, mmix, mask, normalize=True)
assert str(e_info.value) == ('First dimensions (number of samples) of data ({0}) '
'and mask ({1}) do not match.'.format(data.shape[0],
mask.shape[0]))
data.shape[1] != mmix.shape[0]
mask = np.empty((n_samples))
mmix = np.empty((n_vols+1, n_comps))
with pytest.raises(ValueError) as e_info:
computefeats2(data, mmix, mask, normalize=True)
assert str(e_info.value) == ('Second dimensions (number of volumes) of data ({0}) '
'and mmix ({1}) do not match.'.format(data.shape[0],
mmix.shape[0]))


# SMOKE TEST
jbteves marked this conversation as resolved.
Show resolved Hide resolved

def test_smoke_computefeats2():
"""
Ensures that computefeats2 works with random inputs and different optional parameters
"""
n_samples, n_times, n_components = 100, 20, 6
data = np.random.random((n_samples, n_times))
mmix = np.random.random((n_times, n_components))
mask = np.random.randint(2, size=n_samples)

assert computefeats2(data, mmix) is not None
assert computefeats2(data, mmix, mask=mask) is not None
assert computefeats2(data, mmix, normalize=False) is not None


"""
Tests for tedana.stats.get_coeffs
"""
def test_get_coeffs():
"""
Check least squares coefficients.
Expand Down Expand Up @@ -94,3 +161,27 @@ def test_smoke_get_coeffs():
# assert get_coeffs(data_3d, x) is not None TODO: submit an issue for the bug
assert get_coeffs(data_2d, x, mask=mask) is not None
assert get_coeffs(data_2d, x, add_const=True) is not None


"""
Tests for tedana.stats.getfbounds
"""
def test_getfbounds():
good_inputs = range(1, 12)

for n_echos in good_inputs:
getfbounds(n_echos)


# SMOKE TEST
jbteves marked this conversation as resolved.
Show resolved Hide resolved

def test_smoke_getfbounds():
"""
Ensures that getfbounds returns outputs when fed in a random number of echos
"""
n_echos = random.randint(3, 10) # At least two echos!
f05, f025, f01 = getfbounds(n_echos)

assert f05 is not None
assert f025 is not None
assert f01 is not None
69 changes: 0 additions & 69 deletions tedana/tests/test_stats_computefeats2.py

This file was deleted.

30 changes: 0 additions & 30 deletions tedana/tests/test_stats_getfbounds.py

This file was deleted.