tests/size.R

###
### $Id: size.R 22 2022-05-30 18:03:47Z proebuck $
###


##-----------------------------------------------------------------------------
test.size <- function(input, expected) {
    output <- do.call(getFromNamespace("size", "matlab"), input)
    identical(as.integer(output), expected)
}

X.vec <- 2:9
size.expected.X.vec <- c(1, length(X.vec))

test.size(list(X = X.vec), size.expected.X.vec)
test.size(list(X = X.vec, 1), as.integer(1))
test.size(list(X = X.vec, 2), length(X.vec))


X.mat <- matrix(X.vec, 4, 2)
size.expected.X.mat <- dim(X.mat)

test.size(list(X = X.mat), size.expected.X.mat)
test.size(list(X = X.mat, 1), size.expected.X.mat[1])
test.size(list(X = X.mat, 2), size.expected.X.mat[2])
test.size(list(X = X.mat, 3), as.integer(1))	# singleton dimension

X.arr <- array(2:25, c(4, 3, 2))
size.expected.X.arr <- dim(X.arr)

test.size(list(X = X.arr), size.expected.X.arr)
test.size(list(X = X.arr, 1), size.expected.X.arr[1])
test.size(list(X = X.arr, 2), size.expected.X.arr[2])
test.size(list(X = X.arr, 3), size.expected.X.arr[3])

Try the matlab package in your browser

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

matlab documentation built on July 1, 2024, 5:07 p.m.