Skip to content

Commit

Permalink
work on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsp-spirit committed Aug 25, 2020
1 parent de0c828 commit a2b3e22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/read_fs_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ read.fs.label.native <- function(filepath, return_one_based_indices=TRUE, full=F
vertices = vertices_df$vertex_index;

if(length(vertices) != num_verts) {
stop(sprintf("Expected %d vertex rows in label file '%s' from header, but received %d.\n", num_verts, filepath, length(vertices)));
stop(sprintf("Expected %d vertex rows in label file '%s' from header, but received %d.\n", num_verts, filepath, length(vertices))); # nocov
}

if(any(vertices < 0L)) {
Expand Down Expand Up @@ -172,15 +172,15 @@ read.fs.label.gii <- function(filepath, label_value=1L, element_index=1L) {
gii = gifti::read_gifti(filepath);
intent = gii$data_info$Intent[[element_index]];
if(intent != 'NIFTI_INTENT_LABEL') {
warning(sprintf("The intent of the gifti file is '%s', expected 'NIFTI_INTENT_LABEL'.\n", intent));
warning(sprintf("The intent of the gifti file is '%s', expected 'NIFTI_INTENT_LABEL'.\n", intent)); # nocov
}
if(is.null(gii$label)) {
stop(sprintf("The gifti file '%s' does not contain label information.\n", filepath));
stop(sprintf("The gifti file '%s' does not contain label information.\n", filepath)); # nocov
} else {

#label_data_num_columns = ncol(gii$data[[element_index]]); # must be 1D for surface labels: 1 column of vertex indices (the data is returned as a matrix).
if(gii$data_info$Dimensionality != 1L) {
stop(sprintf("Label data has %d dimensions, expected 1. This does not look like a 1D surface label.\n", gii$data_info$Dimensionality));
stop(sprintf("Label data has %d dimensions, expected 1. This does not look like a 1D surface label.\n", gii$data_info$Dimensionality)); # nocov
}

annot_data = as.integer(gii$data[[element_index]]); # note that as.integer() turns the (1 column) matrix into a vector.
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-read_fs_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ test_that("Our demo label file can be read with one-based R indices", {
test_that("Our demo label file can be read into an fs.label instance", {
labelfile = system.file("extdata", "lh.entorhinal_exvivo.label", package = "freesurferformats", mustWork = TRUE);

label_zero_based = read.fs.label(labelfile, full=TRUE, return_one_based_indices = FALSE);
expect_true(is.fs.label(label_zero_based));

label = read.fs.label(labelfile, full=TRUE);
known_vertex_count_label = 1085;

Expand Down

0 comments on commit a2b3e22

Please sign in to comment.