Skip to content

Commit

Permalink
Add some more unit tests for H5S functions
Browse files Browse the repository at this point in the history
  • Loading branch information
grimbough committed Mar 1, 2024
1 parent 2faea14 commit e22b821
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/testthat/test_H5S.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ test_that("We can create a simple dataspace", {
expect_equal(dspace_dims$size, dspace_dims$maxsize)
expect_equal(dspace_dims$rank, 2)

## if maxdims isn't supplied, it just matches dims
expect_silent(H5Sset_extent_simple(sid, dims = c(1,1,1)))
dspace_dims <- H5Sget_simple_extent_dims(sid)
expect_equal(dspace_dims$size, dspace_dims$maxsize)

expect_silent(H5Sset_extent_simple(sid, dims = c(1,2,3), maxdims = c(10,20,30)))
expect_is(dspace_dims <- H5Sget_simple_extent_dims(sid), "list")
expect_false( identical(dspace_dims$size, dspace_dims$maxsize) )
Expand Down Expand Up @@ -121,6 +126,56 @@ test_that("Selecting using an index", {
expect_silent(H5Sclose(sid))
})

test_that("Other selection functions", {

dims <- c(10,20,30)
expect_silent(sid <- H5Screate_simple(dims = dims))

expect_silent( H5Sselect_all(sid) )
expect_identical( H5Sget_select_npoints(sid), prod(dims) )

expect_silent( H5Sselect_none(sid) )
expect_identical( H5Sget_select_npoints(sid), 0 )

expect_silent(H5Sclose(sid))
})

test_that("Combining selections", {

sid_1 <- H5Screate_simple(dims = 20)
sid_2 <- H5Screate_simple(dims = 10)

## select a single block of 5 points in sid_1
## this is equivalent to [11:16] in R syntax
H5Sselect_hyperslab(sid_1, start = 11, stride = 1,
block = 5, count = 1)

## select 2 blocks of 1 point from sid_2
## equivalent to [c(3,5)] in R syntax
H5Sselect_hyperslab(sid_2, start = 3, stride = 2,
block = 1, count = 2)

## confirm we have select 5 and 2 points resepectively
expect_equal(H5Sget_select_npoints(sid_1), 5)
expect_equal(H5Sget_select_npoints(sid_2), 2)

## combine the two dataset selections keeping points that
## are in one or both of the selections
sid_3 <- H5Scombine_select(sid_1, "H5S_SELECT_OR", sid_2)

## extent of the new dataset is the same as sid_1
sid_3
## confirm the selection contains 7 points
expect_equal(H5Sget_select_npoints(sid_3), 7)

## tidy up
H5Sclose(sid_1)
H5Sclose(sid_2)
H5Sclose(sid_3)


})

############################################################
context("H5S cleanup")
##########################################################
Expand Down

0 comments on commit e22b821

Please sign in to comment.