tests/testthat/test-impute-root.R

test_that("impute_root", {
    data <- data.frame(n = c(1, 1, 5),
                       n_pos = c(1, 0, 3),
                       freq = c(10, 2, 4))
    out <- impute_root(data, prob_pos = 1,
                       B = 1)
    expect_equal(as.numeric(out[1,-c(1:2)]), c(2, 2, 10))
    expect_equal(as.numeric(out[2,-c(1:2)]), c(2, 1, 2))
    expect_equal(as.numeric(out[3,-c(1:2)]), c(6, 4, 4))
    ##
    data <- data.frame(n = c(1, 1, 5),
                       n_pos = c(1, 0, 3),
                       freq = c(10, 2, 4))
    out <- impute_root(data, prob_pos = .5,
                       B = 10)
    expect_equal(sum(out$B), 10 * nrow(data))

   


})


test_that("impute_root_inner", {
    df <- data.frame(n = 3,
                     n_pos = 3,
                     freq = 1)
    out <- impute_root_inner(df, prob_pos = 1,
                             n = df$n,
                             n_pos = df$n_pos)
                            
    expect_equal(as.numeric(out), c(4, 4, 1))
    ##
    df <- data.frame(n = 3,
                     n_pos = 3,
                     freq = 1)
    out <- impute_root_inner(df,
                             prob_pos = 1,
                             B = 10,
                             n = df$n,
                             n_pos = df$n_pos)
    expect_equal(as.numeric(out), c(4, 4, 10))
    ##
    df <- data.frame(n = 3,
                     n_pos = 3,
                     freq = 4,
                     B = 5 )
    out <- impute_root_inner(df, prob_pos = .5, B = 5,
                             n = df$n,
                             n_pos = df$n_pos)
                             
    expect_equal(sum(out$B), 5)

})
skgallagher/TBornotTB documentation built on April 21, 2020, 1:19 p.m.