tests/testthat/test_makeSparseMatrix.R

context("makeSparseMatrix tests")

test_that("no clusters", {
    x <- diag(x=1:10)
    expect_error(makeSparseMatrix(x, thresh=0.5, verbose=FALSE), "dimnames")
    colnames(x) <- 1:10
    sm <- makeSparseMatrix(x, thresh=0.5, verbose=FALSE)
    expect_true(is(sm, "sparseMatrix"))
    expect_true(isDiagonal(sm))
    expect_true(setequal(diag(x), diag(sm)))
})

test_that("two clusters", {
    x <- diag(nrow=10, ncol=10)
    rownames(x) <- 1:10
    x[2:4,2:4] <- 0.5
    x[7:9,7:9] <- 0.5
    diag(x) <- 1
    expect_message(sm <- makeSparseMatrix(x, thresh=0), "2 clusters")
    expect_true(is(sm, "sparseMatrix"))
})

test_that("sample include", {
    x <- diag(x=1:10)
    dimnames(x) <- list(1:10,1:10)
    sm <- makeSparseMatrix(x, sample.include=2:6, thresh=0, verbose=FALSE)
    expect_equal(dimnames(sm), list(as.character(2:6), as.character(2:6)))
    expect_equal(diag(sm), 2:6)
})

Try the GENESIS package in your browser

Any scripts or data that you put into this service are public.

GENESIS documentation built on Jan. 30, 2021, 2:01 a.m.