Skip to content

Commit

Permalink
Further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonclayden committed Oct 18, 2019
1 parent 870f280 commit dda5414
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/testthat/test-08-composite.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ context("Handling composite types")
test_that("complex datatypes are handled properly", {
image <- readNifti(system.file("extdata", "example.nii.gz", package="RNifti"))
tempPath <- paste(tempfile(), "nii.gz", sep=".")

data <- sqrt(array(as.complex(image)-468, dim=dim(image)))
complexImage <- updateNifti(data, image)

Expand All @@ -23,12 +24,24 @@ test_that("complex datatypes are handled properly", {

test_that("RGB datatypes are handled properly", {
image <- readNifti(system.file("extdata", "example.nii.gz", package="RNifti"))
tempPath <- paste(tempfile(), "nii.gz", sep=".")

set.seed(1)
k <- stats::kmeans(as.vector(image), 3L)
data <- rgbArray(k$cluster==1, k$cluster==2, k$cluster==3, dim=dim(image))
rgbImage <- updateNifti(data, image)
refValue <- rgbArray(diag(3))[k$cluster[40 + 39*96 + 29*9216]]

expect_s3_class(data, "rgbArray")
expect_equal(rgbImage[40,40,30], refValue)
expect_equal(rgbImage$datatype, 128L)
expect_equal(rgbImage$bitpix, 24L)
expect_equivalent(unclass(data), unclass(as.array(rgbImage)))

writeNifti(rgbImage, tempPath)
header <- niftiHeader(tempPath)
expect_equal(header$datatype, 128L)
expect_equal(header$bitpix, 24L)

complexImage <- readNifti(tempPath, internal=TRUE)
expect_equal(complexImage[40,40,30], refValue)
})

0 comments on commit dda5414

Please sign in to comment.