Skip to content

Commit

Permalink
Getting that testing up and running.
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Jan 8, 2018
1 parent 47e2081 commit 06a8c81
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions R/datatype.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ setMethod("datatype<-",
}
return(object)
})

#' @rdname datatype-methods
#' @aliases datatype,ANY-method
#' @export
#' @importFrom RNifti dumpNifti
setMethod("datatype", "ANY", function(object) {
if (inherits(object, "niftiImage")) {
return(RNifti::dumpNifti(object)$datatype)
} else {
stop("Not implemented for this type!")
}
})

#' @rdname datatype-methods
#' @aliases datatype<-,anlz-method
#' @export
Expand Down
3 changes: 3 additions & 0 deletions man/datatype-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/testthat/test_anlz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ img01 <- anlz(array(1:64, c(4,4,4,1)), datatype=4)
ximg01 = img01
img02 <- anlz(array(64:1, c(4,4,4,1)), datatype=4)

test_that("as.nifti", {
expect_s4_class(as.nifti(img01), "nifti")
expect_s4_class(as.anlz(img01), "anlz")
})


test_that("operators", {
expect_true(is.anlz(img01 + img02))
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test_nifti.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ img01 <- nifti(array(1:64, c(4,4,4,1)), datatype=4)
ximg01 = img01
img02 <- nifti(array(64:1, c(4,4,4,1)), datatype=4)

test_that("as.nifti", {
expect_s4_class(as.nifti(img01), "nifti")
anlz_img = as.anlz(img01)
expect_s4_class(anlz_img, "anlz")
expect_s4_class(img01 + anlz_img, "nifti")
expect_s4_class(img01 + anlz_img, "nifti")
})

test_that("operators", {
expect_false(is.afni(img01))
expect_false(is.anlz(img01))
expect_true(is.nifti(img01 + img02))
expect_true(is.nifti(sqrt(2) * img01))
expect_true(is.nifti(img02 / pi))
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test_nii2oro.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
context("oro2 other stuff")

nim <- readNIfTI(system.file("nifti/mniRL.nii.gz", package = "oro.nifti"))
nii_img = oro2nii(nim)

test_that("nii2oro()", {
expect_s4_class(nii2oro(nim), "nifti")
Expand All @@ -14,3 +15,13 @@ test_that("oro2nii and back again", {
expect_s4_class(nii2oro(nii_img), "nifti")
})



test_that("nii object", {
expect_silent(dim_( nii_img))
expect_silent(origin( nii_img))
expect_silent(voxdim( nii_img))
expect_silent(datatype( nii_img))

})

0 comments on commit 06a8c81

Please sign in to comment.