Skip to content

Commit

Permalink
new test and bug fix for samp_by_grp
Browse files Browse the repository at this point in the history
  • Loading branch information
joshyam-k committed Mar 27, 2024
1 parent 30b8825 commit 7f4ddc0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ samp_by_grp <- function(samp, pop, dom_nm, B) {
dplyr::mutate(map_args = list(list(n.x, n.y, add_to)))

all_samps <- vector("list", length = B)
ord <- rep(setup[[dom_nm]], times = setup$n.x)
pop_ordered <- pop[match(ord, pop[[dom_nm]]), ]

for (i in 1:B) {
ids <- setup |>
Expand All @@ -41,7 +43,7 @@ samp_by_grp <- function(samp, pop, dom_nm, B) {
dplyr::pull(samps) |>
unlist()

out <- pop[ids, ]
out <- pop_ordered[ids, ]
all_samps[[i]] <- out
}

Expand Down
16 changes: 9 additions & 7 deletions tests/testthat/test-saeczi.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ samp <- samp |>


set.seed(5)
result <- saeczi(samp,
pop,
lin_formula,
domain_level = "COUNTYFIPS",
mse_est = TRUE,
B = 10L,
parallel = FALSE)
suppressWarnings(
result <- saeczi(samp,
pop,
lin_formula,
domain_level = "COUNTYFIPS",
mse_est = TRUE,
B = 10L,
parallel = FALSE)
)

test_that("result$res is a df", {
expect_s3_class(result$res, "data.frame")
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-samp_by_grp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data(samp)
data(pop)

res <- samp_by_grp(samp, pop, "COUNTYFIPS", 10)

test_that("plots per group are correct", {
out <- vector(mode = "logical", length = 10)
chk <- as.data.frame(table(samp$COUNTYFIPS))
for (i in 1:10) {
cmp <- as.data.frame(table(res[[i]]$COUNTYFIPS))
mtch <- all.equal(chk$Freq, cmp$Freq)
out[i] <- mtch
}
expect_true(all(out))
})

0 comments on commit 7f4ddc0

Please sign in to comment.