From e22b821aefeacbf12458c975a0e7e7711fa1d9bf Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Fri, 1 Mar 2024 19:20:01 +0100 Subject: [PATCH] Add some more unit tests for H5S functions --- tests/testthat/test_H5S.R | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/testthat/test_H5S.R b/tests/testthat/test_H5S.R index 4e12059..25c8417 100644 --- a/tests/testthat/test_H5S.R +++ b/tests/testthat/test_H5S.R @@ -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) ) @@ -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") ##########################################################