File: test-scale.R

package info (click to toggle)
r-bioc-scaledmatrix 1.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 172 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 756 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This tests the auto-scaling in the constructor.
# library(testthat); library(ScaledMatrix); source("test-scale.R")

stripscale <- function(mat, ...) {
    out <- scale(mat, ...)
    attr(out, "scaled:center") <- NULL
    attr(out, "scaled:scale") <- NULL
    out
}

test_that("ScaledMatrix mimics scale()", {
    mat <- matrix(rnorm(10000), ncol=10)

    out <- ScaledMatrix(mat, center=TRUE)
    expect_identical(as.matrix(out), stripscale(mat, scale=FALSE))

    out <- ScaledMatrix(mat, scale=TRUE)
    expect_identical(as.matrix(out), stripscale(mat, center=FALSE))

    out <- ScaledMatrix(mat, center=TRUE, scale=TRUE)
    expect_identical(as.matrix(out), stripscale(mat))

    out <- ScaledMatrix(mat)
    expect_identical(as.matrix(out), mat)
})