Skip to content

Commit

Permalink
create_batch_glossary() always returns a tibble
Browse files Browse the repository at this point in the history
ref #452
  • Loading branch information
wibeasley committed Oct 23, 2022
1 parent 52109c2 commit c10e4d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/create-batch-glossary.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ create_batch_glossary <- function(row_count, batch_size) {
start_index <- base::seq.int(from=1, to=row_count, by=batch_size)

ds_batch <-
base::data.frame(
tibble::tibble(
id = seq_along(start_index),
start_index = start_index
)
Expand Down
23 changes: 14 additions & 9 deletions tests/testthat/test-create-batch-glossary.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ test_that("N100B3", {
"27_079_081", "28_082_084", "29_085_087", "30_088_090", "31_091_093",
"32_094_096", "33_097_099", "34_100_100")), .Names = c("id",
"start_index", "stop_index", "index_pretty", "start_index_pretty",
"stop_index_pretty", "label"), row.names = c(NA, -34L), class = "data.frame")
"stop_index_pretty", "label"), row.names = c(NA, -34L),
class = c("tbl_df", "tbl", "data.frame"))


expect_equal(object=nrow(ds_result), expected=expected_glossary_count, info="The number of batches should be correct.")
expect_equal(object=colnames(ds_result), expected=expected_column_names, info="The column namesshould be correct.")
Expand All @@ -50,7 +52,9 @@ test_that("N100B100", {
ds_expected <- structure(list(id = 1L, start_index = 1, stop_index = 100, index_pretty = "1",
start_index_pretty = "001", stop_index_pretty = "100", label = "1_001_100"), .Names = c("id",
"start_index", "stop_index", "index_pretty", "start_index_pretty",
"stop_index_pretty", "label"), row.names = c(NA, -1L), class = "data.frame")
"stop_index_pretty", "label"), row.names = c(NA, -1L),
class = c("tbl_df", "tbl", "data.frame"))


expect_equal(object=nrow(ds_result), expected=expected_glossary_count, info="The number of batches should be correct.")
expect_equal(object=colnames(ds_result), expected=expected_column_names, info="The column names should be correct.")
Expand All @@ -64,13 +68,14 @@ test_that("N50B10", {

ds_result <- REDCapR::create_batch_glossary(row_count=row_count, batch_size=batch_size) # dput(ds_result)
ds_expected <- structure(list(id = 1:5, start_index = c(1, 11, 21, 31, 41),
stop_index = c(10, 20, 30, 40, 50), index_pretty = c("1",
"2", "3", "4", "5"), start_index_pretty = c("01", "11", "21",
"31", "41"), stop_index_pretty = c("10", "20", "30", "40",
"50"), label = c("1_01_10", "2_11_20", "3_21_30", "4_31_40",
"5_41_50")), .Names = c("id", "start_index", "stop_index",
"index_pretty", "start_index_pretty", "stop_index_pretty", "label"
), row.names = c(NA, -5L), class = "data.frame")
stop_index = c(10, 20, 30, 40, 50), index_pretty = c("1",
"2", "3", "4", "5"), start_index_pretty = c("01", "11", "21",
"31", "41"), stop_index_pretty = c("10", "20", "30", "40",
"50"), label = c("1_01_10", "2_11_20", "3_21_30", "4_31_40",
"5_41_50")), .Names = c("id", "start_index", "stop_index",
"index_pretty", "start_index_pretty", "stop_index_pretty", "label"
), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"))

expect_equal(object=nrow(ds_result), expected=expected_glossary_count, info="The number of batches should be correct.")
expect_equal(object=colnames(ds_result), expected=expected_column_names, info="The column names should be correct.")
expect_equal(object=ds_result, expected=ds_expected, info="The returned batch glossary should be correct.")
Expand Down

0 comments on commit c10e4d2

Please sign in to comment.