File: sum.R

package info (click to toggle)
r-cran-matlab 1.0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: sh: 13; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 931 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
26
27
28
29
30
31
32
33
34
###
### $Id: sum.R 22 2022-05-30 18:03:47Z proebuck $
###


##-----------------------------------------------------------------------------
test.sum <- function(input, expected) {
    output <- do.call(getFromNamespace("sum", "matlab"), input)
    identical(all.equal(output,
                        expected,
                        tolerance = 0.0001),
              TRUE)
}

X.vec <- 1:9
sum.expected.vec <- 45

cat("vector test", "\n")
test.sum(list(x = X.vec, na.rm = FALSE), sum.expected.vec)

X.mat <- matrix(X.vec, 3, 3, byrow = TRUE)
sum.expected.mat.by.col <- c(12, 15, 18)
sum.expected.mat.by.row <- c(6, 15, 24)

cat("matrix test", "\n")
test.sum(list(x = X.mat, na.rm = FALSE), sum.expected.mat.by.col)
test.sum(list(x = t(X.mat), na.rm = FALSE), sum.expected.mat.by.row)

X.log <- c(TRUE, TRUE, FALSE, TRUE)
sum.expected.log <- 3

cat("logical test", "\n")
test.sum(list(x = X.log, na.rm = FALSE), sum.expected.log)