forked from school-brainhack/testing_CI_module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
27 lines (22 loc) · 852 Bytes
/
Copy pathtest_main.py
File metadata and controls
27 lines (22 loc) · 852 Bytes
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
from main import extract_nifti_data, threshold_data, get_mean
import nibabel as nib
import numpy as np
import os
# Write a test for each function
# You shoudln't upload data on github
def test_extract_nifti_data(tmpdir):
data = np.ones((32, 32, 15, 100), dtype=np.int16)
img = nib.Nifti1Image(data, np.eye(4))
path = os.path.join(tmpdir, "./test.nii")
nib.save(img, path)
loaded_data = extract_nifti_data(path)
assert np.array_equal(loaded_data, data), "loading is incorrect"
def test_threshold_data():
data = np.random.rand(5 ,5)
threshold = 0.1
thresholded_data = threshold_data(data, threshold)
assert (thresholded_data > threshold).all(), "thresholding is incorrect"
def test_get_mean():
data = np.ones((4, 4))
average = get_mean(data)
assert average == 1.0, "mean calculation is incorrect"