-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest-coloredmesh.R
More file actions
82 lines (60 loc) · 4.06 KB
/
test-coloredmesh.R
File metadata and controls
82 lines (60 loc) · 4.06 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
test_that("A coloredmesh can be created from native space morph data", {
testthat::skip_on_cran();
skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");
fsbrain::download_optional_data();
subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
skip_if_not(dir.exists(subjects_dir), message="Test data missing.");
cm = coloredmesh.from.morph.native(subjects_dir, 'subject1', 'thickness', 'lh');
# errors
expect_error(coloredmesh.from.morph.native(subjects_dir, 'subject1', 'thickness', 'nosuchhemi')); # invalid hemi
})
test_that("A coloredmesh can be created from color data", {
testthat::skip_on_cran();
skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");
fsbrain::download_optional_data();
subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
skip_if_not(dir.exists(subjects_dir), message="Test data missing.");
cm = coloredmeshes.from.color(subjects_dir, 'subject1', color_data="blue", hemi='lh');
# errors
expect_error(cm = coloredmeshes.from.color(subjects_dir, 'subject1', color_data="blue", hemi='nosuchhemi')); # invalid hemi
expect_error(cm = coloredmeshes.from.color(subjects_dir, 'subject1', color_data=c("blue", 'red'), hemi='nosuchhemi')); # number of colors not 1 and not number of verts
})
test_that("A coloredmesh can be created from standard space morph data", {
testthat::skip_on_cran();
skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");
fsbrain::download_optional_data();
fsbrain::download_fsaverage(accept_freesurfer_license = TRUE);
fsbrain::download_fsaverage3(accept_freesurfer_license = TRUE);
subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
skip_if_not(dir.exists(subjects_dir), message="Test data missing.");
cm = coloredmesh.from.morph.standard(subjects_dir, 'subject1', 'thickness', hemi='lh', fwhm='10');
# Test with a custom template subject.
cm_fsaverage3 = coloredmesh.from.morph.standard(subjects_dir, 'subject1', 'thickness', hemi='lh', fwhm='0', template_subject = 'fsaverage3');
# errors
expect_error(cm = coloredmesh.from.morph.standard(subjects_dir, 'subject1', 'thickness', hemi='nosuchhemi', fwhm='10')); # invalid hemi
})
test_that("A coloredmesh can be created from arbitrary pre-loaded data", {
testthat::skip_on_cran();
skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");
fsbrain::download_optional_data();
subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
skip_if_not(dir.exists(subjects_dir), message="Test data missing.");
num_verts_subject1_lh = 149244L;
morph_data = rnorm(num_verts_subject1_lh, 3.0, 1.0);
cm = coloredmesh.from.morphdata(subjects_dir, 'subject1', morph_data=morph_data, hemi='lh');
# errors and warnings
expect_error(coloredmesh.from.morphdata(subjects_dir, 'subject1', morph_data = morph_data, hemi='nosuchhemi')); # invalid hemi
morph_data_broken = rnorm((num_verts_subject1_lh + 300L), 3.0, 1.0);
expect_warning(coloredmesh.from.morphdata(subjects_dir, 'subject1', morph_data = morph_data_broken, hemi='lh')); # morph data count does not match
})
test_that("A coloredmesh can be created from a label", {
testthat::skip_on_cran();
skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");
fsbrain::download_optional_data();
subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
skip_if_not(dir.exists(subjects_dir), message="Test data missing.");
label = c(1L, 24L, 100L, 40000L);
cm = coloredmesh.from.label(subjects_dir, 'subject1', label = label, hemi='lh');
# errors and warnings
expect_error(coloredmesh.from.label(subjects_dir, 'subject1', label = label, hemi='nosuchhemi')); # invalid hemi
})