tests/testthat/test_combineScores.R

library("BioCor")
context("Testing combineScores")

test_that("combineScores", {
    methods <- c("avg", "max", "rcmax", "rcmax.avg", "BMA", "reciprocal")
    test <- sapply(methods, combineScores, scores = d)
    expect_equal(as.numeric(test["rcmax.avg"]), as.numeric(test["BMA"]))
    expect_true(all(test["max"] > test[-2]))
    expect_equal(as.numeric(test["avg"]), 0.339770723104056)
    expect_equal(as.numeric(test["max"]), 0.6)
    expect_equal(as.numeric(test["rcmax"]), 0.5)
    expect_equal(as.numeric(test["rcmax.avg"]), 0.464285714285714)
    expect_equal(as.numeric(test["reciprocal"]), 0.2)

    expect_error(combineScores(d, "reciprocal", t = "a"), "between")
    expect_error(combineScores(d, "reciprocal", t = 2), "between")
    expect_error(combineScores(d, "reciprocal", t = -2), "between")
    expect_true(is.na(combineScores(d, "reciprocal", t = 0.6)))
    d2 <- list("d" = d)
    expect_equal(combineScores(d2, "max"), 0.6)

    test2 <- sapply(methods, combineScores, scores = d, round = TRUE)
    expect_equal(as.numeric(test2["rcmax.avg"]), as.numeric(test2["BMA"]))
    expect_true(all(test2["max"] > test2[-2]))
    expect_equal(as.numeric(test2["avg"]), 0.340)
    expect_equal(as.numeric(test2["max"]), 0.6)
    expect_equal(as.numeric(test2["rcmax"]), 0.5)
    expect_equal(as.numeric(test2["rcmax.avg"]), 0.464)
    expect_equal(as.numeric(test2["reciprocal"]), 0.2)
    expect_error(combineScores(as.vector(d), "max"), "matrix")
    expect_error(combineScores(d, "max", round = "a"), "logical")
})

test_that("combineScoresPar", {
    methods <- c("avg", "max", "rcmax", "rcmax.avg", "BMA", "reciprocal")
    e <- structure(c(0.4, 0.6, 0.222222222222222, 0.4, 0.4, 0, 0.25, 0.5,
                      0.285714285714286), .Dim = c(3L, 3L),
                    .Dimnames = list(c("a", "b", "c"), c("a", "b", "c")))
    subSet <- list(a = c("a", "b"), b = c("b", "c"))
    expect_warning(combineScoresPar(e, subSet, NULL,
                     method = "max"), "symmetric")
    expect_warning(test3 <- combineScoresPar(e, subSet, bpparam(1),
                                             method = "max"),
                   "symmetric")
    class(test3)
})
Bioconductor-mirror/BioCor documentation built on May 29, 2017, 12:07 a.m.