Debian Codegraph @

inst/testme/test-serializedSize.R

raw
1 library(parallelly)
2
3 message("serializedSize() ...")
4
5 # Test with a simple integer vector
6 obj_int_vec <- 1:100
7 str(obj_int_vec)
8 size_int_vec <- serializedSize(obj_int_vec)
9 message("size_int_vec: ", size_int_vec)
10 stopifnot(is.double(size_int_vec), size_int_vec > 0)
11
12 # Test with a character vector
13 obj_char_vec <- letters
14 str(obj_char_vec)
15 size_char_vec <- serializedSize(obj_char_vec)
16 message("size_char_vec: ", size_char_vec)
17 stopifnot(is.double(size_char_vec), size_char_vec > 0)
18
19 # Test with a list of mixed types
20 obj_list_mixed <- list(a = 1:10, b = "hello", c = TRUE)
21 str(obj_list_mixed)
22 size_list_mixed <- serializedSize(obj_list_mixed)
23 message("size_list_mixed: ", size_list_mixed)
24 stopifnot(is.double(size_list_mixed), size_list_mixed > 0)
25
26 # Test with an empty object (e.g., NULL)
27 obj_null <- NULL
28 str(obj_null)
29 size_null <- serializedSize(obj_null)
30 message("size_null: ", size_null)
31 stopifnot(is.double(size_null), size_null >= 0) # Can be 0 or small positive for NULL
32
33 # Test with a data frame created on the fly
34 obj_df_custom <- data.frame(id = 1:5, name = c("A", "B", "C", "D", "E"), value = c(10.1, 12.3, 15.0, 11.8, 13.5))
35 str(obj_df_custom)
36 size_df_custom <- serializedSize(obj_df_custom)
37 message("size_df_custom: ", size_df_custom)
38 stopifnot(is.double(size_df_custom), size_df_custom > 0)
39
40
41 message("serializedSize() ... done")