Skip to content

Commit 606532a

Browse files
committed
add test
1 parent efde12e commit 606532a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/testthat/test-io.r

+28
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ test_that("saved and re-loaded objects are the same", {
149149
expect_true(all(unlist(values1) - unlist(values2) < 1e-5))
150150
})
151151

152+
test_that("IO works with character strings", {
153+
test_char <- lapply(test_output, function(df) {
154+
if ("a" %in% colnames(df)) df$a <- as.character(df$a)
155+
return(df)
156+
})
157+
filename <- tempfile(fileext = ".nc")
158+
out <- bi_write(filename, test_output, guess_time = TRUE)
159+
test_output2 <- bi_read(
160+
filename, coord_dims = out$coord_dims, dims = out$dims
161+
)
162+
lists <- vapply(test_output, is.list, logical(1))
163+
list_names <- names(lists[lists])
164+
list_cols <- lapply(list_names, function(x) {
165+
setdiff(colnames(test_output[[x]]), "value")
166+
})
167+
names(list_cols) <- list_names
168+
169+
for (name in list_names) {
170+
setorderv(test_output[[name]], list_cols[[name]])
171+
setorderv(test_output2[[name]], list_cols[[name]])
172+
}
173+
174+
values1 <- lapply(test_output[list_names], function(x) x[["value"]])
175+
values2 <- lapply(test_output2[list_names], function(x) x[["value"]])
176+
177+
expect_true(all(unlist(values1) - unlist(values2) < 1e-5))
178+
})
179+
152180
test_that("basic I/O functions work", {
153181
bi <- attach_data(bi, file = "init", test_output[c("e", "m")])
154182
bi <- attach_data(bi, "obs", test_output_sparse[c("M", "e")])

0 commit comments

Comments
 (0)