Running 'andersondarling_behaviour.r' [151s]
  Running 'andersondarling_correctness.r' [177s]
  Running 'andersondarling_errors.r' [0s]
  Running 'andersondarling_warnings.r' [0s]
  Running 'bartlett_behaviour.r' [167s]
  Running 'bartlett_correctness.r' [157s]
  Running 'bartlett_errors.r' [0s]
  Running 'bartlett_warnings.r' [168s]
  Running 'brownforsythe_behaviour.r' [0s]
  Running 'brownforsythe_correctness.r' [7s]
  Running 'brownforsythe_errors.r' [165s]
  Running 'brownforsythe_warnings.r' [0s]
  Running 'cor_pearson_behaviour.r' [170s]
  Running 'cor_pearson_correctness.r' [153s]
  Running 'cor_pearson_errors.r' [0s]
  Running 'cor_pearson_warnings.r' [160s]
  Running 'cosinor_behaviour.r' [0s]
  Running 'cosinor_correctness.r' [17s]
  Running 'cosinor_errors.r' [0s]
  Running 'cosinor_warnings.r' [157s]
  Running 'f_var_behaviour.r' [0s]
  Running 'f_var_correctness.r' [174s]
  Running 'f_var_errors.r' [0s]
  Running 'f_var_warnings.r' [0s]
  Running 'flignerkilleen_behaviour.r' [0s]
  Running 'flignerkilleen_correctness.r' [165s]
  Running 'flignerkilleen_errors.r' [168s]
  Running 'flignerkilleen_warnings.r' [0s]
  Running 'jarquebera_behaviour.r' [0s]
  Running 'jarquebera_correctness.r' [1s]
  Running 'jarquebera_errors.r' [143s]
  Running 'jarquebera_warnings.r' [156s]
  Running 'kolmogorovsmirnov_twosample_behavioiur.r' [149s]
  Running 'kolmogorovsmirnov_twosample_correctness.r' [176s]
  Running 'kolmogorovsmirnov_twosample_errors.r' [0s]
  Running 'kolmogorovsmirnov_twosample_warnings.r' [153s]
  Running 'kruskalwallis_behaviour.r' [0s]
  Running 'kruskalwallis_correctness.r' [3s]
  Running 'kruskalwallis_errors.r' [166s]
  Running 'kruskalwallis_warnings.r' [161s]
  Running 'levene_behaviour.r' [0s]
  Running 'levene_correctness.r' [8s]
  Running 'levene_errors.r' [0s]
  Running 'levene_warnings.r' [158s]
  Running 'oneway_equalvar_behaviour.r' [0s]
  Running 'oneway_equalvar_correctness.r' [5s]
  Running 'oneway_equalvar_errors.r' [170s]
  Running 'oneway_equalvar_warnings.r' [0s]
  Running 'oneway_welch_behaviour.r' [0s]
  Running 'oneway_welch_correctness.r' [150s]
  Running 'oneway_welch_errors.r' [0s]
  Running 'oneway_welch_warnings.r' [0s]
  Running 't_equalvar_behaviour.r' [0s]
  Running 't_equalvar_correctness.r' [1s]
  Running 't_equalvar_errors.r' [0s]
  Running 't_equalvar_warnings.r' [171s]
  Running 't_onesample_behaviour.r' [0s]
  Running 't_onesample_correctness.r' [171s]
  Running 't_onesample_errors.r' [0s]
  Running 't_onesample_warnings.r' [152s]
  Running 't_paired_behaviour.r' [160s]
  Running 't_paired_correctness.r' [1s]
  Running 't_paired_errors.r' [0s]
  Running 't_paired_warnings.r' [167s]
  Running 't_welch_behaviour.r' [161s]
  Running 't_welch_correctness.r' [151s]
  Running 't_welch_errors.r' [155s]
  Running 't_welch_warnings.r' [0s]
  Running 'waerden_behaviour.r' [0s]
  Running 'waerden_correctness.r' [3s]
  Running 'waerden_errors.r' [157s]
  Running 'waerden_warnings.r' [0s]
  Running 'wilcoxon_onesample_behaviour.r' [170s]
  Running 'wilcoxon_onesample_correctness.r' [2s]
  Running 'wilcoxon_onesample_errors.r' [160s]
  Running 'wilcoxon_onesample_warnings.r' [0s]
  Running 'wilcoxon_paired_behaviour.r' [167s]
  Running 'wilcoxon_paired_correctness.r' [165s]
  Running 'wilcoxon_paired_errors.r' [0s]
  Running 'wilcoxon_paired_warnings.r' [150s]
  Running 'wilcoxon_twosample_behaviour.r' [158s]
  Running 'wilcoxon_twosample_correctness.r' [10s]
  Running 'wilcoxon_twosample_errors.r' [170s]
  Running 'wilcoxon_twosample_warnings.r' [0s]
Running the tests in 'tests/andersondarling_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x can be a vector
  > x <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > stopifnot(all.equal(row_andersondarling(x), row_andersondarling(X)))
  > 
  > # x can be numeric data.frame
  > x <- cbind(iris[,1:4], iris[,1:4])
  > X <- as.matrix(x)
  > stopifnot(all.equal(row_andersondarling(x), row_andersondarling(X)))
  > 
  > # x can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_andersondarling(x)), 0))
  > 
  > # x can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_andersondarling(x)), 0))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(8),NA)
  > res1 <- row_andersondarling(x)
  > res2 <- row_andersondarling(x[!is.na(x)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # no difference between NA and NaN in x
  > x1 <- c(NA,NA,1:8,NA)
  > x2 <- c(NaN,NaN,1:8,NaN)
  > res1 <- row_andersondarling(x1)
  > res2 <- row_andersondarling(x2)
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 8)
  > res <- suppressWarnings(row_andersondarling(x))
  > stopifnot(all.equal(res$obs, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > res <- row_andersondarling(x)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_andersondarling(x)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > res <- row_andersondarling(x)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(40), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > res <- row_andersondarling(x)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.26    0.07    0.28 
Running the tests in 'tests/andersondarling_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > nortest_andersondarling <- function(mat) {
  +   if(is.vector(mat)) mat <- matrix(mat, nrow=1)
  + 
  +   n <- st <- p <- numeric(nrow(mat))
  +   for(i in 1:nrow(mat)) {
  +     vec <- na.omit(mat[i,])
  + 
  +     res <- nortest::ad.test(x=as.numeric(vec))
  + 
  +     n[i]    <- length(vec)
  +     st[i]   <- res$statistic
  +     p[i]    <- res$p.value
  +   }
  + 
  +   data.frame(obs=n, statistic=st, pvalue=p)
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # 10 observations
  > x <- matrix(rnorm(10000), ncol=10)
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 100 observations
  > x <- matrix(rnorm(100000), ncol=100)
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 20 observations - highly non normal
  > x <- cbind(matrix(runif(10000), ncol=10), matrix(runif(10000, 10, 11), ncol=10))
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000,
  +        100000000000003, 100000000000002, 100000000000003, 100000000000000
  +        )
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(1.00000000000004, 1.00000000000002, 1.00000000000003, 1.00000000000000,
  +        1.00000000000003, 1.00000000000002, 1.00000000000003, 1.00000000000000
  +        )
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # extremely non normal
  > x <- 1:10000
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(10^6)
  > # res1 <- nortest_andersondarling(x)
  > # res2 <- row_andersondarling(x)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # eight numbers
  > x <- rnorm(8)
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # eight numbers with NAs
  > x <- c(NA, rnorm(8))
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # nine numbers
  > x <- rnorm(9)
  > res1 <- nortest_andersondarling(x)
  > res2 <- row_andersondarling(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > proc.time()
     user  system elapsed 
     1.14    0.09    1.21 
Running the tests in 'tests/bartlett_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x can be a vector
  > x <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > g <- rep(letters[1:3], each=3)
  > stopifnot(all.equal(row_bartlett(x, g), row_bartlett(X, g)))
  > 
  > # x can be numeric data.frame
  > x <- iris[,1:4]
  > X <- as.matrix(x)
  > g <- c("a","a","b","b")
  > stopifnot(all.equal(row_bartlett(x, g), row_bartlett(X, g)))
  > 
  > # x can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > g <- c("a","a","b","b")
  > stopifnot(all.equal(nrow(row_bartlett(x, g)), 0))
  > 
  > # x can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > g <- character()
  > stopifnot(all.equal(nrow(row_bartlett(x, g)), 0))
  > 
  > # groups can be infinities
  > x <- rnorm(4)
  > g1 <- c(Inf, Inf, -Inf, -Inf)
  > g2 <- c("a","a","b","b")
  > stopifnot(all.equal(row_bartlett(x, g1), row_bartlett(x, g2)))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > g <- rep(letters[1:2], each=5)
  > res1 <- row_bartlett(x, g)
  > res2 <- row_bartlett(x[!is.na(x)], g[!is.na(x)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in x for whole group are removed correctly
  > x <- c(rep(NA, 5), rnorm(10))
  > g <- rep(letters[1:3], each=5)
  > res1 <- suppressWarnings(row_bartlett(x, g))
  > res2 <- row_bartlett(x[!is.na(x)], g[!is.na(x)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # no difference between NA and NaN in x
  > x1 <- c(NA,NA,1:7,NA)
  > x2 <- c(NaN,NaN,1:7,NaN)
  > g <- rep(letters[1:2], each=5)
  > res1 <- row_bartlett(x1, g)
  > res2 <- row_bartlett(x2, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in g are removed
  > x <- rnorm(10)
  > g <- c(NA, NA, rep(letters[1:2], c(3,4)), NA)
  > res1 <- suppressWarnings(row_bartlett(x, g))
  > res2 <- row_bartlett(x[!is.na(g)], g[!is.na(g)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # no difference between NA and NaN in g
  > x <- rnorm(10)
  > g1 <- c(NA, NA, rep(1:2, c(3,4)), NA)
  > g2 <- c(NaN, NaN, rep(1:2, c(3,4)), NaN)
  > res1 <- suppressWarnings(row_bartlett(x, g1))
  > res2 <- suppressWarnings(row_bartlett(x, g2))
  > stopifnot(all.equal(res1, res2))
  > 
  > # correct synergy between NAs in x and NAs in g
  > x <- c(NA, NA, rnorm(13))
  > g <- c(NA, "a", NA, rep(letters[2:5], each=3))
  > res1 <- suppressWarnings(row_bartlett(x, g))
  > res2 <- row_bartlett(x[!is.na(x) & !is.na(g)], g[!is.na(x) & !is.na(g)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > g <- rep(NA, 4)
  > res <- suppressWarnings(row_bartlett(x, g))
  > stopifnot(all.equal(res$obs.tot, 0))
  > stopifnot(all.equal(res$obs.groups, 0))
  > 
  > 
  > #--- groups with one remaining observation -------------------------------------
  > 
  > # all groups with one observation - all are removed
  > x <- rnorm(10)
  > g <- letters[1:10]
  > res1 <- suppressWarnings(row_bartlett(x, g))
  > res2 <- suppressWarnings(row_bartlett(NA_integer_, NA))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res1$obs.tot, 0))
  > stopifnot(all.equal(res1$obs.groups, 0))
  > 
  > # groups with one observation are removed and others retained
  > x <- rnorm(12)
  > g <- c(rep(letters[1:3], each=3), "d", "e", "f")
  > res1 <- suppressWarnings(row_bartlett(x, g))
  > res2 <- suppressWarnings(row_bartlett(x[g %in% names(which(table(g)!=1))], g[g %in% names(which(table(g)!=1))]))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res1$obs.tot, 9))
  > stopifnot(all.equal(res1$obs.groups, 3))
  > 
  > # correct synergy with NA values
  > x <- c(NA, rnorm(10), NA, rnorm(1))
  > g <- c(NA, rep(letters[1:3], each=3), NA, letters[1], letters[4])
  > res1 <- suppressWarnings(row_bartlett(x, g))
  > res2 <- suppressWarnings(row_bartlett(x[!is.na(x) & !is.na(g)], g[!is.na(x) & !is.na(g)]))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res1$obs.tot, 9))
  > stopifnot(all.equal(res1$obs.groups, 3))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > g <- rep(letters[1:2], each=5)
  > res <- row_bartlett(x, g)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > g <- rep(letters[1:2], each=5)
  > res <- row_bartlett(x, g)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > g <- rep(letters[1:2], each=5)
  > res <- row_bartlett(x, g)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(40), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > g <- rep(letters[1:2], each=5)
  > res <- row_bartlett(x, g)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.25    0.14    0.31 
Running the tests in 'tests/bartlett_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_bartlett <- function(mat, groups) {
  +   if(is.vector(mat)) mat <- matrix(mat, nrow=1)
  + 
  +   bad <- is.na(groups)
  +   mat    <- mat[,!bad,drop=FALSE]
  +   groups <- groups[!bad]
  + 
  +   ng <- nt <- vt <- ks <- p <- df <- numeric(nrow(mat))
  +   for(i in 1:nrow(mat)) {
  +     bad <- is.na(mat[i,])
  +     vec <- na.omit(mat[i,!bad])
  +     grp <- na.omit(groups[!bad])
  + 
  +     badgr <- names(which(table(grp)==1))
  +     bad   <- grp %in% badgr
  +     vec   <- vec[!bad]
  +     grp   <- grp[!bad]
  + 
  +     res <- bartlett.test(vec, factor(grp))
  + 
  +     # if p-value is NA turn df to NA as well
  +     if(is.na(res$p.value)) res$parameter <- NA
  + 
  +     ng[i] <- length(unique(grp))
  +     nt[i] <- length(vec)
  +     vt[i] <- sum((tapply(vec, grp, length)-1) * tapply(vec, grp, var, na.rm=TRUE)) / (nt[i]-ng[i])
  +     ks[i] <- res$statistic
  +     p[i]  <- res$p.value
  +     df[i] <- res$parameter
  +   }
  + 
  +   data.frame(obs.tot=nt, obs.groups=ng, var.pooled=vt, df=df, statistic=ks,
  +              pvalue=p, stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # two groups
  > x <- matrix(rnorm(10000), ncol=10)
  > g <- sample(letters[1:2], 6, replace=TRUE)
  > g <- sample(c("a", "a", "b", "b", g))  # ensure both groups have at least 2 obs
  > res1 <- base_bartlett(x, g)
  > res2 <- row_bartlett(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # lots of groups
  > x <- matrix(rnorm(100000), ncol=100)
  > g <- sample(letters[1:15], 100, replace=TRUE)
  > res1 <- base_bartlett(x, g)
  > res2 <- row_bartlett(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000,
  +        100000000000003, 100000000000002, 100000000000003, 100000000000000
  +        )
  > g <- c(rep("a", 4), rep("b", 4))
  > res1 <- base_bartlett(x, g)
  > res2 <- row_bartlett(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(1.00000000000004, 1.00000000000002, 1.00000000000003, 1.00000000000000,
  +        1.00000000000003, 1.00000000000002, 1.00000000000003, 1.00000000000000
  +        )
  > g <- c(rep("a", 4), rep("b", 4))
  > res1 <- base_bartlett(x, g)
  > res2 <- row_bartlett(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(3 * 10^6)
  > # g <- rep(letters[1:3], each=10^6)
  > # res1 <- base_bartlett(x, g)
  > # res2 <- row_bartlett(x, g)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # two groups with two values each
  > x <- rnorm(4)
  > g <- c("a","a","b","b")
  > res1 <- base_bartlett(x, g)
  > res2 <- row_bartlett(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # many groups all with two values
  > x <- rnorm(20)
  > g <- rep(letters[1:10], each=2)
  > res1 <- base_bartlett(x, g)
  > res2 <- row_bartlett(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > # all values are zero
  > x <- c(0,0,0,0)
  > g <- c("a","a","b","b")
  > res1 <- base_bartlett(x, g)
  > res2 <- suppressWarnings(row_bartlett(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # all values are constant
  > x <- c(1,1,1,1)
  > g <- c("a","a","b","b")
  > res1 <- base_bartlett(x, g)
  > res2 <- suppressWarnings(row_bartlett(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # within group values are constant
  > x <- c(1,1,2,2)
  > g <- c("a","a","b","b")
  > res1 <- base_bartlett(x, g)
  > res2 <- suppressWarnings(row_bartlett(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # one group's values are constant
  > x <- c(1,1,2,3)
  > g <- c("a","a","b","b")
  > res1 <- base_bartlett(x, g)
  > res2 <- suppressWarnings(row_bartlett(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # all groups have equal variances
  > x <- c(1:3,2:4,3:5,4:6,5:7)
  > g <- rep(1:5, each=3)
  > res1 <- base_bartlett(x, g)
  > res2 <- row_bartlett(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- groups with one element ---------------------------------------------------
  > 
  > # groups with one remaining values are removed
  > x <- rnorm(5)
  > g <- c("a","a","b","b","c")
  > res1 <- base_bartlett(x, g)
  > res2 <- suppressWarnings(row_bartlett(x, g))
  > res3 <- suppressWarnings(row_bartlett(x[-5], g[-5]))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res2$obs.groups, 2))
  > 
  > 
  > proc.time()
     user  system elapsed 
     2.42    0.09    2.50 
Running the tests in 'tests/bartlett_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- removing na groups --------------------------------------------------------
  > 
  > wrn <- '2 columns dropped due to missing group information'
  > 
  > # 2 NAs
  > x <- 1:10
  > g <- c(1,1,1,1,NA,NA,2,2,2,2)
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > 
  > #--- groups with one observations ----------------------------------------------
  > 
  > # TODO: In order to be consistent with tests that remove empty groups either:
  > #       1) Only show this warning in cases where group with 1 observation is removed.
  > #       2) Make other tests show similar warnings where empty groups are removed.
  > wrn <- 'row_bartlett: 1 of the rows had groups with less than 2 observations: those groups were removed.\nFirst occurrence at row 1'
  > 
  > # 3 groups with one having only one observation
  > x <- 1:5
  > g <- c("a","a","b","b","c")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs.tot, 4))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > # 3 groups with 1 having one observation due to NA values
  > x <- c(1:4, NA, 1)
  > g <- c("a","a","b","b","c","c")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs.tot, 4))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > 
  > #--- less than 2 groups --------------------------------------------------------
  > 
  > wrn <- 'row_bartlett: 1 of the rows had less than 2 groups with enough observations.\nFirst occurrence at row 1'
  > nacolumns <- c("df", "statistic", "pvalue")
  > 
  > # all values in one group
  > x <- 1:10
  > g <- rep("a", 10)
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 10))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > 
  > # many groups but all have one observation
  > x <- 1:10
  > g <- letters[1:10]
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 0))
  > stopifnot(all.equal(res$value$obs.groups, 0))
  > 
  > # two groups but one has only a single observation and is removed
  > x <- 1:4
  > g <- c("a","a","a","b")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > 
  > # two groups but one has only NAs
  > x <- c(1:3, NA, NA, NA)
  > g <- rep(c("a","b"), each=3)
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > 
  > 
  > #--- all groups have zero variance ---------------------------------------------
  > 
  > wrn <- 'row_bartlett: 1 of the rows had zero variance in all of the groups.\nFirst occurrence at row 1'
  > nacolumns <- c("df", "statistic", "pvalue")
  > 
  > # two groups - all values are constant
  > x <- c(1,1,1,1)
  > g <- c("a","a","b","b")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 4))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > # two groups - constant values within each group
  > x <- c(3,3,0,0)
  > g <- c("a","a","b","b")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 4))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > # two groups - constant values plus NA within each group
  > x <- c(3,3,NA,0,0,NA)
  > g <- c("a","a","a","b","b","b")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 4))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > 
  > #--- one of the groups has zero variance ---------------------------------------
  > 
  > wrn <- 'row_bartlett: 1 of the rows had groups with zero variance: result might be unreliable.\nFirst occurrence at row 1'
  > 
  > # two groups - one with constant values
  > x <- c(1,2,1,1)
  > g <- c("a","a","b","b")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$statistic, Inf))
  > 
  > # three groups - constant values within two of them
  > x <- c(1,2,3,3,5,5)
  > g <- c("a","a","b","b","c","c")
  > res <- capture(row_bartlett(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$statistic, Inf))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.17    0.09    0.23 
Running the tests in 'tests/brownforsythe_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_brownforsythe())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_brownforsythe(NULL, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_brownforsythe(c("a", "b"), c("a","b")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_brownforsythe(c(TRUE, FALSE), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_brownforsythe(complex(c(1,2), c(3,4)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_brownforsythe(iris, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_brownforsythe(as.list(c(1:5)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_brownforsythe(list(1:5), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- g argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "g" is missing, with no default'
  > res <- capture(row_brownforsythe(1, ))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a matrix with dimensions
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_brownforsythe(matrix(1:4, nrow=1), matrix(letters[1:4], nrow=2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a in a list
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_brownforsythe(1:5, list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # g length must match the observations of x
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_brownforsythe(1:5, letters[1:4]))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.23    0.07    0.25 
Running the tests in 'tests/cor_pearson_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x and y can be vectors
  > x <- rnorm(9)
  > y <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > Y <- matrix(y, nrow=1)
  > stopifnot(all.equal(row_cor_pearson(x, y), row_cor_pearson(X, Y)))
  > 
  > # x and y can be numeric data frames
  > x <- iris[1:50,1:4]
  > y <- iris[51:100,1:4]
  > X <- as.matrix(x)
  > Y <- as.matrix(y)
  > stopifnot(all.equal(row_cor_pearson(x, y), row_cor_pearson(X, Y)))
  > 
  > # x and y can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > y <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_cor_pearson(x, y)), 0))
  > 
  > # x and y can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > y <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_cor_pearson(x, y)), 0))
  > 
  > # alternative values can be partially completed
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_cor_pearson(x, y, alternative="greater"), row_cor_pearson(x, y, alternative="g")))
  > 
  > # conf.level can be 0
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_cor_pearson(x, y, conf.level=0)
  > stopifnot(all.equal(res$conf.low, res$conf.high))
  > 
  > # conf.level can be 1
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_cor_pearson(x, y, conf.level=1)
  > stopifnot(all.equal(res$conf.low, -1))
  > stopifnot(all.equal(res$conf.high, 1))
  > 
  > # conf.level can be NA
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_cor_pearson(x, y, conf.level=NA)
  > stopifnot(all.equal(res$conf.level, NA_real_))
  > stopifnot(all.equal(res$conf.low, NA_real_))
  > stopifnot(all.equal(res$conf.high, NA_real_))
  > 
  > 
  > #--- recycling -----------------------------------------------------------------
  > 
  > # y can be a vector when x is a matrix
  > x <- matrix(rnorm(10), nrow=2)
  > y <- 1:5
  > res1 <- row_cor_pearson(x, y)
  > res2 <- row_cor_pearson(x, rbind(y,y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # alternative can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_cor_pearson(x, y, alternative="g")
  > res2 <- row_cor_pearson(x, y, alternative=c("g","g"))
  > stopifnot(all.equal(res1, res2))
  > 
  > # conf.level can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_cor_pearson(x, y, conf.level=0.98)
  > res2 <- row_cor_pearson(x, y, conf.level=c(0.98,0.98))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- rnorm(10)
  > res1 <- row_cor_pearson(x, y)
  > res2 <- row_cor_pearson(x[!is.na(x)], y[!is.na(x)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in y are removed
  > x <- rnorm(10)
  > y <- c(NA,NA,rnorm(7),NA)
  > res1 <- row_cor_pearson(x, y)
  > res2 <- row_cor_pearson(x[!is.na(y)], y[!is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values from both x and y are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- c(NA,rnorm(7),NA,NA)
  > res1 <- row_cor_pearson(x, y)
  > res2 <- row_cor_pearson(x[!is.na(x) & !is.na(y)], y[!is.na(x) & !is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res1$obs.paired, 6))
  > 
  > # no difference between NA and NaN
  > x1 <- c(NA,NA,1,2,1:5,NA)
  > x2 <- c(NaN,NaN,1,2,1:5,NaN)
  > y1 <- c(NA,NA,8:2,NA)
  > y2 <- c(NaN,NaN,8:2,NaN)
  > res1 <- row_cor_pearson(x1, y1)
  > res2 <- row_cor_pearson(x2, y2)
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > y <- rep(NA_integer_, 4)
  > res <- suppressWarnings(row_cor_pearson(x, y))
  > stopifnot(all.equal(res$obs.paired, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_cor_pearson(x, y)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when not provided - not taken from y
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_cor_pearson(x, y)
  > stopifnot(all.equal(rownames(res), c("1","2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_cor_pearson(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_cor_pearson(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(20), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > y <- matrix(rnorm(20), nrow=4)
  > res <- row_cor_pearson(x, y)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.15    0.14    0.26 
Running the tests in 'tests/cor_pearson_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_cor_pearson <- function(mat1, mat2, alt="two.sided", conf=0.95) {
  +   stopifnot(ncol(mat1)==ncol(mat2))
  +   if(is.vector(mat1)) mat1 <- matrix(mat1, nrow=1)
  +   if(is.vector(mat2)) mat2 <- matrix(mat2, nrow=1)
  +   if(length(alt)==1) alt <- rep(alt, nrow(mat1))
  +   if(length(conf)==1) conf <- rep(conf, nrow(mat1))
  + 
  +   np <- cor <- tst <- p <- cl <- ch <- df <- mu <- cnf <- numeric(nrow(mat1))
  +   al <- character(nrow(mat1))
  +   for(i in 1:nrow(mat1)) {
  +     good <- complete.cases(mat1[i,], mat2[i,])
  +     vec1 <- mat1[i,good]
  +     vec2 <- mat2[i,good]
  +     res <- cor.test(vec1, vec2, alternative=alt[i], conf.level=conf[i],
  +                     method="pearson"
  +                     )
  + 
  +     # if p-value is NA turn df to NA as well
  +     if(is.na(res$p.value)) res$parameter <- NA
  + 
  +     np[i]  <- length(vec1)
  +     cor[i] <- res$estimate
  +     tst[i] <- res$statistic
  +     p[i]   <- res$p.value
  +     cl[i]  <- ifelse(is.null(res$conf.int), NA, res$conf.int[1])
  +     ch[i]  <- ifelse(is.null(res$conf.int), NA, res$conf.int[2])
  +     cnf[i] <- ifelse(is.null(res$conf.int), conf[i], attr(res$conf.int, "conf.level"))
  +     df[i]  <- res$parameter
  +     mu[i]  <- res$null.value
  +     al[i]  <- res$alternative
  +   }
  + 
  +   data.frame(obs.paired=np, cor=cor, df=df, statistic=tst,
  +              pvalue=p, conf.low=cl, conf.high=ch, alternative=al,
  +              cor.null=mu, conf.level=cnf, stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # 5 observations
  > x <- matrix(rnorm(5000), ncol=5)
  > y <- matrix(rnorm(5000), ncol=5)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > cfs  <- sample(seq(0, 1, length.out=nrow(x)))
  > res1 <- base_cor_pearson(x, y, alts, cfs)
  > res2 <- row_cor_pearson(x, y, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 20 observations
  > x <- matrix(rnorm(20000), ncol=20)
  > y <- matrix(rnorm(20000), ncol=20)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > cfs  <- sample(seq(0, 1, length.out=nrow(x)))
  > res1 <- base_cor_pearson(x, y, alts, cfs)
  > res2 <- row_cor_pearson(x, y, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000)
  > y <- c(100000000000003, 100000000000002, 100000000000003, 100000000000000)
  > res1 <- base_cor_pearson(x, y)
  > res2 <- row_cor_pearson(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(1.00000000000004, 1.00000000000002, 1.00000000000003, 1)
  > y <- c(1.00000000000003, 1.00000000000002, 1.00000000000003, 1)
  > res1 <- base_cor_pearson(x, y)
  > res2 <- row_cor_pearson(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(10^6)
  > # y <- rnorm(10^6)
  > # res1 <- base_cor_pearson(x, y)
  > # res2 <- row_cor_pearson(x, y)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # 3 values
  > x <- matrix(rnorm(9), ncol=3)
  > y <- matrix(rnorm(9), ncol=3)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_cor_pearson(x, y)
  > res2 <- suppressWarnings(row_cor_pearson(x, y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # three numbers with NAs
  > x <- matrix(c(rnorm(12), NA, NA, NA), ncol=5)
  > y <- matrix(c(NA, NA, NA, rnorm(12)), ncol=5)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_cor_pearson(x, y)
  > res2 <- suppressWarnings(row_cor_pearson(x, y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # four numbers (will produce confidence intervals)
  > x <- matrix(rnorm(12), ncol=4)
  > y <- matrix(rnorm(12), ncol=4)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_cor_pearson(x, y)
  > res2 <- row_cor_pearson(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- parameter edge cases ------------------------------------------------------
  > 
  > # various corner cases with NAs
  > alt <- c("l", "t", "g")
  > cfs <- c(0, 0.5, 1)
  > pars <- expand.grid(alt, cfs, stringsAsFactors=FALSE)
  > x1 <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > x2 <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > res1 <- base_cor_pearson(x1, x2, pars[,1], pars[,2])
  > res2 <- suppressWarnings(row_cor_pearson(x1, x2, pars[,1], pars[,2]))
  > stopifnot(all.equal(res1, res2))
  > 
  > # NAs in confidence intervals
  > x <- matrix(rnorm(40), ncol=10)
  > y <- matrix(rnorm(40), ncol=10)
  > cnf <- c(0.95, NA, 0.5, NA)
  > res1 <- base_cor_pearson(x, y, conf=ifelse(is.na(cnf), 0.95, cnf))
  > res1[is.na(cnf), c("conf.level", "conf.low", "conf.high")] <- NA
  > res2 <- row_cor_pearson(x, y, conf.level=cnf)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > # all values are 0
  > res1 <- suppressWarnings(base_cor_pearson(rep(0,4), rep(0,4)))
  > res2 <- suppressWarnings(row_cor_pearson(rep(0,4), rep(0,4)))
  > stopifnot(all.equal(res1, res2))
  > 
  > # all values are constant
  > res1 <- suppressWarnings(base_cor_pearson(rep(1,4), rep(2,4)))
  > res2 <- suppressWarnings(row_cor_pearson(rep(1,4), rep(2,4)))
  > stopifnot(all.equal(res1, res2))
  > 
  > # perfect positive correlation
  > res1 <- base_cor_pearson(1:4, 1:4)
  > res2 <- suppressWarnings(row_cor_pearson(1:4, 1:4))
  > stopifnot(all.equal(res1, res2))
  > 
  > # perfect negative correlation
  > res1 <- base_cor_pearson(1:4, 4:1)
  > res2 <- suppressWarnings(row_cor_pearson(1:4, 4:1))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.79    0.03    0.82 
Running the tests in 'tests/cor_pearson_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- less than 3 complete observations -----------------------------------------
  > 
  > wrn <- 'row_cor_pearson: 1 of the rows had less than 3 complete observations.\nFirst occurrence at row 1'
  > nacolumns <- c("cor", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # 0 observations
  > res <- capture(row_cor_pearson(numeric(), numeric()))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > # 1 observation
  > res <- capture(row_cor_pearson(1, 1))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > # 2 observations
  > res <- capture(row_cor_pearson(1:2, 3:4))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > # 2 matched observations after NAs
  > res <- capture(row_cor_pearson(c(NA,1:3), c(3,NA,5,4)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > 
  > #--- exactly 3 complete observations -------------------------------------------
  > 
  > wrn <- 'row_cor_pearson: 1 of the rows had exactly 3 complete observations: no confidence intervals produced.\nFirst occurrence at row 1'
  > nacolumns <- c("conf.low", "conf.high")
  > 
  > # exactly 3 observations
  > res <- capture(row_cor_pearson(c(1,1,2), c(1,2,3)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > # exactly 3 observations after removing NA values
  > res <- capture(row_cor_pearson(c(NA,1:4), c(3,NA,1,3,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > 
  > #--- x has zero variance -------------------------------------------------------
  > 
  > wrn <- 'row_cor_pearson: 1 of the rows had zero standard deviation in x.\nFirst occurrence at row 1'
  > nacolumns <- c("cor", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # all values are the same
  > res <- capture(row_cor_pearson(c(1,1,1,1), 1:4))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > # all values are the same after removing NAs
  > res <- capture(row_cor_pearson(c(1,1,1,1,2), c(1:4,NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > 
  > #--- y has zero variance -------------------------------------------------------
  > 
  > wrn <- 'row_cor_pearson: 1 of the rows had zero standard deviation in y.\nFirst occurrence at row 1'
  > nacolumns <- c("cor", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # all values are the same
  > res <- capture(row_cor_pearson(1:4, c(1,1,1,1)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > # all values are the same after removing NAs
  > res <- capture(row_cor_pearson(c(1:4,NA), c(1,1,1,1,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > 
  > #--- both have 0 variance ------------------------------------------------------
  > 
  > wrnx <- 'row_cor_pearson: 1 of the rows had zero standard deviation in x.\nFirst occurrence at row 1'
  > wrny <- 'row_cor_pearson: 1 of the rows had zero standard deviation in y.\nFirst occurrence at row 1'
  > nacolumns <- c("cor", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # all values are constant in both groups
  > res <- capture(row_cor_pearson(c(1,1,1,1), c(1,1,1,1)))
  > stopifnot(all.equal(res$warning, c(wrnx, wrny)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > # all values are constant in both groups after removing NAs
  > res <- capture(row_cor_pearson(c(NA,1,1,1,1,1,2), c(1,2,2,2,2,2,NA)))
  > stopifnot(all.equal(res$warning, c(wrnx, wrny)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > 
  > 
  > #--- correlation is perfect ----------------------------------------------------
  > 
  > wrn <- 'row_cor_pearson: 1 of the rows had essentially perfect fit: results might be unreliable for small sample sizes.\nFirst occurrence at row 1'
  > 
  > # perfect positive correlation
  > res <- capture(row_cor_pearson(c(1:4), c(1:4)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$statistic, Inf))
  > 
  > # perfect negative correlation
  > res <- capture(row_cor_pearson(c(1:4), -c(1:4)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$statistic, -Inf))
  > 
  > # perfect correlation with NAs
  > res <- capture(row_cor_pearson(-c(1:4,NA), -c(1:4,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$statistic, Inf))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.20    0.03    0.21 
Running the tests in 'tests/cosinor_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- removing na timepoints ----------------------------------------------------
  > 
  > wrn <- '2 columns dropped due to missing time information'
  > 
  > # 2 NAs
  > x <- 1:10
  > t <- c(1,2,3,4,NA,NA,7,8,9,10)
  > res <- capture(row_cosinor(x, t))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs, 8))
  > 
  > 
  > #--- less than 3 observations --------------------------------------------------
  > 
  > wrn <- 'row_cosinor: 1 of the rows had less than 3 complete observations: no p-values produced, amplitude and acrophase will be unreliable.\nFirst occurrence at row 1'
  > nacolumns <- c("df.model", "df.residual", "statistic", "pvalue")
  > 
  > # 1 observations
  > res <- capture(row_cosinor(1, 1))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 1))
  > 
  > # 2 observations
  > res <- capture(row_cosinor(1:2, 1:2))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 2))
  > 
  > # 2 observations with NAs
  > res <- capture(row_cosinor(c(1:2,NA,NA), 1:4))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 2))
  > 
  > 
  > #--- exactly 3 observations ----------------------------------------------------
  > 
  > wrn <- 'row_cosinor: 1 of the rows had exactly 3 complete observations: no p-values produced.\nFirst occurrence at row 1'
  > nacolumns <- c("df.model", "df.residual", "statistic", "pvalue")
  > 
  > # 3 observations
  > res <- capture(row_cosinor(1:3, 1:3))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 3))
  > 
  > # with NAs present
  > res <- capture(row_cosinor(c(1:3,NA), 1:4))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 3))
  > 
  > 
  > #--- 1 unique timepoint --------------------------------------------------------
  > 
  > wrn <- 'row_cosinor: 1 of the rows had only 1 unique timepoint within the specified period: no p-values produced, amplitude and acrophase will be unreliable.\nFirst occurrence at row 1'
  > nacolumns <- c("df.model", "df.residual", "statistic", "pvalue")
  > 
  > # one distinct point, duplicated multiple times
  > res <- capture(row_cosinor(1:4, rep(1,4)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs, 4))
  > 
  > 
  > #--- 2 unique timepoints -------------------------------------------------------
  > 
  > wrn <- 'row_cosinor: 1 of the rows had only 2 unique timepoints within the specified period: amplitude and acrophase will be unreliable.\nFirst occurrence at row 1'
  > 
  > # two distinct points, duplicated multiple times
  > res <- capture(row_cosinor(1:4, c(1,2,1,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs, 4))
  > 
  > # with NAs present
  > res <- capture(res <- row_cosinor(c(1,2,3,4,NA,NA), c(1,2,1,2,3,4)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs, 4))
  > 
  > # four points, but period is such that they are not unique
  > res <- capture(row_cosinor(1:4, c(1,2,3,4), 2))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs, 4))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > wrn <- 'row_cosinor: 1 of the rows had essentially constant values.\nFirst occurrence at row 1'
  > nacolumns <- c("df.model", "df.residual", "statistic", "pvalue")
  > 
  > # all the values are 0
  > res <- capture(row_cosinor(c(0,0,0,0), c(1,2,3,4)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs, 4))
  > 
  > # all the values are constant
  > res <- capture(row_cosinor(c(1,1,1,1), c(1,2,3,4)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs, 4))
  > 
  > # all the vallues are constant with NAs
  > res <- capture(row_cosinor(c(1,1,1,1,4), c(2,2,2,2,NA)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$warning[2], wrn))
  > stopifnot(all.equal(res$value$obs, 4))
  > 
  > 
  > #--- perfect fit ---------------------------------------------------------------
  > 
  > wrn <- 'row_cosinor: 1 of the rows had essentially perfect fit.\nFirst occurrence at row 1'
  > 
  > # perfect sine
  > res <- capture(row_cosinor(sin(2*pi*1:24/24), 1:24))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$statistic, Inf))
  > 
  > # only three distinct points present
  > res <- capture(row_cosinor(c(1:3,3), c(1:3,3), 24))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$statistic, Inf))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.20    0.07    0.26 
Running the tests in 'tests/f_var_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_f_var <- function(mat1, mat2, rat=1, alt="two.sided", conf=0.95) {
  +   if(is.vector(mat1)) mat1 <- matrix(mat1, nrow=1)
  +   if(is.vector(mat2)) mat2 <- matrix(mat2, nrow=1)
  +   if(length(rat)==1) rat <- rep(rat, nrow(mat1))
  +   if(length(alt)==1) alt <- rep(alt, nrow(mat1))
  +   if(length(conf)==1) conf <- rep(conf, nrow(mat1))
  + 
  +   nx <- ny <- nt <- vx <- vy <- vrat <- df1 <- df2 <- stat <- p <- cl <- ch <-
  +     r0 <- cnf <- numeric(nrow(mat1))
  +   al <- character(nrow(mat1))
  +   for(i in 1:nrow(mat1)) {
  +     vec1 <- mat1[i,]
  +     vec2 <- mat2[i,]
  + 
  +     res <- var.test(vec1, vec2, ratio=rat[i], alternative=alt[i], conf.level=conf[i])
  + 
  +     # if p-value is NA turn dfs to NA as well
  +     if(is.na(res$p.value)) res$parameter <- NA
  + 
  +     nx[i]  <- length(na.omit(vec1))
  +     ny[i]  <- length(na.omit(vec2))
  +     nt[i]  <- length(na.omit(vec1)) + length(na.omit(vec2))
  +     vx[i]  <- var(vec1, na.rm=TRUE)
  +     vy[i]  <- var(vec2, na.rm=TRUE)
  +     vrat[i]  <- res$estimate
  +     df1[i]  <- res$parameter[1]
  +     df2[i]  <- res$parameter[2]
  +     stat[i]  <- res$statistic
  +     p[i] <- res$p.value
  +     cl[i]  <- res$conf.int[1]
  +     ch[i]  <- res$conf.int[2]
  +     r0[i]  <- res$null.value
  +     al[i]  <- res$alternative
  +     cnf[i] <- attr(res$conf.int, "conf.level")
  +   }
  + 
  +   data.frame(obs.x=nx, obs.y=ny, obs.tot=nt, var.x=vx, var.y=vy, var.ratio=vrat,
  +              df.num=df1, df.denom=df2, statistic=stat, pvalue=p, conf.low=cl,
  +              conf.high=ch, ratio.null=r0, alternative=al, conf.level=cnf,
  +              stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # 5 observations
  > x <- matrix(rnorm(5000), ncol=5)
  > y <- matrix(rnorm(5000), ncol=5)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > rats <- sample(seq(0.001, 1000, length.out=nrow(x)))
  > cfs  <- sample(seq(0.001, 0.999, length.out=nrow(x)))  # NOTE: using 0.001 instead of 0 because base doesn't allow 0
  > res1 <- base_f_var(x, y, rats, alts, cfs)
  > res2 <- row_f_var(x, y, rats, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 20 observations
  > x <- matrix(rnorm(20000), ncol=20)
  > y <- matrix(rnorm(20000), ncol=20)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > rats <- sample(seq(0.001, 1000, length.out=nrow(x)))
  > cfs  <- sample(seq(0.001, 0.999, length.out=nrow(x)))
  > res1 <- base_f_var(x, y, rats, alts, cfs)
  > res2 <- row_f_var(x, y, rats, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000)
  > y <- c(100000000000003, 100000000000002, 100000000000003, 100000000000000)
  > res1 <- base_f_var(x, y)
  > res2 <- row_f_var(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(0.00000000000004, 0.00000000000002, 0.00000000000003, 0)
  > y <- c(0.00000000000003, 0.00000000000002, 0.00000000000003, 0)
  > res1 <- base_f_var(x, y)
  > res2 <- row_f_var(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(10^6)
  > # y <- rnorm(10^6)
  > # res1 <- base_f_var(x, y)
  > # res2 <- row_f_var(x, y)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # two values in both groups
  > x <- matrix(rnorm(6), ncol=2)
  > y <- matrix(rnorm(6), ncol=2)
  > a <- c("two.sided", "greater", "less")
  > res1 <- base_f_var(x, y, alt=a)
  > res2 <- row_f_var(x, y, alt=a)
  > stopifnot(all.equal(res1, res2))
  > 
  > # two values in both groups with NAs
  > x <- matrix(c(rnorm(6), NA, NA, NA), ncol=3)
  > y <- matrix(rnorm(6), ncol=2)
  > a <- c("two.sided", "greater", "less")
  > res1 <- base_f_var(x, y, alt=a)
  > res2 <- row_f_var(x, y, alt=a)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- parameter edge cases ------------------------------------------------------
  > 
  > # various corner cases with NAs
  > alt <- c("l", "t", "g")
  > rat <- c(0.000001, 0.5, 1, 2, 99999)
  > cfs <- c(0.000001, 0.5, 0.9999)
  > pars <- expand.grid(rat, alt, cfs, stringsAsFactors=FALSE)
  > x <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > y <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > res1 <- base_f_var(x, y, pars[,1], pars[,2], pars[,3])
  > res2 <- row_f_var(x, y, pars[,1], pars[,2], pars[,3])
  > stopifnot(all.equal(res1, res2))
  > 
  > # NAs in confidence intervals
  > x <- matrix(rnorm(40), ncol=10)
  > y <- matrix(rnorm(40), ncol=10)
  > cnf <- c(0.95, NA, 0.5, NA)
  > res1 <- base_f_var(x, y, conf=ifelse(is.na(cnf), 0.95, cnf))
  > res1[is.na(cnf), c("conf.level", "conf.low", "conf.high")] <- NA
  > res2 <- row_f_var(x, y, conf.level=cnf)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > # minimal sample size and both groups have the same values
  > x <- matrix(0, nrow=3, ncol=2)
  > y <- matrix(0, nrow=3, ncol=2)
  > alt <- c("l", "t", "g")
  > res1 <- base_f_var(x, y, alt=alt)
  > res1$conf.low[1]  <- NA  # NOTE: var.test sets lower confidence interval to 0 when alternative is "less"
  > res1$conf.high[3] <- NA  # NOTE: var.test sets higher confidence interval to Inf when alternative is "greater"
  > res2 <- suppressWarnings(row_f_var(x, y, alt=alt))
  > stopifnot(all.equal(res1, res2))
  > 
  > # minimal sample size and both groups have zero variance
  > x <- matrix(1, nrow=3, ncol=2)
  > y <- matrix(2, nrow=3, ncol=2)
  > alt <- c("l", "t", "g")
  > res1 <- base_f_var(x, y, alt=alt)
  > res1$conf.low[1]  <- NA  # NOTE: var.test sets lower confidence interval to 0 when alternative is "less"
  > res1$conf.high[3] <- NA  # NOTE: var.test sets higher confidence interval to Inf when alternative is "greater"
  > res2 <- suppressWarnings(row_f_var(x, y, alt=alt))
  > stopifnot(all.equal(res1, res2))
  > 
  > # variance is equal in both groups
  > x <- matrix(c(1,1,1,2,2,2), nrow=3, ncol=2)
  > y <- matrix(c(1,1,1,2,2,2), nrow=3, ncol=2)
  > alt <- c("l", "t", "g")
  > res1 <- base_f_var(x, y, alt=alt)
  > res2 <- suppressWarnings(row_f_var(x, y, alt=alt))
  > stopifnot(all.equal(res1, res2))
  > 
  > # parameter edge cases when x is constant
  > alt <- c("l", "t", "g")
  > rat <- c(0.000001, 0.5, 1, 2, 99999)
  > cfs <- c(0.000001, 0.5, 0.9999)
  > pars <- expand.grid(rat, alt, cfs, stringsAsFactors=FALSE)
  > x <- matrix(1, nrow=nrow(pars), ncol=10)
  > y <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > res1 <- base_f_var(x, y, pars[,1], pars[,2], pars[,3])
  > res2 <- suppressWarnings(row_f_var(x, y, pars[,1], pars[,2], pars[,3]))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2$var.x, rep(0, nrow(x))))
  > 
  > # parameter edge cases when y is constant
  > alt <- c("l", "t", "g")
  > rat <- c(0.000001, 0.5, 1, 2, 99999)
  > cfs <- c(0.000001, 0.5, 0.9999)
  > pars <- expand.grid(rat, alt, cfs, stringsAsFactors=FALSE)
  > x <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > y <- matrix(1, nrow=nrow(pars), ncol=10)
  > res1 <- base_f_var(x, y, pars[,1], pars[,2], pars[,3])
  > res2 <- suppressWarnings(row_f_var(x, y, pars[,1], pars[,2], pars[,3]))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2$var.y, rep(0, nrow(y))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.90    0.06    0.93 
Running the tests in 'tests/flignerkilleen_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_fligner <- function(mat, groups) {
  +   if(is.vector(mat)) mat <- matrix(mat, nrow=1)
  + 
  +   bad    <- is.na(groups)
  +   mat    <- mat[,!bad,drop=FALSE]
  +   groups <- groups[!bad]
  + 
  +   ng <- nt <- ks <- p <- df <- numeric(nrow(mat))
  +   for(i in 1:nrow(mat)) {
  +     bad <- is.na(mat[i,])
  +     vec <- na.omit(mat[i,!bad])
  +     grp <- na.omit(groups[!bad])
  + 
  +     res <- fligner.test(vec, factor(grp))
  + 
  +     # if p-value is NA turn df to NA as well
  +     if(is.na(res$p.value)) res$parameter <- NA
  + 
  +     ng[i] <- length(unique(grp))
  +     nt[i] <- length(vec)
  +     ks[i] <- res$statistic
  +     p[i]  <- res$p.value
  +     df[i] <- res$parameter
  +   }
  + 
  +   data.frame(obs.tot=nt, obs.groups=ng, df=df, statistic=ks, pvalue=p,
  +              stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # two groups
  > x <- matrix(rnorm(10000), ncol=10)
  > g <- sample(letters[1:2], 6, replace=TRUE)
  > g <- sample(c("a", "a", "b", "b", g))  # ensure both groups have at least 2 obs
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # lots of groups
  > x <- matrix(rnorm(100000), ncol=100)
  > g <- sample(letters[1:15], 100, replace=TRUE)
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # TODO: test why the following returns NA: row_flignerkilleen(c(1,2,4,3), c(1,1,2,2))
  > #       it returns NAs for both base and matrixTests version, so probably not an error
  > # NOTE: this happens because all absolute residuals from the median are equal (in both groups)
  > #       to fix - probably best to throw a separate warning (similar to levene case)
  > #       maybe suggest a patch to base R
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000,
  +        100000000000003, 100000000000002, 100000000000003, 100000000000000
  +        )
  > g <- c(rep("a", 4), rep("b", 4))
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(1.00000000000004, 1.00000000000002, 1.00000000000003, 1.00000000000000,
  +        1.00000000000003, 1.00000000000002, 1.00000000000003, 1.00000000000000
  +        )
  > g <- c(rep("a", 4), rep("b", 4))
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(3*10^6)
  > # g <- rep(letters[1:3], each=10^6)
  > # res1 <- base_fligner(x, g)
  > # res2 <- row_flignerkilleen(x, g)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # two groups one with 2 samples and another with 1
  > x <- rnorm(3)
  > g <- c("a", "a", "b")
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # two groups both with 2 values
  > x <- rnorm(4)
  > g <- c("a", "a", "b", "b")
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # many groups one with 2 values and the rest with 1
  > x <- rnorm(15)
  > g <- c("a", letters[1:14])
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # two groups one with 3 samples and another with 1
  > x <- rnorm(4)
  > g <- c("a", "a", "a", "b")
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # two groups one with 2 samples and another with 1 plus NAs
  > x <- c(rnorm(2), NA, NA, NA, rnorm(1))
  > g <- c("a","a","a","b","b","b")
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > # one group's values are constant
  > x <- c(1,1,1,2,3,4)
  > g <- c("a","a","a","b","b","b")
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # all groups have equal variances
  > x <- c(1:3,2:4,3:5,4:6,5:7)
  > g <- rep(1:5, each=3)
  > res1 <- base_fligner(x, g)
  > res2 <- row_flignerkilleen(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > proc.time()
     user  system elapsed 
     2.60    0.10    2.67 
Running the tests in 'tests/flignerkilleen_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_flignerkilleen())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_flignerkilleen(NULL, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_flignerkilleen(c("a", "b"), c("a","b")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_flignerkilleen(c(TRUE, FALSE), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_flignerkilleen(complex(c(1,2), c(3,4)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_flignerkilleen(iris, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_flignerkilleen(as.list(c(1:5)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_flignerkilleen(list(1:5), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- g argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "g" is missing, with no default'
  > res <- capture(row_flignerkilleen(1, ))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a matrix with dimensions
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_flignerkilleen(matrix(1:4, nrow=1), matrix(letters[1:4], nrow=2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a in a list
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_flignerkilleen(1:5, list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # g length must match the observations of x
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_flignerkilleen(1:5, letters[1:4]))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.18    0.09    0.26 
Running the tests in 'tests/jarquebera_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_jarquebera())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_jarquebera(NULL))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_jarquebera(c("a", "b")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_jarquebera(c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_jarquebera(complex(c(1,2), c(3,4))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_jarquebera(iris))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_jarquebera(as.list(c(1:5))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_jarquebera(list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.04    0.25 
Running the tests in 'tests/jarquebera_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- less than 2 observations --------------------------------------------------
  > 
  > wrn <- 'row_jarquebera: 1 of the rows had less than 2 total observations.\nFirst occurrence at row 1'
  > nacolumns <- c("df", "statistic", "pvalue")
  > 
  > # single observation
  > res <- capture(row_jarquebera(1))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 1))
  > 
  > # single observation with some NA values
  > res <- capture(row_jarquebera(c(1,NA,NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 1))
  > 
  > # zero observations
  > res <- capture(row_jarquebera(NA_integer_))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 0))
  > 
  > 
  > #--- all values are constant ---------------------------------------------------
  > 
  > wrn <- 'row_jarquebera: 1 of the rows had essentially constant values.\nFirst occurrence at row 1'
  > nacolumns <- c("df", "statistic", "pvalue")
  > 
  > # two equal observations
  > res <- capture(row_jarquebera(c(1,1)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 2))
  > 
  > # three equal observations with some NA values
  > res <- capture(row_jarquebera(c(0,0,0,NA,NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 3))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.20    0.07    0.25 
Running the tests in 'tests/kolmogorovsmirnov_twosample_behavioiur.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x and y can be vectors
  > x <- rnorm(9)
  > y <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > Y <- matrix(y, nrow=1)
  > stopifnot(all.equal(row_kolmogorovsmirnov_twosample(x, y), row_kolmogorovsmirnov_twosample(X, Y)))
  > 
  > # x and y can be numeric data frames
  > x <- iris[1:50,1:4]
  > y <- iris[51:100,1:4]
  > X <- as.matrix(x)
  > Y <- as.matrix(y)
  > stopifnot(all.equal(suppressWarnings(row_kolmogorovsmirnov_twosample(x, y)), suppressWarnings(row_kolmogorovsmirnov_twosample(X, Y))))
  > 
  > # x and y can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > y <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_kolmogorovsmirnov_twosample(x, y)), 0))
  > 
  > # x and y can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > y <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_kolmogorovsmirnov_twosample(x, y)), 0))
  > 
  > # alternative values can be partially completed
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_kolmogorovsmirnov_twosample(x, y, alternative="greater"), row_kolmogorovsmirnov_twosample(x, y, alternative="g")))
  > 
  > # exact can be NA
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_kolmogorovsmirnov_twosample(x, y, exact=NA), row_kolmogorovsmirnov_twosample(x, y, exact=TRUE)))
  > 
  > # TODO: investigate if null can be allowed Inf values.
  > 
  > 
  > #--- recycling -----------------------------------------------------------------
  > 
  > # y can be a vector when x is a matrix
  > x <- matrix(rnorm(10), nrow=2)
  > y <- 1:5
  > res1 <- row_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x, rbind(y,y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # alternative can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_kolmogorovsmirnov_twosample(x, y, alternative="g")
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alternative=c("g","g"))
  > stopifnot(all.equal(res1, res2))
  > 
  > # exact can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_kolmogorovsmirnov_twosample(x, y, exact=TRUE)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, exact=c(TRUE, TRUE))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- rnorm(10)
  > res1 <- row_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x[!is.na(x)], y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in y are removed
  > x <- rnorm(10)
  > y <- c(NA,NA,rnorm(7),NA)
  > res1 <- row_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y[!is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values from both x and y are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- c(NA,rnorm(7),NA,NA)
  > res1 <- row_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x[!is.na(x)], y[!is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # no difference between NA and NaN
  > x1 <- c(NA,NA,1,2,7:3,NA)
  > x2 <- c(NaN,NaN,1,2,7:3,NaN)
  > y1 <- c(NA,NA,18:12,NA)
  > y2 <- c(NaN,NaN,18:12,NaN)
  > res1 <- row_kolmogorovsmirnov_twosample(x1, y1)
  > res2 <- row_kolmogorovsmirnov_twosample(x2, y2)
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > y <- rep(NA_integer_, 4)
  > res <- suppressWarnings(row_kolmogorovsmirnov_twosample(x, y))
  > stopifnot(all.equal(res$obs.tot, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_kolmogorovsmirnov_twosample(x, y)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when not provided - not taken from y
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_kolmogorovsmirnov_twosample(x, y)
  > stopifnot(all.equal(rownames(res), c("1","2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_kolmogorovsmirnov_twosample(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_kolmogorovsmirnov_twosample(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(20), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > y <- matrix(rnorm(20), nrow=4)
  > res <- row_kolmogorovsmirnov_twosample(x, y)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.31    0.06    0.31 
Running the tests in 'tests/kolmogorovsmirnov_twosample_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_kolmogorovsmirnov_twosample <- function(mat1, mat2, alternative="t", exact=NA) {
  +   if(is.vector(mat1)) mat1 <- matrix(mat1, nrow=1)
  +   if(is.vector(mat2)) mat2 <- matrix(mat2, nrow=1)
  +   if(length(alternative)==1) alternative <- rep(alternative, nrow(mat1))
  +   if(length(exact)==1) exact <- rep(exact, nrow(mat1))
  + 
  +   nx  <- ny <- nxy <- stat <- p <- numeric(nrow(mat1))
  +   al  <- character(nrow(mat1))
  +   ext <- logical(nrow(mat1))
  +   for(i in 1:nrow(mat1)) {
  +     ex  <- if(is.na(exact[i])) NULL else exact[i]
  + 
  +     res <- ks.test(mat1[i,], mat2[i,], alternative=alternative[i], exact=ex)
  + 
  +     nx[i]   <- sum(!is.na(mat1[i,]))
  +     ny[i]   <- sum(!is.na(mat2[i,]))
  +     nxy[i]  <- nx[i] + ny[i]
  +     stat[i] <- res$statistic
  +     p[i]    <- res$p.value
  +     al[i]   <- c(l="less", g="greater", t="two.sided")[alternative[i]]
  +     ext[i]  <- res$exact
  +   }
  + 
  +   data.frame(obs.x=nx, obs.y=ny, obs.tot=nxy, statistic=stat, pvalue=p,
  +              alternative=al, exact=ext, stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # 25 samples per group (not exceeding exact cutoff)
  > x <- matrix(rnorm(2000), ncol=2)
  > y <- matrix(rnorm(4000), ncol=4)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > ext <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 25 samples per group with ties (not exceeding exact cutoff)
  > x <- matrix(round(runif(25000, -15, 15)), ncol=25)
  > y <- matrix(round(runif(25000, -15, 15)), ncol=25)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > ext <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- suppressWarnings(base_kolmogorovsmirnov_twosample(x, y, alts, exact=ext))
  > res2 <- suppressWarnings(row_kolmogorovsmirnov_twosample(x, y, alts, exact=ext))
  > stopifnot(all.equal(res1, res2))
  > 
  > # 2 samples in one group and 101 in another (not exceeding exact cutoff)
  > x <- matrix(rnorm(2000), ncol=2)
  > y <- matrix(rnorm(101000), ncol=101)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > ext <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 101 samples per group (exceeding exact cutoff)
  > x <- matrix(rnorm(101000), ncol=101)
  > y <- matrix(rnorm(101000), ncol=101)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > ext <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 101 samples per group with ties (exceeding exact cutoff)
  > x <- matrix(round(runif(101000, -15, 15)), ncol=101)
  > y <- matrix(round(runif(101000, -15, 15)), ncol=101)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > ext <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- suppressWarnings(base_kolmogorovsmirnov_twosample(x, y, alts, exact=ext))
  > res2 <- suppressWarnings(row_kolmogorovsmirnov_twosample(x, y, alts, exact=ext))
  > stopifnot(all.equal(res1, res2))
  > 
  > # 2 samples in one group and 5001 in another (exceeding exact cutoff)
  > x <- matrix(rnorm(2000), ncol=2)
  > y <- matrix(rnorm(5001000), ncol=5001)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > ext <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alts, exact=ext)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000)
  > x    <- matrix(x, nrow=nrow(pars), ncol=length(x), byrow=TRUE)
  > y    <- c(100000000000005, 100000000000006, 100000000000009)
  > y    <- matrix(y, nrow=nrow(pars), ncol=length(y), byrow=TRUE)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- c(0.00000000000004, 0.00000000000002, 0.00000000000003, 0.00000000000001)
  > x    <- matrix(x, nrow=nrow(pars), ncol=length(x), byrow=TRUE)
  > y    <- c(0.00000000000005, 0.00000000000006, 0.00000000000000)
  > y    <- matrix(y, nrow=nrow(pars), ncol=length(y), byrow=TRUE)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample (only non-exact, because of computation time)
  > # pars <- expand.grid(c("t","g","l"), stringsAsFactors=FALSE)
  > # x <- rnorm(10^6)
  > # y <- rnorm(10^6)
  > # x <- matrix(x, nrow=nrow(pars), ncol=length(x), byrow=TRUE)
  > # y <- matrix(y, nrow=nrow(pars), ncol=length(y), byrow=TRUE)
  > # res1 <- base_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1])
  > # res2 <- row_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1])
  > # stopifnot(all.equal(res1, res2))
  > 
  > # x and y have infinities (exact)
  > x <- matrix(rnorm(100), ncol=10)
  > y <- matrix(rnorm(100), ncol=10)
  > x[1,1] <- Inf
  > x[2,1] <- -Inf
  > y[3,1] <- Inf
  > y[4,1] <- -Inf
  > x[5,1:2] <- c(Inf, -Inf)
  > y[6,1:2] <- c(Inf, -Inf)
  > x[7,1] <- Inf; y[7,1] <- Inf
  > x[8,1] <- Inf; y[8,1] <- -Inf
  > x[9,1] <- -Inf; y[9,1] <- -Inf
  > x[10,] <- Inf; y[10,] <- -Inf
  > # exact
  > res1 <- base_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y)
  > stopifnot(all.equal(res1, res2))
  > # not exact
  > res1 <- suppressWarnings(base_kolmogorovsmirnov_twosample(x, y, exact=FALSE))
  > res2 <- suppressWarnings(row_kolmogorovsmirnov_twosample(x, y, exact=FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # single number in each group
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- matrix(rnorm(nrow(pars)), ncol=1)
  > y    <- matrix(rnorm(nrow(pars)), ncol=1)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2$obs.x, rep(1, nrow(x))))
  > stopifnot(all.equal(res2$obs.y, rep(1, nrow(x))))
  > stopifnot(all.equal(res2$obs.tot, rep(2, nrow(x))))
  > 
  > # 3 observation in both, but only one non NA
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- cbind(matrix(rnorm(nrow(pars)), ncol=1), NA, NaN)
  > y    <- cbind(NaN, NA, matrix(rnorm(nrow(pars)), ncol=1))
  > res1 <- base_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2])
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2$obs.x, rep(1, nrow(x))))
  > stopifnot(all.equal(res2$obs.y, rep(1, nrow(x))))
  > stopifnot(all.equal(res2$obs.tot, rep(2, nrow(x))))
  > 
  > # single equal number in each group
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- matrix(rep(1, nrow(pars)), ncol=1)
  > y    <- matrix(rep(1, nrow(pars)), ncol=1)
  > res1 <- suppressWarnings(base_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2]))
  > res2 <- suppressWarnings(row_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2]))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2$obs.x, rep(1, nrow(x))))
  > stopifnot(all.equal(res2$obs.y, rep(1, nrow(x))))
  > stopifnot(all.equal(res2$obs.tot, rep(2, nrow(x))))
  > 
  > # three numbers in both groups, all equal
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- matrix(rnorm(nrow(pars)), ncol=1)
  > x    <- cbind(x,x,x)
  > y    <- x
  > res1 <- suppressWarnings(base_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2]))
  > res2 <- suppressWarnings(row_kolmogorovsmirnov_twosample(x, y, alternative=pars[,1], exact=pars[,2]))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- various cases for exact ---------------------------------------------------
  > 
  > # 99 samples with exact = NA should be the same as exact = TRUE
  > x <- rnorm(99)
  > y <- rnorm(99)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, exact=NA)
  > res3 <- row_kolmogorovsmirnov_twosample(x, y, exact=TRUE)
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 100 samples with one NA and exact = NA should be exact = TRUE
  > x <- c(rnorm(99), NA)
  > y <- c(NA, rnorm(99))
  > res1 <- base_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, exact=NA)
  > res3 <- row_kolmogorovsmirnov_twosample(x, y, exact=TRUE)
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 100 samples with exact = NA should be exact = FALSE
  > x <- rnorm(100)
  > y <- rnorm(100)
  > res1 <- base_kolmogorovsmirnov_twosample(x, y)
  > res2 <- row_kolmogorovsmirnov_twosample(x, y, exact=NA)
  > res3 <- row_kolmogorovsmirnov_twosample(x, y, exact=FALSE)
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > 
  > proc.time()
     user  system elapsed 
     6.42    1.65    8.07 
Running the tests in 'tests/kolmogorovsmirnov_twosample_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x has less than 1 observation ---------------------------------------------
  > 
  > wrn <- 'row_kolmogorovsmirnov_twosample: 1 of the rows had less than 1 "x" observation.\nFirst occurrence at row 1'
  > nacolumns <- c("statistic", "pvalue")
  > 
  > # 0 observations
  > res <- capture(row_kolmogorovsmirnov_twosample(numeric(), 1))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.tot, 1))
  > 
  > # only NA observations
  > res <- capture(row_kolmogorovsmirnov_twosample(c(NA_integer_, NA_integer_), 1))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.tot, 1))
  > 
  > 
  > #--- y has less than 1 observations --------------------------------------------
  > 
  > wrn <- 'row_kolmogorovsmirnov_twosample: 1 of the rows had less than 1 "y" observation.\nFirst occurrence at row 1'
  > nacolumns <- c("statistic", "pvalue")
  > 
  > # 0 observations
  > res <- capture(row_kolmogorovsmirnov_twosample(1, numeric()))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 1))
  > 
  > # only NA observations
  > res <- capture(row_kolmogorovsmirnov_twosample(1, c(NA_integer_, NA_integer_)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 1))
  > 
  > 
  > #--- both x and y have less than 1 observation ---------------------------------
  > 
  > wrnx <- 'row_kolmogorovsmirnov_twosample: 1 of the rows had less than 1 "x" observation.\nFirst occurrence at row 1'
  > wrny <- 'row_kolmogorovsmirnov_twosample: 1 of the rows had less than 1 "y" observation.\nFirst occurrence at row 1'
  > nacolumns <- c("statistic", "pvalue")
  > 
  > # 0 observations
  > res <- capture(row_kolmogorovsmirnov_twosample(numeric(), numeric()))
  > stopifnot(all.equal(res$warning[1:2], c(wrnx, wrny)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 0))
  > 
  > # only NA observations
  > res <- capture(row_kolmogorovsmirnov_twosample(c(NA_integer_, NA_integer_), c(NA_integer_, NA_integer_)))
  > stopifnot(all.equal(res$warning[1:2], c(wrnx, wrny)))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 0))
  > 
  > 
  > #--- ties are present ----------------------------------------------------------
  > 
  > wrn <- 'row_kolmogorovsmirnov_twosample: 1 of the rows had ties: asymptotic p-values will be approximate.\nFirst occurrence at row 1'
  > 
  > # warning when exact=TRUE
  > res <- capture(row_kolmogorovsmirnov_twosample(c(3,3,1,2), c(2,0,5,-2), exact=FALSE))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$exact, FALSE))
  > stopifnot(all.equal(res$value$obs.x, 4))
  > stopifnot(all.equal(res$value$obs.y, 4))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > 
  > # no warning when exact=FALSE
  > res <- capture(row_kolmogorovsmirnov_twosample(c(3,3,1,2), c(2,0,5,-2), exact=TRUE))
  > stopifnot(all.equal(res$warning, NULL))
  > stopifnot(all.equal(res$value$exact, TRUE))
  > stopifnot(all.equal(res$value$obs.x, 4))
  > stopifnot(all.equal(res$value$obs.y, 4))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.07    0.28 
Running the tests in 'tests/kruskalwallis_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_kruskalwallis())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_kruskalwallis(NULL, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_kruskalwallis(c("a", "b"), c("a","b")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_kruskalwallis(c(TRUE, FALSE), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_kruskalwallis(complex(c(1,2), c(3,4)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_kruskalwallis(iris, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_kruskalwallis(as.list(c(1:5)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_kruskalwallis(list(1:5), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- g argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "g" is missing, with no default'
  > res <- capture(row_kruskalwallis(1, ))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a matrix with dimensions
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_kruskalwallis(matrix(1:4, nrow=1), matrix(letters[1:4], nrow=2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a in a list
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_kruskalwallis(1:5, list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # g length must match the observations of x
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_kruskalwallis(1:5, letters[1:4]))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.25    0.04    0.28 
Running the tests in 'tests/kruskalwallis_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- removing NA groups --------------------------------------------------------
  > 
  > wrn <- '2 columns dropped due to missing group information'
  > 
  > # 2 NAs
  > x <- 1:10
  > g <- c(1,1,1,1,NA,NA,2,2,2,2)
  > res <- capture(row_kruskalwallis(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > 
  > #--- less than 2 observations --------------------------------------------------
  > 
  > wrn <- 'row_kruskalwallis: 1 of the rows had less than 2 total observations.\nFirst occurrence at row 1'
  > nacolumns <- c("df", "statistic", "pvalue")
  > 
  > # one value one group
  > res <- capture(row_kruskalwallis(1, "a"))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > stopifnot(all.equal(res$value$obs.tot, 1))
  > 
  > # one value one group with NAs
  > res <- capture(row_kruskalwallis(c(1,NA,NA,NA), c(1,1,2,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > stopifnot(all.equal(res$value$obs.tot, 1))
  > 
  > 
  > #--- less than 2 groups --------------------------------------------------------
  > 
  > wrn <- 'row_kruskalwallis: 1 of the rows had less than 2 groups with enough observations.\nFirst occurrence at row 1'
  > nacolumns <- c("df", "statistic", "pvalue")
  > 
  > # single group with 10 observations
  > res <- capture(row_kruskalwallis(1:10, rep(1,10)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > stopifnot(all.equal(res$value$obs.tot, 10))
  > 
  > # 3 groups but others have only NA values
  > x <- c(1:8, NA, NA)
  > g <- c(rep("a", 8), "b", "c")
  > res <- capture(row_kruskalwallis(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > 
  > 
  > #--- single unique value -------------------------------------------------------
  > 
  > wrn <- 'row_kruskalwallis: 1 of the rows had essentially constant values.\nFirst occurrence at row 1'
  > nacolumns <- c("df", "statistic", "pvalue")
  > 
  > # two groups
  > res <- capture(row_kruskalwallis(rep(1, 3), c("a","a","b")))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > 
  > # two groups with NA values
  > x <- c(rep(1,8),NA,NA)
  > g <- c(rep("a", 4), rep("b", 4), "c", "d")
  > res <- capture(row_kruskalwallis(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.20    0.10    0.28 
Running the tests in 'tests/levene_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- removing na groups --------------------------------------------------------
  > 
  > wrn <- '2 columns dropped due to missing group information'
  > 
  > # 2 NAs
  > x <- 1:10
  > g <- c(1,1,1,1,NA,NA,2,2,2,2)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > 
  > #--- less than 2 groups --------------------------------------------------------
  > 
  > wrn <- 'row_levene: 1 of the rows had less than 2 groups with enough observations.\nFirst occurrence at row 1'
  > nacolumns <- c("df.between", "df.within", "statistic", "pvalue")
  > 
  > # all values in one group
  > x <- 1:10
  > g <- rep("a", 10)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 10))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > 
  > # two groups but one has only NAs
  > x <- c(1:3, NA, NA, NA)
  > g <- rep(c("a","b"), each=3)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > stopifnot(all.equal(res$value$obs.groups, 1))
  > 
  > 
  > #--- no groups with 3 observations ---------------------------------------------
  > 
  > wrn <- 'row_levene: 1 of the rows had no groups with at least 3 observations.\nFirst occurrence at row 1'
  > nacolumns <- c("df.between", "df.within", "statistic", "pvalue")
  > 
  > # 10 groups all with a single value
  > x <- 1:10
  > g <- letters[1:10]
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 10))
  > stopifnot(all.equal(res$value$obs.groups, 10))
  > 
  > # 5 groups 2 observations each
  > x <- 1:10
  > g <- rep(letters[1:5], each=2)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 10))
  > stopifnot(all.equal(res$value$obs.groups, 5))
  > 
  > # two groups one with 3 observations but one of them is NA
  > x <- c(1:3, NA)
  > g <- c("a", "b", "b","b")
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > 
  > #--- close to constant variance ------------------------------------------------
  > 
  > wrn <- 'row_levene: 1 of the rows had essentially constant absolute residuals from the mean: results might be unreliable.\nFirst occurrence at row 1'
  > 
  > # two groups - close to constant values within group
  > x <- c(1.00000000000004, 1.00000000000002, 1.00000000000003, 1.00000000000000,
  +        1.00000000000003, 1.00000000000002, 1.00000000000003, 1.00000000000000
  +        )
  > g <- rep(c("a","b"), each=4)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs.tot, 8))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > 
  > #--- constant variance after residuals -----------------------------------------
  > 
  > wrn <- 'row_levene: 1 of the rows had zero within group variance of absolute residuals from the mean.\nFirst occurrence at row 1'
  > nacolumns <- c("df.between", "df.within", "statistic", "pvalue")
  > 
  > # two groups - all zero values
  > x <- rep(0,6)
  > g <- rep(letters[1:2], each=3)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 6))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > # two groups - all constant values
  > x <- rep(1,6)
  > g <- rep(letters[1:2], each=3)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 6))
  > stopifnot(all.equal(res$value$obs.groups, 2))
  > 
  > # three groups - constant values plus NAs
  > x <- c(1,1,1,NA,2,2,2,NA,3,3,3,NA)
  > g <- rep(1:3, each=4)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 9))
  > stopifnot(all.equal(res$value$obs.groups, 3))
  > 
  > # values become constant after residuals
  > x <- c(1,1,2,2,3,3,4,4,5,5,6,6)
  > g <- rep(letters[1:3], each=4)
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 12))
  > stopifnot(all.equal(res$value$obs.groups, 3))
  > 
  > # values become constant after residuals with different groups sizes
  > x <- c(1,1,1,2,2,2,3,3,4,4,5,6,7)
  > g <- rep(letters[1:4], c(6,4,2,1))
  > res <- capture(row_levene(x, g))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.tot, 13))
  > stopifnot(all.equal(res$value$obs.groups, 4))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.26    0.10    0.36 
Running the tests in 'tests/oneway_equalvar_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_oneway_equalvar())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_oneway_equalvar(NULL, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_oneway_equalvar(c("a", "b"), c("a","b")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_oneway_equalvar(c(TRUE, FALSE), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_oneway_equalvar(complex(c(1,2), c(3,4)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_oneway_equalvar(iris, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_oneway_equalvar(as.list(c(1:5)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_oneway_equalvar(list(1:5), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- g argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "g" is missing, with no default'
  > res <- capture(row_oneway_equalvar(1, ))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a matrix with dimensions
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_oneway_equalvar(matrix(1:4, nrow=1), matrix(letters[1:4], nrow=2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a in a list
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_oneway_equalvar(1:5, list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # g length must match the observations of x
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_oneway_equalvar(1:5, letters[1:4]))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.10    0.26 
Running the tests in 'tests/oneway_welch_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_oneway_welch <- function(mat, groups) {
  +   if(is.vector(mat)) mat <- matrix(mat, nrow=1)
  + 
  +   bad <- is.na(groups)
  +   mat    <- mat[,!bad,drop=FALSE]
  +   groups <- groups[!bad]
  + 
  +   ot <- og <- dft <- dfr <- fst <- p <- numeric(nrow(mat))
  +   for(i in 1:nrow(mat)) {
  +     bad <- is.na(mat[i,])
  +     vec <- na.omit(mat[i,!bad])
  +     grp <- na.omit(groups[!bad])
  + 
  +     badgr <- names(which(table(grp)==1))
  +     bad   <- grp %in% badgr
  +     vec   <- vec[!bad]
  +     grp   <- grp[!bad]
  + 
  +     res <- oneway.test(vec ~ grp)
  + 
  +     # if p-value is NA then turn dfs to NA as well
  +     if(is.na(res$p.value)) res$parameter <- NA
  + 
  +     dft[i] <- res$parameter[1]
  +     dfr[i] <- res$parameter[2]
  +     fst[i] <- res$statistic
  +     p[i]   <- res$p.value
  +     ot[i]  <- length(vec)
  +     og[i]  <- length(unique(grp))
  +   }
  + 
  +   data.frame(obs.tot=ot, obs.groups=og, df.between=dft, df.within=dfr,
  +              statistic=fst, pvalue=p
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # two groups
  > x <- matrix(rnorm(10000), ncol=10)
  > g <- sample(letters[1:2], 6, replace=TRUE)
  > g <- sample(c("a", "a", "b", "b", g))  # ensure both groups have at least 2 obs
  > res1 <- base_oneway_welch(x, factor(g))
  > res2 <- row_oneway_welch(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # lots of groups
  > x <- matrix(rnorm(100000), ncol=100)
  > g <- sample(letters[1:15], 100, replace=TRUE)
  > res1 <- base_oneway_welch(x, factor(g))
  > res2 <- row_oneway_welch(x, g)
  Warning message:
  row_oneway_welch: 1000 of the rows had groups with less than 2 observations: those groups were removed.
  First occurrence at row 1 
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000,
  +        100000000000003, 100000000000002, 100000000000003, 100000000000000
  +        )
  > g <- c(rep("a", 4), rep("b", 4))
  > res1 <- base_oneway_welch(x, g)
  > res2 <- row_oneway_welch(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(1.00000000000004, 1.00000000000002, 1.00000000000003, 1.00000000000000,
  +        1.00000000000003, 1.00000000000002, 1.00000000000003, 1.00000000000000
  +        )
  > g <- c(rep("a", 4), rep("b", 4))
  > res1 <- base_oneway_welch(x, g)
  > res2 <- row_oneway_welch(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(3 * 10^6)
  > # g <- rep(letters[1:3], each=10^6)
  > # res1 <- base_oneway_welch(x, g)
  > # res2 <- row_oneway_welch(x, g)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # two groups with two values each
  > x <- rnorm(4)
  > g <- c("a","a","b","b")
  > res1 <- base_oneway_welch(x, g)
  > res2 <- row_oneway_welch(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > # many groups all with two values
  > x <- rnorm(20)
  > g <- rep(letters[1:10], each=2)
  > res1 <- base_oneway_welch(x, g)
  > res2 <- row_oneway_welch(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > # all values are zero
  > x <- c(0,0,0,0)
  > g <- c("a","a","b","b")
  > res1 <- base_oneway_welch(x, g)
  > res2 <- suppressWarnings(row_oneway_welch(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # all values are constant
  > x <- c(1,1,1,1)
  > g <- c("a","a","b","b")
  > res1 <- base_oneway_welch(x, g)
  > res2 <- suppressWarnings(row_oneway_welch(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # within group values are constant
  > x <- c(1,1,2,2)
  > g <- c("a","a","b","b")
  > res1 <- base_oneway_welch(x, g)
  > res2 <- suppressWarnings(row_oneway_welch(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: matrixTests gives a warning and proceeds to calculate p-value when one group has constant variance.
  > # base produces NaN values without a warning.
  > # therefore here we change the values of base manually to match those returned by matrixTests
  > x <- c(1,1,2,3)
  > g <- c("a","a","b","b")
  > res1 <- base_oneway_welch(x, g)
  > res1$df.between <- 1; res1$df.within <- 1; res1$statistic <- Inf; res1$pvalue <- 0
  > res2 <- suppressWarnings(row_oneway_welch(x, g))
  > stopifnot(all.equal(res1, res2))
  > 
  > # groups with equal variances give equal results
  > x <- c(1:3,2:4,3:5,4:6,5:7)
  > g <- rep(1:5, each=3)
  > res1 <- base_oneway_welch(x, g)
  > res2 <- row_oneway_welch(x, g)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- groups with one element ---------------------------------------------------
  > 
  > # groups with one remaining values are removed
  > x <- rnorm(5)
  > g <- c("a","a","b","b","c")
  > res1 <- base_oneway_welch(x, g)
  > res2 <- suppressWarnings(row_oneway_welch(x, g))
  > res3 <- suppressWarnings(row_oneway_welch(x[-5], g[-5]))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res2$obs.groups, 2))
  > 
  > 
  > proc.time()
     user  system elapsed 
     2.70    0.12    2.81 
Running the tests in 'tests/t_equalvar_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- less than 3 observations --------------------------------------------------
  > 
  > wrn <- 'row_t_equalvar: 1 of the rows had less than 3 total observations.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # 0 observations
  > res <- capture(row_t_equalvar(NA_integer_, NA_integer_))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 0))
  > 
  > # 1 observation in each group
  > res <- capture(row_t_equalvar(1, 2))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 1))
  > stopifnot(all.equal(res$value$obs.y, 1))
  > stopifnot(all.equal(res$value$obs.tot, 2))
  > 
  > # 2 observations in x and 0 in y
  > res <- capture(row_t_equalvar(1:2, numeric()))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 2))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 2))
  > 
  > # 0 observations in x and 2 in y
  > res <- capture(row_t_equalvar(numeric(), 1:2))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 2))
  > stopifnot(all.equal(res$value$obs.tot, 2))
  > 
  > # both have 2 observations but one is NA in each
  > res <- capture(row_t_equalvar(c(1,NA), c(NA,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 1))
  > stopifnot(all.equal(res$value$obs.y, 1))
  > stopifnot(all.equal(res$value$obs.tot, 2))
  > 
  > 
  > #--- one group has no observations ---------------------------------------------
  > 
  > wrn <- 'row_t_equalvar: 1 of the rows had zero "x" observations.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # no observations in x
  > res <- capture(row_t_equalvar(numeric(), 1:3))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 3))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > 
  > # only NA observations in x
  > res <- capture(row_t_equalvar(c(NA_integer_, NA_integer_), 1:3))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 3))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > 
  > 
  > wrn <- 'row_t_equalvar: 1 of the rows had zero "y" observations.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # no observations in y
  > res <- capture(row_t_equalvar(1:3, numeric()))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 3))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > 
  > # only NA observations in y
  > res <- capture(row_t_equalvar(1:3, c(NA_integer_, NA_integer_)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 3))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.tot, 3))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > wrn <- 'row_t_equalvar: 1 of the rows had essentially constant values.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # all values are the same
  > res <- capture(row_t_equalvar(c(1,1,1,1), c(1,1,1,1)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.x, 0))
  > stopifnot(all.equal(res$value$var.y, 0))
  > stopifnot(all.equal(res$value$var.pooled, 0))
  > 
  > # all values are the equal within each group
  > res <- capture(row_t_equalvar(c(1,1,1,1), c(2,2,2,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.x, 0))
  > stopifnot(all.equal(res$value$var.y, 0))
  > stopifnot(all.equal(res$value$var.pooled, 0))
  > 
  > # all values are the equal within each group after NAs
  > res <- capture(row_t_equalvar(c(NA,1,1,1,1), c(2,2,2,2,NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.x, 0))
  > stopifnot(all.equal(res$value$var.y, 0))
  > stopifnot(all.equal(res$value$var.pooled, 0))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.12    0.31 
Running the tests in 'tests/t_onesample_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_t_onesample <- function(mat, null=0, alternative="two.sided", conf=0.95) {
  +   if(is.vector(mat)) mat <- matrix(mat, nrow=1)
  +   if(length(alternative)==1) alternative <- rep(alternative, nrow(mat))
  +   if(length(null)==1) null <- rep(null, nrow(mat))
  +   if(length(conf)==1) conf <- rep(conf, nrow(mat))
  + 
  +   mx <- vx <- nx <- tst <- p <- cl <- ch <- se <- df <- m0 <- cnf <- numeric(nrow(mat))
  +   al <- character(nrow(mat))
  +   for(i in 1:nrow(mat)) {
  +     vec <- na.omit(mat[i,])
  + 
  +     res <- t.test(vec, alternative=alternative[i], mu=null[i], conf.level=conf[i])
  + 
  +     # if p-value is NA turn stderr and df to NA as well
  +     if(is.na(res$p.value)) {
  +       res$stderr <- NA
  +       res$parameter <- NA
  +     }
  + 
  +     vx[i]  <- var(vec)
  +     nx[i]  <- length(vec)
  +     mx[i]  <- res$estimate
  +     tst[i] <- res$statistic
  +     p[i]   <- res$p.value
  +     cl[i]  <- res$conf.int[1]
  +     ch[i]  <- res$conf.int[2]
  +     se[i]  <- res$stderr
  +     df[i]  <- res$parameter
  +     m0[i]  <- res$null.value
  +     al[i]  <- res$alternative
  +     cnf[i] <- attr(res$conf.int, "conf.level")
  +   }
  + 
  +   data.frame(obs=nx, mean=mx, var=vx, stderr=se, df=df, statistic=tst,
  +              pvalue=p, conf.low=cl, conf.high=ch, mean.null=m0, alternative=al,
  +              conf.level=cnf, stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # 5 observations
  > x <- matrix(rnorm(5000), ncol=5)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- runif(nrow(x), -1, 1)
  > cfs  <- sample(seq(0, 1, length.out=nrow(x)))
  > res1 <- base_t_onesample(x, mus, alts, cfs)
  > res2 <- row_t_onesample(x, mus, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 20 observations
  > x <- matrix(rnorm(20000), ncol=20)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- runif(nrow(x), -1, 1)
  > cfs  <- sample(seq(0, 1, length.out=nrow(x)))
  > res1 <- base_t_onesample(x, mus, alts, cfs)
  > res2 <- row_t_onesample(x, mus, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000)
  > res1 <- base_t_onesample(x)
  > res2 <- row_t_onesample(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(0.00000000000004, 0.00000000000002, 0.00000000000003, 0)
  > res1 <- base_t_onesample(x)
  > res2 <- row_t_onesample(x)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(10^6)
  > # res1 <- base_t_onesample(x)
  > # res2 <- row_t_onesample(x)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # two numbers
  > x <- matrix(rnorm(6), ncol=2)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_t_onesample(x, alternative=alt)
  > res2 <- row_t_onesample(x, alternative=alt)
  > stopifnot(all.equal(res1, res2))
  > 
  > # three numbers with NAs
  > x <- matrix(c(rnorm(6),NA,NA,NA), ncol=3)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_t_onesample(x, alternative=alt)
  > res2 <- row_t_onesample(x, alternative=alt)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- parameter edge cases ------------------------------------------------------
  > 
  > # various corner cases with NAs
  > mus <- c(-Inf, -1, 0, 1, Inf)
  > alt <- c("l", "t", "g")
  > cfs <- c(0, 0.5, 1)
  > pars <- expand.grid(mus, alt, cfs, stringsAsFactors=FALSE)
  > x <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > res1 <- base_t_onesample(x, pars[,1], pars[,2], pars[,3])
  > res2 <- row_t_onesample(x, pars[,1], pars[,2], pars[,3])
  > stopifnot(all.equal(res1, res2))
  > 
  > # NAs in confidence intervals
  > x <- matrix(rnorm(40), ncol=10)
  > cnf <- c(0.95, NA, 0.5, NA)
  > res1 <- base_t_onesample(x, conf=ifelse(is.na(cnf), 0.95, cnf))
  > res1[is.na(cnf), c("conf.level", "conf.low", "conf.high")] <- NA
  > res2 <- row_t_onesample(x, conf.level=cnf)
  > stopifnot(all.equal(res1, res2))
  > 
  > # null exactly equal to the mean
  > res1 <- base_t_onesample(c(1,2,3), null=2)
  > res2 <- row_t_onesample(c(1,2,3), null=2)
  > stopifnot(all.equal(res2$pvalue, 1))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.57    0.09    0.64 
Running the tests in 'tests/t_onesample_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x has less than 2 observations --------------------------------------------
  > 
  > wrn <- 'row_t_onesample: 1 of the rows had less than 2 "x" observations.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # 0 observations
  > res <- capture(row_t_onesample(numeric()))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 0))
  > 
  > # 1 observation
  > res <- capture(row_t_onesample(1))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 1))
  > 
  > # 1 observations with NAs
  > res <- capture(row_t_onesample(c(NA,1,NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 1))
  > 
  > 
  > #--- all values are constant ---------------------------------------------------
  > 
  > wrn <- 'row_t_onesample: 1 of the rows had essentially constant values.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # 2 equal observations
  > res <- capture(row_t_onesample(c(1,1)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 2))
  > stopifnot(all.equal(res$value$var, 0))
  > 
  > # 3 equal observations and some NAs
  > res <- capture(row_t_onesample(c(NA,2,2,2,NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs, 3))
  > stopifnot(all.equal(res$value$var, 0))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.18    0.07    0.23 
Running the tests in 'tests/t_paired_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x and y can be vectors
  > x <- rnorm(9)
  > y <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > Y <- matrix(y, nrow=1)
  > stopifnot(all.equal(row_t_paired(x, y), row_t_paired(X, Y)))
  > 
  > # x and y can be numeric data frames
  > x <- iris[1:50,1:4]
  > y <- iris[51:100,1:4]
  > X <- as.matrix(x)
  > Y <- as.matrix(y)
  > stopifnot(all.equal(row_t_paired(x, y), row_t_paired(X, Y)))
  > 
  > # x and y can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > y <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_t_paired(x, y)), 0))
  > 
  > # x and y can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > y <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_t_paired(x, y)), 0))
  > 
  > # alternative values can be partially completed
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_t_paired(x, y, alternative="greater"), row_t_paired(x, y, alternative="g")))
  > 
  > # null can be +Inf
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_paired(x, y, null=Inf)
  > stopifnot(all.equal(res$pvalue, 0))
  > stopifnot(all.equal(res$statistic, -Inf))
  > 
  > # null can be -Inf
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_paired(x, y, null=-Inf)
  > stopifnot(all.equal(res$pvalue, 0))
  > stopifnot(all.equal(res$statistic, Inf))
  > 
  > # conf.level can be 0
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_paired(x, y, conf.level=0)
  > stopifnot(all.equal(res$conf.low, res$conf.high))
  > 
  > # conf.level can be 1
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_paired(x, y, conf.level=1)
  > stopifnot(all.equal(res$conf.low, -Inf))
  > stopifnot(all.equal(res$conf.high, Inf))
  > 
  > # conf.level can be NA
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_paired(x, y, conf.level=NA)
  > stopifnot(all.equal(res$conf.level, NA_real_))
  > stopifnot(all.equal(res$conf.low, NA_real_))
  > stopifnot(all.equal(res$conf.high, NA_real_))
  > 
  > 
  > #--- recycling -----------------------------------------------------------------
  > 
  > # y can be a vector when x is a matrix
  > x <- matrix(rnorm(10), nrow=2)
  > y <- 1:5
  > res1 <- row_t_paired(x, y)
  > res2 <- row_t_paired(x, rbind(y,y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # null can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_t_paired(x, y, null=2)
  > res2 <- row_t_paired(x, y, null=c(2,2))
  > stopifnot(all.equal(res1, res2))
  > 
  > # alternative can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_t_paired(x, y, alternative="g")
  > res2 <- row_t_paired(x, y, alternative=c("g","g"))
  > stopifnot(all.equal(res1, res2))
  > 
  > # conf.level can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_t_paired(x, y, conf.level=0.98)
  > res2 <- row_t_paired(x, y, conf.level=c(0.98,0.98))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- rnorm(10)
  > res1 <- row_t_paired(x, y)
  > res2 <- row_t_paired(x[!is.na(x)], y[!is.na(x)])
  > res2[,c(2,5,8)]  <- res1[,c(2,5,8)]   # NOTE: row_t_paired uses all values to calculate stats (even the ones that do not have a pair)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in y are removed
  > x <- rnorm(10)
  > y <- c(NA,NA,rnorm(7),NA)
  > res1 <- row_t_paired(x, y)
  > res2 <- row_t_paired(x[!is.na(y)], y[!is.na(y)])
  > res2[,c(1,4,7)]  <- res1[,c(1,4,7)]   # NOTE: row_t_paired uses all values to calculate stats (even the ones that do not have a pair)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values from both x and y are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- c(NA,rnorm(7),NA,NA)
  > res1 <- row_t_paired(x, y)
  > res2 <- row_t_paired(x[!is.na(x) & !is.na(y)], y[!is.na(x) & !is.na(y)])
  > res2[,c(1,2,4,5,7,8)]  <- res1[,c(1,2,4,5,7,8)]  # NOTE: row_t_paired uses all values to calculate stats (even the ones that do not have a pair)
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res1$obs.paired, 6))
  > 
  > # no difference between NA and NaN
  > x1 <- c(NA,NA,1,2,1:5,NA)
  > x2 <- c(NaN,NaN,1,2,1:5,NaN)
  > y1 <- c(NA,NA,8:2,NA)
  > y2 <- c(NaN,NaN,8:2,NaN)
  > res1 <- row_t_paired(x1, y1)
  > res2 <- row_t_paired(x2, y2)
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > y <- rep(NA_integer_, 4)
  > res <- suppressWarnings(row_t_paired(x, y))
  > stopifnot(all.equal(res$obs.paired, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_t_paired(x, y)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when not provided - not taken from y
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_t_paired(x, y)
  > stopifnot(all.equal(rownames(res), c("1","2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_t_paired(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_t_paired(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(20), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > y <- matrix(rnorm(20), nrow=4)
  > res <- row_t_paired(x, y)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.31    0.09    0.34 
Running the tests in 'tests/t_paired_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- less than 2 paired observations -------------------------------------------
  > 
  > wrn <- 'row_t_paired: 1 of the rows had less than 2 paired observations.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # 0 observations
  > res <- capture(row_t_paired(NA_integer_, NA_integer_))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.pair, 0))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > 
  > # 0 observations in x and 2 in y
  > res <- capture(row_t_paired(c(NA_integer_, NA_integer_), 1:2))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.pair, 0))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 2))
  > 
  > # 1 observation
  > res <- capture(row_t_paired(1, 2))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.pair, 1))
  > stopifnot(all.equal(res$value$obs.x, 1))
  > stopifnot(all.equal(res$value$obs.y, 1))
  > 
  > # 2 observations in x and 1 in y
  > res <- capture(row_t_paired(1:2, c(1, NA_integer_)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.pair, 1))
  > stopifnot(all.equal(res$value$obs.x, 2))
  > stopifnot(all.equal(res$value$obs.y, 1))
  > 
  > # 1 paired observation after removing NAs
  > res <- capture(row_t_paired(c(1,2,3,NA,NA), c(NA,NA,2,1,4)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.pair, 1))
  > stopifnot(all.equal(res$value$obs.x, 3))
  > stopifnot(all.equal(res$value$obs.y, 3))
  > 
  > 
  > #--- constant paired values ----------------------------------------------------
  > 
  > wrn <- 'row_t_paired: 1 of the rows had essentially constant values.\nFirst occurrence at row 1'
  > nacolumns <- c("stderr", "df", "statistic", "pvalue", "conf.low", "conf.high")
  > 
  > # all values are the same
  > res <- capture(row_t_paired(c(1,1,1,1), c(1,1,1,1)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.x, 0))
  > stopifnot(all.equal(res$value$var.y, 0))
  > stopifnot(all.equal(res$value$var.diff, 0))
  > 
  > # all values are equal within each group
  > res <- capture(row_t_paired(c(1,1,1,1), c(2,2,2,2)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.x, 0))
  > stopifnot(all.equal(res$value$var.y, 0))
  > stopifnot(all.equal(res$value$var.diff, 0))
  > 
  > # all values are equal within each group after NAs
  > res <- capture(row_t_paired(c(NA,1,1,1,1,3), c(4,2,2,2,2,NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.diff, 0))
  > 
  > # values are equal after taking differene
  > res <- capture(row_t_paired(c(3,2,0), c(2,1,-1)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.diff, 0))
  > 
  > # values are equal after taking differene with NAs
  > res <- capture(row_t_paired(c(100,3,2,0,NA), c(NA,2,1,-1,-50)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$var.diff, 0))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.06    0.28 
Running the tests in 'tests/t_welch_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x and y can be vectors
  > x <- rnorm(9)
  > y <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > Y <- matrix(y, nrow=1)
  > stopifnot(all.equal(row_t_welch(x, y), row_t_welch(X, Y)))
  > 
  > # x and y can be numeric data frames
  > x <- iris[1:50,1:4]
  > y <- iris[51:100,1:4]
  > X <- as.matrix(x)
  > Y <- as.matrix(y)
  > stopifnot(all.equal(row_t_welch(x, y), row_t_welch(X, Y)))
  > 
  > # x and y can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > y <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_t_welch(x, y)), 0))
  > 
  > # x and y can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > y <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_t_welch(x, y)), 0))
  > 
  > # alternative values can be partially completed
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_t_welch(x, y, alternative="greater"), row_t_welch(x, y, alternative="g")))
  > 
  > # null can be +Inf
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_welch(x, y, null=Inf)
  > stopifnot(all.equal(res$pvalue, 0))
  > stopifnot(all.equal(res$statistic, -Inf))
  > 
  > # null can be -Inf
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_welch(x, y, null=-Inf)
  > stopifnot(all.equal(res$pvalue, 0))
  > stopifnot(all.equal(res$statistic, Inf))
  > 
  > # conf.level can be 0
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_welch(x, y, conf.level=0)
  > stopifnot(all.equal(res$conf.low, res$conf.high))
  > 
  > # conf.level can be 1
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_welch(x, y, conf.level=1)
  > stopifnot(all.equal(res$conf.low, -Inf))
  > stopifnot(all.equal(res$conf.high, Inf))
  > 
  > # conf.level can be NA
  > x <- rnorm(5)
  > y <- rnorm(5)
  > res <- row_t_welch(x, y, conf.level=NA)
  > stopifnot(all.equal(res$conf.level, NA_real_))
  > stopifnot(all.equal(res$conf.low, NA_real_))
  > stopifnot(all.equal(res$conf.high, NA_real_))
  > 
  > 
  > #--- recycling -----------------------------------------------------------------
  > 
  > # y can be a vector when x is a matrix
  > x <- matrix(rnorm(10), nrow=2)
  > y <- 1:5
  > res1 <- row_t_welch(x, y)
  > res2 <- row_t_welch(x, rbind(y,y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # null can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_t_welch(x, y, null=2)
  > res2 <- row_t_welch(x, y, null=c(2,2))
  > stopifnot(all.equal(res1, res2))
  > 
  > # alternative can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_t_welch(x, y, alternative="g")
  > res2 <- row_t_welch(x, y, alternative=c("g","g"))
  > stopifnot(all.equal(res1, res2))
  > 
  > # conf.level can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_t_welch(x, y, conf.level=0.98)
  > res2 <- row_t_welch(x, y, conf.level=c(0.98,0.98))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- rnorm(10)
  > res1 <- row_t_welch(x, y)
  > res2 <- row_t_welch(x[!is.na(x)], y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in y are removed
  > x <- rnorm(10)
  > y <- c(NA,NA,rnorm(7),NA)
  > res1 <- row_t_welch(x, y)
  > res2 <- row_t_welch(x, y[!is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values from both x and y are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- c(NA,rnorm(7),NA,NA)
  > res1 <- row_t_welch(x, y)
  > res2 <- row_t_welch(x[!is.na(x)], y[!is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # no difference between NA and NaN
  > x1 <- c(NA,NA,1,2,1:5,NA)
  > x2 <- c(NaN,NaN,1,2,1:5,NaN)
  > y1 <- c(NA,NA,8:2,NA)
  > y2 <- c(NaN,NaN,8:2,NaN)
  > res1 <- row_t_welch(x1, y1)
  > res2 <- row_t_welch(x2, y2)
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > y <- rep(NA_integer_, 4)
  > res <- suppressWarnings(row_t_welch(x, y))
  > stopifnot(all.equal(res$obs.tot, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_t_welch(x, y)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when not provided - not taken from y
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_t_welch(x, y)
  > stopifnot(all.equal(rownames(res), c("1","2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_t_welch(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_t_welch(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(20), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > y <- matrix(rnorm(20), nrow=4)
  > res <- row_t_welch(x, y)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.20    0.12    0.29 
Running the tests in 'tests/t_welch_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_t_welch <- function(mat1, mat2, null=0, alternative="two.sided", conf=0.95) {
  +   if(is.vector(mat1)) mat1 <- matrix(mat1, nrow=1)
  +   if(is.vector(mat2)) mat2 <- matrix(mat2, nrow=1)
  +   if(length(alternative)==1) alternative <- rep(alternative, nrow(mat1))
  +   if(length(null)==1) null <- rep(null, nrow(mat1))
  +   if(length(conf)==1) conf <- rep(conf, nrow(mat1))
  + 
  +   mx <- my <- md <- vx <- vy <- vp <- nx <- ny <- nt <- tst <- p <- cl <- ch <-
  +     se <- df <- m0 <- cnf <- numeric(nrow(mat1))
  +   al <- character(nrow(mat1))
  +   for(i in 1:nrow(mat1)) {
  +     vec1 <- na.omit(mat1[i,])
  +     vec2 <- na.omit(mat2[i,])
  +     res <- t.test(vec1, vec2, alternative=alternative[i], mu=null[i], conf.level=conf[i])
  + 
  +     # if p-value is NA turn stderr and df to NA as well
  +     if(is.na(res$p.value)) {
  +       res$stderr <- NA
  +       res$parameter <- NA
  +     }
  + 
  +     vx[i]  <- var(vec1)
  +     vy[i]  <- var(vec2)
  +     nx[i]  <- length(vec1)
  +     ny[i]  <- length(vec2)
  +     nt[i]  <- nx[i] + ny[i]
  +     mx[i]  <- res$estimate[1]
  +     my[i]  <- res$estimate[2]
  +     md[i]  <- mx[i]-my[i]
  +     tst[i] <- res$statistic
  +     p[i]   <- res$p.value
  +     cl[i]  <- res$conf.int[1]
  +     ch[i]  <- res$conf.int[2]
  +     df[i]  <- res$parameter
  +     m0[i]  <- res$null.value
  +     al[i]  <- res$alternative
  +     se[i]  <- res$stderr
  +     cnf[i] <- attr(res$conf.int, "conf.level")
  +   }
  + 
  +   data.frame(obs.x=nx, obs.y=ny, obs.tot=nt, mean.x=mx, mean.y=my, mean.diff=md,
  +              var.x=vx, var.y=vy, stderr=se, df=df, statistic=tst, pvalue=p,
  +              conf.low=cl, conf.high=ch, mean.null=m0, alternative=al,
  +              conf.level=cnf, stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # 3 and 2 observations
  > x <- matrix(rnorm(3000), ncol=3)
  > y <- matrix(rnorm(2000), ncol=2)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- sample(seq(-1, 1, length.out=nrow(x)))
  > cfs  <- sample(seq(0, 1, length.out=nrow(x)))
  > res1 <- base_t_welch(x, y, mus, alts, cfs)
  > res2 <- row_t_welch(x, y, mus, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 20 observations in each group
  > x <- matrix(rnorm(20000), ncol=20)
  > y <- matrix(rnorm(20000), ncol=20)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- sample(seq(-1, 1, length.out=nrow(x)))
  > cfs  <- sample(seq(0, 1, length.out=nrow(x)))
  > res1 <- base_t_welch(x, y, mus, alts, cfs)
  > res2 <- row_t_welch(x, y, mus, alts, cfs)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000)
  > y <- c(100000000000003, 100000000000002, 100000000000003)
  > res1 <- base_t_welch(x, y)
  > res2 <- row_t_welch(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > x <- c(0.00000000000004, 0.00000000000002, 0.00000000000003, 0)
  > y <- c(0.00000000000003, 0.00000000000002, 0.00000000000003)
  > res1 <- base_t_welch(x, y)
  > res2 <- row_t_welch(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # x <- rnorm(10^6)
  > # y <- rnorm(10^6)
  > # res1 <- base_t_welch(x, y)
  > # res2 <- row_t_welch(x, y)
  > # stopifnot(all.equal(res1, res2))
  > 
  > # TODO: add tests for Inf and -Inf values once decided how to handle them.
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # 2 observations in both groups
  > x <- matrix(rnorm(6), ncol=2)
  > y <- matrix(rnorm(6), ncol=2)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_t_welch(x, y, alternative=alt)
  > res2 <- row_t_welch(x, y, alternative=alt)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 2 observations in first group and 4 in second
  > x <- matrix(rnorm(6), ncol=2)
  > y <- matrix(rnorm(12), ncol=4)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_t_welch(x, y, alternative=alt)
  > res2 <- row_t_welch(x, y, alternative=alt)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 3 observations in both groups but one is NA
  > x <- matrix(c(rnorm(6), NA,NA,NA), ncol=3)
  > y <- matrix(c(NA,NA,NA,rnorm(6)), ncol=3)
  > alt <- c("two.sided", "greater", "less")
  > res1 <- base_t_welch(x, y, alternative=alt)
  > res2 <- row_t_welch(x, y, alternative=alt)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- parameter edge cases ------------------------------------------------------
  > 
  > # various corner cases with NAs
  > mus <- c(-Inf, -1, 0, 1, Inf)
  > alt <- c("l", "t", "g")
  > cfs <- c(0, 0.5, 1)
  > pars <- expand.grid(mus, alt, cfs, stringsAsFactors=FALSE)
  > x <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > y <- matrix(rnorm(10*nrow(pars)), ncol=10)
  > res1 <- base_t_welch(x, y, pars[,1], pars[,2], pars[,3])
  > res2 <- row_t_welch(x, y, pars[,1], pars[,2], pars[,3])
  > stopifnot(all.equal(res1, res2))
  > 
  > # NAs in confidence intervals
  > x <- matrix(rnorm(40), ncol=10)
  > y <- matrix(rnorm(40), ncol=10)
  > cnf <- c(0.95, NA, 0.5, NA)
  > res1 <- base_t_welch(x, y, conf=ifelse(is.na(cnf), 0.95, cnf))
  > res1[is.na(cnf), c("conf.level", "conf.low", "conf.high")] <- NA
  > res2 <- row_t_welch(x, y, conf.level=cnf)
  > stopifnot(all.equal(res1, res2))
  > 
  > # null exactly equal to the mean
  > res1 <- base_t_welch(c(1,2,3), c(0,0,0), null=2)
  > res2 <- row_t_welch(c(1,2,3), c(0,0,0), null=2)
  > stopifnot(all.equal(res2$pvalue, 1))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- constant values -----------------------------------------------------------
  > 
  > # first group values are constant
  > x <- matrix(1, nrow=3, ncol=3)
  > y <- matrix(rnorm(9), nrow=3, ncol=3)
  > alt <- c("l", "t", "g")
  > res1 <- base_t_welch(x, y, alternative=alt)
  > res2 <- row_t_welch(x, y, alternative=alt)
  > stopifnot(all.equal(res2$var.x, rep(0, nrow(x))))
  > 
  > # second group values are constant
  > x <- matrix(rnorm(9), nrow=3, ncol=3)
  > y <- matrix(1, nrow=3, ncol=3)
  > alt <- c("l", "t", "g")
  > res1 <- base_t_welch(x, y, alternative=alt)
  > res2 <- row_t_welch(x, y, alternative=alt)
  > stopifnot(all.equal(res2$var.y, rep(0, nrow(y))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.81    0.04    0.84 
Running the tests in 'tests/t_welch_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_t_welch())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(NULL, 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(c("1", "2"), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(c(TRUE, FALSE), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(complex(c(1,2), c(3,4)), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(iris, 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(as.list(c(1:5)), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(list(1:5), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- y argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "y" is missing, with no default'
  > res <- capture(row_t_welch(1))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(1, NULL))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(1:2, c("1","2")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(1:2, c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(1:2, complex(c(1,2), c(3,4))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(1:2, iris))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(1:2, as.list(c(1:5))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_t_welch(1:2, list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- alternative argument errors -----------------------------------------------
  > 
  > err <- '"alternative" must be a character vector with length 1 or nrow(x)'
  > 
  > # cannot be NA
  > res <- capture(row_t_welch(x=1:3, y=2:4, alternative=NA))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be numeric
  > res <- capture(row_t_welch(x=1:3, y=2:4, alternative=1))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_t_welch(x=1:3, y=2:4, alternative=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_t_welch(x=1:3, y=2:4, alternative=list("less")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_t_welch(x=1:3, y=2:4, alternative=data.frame("less")))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- 'all "alternative" values must be in: two.sided, less, greater'
  > 
  > # must be in correct set
  > res <- capture(row_t_welch(x=1:3, y=2:4, alternative="ga"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # error produced even when some are correct
  > res <- capture(row_t_welch(x=matrix(1:10, nrow=2), y=matrix(1:10, nrow=2), alternative=c("g","c")))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- null argument errors ------------------------------------------------------
  > 
  > err <- '"null" must be a numeric vector with length 1 or nrow(x)'
  > 
  > # cannot be a character
  > res <- capture(row_t_welch(x=1:3, y=1:3, null="1"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_t_welch(x=1:3, y=1:3, null=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_t_welch(x=1:3, y=1:3, null=list(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_t_welch(x=1:3, y=1:3, null=data.frame(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- 'all "null" values must be between: -Inf and Inf'
  > 
  > # cannot be NA
  > res <- capture(row_t_welch(x=1:3, y=1:3, null=NA_integer_))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NaN
  > res <- capture(row_t_welch(x=1:3, y=1:3, null=NaN))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- conf.level argument errors ------------------------------------------------
  > 
  > err <- '"conf.level" must be a numeric vector with length 1 or nrow(x)'
  > 
  > # cannot be character
  > res <- capture(row_t_welch(x=1:3, y=2:4, conf.level="0.95"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_t_welch(x=1:3, y=2:4, conf.level=complex(0.95)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_t_welch(x=1:3, y=2:4, conf.level=list(0.95)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_t_welch(x=1:3, y=2:4, conf.level=data.frame(0.95)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- 'all "conf.level" values must be between: 0 and 1'
  > 
  > # cannot be below 0
  > res <- capture(row_t_welch(x=1:3, y=2:4, conf.level=-0.0001))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be above 1
  > res <- capture(row_t_welch(x=1:3, y=2:4, conf.level=1.0001))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # y number of rows must match x number of rows
  > err <- '"x" and "y" must have the same number of rows'
  > x <- matrix(1:10, nrow=2)
  > y <- matrix(1:10, nrow=5)
  > res <- capture(row_t_welch(x, y))
  > stopifnot(all.equal(res$error, err))
  > 
  > # null must match x number of rows
  > err <- '"null" must be a numeric vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > y <- matrix(1:12, nrow=4)
  > res <- capture(row_t_welch(x, y, null=c(1,2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # alternative must match x number of rows
  > err <- '"alternative" must be a character vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > y <- matrix(1:12, nrow=4)
  > res <- capture(row_t_welch(x, y, alternative=c("g","l")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # conf.level must match x number of rows
  > err <- '"conf.level" must be a numeric vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > y <- matrix(1:12, nrow=4)
  > res <- capture(row_t_welch(x, y, conf.level=c(0.95, 0.99)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.25    0.06    0.28 
Running the tests in 'tests/waerden_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_waerden())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_waerden(NULL, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_waerden(c("a", "b"), c("a","b")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_waerden(c(TRUE, FALSE), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_waerden(complex(c(1,2), c(3,4)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_waerden(iris, "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_waerden(as.list(c(1:5)), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_waerden(list(1:5), "a"))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- g argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "g" is missing, with no default'
  > res <- capture(row_waerden(1, ))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a matrix with dimensions
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_waerden(matrix(1:4, nrow=1), matrix(letters[1:4], nrow=2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a in a list
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_waerden(1:5, list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # g length must match the observations of x
  > err <- '"g" must be a vector with length ncol(x)'
  > res <- capture(row_waerden(1:5, letters[1:4]))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.14    0.06    0.18 
Running the tests in 'tests/wilcoxon_onesample_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x and can be vector
  > x <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > stopifnot(all.equal(row_wilcoxon_onesample(x), row_wilcoxon_onesample(X)))
  > 
  > # x and be numeric data frame
  > x <- iris[,1:4]
  > X <- as.matrix(x)
  > stopifnot(all.equal(row_wilcoxon_onesample(x), row_wilcoxon_onesample(X)))
  > 
  > # x can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_wilcoxon_onesample(x)), 0))
  > 
  > # x can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_wilcoxon_onesample(x)), 0))
  > 
  > # alternative values can be partially completed
  > x <- rnorm(5)
  > stopifnot(all.equal(row_wilcoxon_onesample(x, alternative="greater"), row_wilcoxon_onesample(x, alternative="g")))
  > 
  > # exact can be NA
  > x <- rnorm(5)
  > stopifnot(all.equal(row_wilcoxon_onesample(x, exact=NA), row_wilcoxon_onesample(x, exact=TRUE)))
  > 
  > # TODO: investigate if null can be allowed Inf values.
  > 
  > 
  > #--- recycling -----------------------------------------------------------------
  > 
  > # null can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_onesample(x, null=2)
  > res2 <- row_wilcoxon_onesample(x, null=c(2,2))
  > stopifnot(all.equal(res1, res2))
  > 
  > # alternative can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_onesample(x, alternative="g")
  > res2 <- row_wilcoxon_onesample(x, alternative=c("g","g"))
  > stopifnot(all.equal(res1, res2))
  > 
  > # exact can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_onesample(x, exact=TRUE)
  > res2 <- row_wilcoxon_onesample(x, exact=c(TRUE, TRUE))
  > stopifnot(all.equal(res1, res2))
  > 
  > # correct can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_onesample(x, exact=FALSE, correct=FALSE)
  > res2 <- row_wilcoxon_onesample(x, exact=FALSE, correct=c(FALSE, FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > res1 <- row_wilcoxon_onesample(x)
  > res2 <- row_wilcoxon_onesample(x[!is.na(x)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # no difference between NA and NaN
  > x1 <- c(NA,NA,1:7,NA)
  > x2 <- c(NaN,NaN,1:7,NaN)
  > res1 <- row_wilcoxon_onesample(x1)
  > res2 <- row_wilcoxon_onesample(x2)
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > res <- suppressWarnings(row_wilcoxon_onesample(x))
  > stopifnot(all.equal(res$obs, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > res <- row_wilcoxon_onesample(x)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_wilcoxon_onesample(x)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > res <- row_wilcoxon_onesample(x)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(40), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > res <- row_wilcoxon_onesample(x)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.23    0.07    0.28 
Running the tests in 'tests/wilcoxon_onesample_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_wilcoxon_onesample())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_onesample(NULL))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_onesample(c("1", "2")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_onesample(c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_onesample(complex(c(1,2), c(3,4))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_onesample(iris))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_onesample(as.list(c(1:5))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_onesample(list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- alternative argument errors -----------------------------------------------
  > 
  > err <- '"alternative" must be a character vector with length 1 or nrow(x)'
  > 
  > # cannot be NA
  > res <- capture(row_wilcoxon_onesample(x=1:3, alternative=NA))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be numeric
  > res <- capture(row_wilcoxon_onesample(x=1:3, alternative=1))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_onesample(x=1:3, alternative=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_onesample(x=1:3, alternative=list("less")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_onesample(x=1:3, alternative=data.frame("less")))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- 'all "alternative" values must be in: two.sided, less, greater'
  > 
  > # must be in correct set
  > res <- capture(row_wilcoxon_onesample(x=1:3, alternative="ga"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # error produced even when some are correct
  > res <- capture(row_wilcoxon_onesample(x=matrix(1:10, nrow=2), alternative=c("g","c")))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- null argument errors ------------------------------------------------------
  > 
  > err <- '"null" must be a numeric vector with length 1 or nrow(x)'
  > 
  > # cannot be a character
  > res <- capture(row_wilcoxon_onesample(x=1:3, null="1"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_onesample(x=1:3, null=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_onesample(x=1:3, null=list(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_onesample(x=1:3, null=data.frame(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- 'all "null" values must be greater than -Inf and lower than Inf'
  > 
  > # cannot be NA
  > res <- capture(row_wilcoxon_onesample(x=1:3, null=NA_integer_))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NaN
  > res <- capture(row_wilcoxon_onesample(x=1:3, null=NaN))
  > stopifnot(all.equal(res$error, err))
  > 
  > # TODO: check if can be made to work with Inf
  > # cannot be Inf
  > res <- capture(row_wilcoxon_onesample(x=1:3, null=Inf))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be -Inf
  > res <- capture(row_wilcoxon_onesample(x=1:3, null=-Inf))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- exact argument errors -----------------------------------------------------
  > 
  > err <- '"exact" must be a logical vector with length 1 or nrow(x)'
  > 
  > # cannot be non-logical NA
  > res <- capture(row_wilcoxon_onesample(x=1:3, exact=NA_integer_))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be numeric
  > res <- capture(row_wilcoxon_onesample(x=1:3, exact=1))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > res <- capture(row_wilcoxon_onesample(x=1:3, exact="TRUE"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_onesample(x=1:3, exact=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_onesample(x=1:3, exact=list(TRUE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_onesample(x=1:3, exact=data.frame(TRUE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- correct argument errors ---------------------------------------------------
  > 
  > err <- 'all "correct" values must be in: TRUE, FALSE'
  > 
  > # cannot be NA
  > res <- capture(row_wilcoxon_onesample(x=1:3, correct=NA))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- '"correct" must be a logical vector with length 1 or nrow(x)'
  > 
  > # cannot be numeric
  > res <- capture(row_wilcoxon_onesample(x=1:3, correct=0))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > res <- capture(row_wilcoxon_onesample(x=1:3, correct="FALSE"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_onesample(x=1:3, correct=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_onesample(x=1:3, correct=list(FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_onesample(x=1:3, correct=data.frame(FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # null must match x number of rows
  > err <- '"null" must be a numeric vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_onesample(x, null=c(1,2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # alternative must match x number of rows
  > err <- '"alternative" must be a character vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_onesample(x, alternative=c("g","l")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # exact must match x number of rows
  > err <- '"exact" must be a logical vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_onesample(x, exact=c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # correct must match x number of rows
  > err <- '"correct" must be a logical vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_onesample(x, correct=c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.18    0.04    0.21 
Running the tests in 'tests/wilcoxon_paired_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x and y can be vectors
  > x <- rnorm(9)
  > y <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > Y <- matrix(y, nrow=1)
  > stopifnot(all.equal(row_wilcoxon_paired(x, y), row_wilcoxon_paired(X, Y)))
  > 
  > # x and y can be numeric data frames
  > x <- iris[1:50,1:4]
  > y <- iris[51:100,1:4]
  > X <- as.matrix(x)
  > Y <- as.matrix(y)
  > stopifnot(all.equal(suppressWarnings(row_wilcoxon_paired(x, y)), suppressWarnings(row_wilcoxon_paired(X, Y))))
  > 
  > # x and y can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > y <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_wilcoxon_paired(x, y)), 0))
  > 
  > # x and y can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > y <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_wilcoxon_paired(x, y)), 0))
  > 
  > # alternative values can be partially completed
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_wilcoxon_paired(x, y, alternative="greater"), row_wilcoxon_paired(x, y, alternative="g")))
  > 
  > # exact can be NA
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_wilcoxon_paired(x, y, exact=NA), row_wilcoxon_paired(x, y, exact=TRUE)))
  > 
  > # TODO: investigate if null can be allowed Inf values.
  > 
  > 
  > #--- recycling -----------------------------------------------------------------
  > 
  > # y can be a vector when x is a matrix
  > x <- matrix(rnorm(10), nrow=2)
  > y <- 1:5
  > res1 <- row_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, rbind(y,y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # null can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_paired(x, y, null=2)
  > res2 <- row_wilcoxon_paired(x, y, null=c(2,2))
  > stopifnot(all.equal(res1, res2))
  > 
  > # alternative can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_paired(x, y, alternative="g")
  > res2 <- row_wilcoxon_paired(x, y, alternative=c("g","g"))
  > stopifnot(all.equal(res1, res2))
  > 
  > # exact can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_paired(x, y, exact=TRUE)
  > res2 <- row_wilcoxon_paired(x, y, exact=c(TRUE, TRUE))
  > stopifnot(all.equal(res1, res2))
  > 
  > # correct can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_paired(x, y, exact=FALSE, correct=FALSE)
  > res2 <- row_wilcoxon_paired(x, y, exact=FALSE, correct=c(FALSE, FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- rnorm(10)
  > res1 <- row_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x[!is.na(x)], y[!is.na(x)])
  > res2[,2] <- res1[,2]   # NOTE: row_wilcoxon_paired uses all values to calculate stats (even the ones that do not have a pair)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in y are removed
  > x <- rnorm(10)
  > y <- c(NA,NA,rnorm(7),NA)
  > res1 <- row_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x[!is.na(y)], y[!is.na(y)])
  > res2[,1] <- res1[,1]   # NOTE: row_wilcoxon_paired uses all values to calculate stats (even the ones that do not have a pair)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values from both x and y are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- c(NA,rnorm(7),NA,NA)
  > res1 <- row_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x[!is.na(x) & !is.na(y)], y[!is.na(x) & !is.na(y)])
  > res2[,1:2]  <- res1[,1:2]  # NOTE: row_wilcoxon_paired uses all values to calculate stats (even the ones that do not have a pair)
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res1$obs.paired, 6))
  > 
  > # no difference between NA and NaN
  > x1 <- c(NA,NA,1,2,7:3,NA)
  > x2 <- c(NaN,NaN,1,2,7:3,NaN)
  > y1 <- c(NA,NA,18:12,NA)
  > y2 <- c(NaN,NaN,18:12,NaN)
  > res1 <- suppressWarnings(row_wilcoxon_paired(x1, y1))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x2, y2))
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > y <- rep(NA_integer_, 4)
  > res <- suppressWarnings(row_wilcoxon_paired(x, y))
  > stopifnot(all.equal(res$obs.paired, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_wilcoxon_paired(x, y)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when not provided - not taken from y
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_wilcoxon_paired(x, y)
  > stopifnot(all.equal(rownames(res), c("1","2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_wilcoxon_paired(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_wilcoxon_paired(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(20), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > y <- matrix(rnorm(20), nrow=4)
  > res <- row_wilcoxon_paired(x, y)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.28    0.09    0.34 
Running the tests in 'tests/wilcoxon_paired_correctness.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- functions -----------------------------------------------------------------
  > 
  > base_wilcoxon_paired <- function(mat1, mat2, null=0, alternative="two.sided", exact=NA, correct=TRUE) {
  +   if(is.vector(mat1)) mat1 <- matrix(mat1, nrow=1)
  +   if(is.vector(mat2)) mat2 <- matrix(mat2, nrow=1)
  +   if(length(alternative)==1) alternative <- rep(alternative, nrow(mat1))
  +   if(length(null)==1) null <- rep(null, nrow(mat1))
  +   if(length(exact)==1) exact <- rep(exact, nrow(mat1))
  +   if(length(correct)==1) correct <- rep(correct, nrow(mat1))
  + 
  +   nx <- ny <- nxy <- stat <- p <- m0 <- numeric(nrow(mat1))
  +   al <- character(nrow(mat1))
  +   ext <- cor <- logical(nrow(mat1))
  +   for(i in 1:nrow(mat1)) {
  +     ex  <- if(is.na(exact[i])) NULL else exact[i]
  +     res <- wilcox.test(mat1[i,], mat2[i,], alternative=alternative[i], mu=null[i], paired=TRUE, exact=ex, correct=correct[i])
  + 
  +     inds <- complete.cases(mat1[i,], mat2[i,])
  +     vec1 <- mat1[i,inds]
  +     vec2 <- mat2[i,inds]
  +     nx[i]   <- sum(!is.na(mat1[i,]))
  +     ny[i]   <- sum(!is.na(mat2[i,]))
  +     nxy[i]  <- sum((vec1 - vec2 - null[i]) != 0, na.rm=TRUE)
  +     stat[i] <- res$statistic
  +     p[i]    <- res$p.value
  +     al[i]   <- res$alternative
  +     m0[i]   <- res$null.value
  + 
  +     cor[i] <- grepl("continuity correction", res$method)
  +     ext[i] <- if(is.na(exact[i])) (nxy[i] < 50) else exact[i]
  +     ext[i] <- if(length(unique(abs(vec1-vec2-m0[i]))) != length(vec1)) FALSE else ext[i]
  +     ext[i] <- if(any((vec1-vec2-m0[i]) == 0)) FALSE else ext[i]
  +   }
  + 
  +   data.frame(obs.x=nx, obs.y=ny, obs.paired=nxy, statistic=stat, pvalue=p,
  +              location.null=m0, alternative=al, exact=ext, corrected=cor,
  +              stringsAsFactors=FALSE
  +              )
  + }
  > 
  > 
  > #--- montecarlo ----------------------------------------------------------------
  > 
  > # 4 paired samples
  > x <- matrix(rnorm(4000), ncol=4)
  > y <- matrix(rnorm(4000), ncol=4)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- runif(nrow(x), -1, 1)
  > cor  <- sample(c(TRUE, FALSE), nrow(x), replace=TRUE)
  > ext  <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- base_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor)
  > res2 <- row_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor)
  > stopifnot(all.equal(res1, res2))
  > 
  > # 60 paired samples
  > x <- matrix(rnorm(60000), ncol=60)
  > y <- matrix(rnorm(60000), ncol=60)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- runif(nrow(x), -1, 1)
  > cor  <- sample(c(TRUE, FALSE), nrow(x), replace=TRUE)
  > ext  <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- base_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor)
  > res2 <- row_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor)
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > # 6 paired samples per group with ties and zeroes
  > x <- matrix(round(runif(6000, -10, 10)), ncol=6)
  > y <- matrix(round(runif(6000, -10, 10)), ncol=6)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- runif(nrow(x), -1, 1)
  > mus[sample(length(mus), length(mus)/8)] <- 0
  > mus[sample(length(mus), length(mus)/8)] <- 1
  > cor  <- sample(c(TRUE, FALSE), nrow(x), replace=TRUE)
  > ext  <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor))
  > stopifnot(all.equal(res1, res2))
  > 
  > # 60 paired samples per group with ties and zeroes
  > x <- matrix(round(runif(60000, -15, 15)), ncol=60)
  > y <- matrix(round(runif(60000, -15, 15)), ncol=60)
  > alts <- sample(c("t", "g", "l"), nrow(x), replace=TRUE)
  > mus  <- runif(nrow(x), -1, 1)
  > mus[sample(length(mus), length(mus)/8)] <- 0
  > mus[sample(length(mus), length(mus)/8)] <- 1
  > cor  <- sample(c(TRUE, FALSE), nrow(x), replace=TRUE)
  > ext  <- sample(c(TRUE, FALSE, NA), nrow(x), replace=TRUE)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, mus, alts, exact=ext, correct=cor))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- extreme numbers -----------------------------------------------------------
  > 
  > # big numbers
  > pars  <- expand.grid(c("t","g","l"), c(TRUE, FALSE), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x <- c(100000000000004, 100000000000002, 100000000000003, 100000000000000)
  > y <- c(100000000000002, 100000000000003, 100000000000000, 100000000000004)
  > x <- matrix(x, nrow=nrow(pars), ncol=length(x), byrow=TRUE)
  > y <- matrix(y, nrow=nrow(pars), ncol=length(y), byrow=TRUE)
  > res1 <- base_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > res2 <- row_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > stopifnot(all.equal(res1, res2))
  > 
  > # small numbers
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x <- c(0.00000000000004, 0.00000000000002, 0.00000000000003, 0.00000000000001)
  > y <- c(0.00000000000002, 0.00000000000003, 0.00000000000000, 0.00000000000005)
  > x <- matrix(x, nrow=nrow(pars), ncol=length(x), byrow=TRUE)
  > y <- matrix(y, nrow=nrow(pars), ncol=length(y), byrow=TRUE)
  > res1 <- base_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > res2 <- row_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > stopifnot(all.equal(res1, res2))
  > 
  > # NOTE: turned-off because of precission errors on architectures without long doubles
  > # large sample
  > # pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > # x <- rnorm(10^6)
  > # y <- rnorm(10^6)
  > # x <- matrix(x, nrow=nrow(pars), ncol=length(x), byrow=TRUE)
  > # y <- matrix(y, nrow=nrow(pars), ncol=length(y), byrow=TRUE)
  > # res1 <- base_wilcoxon_paired(x, y, alternative=pars[,1], correct=pars[,2])
  > # res2 <- row_wilcoxon_paired(x, y, alternative=pars[,1], correct=pars[,2])
  > # stopifnot(all.equal(res1, res2))
  > 
  > # x has infinity
  > x <- c(Inf, rnorm(4))
  > y <- rnorm(5)
  > res1 <- base_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # x has both positive and negative infinities
  > x <- c(Inf, rnorm(4), -Inf)
  > y <- rnorm(6)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # y has infinity
  > x <- rnorm(5)
  > y <- c(Inf, rnorm(4))
  > res1 <- base_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # y has positive and negative infinities
  > x <- rnorm(6)
  > y <- c(Inf, rnorm(4), -Inf)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # both and y have various infinities
  > # NOTE: base implementation doesn't work when both Inf with the same sign is present in both groups
  > x <- c(-Inf, rnorm(4), Inf, Inf)
  > y <- c(Inf, Inf, rnorm(4), -Inf)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # infinities are treated as highest ranks
  > # NOTE: this scenario is a bit more complex because the ranks are calculated after taking differences.
  > x1 <- c(-Inf, 1:10, Inf, Inf)
  > y1 <- c(-Inf, Inf, 31:40, -Inf)
  > x2 <- c(-100, 0, 2:10, 200, 100)
  > y2 <- c(-100, 200, 31:39, 0, -100)
  > res1 <- suppressWarnings(row_wilcoxon_paired(x1, y1))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x2, y2))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- minimal sample size -------------------------------------------------------
  > 
  > # single paired number
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- matrix(rnorm(nrow(pars)), ncol=1)
  > y    <- matrix(rnorm(nrow(pars)), ncol=1)
  > res1 <- base_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > res2 <- row_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2$obs.paired, rep(1, nrow(x))))
  > 
  > # 3 paired numbers but only one common, others are paired with NAs
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- cbind(matrix(rnorm(nrow(pars)*2), ncol=2), NA)
  > y    <- cbind(NA, matrix(rnorm(nrow(pars)*2), ncol=2))
  > res1 <- base_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > res2 <- row_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3])
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2$obs.paired, rep(1, nrow(x))))
  > 
  > # three paired numbers all equal
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x    <- matrix(rnorm(nrow(pars)), nrow=nrow(pars), ncol=3)
  > y    <- matrix(rnorm(nrow(pars)), nrow=nrow(pars), ncol=3)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3]))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3]))
  > stopifnot(all.equal(res1, res2))
  > 
  > # three numbers all differences equal
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x <- matrix(rnorm(nrow(pars)*3), ncol=3)
  > y <- x + 0.2
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3]))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, alternative=pars[,1], exact=pars[,2], correct=pars[,3]))
  > stopifnot(all.equal(res1, res2))
  > 
  > # three numbers, two equal to null after subtraction
  > # NOTE: seems to be numerically unstable
  > pars <- expand.grid(c("t","g","l"), c(TRUE, FALSE), c(TRUE, FALSE), stringsAsFactors=FALSE)
  > x <- matrix(rnorm(nrow(pars)*3), ncol=3)
  > y <- matrix(rnorm(nrow(pars)*3), ncol=3)
  > y[,1:2] <- x[,1:2]-1
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, alternative=pars[,1], 1, exact=pars[,2], correct=pars[,3]))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, alternative=pars[,1], 1, exact=pars[,2], correct=pars[,3]))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- parameter edge cases ------------------------------------------------------
  > 
  > # various corner cases with NAs
  > mus  <- c(-10000, 0, 10000)  # TODO: decide if Inf is reasonable null for this test
  > alt  <- c("l", "t", "g")
  > ext  <- c(TRUE, FALSE, NA)
  > cor  <- c(TRUE, FALSE)
  > pars <- expand.grid(mus, alt, ext, cor, stringsAsFactors=FALSE)
  > x <- matrix(round(runif(10*nrow(pars), -15, 15)), ncol=10)
  > y <- matrix(round(runif(10*nrow(pars), -15, 15)), ncol=10)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, pars[,1], pars[,2], pars[,3], pars[,4]))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, pars[,1], pars[,2], pars[,3], pars[,4]))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- interactions with exact and correct ---------------------------------------
  > 
  > # 49 samples (< 50: exact = TRUE)
  > x <- rnorm(49)
  > y <- rnorm(49)
  > res1 <- base_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, y, exact=NA)
  > res3 <- row_wilcoxon_paired(x, y, exact=TRUE)
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res2$obs.paired, 49))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 50 samples with one NA (< 50: exact = TRUE)
  > x <- c(NA, rnorm(49))
  > y <- rnorm(50)
  > res1 <- base_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, y, exact=NA)
  > res3 <- row_wilcoxon_paired(x, y, exact=TRUE)
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res2$obs.paired, 49))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 51 samples with NA and NaN (< 50: exact = TRUE)
  > x <- c(rnorm(50), NA)
  > y <- c(NaN, rnorm(50))
  > res1 <- base_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, y, exact=NA)
  > res3 <- row_wilcoxon_paired(x, y, exact=TRUE)
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res2$obs.paired, 49))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 50 samples (>= 50: exact = FALSE)
  > x <- rnorm(50)
  > y <- rnorm(50)
  > res1 <- base_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, y, exact=NA)
  > res3 <- row_wilcoxon_paired(x, y, exact=FALSE)
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$obs.paired, 50))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 51 samples with one NA (>= 50: exact = FALSE)
  > x <- rnorm(51)
  > y <- c(rnorm(50), NA)
  > res1 <- base_wilcoxon_paired(x, y)
  > res2 <- row_wilcoxon_paired(x, y, exact=NA)
  > res3 <- row_wilcoxon_paired(x, y, exact=FALSE)
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$obs.paired, 50))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 50 samples with 1 value equal to null (>= 50: exact = FALSE)
  > # NOTE: even thou 49 paired observations are left, base and matrixTests still treats it as 50
  > x <- c(rnorm(49),1.2)
  > y <- c(rnorm(49),1.2)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=NA))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=FALSE))
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$obs.paired, 49))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # 10 samples with one tie (ties: exact = FALSE)
  > x <- c(rnorm(8), 2, 2)
  > y <- c(rnorm(8), 1, 1)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=NA))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=TRUE))
  > res4 <- row_wilcoxon_paired(x, y, exact=FALSE)
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res3, res4))
  > 
  > # 105 samples with 5 ties (ties: exact = FALSE)
  > x <- c(rnorm(100), 2, 2, 2, 2, 2)
  > y <- c(rnorm(100), 1, 1, 1, 1, 1)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=NA))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=TRUE))
  > res4 <- row_wilcoxon_paired(x, y, exact=FALSE)
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res3, res4))
  > 
  > # 10 samples with 1 zero (zeroes: exact = FALSE)
  > x <- c(rnorm(9), 2)
  > y <- c(rnorm(9), 1)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=NA))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res4 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=FALSE))
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$obs.paired, 9))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res3, res4))
  > 
  > # 105 samples with 5 zeroes (zeroes: exact = FALSE)
  > x <- c(rnorm(100), 2, 2, 2, 2, 2)
  > y <- c(rnorm(100), 1, 1, 1, 1, 1)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=NA))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res4 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=FALSE))
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$obs.paired, 100))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res3, res4))
  > 
  > # 11 samples with one zero and one tie (zeroes or ties: exact = FALSE)
  > x <- c(rnorm(8), 2, 2, 3)
  > y <- c(rnorm(8), 4, 4, 2)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=NA))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res4 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=FALSE))
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$obs.paired, 10))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res3, res4))
  > 
  > # 110 samples with 5 zeroes and 5 ties
  > x <- c(rnorm(100), 2,2,2,2,2, 3,3,3,3,3)
  > y <- c(rnorm(100), 4,4,4,4,4, 2,2,2,2,2)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=NA))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=TRUE))
  > res4 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=FALSE))
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$obs.paired, 105))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > stopifnot(all.equal(res3, res4))
  > 
  > 
  > # big sample size so exact=FALSE (exact = FALSE: correct can be specified)
  > x <- rnorm(100)
  > y <- rnorm(100)
  > res1 <- base_wilcoxon_paired(x, y, correct=FALSE)
  > res2 <- row_wilcoxon_paired(x, y, exact=NA, correct=FALSE)
  > res3 <- row_wilcoxon_paired(x, y, exact=FALSE, correct=FALSE)
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$corrected, FALSE))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # big sample size, exact is turned on but exact=FALSE because of ties (exact = FALSE: correct can be specified)
  > x <- c(rnorm(100), 2, 2, 3)
  > y <- c(rnorm(100), 4, 4, 2)
  > res1 <- suppressWarnings(base_wilcoxon_paired(x, y, null=1, exact=TRUE, correct=FALSE))
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=NA, correct=FALSE))
  > res3 <- suppressWarnings(row_wilcoxon_paired(x, y, null=1, exact=TRUE, correct=FALSE))
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$corrected, FALSE))
  > stopifnot(all.equal(res1, res2))
  > stopifnot(all.equal(res2, res3))
  > 
  > # small sample size but exact is turned off (exact = FALSE: correct can be specified)
  > x <- rnorm(20)
  > y <- rnorm(20)
  > res1 <- base_wilcoxon_paired(x, y, exact=FALSE, correct=FALSE)
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=FALSE, correct=FALSE))
  > stopifnot(all.equal(res2$exact, FALSE))
  > stopifnot(all.equal(res2$corrected, FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > # big sample size with exact=TRUE (exact = TRUE: correct turned to FALSE)
  > x <- rnorm(100)
  > y <- rnorm(100)
  > res1 <- base_wilcoxon_paired(x, y, exact=TRUE, correct=TRUE)
  > res2 <- row_wilcoxon_paired(x, y, exact=TRUE, correct=TRUE)
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res2$corrected, FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > # big sample size but NAs make it less than 50 so exact is turned on (exact = TRUE: correct turned to FALSE)
  > x <- rnorm(51)
  > y <- c(rnorm(49), NaN, NA)
  > res1 <- base_wilcoxon_paired(x, y, correct=TRUE)
  > res2 <- row_wilcoxon_paired(x, y, correct=TRUE)
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res2$corrected, FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > # small sample size and exact is left as NA (exact = TRUE: correct turned to FALSE)
  > x <- rnorm(20)
  > y <- rnorm(20)
  > res1 <- base_wilcoxon_paired(x, y, exact=NA, correct=TRUE)
  > res2 <- suppressWarnings(row_wilcoxon_paired(x, y, exact=NA, correct=TRUE))
  > stopifnot(all.equal(res2$exact, TRUE))
  > stopifnot(all.equal(res2$corrected, FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > proc.time()
     user  system elapsed 
     2.75    0.17    2.87 
Running the tests in 'tests/wilcoxon_paired_warnings.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- hes less than 1 paired observation ----------------------------------------
  > 
  > wrn <- 'row_wilcoxon_paired: 1 of the rows had less than 1 paired observation.\nFirst occurrence at row 1'
  > nacolumns <- c("statistic", "pvalue")
  > 
  > # no observations
  > res <- capture(row_wilcoxon_paired(numeric(), numeric()))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.paired, 0))
  > 
  > # x only has NAs
  > res <- capture(row_wilcoxon_paired(c(NA, NaN, NA), 1:3))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 3))
  > stopifnot(all.equal(res$value$obs.paired, 0))
  > 
  > # y only has NAs
  > res <- capture(row_wilcoxon_paired(1:3, c(NA, NaN, NA)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 3))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.paired, 0))
  > 
  > # both x and y only NA observations
  > res <- capture(row_wilcoxon_paired(c(NA,NaN,NA), c(NA, NA, NaN)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 0))
  > stopifnot(all.equal(res$value$obs.y, 0))
  > stopifnot(all.equal(res$value$obs.paired, 0))
  > 
  > # no common complete observations
  > res <- capture(row_wilcoxon_paired(c(1, NA, 3, NA), c(NA, 2, NA, 4)))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all(is.na(res$value[,nacolumns])))
  > stopifnot(all.equal(res$value$obs.x, 2))
  > stopifnot(all.equal(res$value$obs.y, 2))
  > stopifnot(all.equal(res$value$obs.paired, 0))
  > 
  > 
  > #--- ties are present ----------------------------------------------------------
  > 
  > wrn <- 'row_wilcoxon_paired: 1 of the rows had ties: cannot compute exact p-values with ties.\nFirst occurrence at row 1'
  > 
  > # warning when exact=TRUE
  > res <- capture(row_wilcoxon_paired(c(3,3,1,2), c(2,2,5,-2), exact=TRUE))
  > stopifnot(all.equal(res$warning, wrn))
  > stopifnot(all.equal(res$value$obs.x, 4))
  > stopifnot(all.equal(res$value$obs.y, 4))
  > stopifnot(all.equal(res$value$obs.paired, 4))
  > 
  > # no warning when exact=FALSE
  > res <- capture(row_wilcoxon_paired(c(3,3,1,2), c(2,2,5,-2), exact=FALSE))
  > stopifnot(all.equal(res$warning, NULL))
  > stopifnot(all.equal(res$value$obs.x, 4))
  > stopifnot(all.equal(res$value$obs.y, 4))
  > stopifnot(all.equal(res$value$obs.paired, 4))
  > 
  > 
  > #--- warning about zero values -------------------------------------------------
  > 
  > wrn1 <- 'row_wilcoxon_paired: 1 of the rows had observations with "x-y" equal "null" that were removed.\nFirst occurrence at row 1'
  > wrn2 <- 'row_wilcoxon_paired: 1 of the rows had zeroes: cannot compute exact p-values with zeroes.\nFirst occurrence at row 1'
  > 
  > # warning when exact = TRUE
  > res <- capture(row_wilcoxon_paired(1:4, c(0,2,4,3), null=1, exact=TRUE))
  > stopifnot(all.equal(res$warning, c(wrn1, wrn2)))
  > stopifnot(all.equal(res$value$obs.x, 4))
  > stopifnot(all.equal(res$value$obs.y, 4))
  > stopifnot(all.equal(res$value$obs.paired, 2))
  > 
  > # no warning when exact = FALSE
  > res <- capture(row_wilcoxon_paired(1:4, c(0,2,4,3), null=1, exact=FALSE))
  > stopifnot(all.equal(res$warning, wrn1))
  > stopifnot(all.equal(res$value$obs.x, 4))
  > stopifnot(all.equal(res$value$obs.y, 4))
  > stopifnot(all.equal(res$value$obs.paired, 2))
  > 
  > # if both ties and zeroes are presnet - only warn about zero
  > res <- capture(row_wilcoxon_paired(1:5, c(1,1,2,9,9), exact=TRUE))
  > stopifnot(all.equal(res$warning, c(wrn1, wrn2)))
  > stopifnot(all.equal(res$value$exact, FALSE))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.34    0.03    0.32 
Running the tests in 'tests/wilcoxon_twosample_behaviour.r' failed.
Complete output:
  > library(matrixTests)
  > 
  > #--- special argument cases ----------------------------------------------------
  > 
  > # x and y can be vectors
  > x <- rnorm(9)
  > y <- rnorm(9)
  > X <- matrix(x, nrow=1)
  > Y <- matrix(y, nrow=1)
  > stopifnot(all.equal(row_wilcoxon_twosample(x, y), row_wilcoxon_twosample(X, Y)))
  > 
  > # x and y can be numeric data frames
  > x <- iris[1:50,1:4]
  > y <- iris[51:100,1:4]
  > X <- as.matrix(x)
  > Y <- as.matrix(y)
  > stopifnot(all.equal(suppressWarnings(row_wilcoxon_twosample(x, y)), suppressWarnings(row_wilcoxon_twosample(X, Y))))
  > 
  > # x and y can have 0 rows
  > x <- matrix(0, nrow=0, ncol=4)
  > y <- matrix(0, nrow=0, ncol=4)
  > stopifnot(all.equal(nrow(row_wilcoxon_twosample(x, y)), 0))
  > 
  > # x and y can have 0 rows and 0 columns
  > x <- matrix(0, nrow=0, ncol=0)
  > y <- matrix(0, nrow=0, ncol=0)
  > stopifnot(all.equal(nrow(row_wilcoxon_twosample(x, y)), 0))
  > 
  > # alternative values can be partially completed
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_wilcoxon_twosample(x, y, alternative="greater"), row_wilcoxon_twosample(x, y, alternative="g")))
  > 
  > # exact can be NA
  > x <- rnorm(5)
  > y <- rnorm(5)
  > stopifnot(all.equal(row_wilcoxon_twosample(x, y, exact=NA), row_wilcoxon_twosample(x, y, exact=TRUE)))
  > 
  > # TODO: investigate if null can be allowed Inf values.
  > 
  > 
  > #--- recycling -----------------------------------------------------------------
  > 
  > # y can be a vector when x is a matrix
  > x <- matrix(rnorm(10), nrow=2)
  > y <- 1:5
  > res1 <- row_wilcoxon_twosample(x, y)
  > res2 <- row_wilcoxon_twosample(x, rbind(y,y))
  > stopifnot(all.equal(res1, res2))
  > 
  > # null can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_twosample(x, y, null=2)
  > res2 <- row_wilcoxon_twosample(x, y, null=c(2,2))
  > stopifnot(all.equal(res1, res2))
  > 
  > # alternative can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_twosample(x, y, alternative="g")
  > res2 <- row_wilcoxon_twosample(x, y, alternative=c("g","g"))
  > stopifnot(all.equal(res1, res2))
  > 
  > # exact can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_twosample(x, y, exact=TRUE)
  > res2 <- row_wilcoxon_twosample(x, y, exact=c(TRUE, TRUE))
  > stopifnot(all.equal(res1, res2))
  > 
  > # correct can be specified for each row
  > x <- matrix(rnorm(10), nrow=2)
  > y <- matrix(rnorm(10), nrow=2)
  > res1 <- row_wilcoxon_twosample(x, y, exact=FALSE, correct=FALSE)
  > res2 <- row_wilcoxon_twosample(x, y, exact=FALSE, correct=c(FALSE, FALSE))
  > stopifnot(all.equal(res1, res2))
  > 
  > 
  > #--- missing values ------------------------------------------------------------
  > 
  > # missing values in x are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- rnorm(10)
  > res1 <- row_wilcoxon_twosample(x, y)
  > res2 <- row_wilcoxon_twosample(x[!is.na(x)], y)
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values in y are removed
  > x <- rnorm(10)
  > y <- c(NA,NA,rnorm(7),NA)
  > res1 <- row_wilcoxon_twosample(x, y)
  > res2 <- row_wilcoxon_twosample(x, y[!is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # missing values from both x and y are removed
  > x <- c(NA,NA,rnorm(7),NA)
  > y <- c(NA,rnorm(7),NA,NA)
  > res1 <- row_wilcoxon_twosample(x, y)
  > res2 <- row_wilcoxon_twosample(x[!is.na(x)], y[!is.na(y)])
  > stopifnot(all.equal(res1, res2))
  > 
  > # no difference between NA and NaN
  > x1 <- c(NA,NA,1,2,7:3,NA)
  > x2 <- c(NaN,NaN,1,2,7:3,NaN)
  > y1 <- c(NA,NA,18:12,NA)
  > y2 <- c(NaN,NaN,18:12,NaN)
  > res1 <- row_wilcoxon_twosample(x1, y1)
  > res2 <- row_wilcoxon_twosample(x2, y2)
  > stopifnot(all.equal(res1, res2))
  > 
  > # everything can be NA
  > x <- rep(NA_integer_, 4)
  > y <- rep(NA_integer_, 4)
  > res <- suppressWarnings(row_wilcoxon_twosample(x, y))
  > stopifnot(all.equal(res$obs.tot, 0))
  > 
  > 
  > #--- rownames ------------------------------------------------------------------
  > 
  > # when not provided - numbers are used instead.
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_wilcoxon_twosample(x, y)
  > stopifnot(all.equal(rownames(res), c("1", "2")))
  > 
  > # when not provided - not taken from y
  > x <- matrix(rnorm(20), nrow=2)
  > y <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > res <- row_wilcoxon_twosample(x, y)
  > stopifnot(all.equal(rownames(res), c("1","2")))
  > 
  > # when provided - preserved (matrix)
  > x <- matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B")))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_wilcoxon_twosample(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when provided - preserved (data.frame)
  > x <- data.frame(matrix(rnorm(20), nrow=2, dimnames=list(c("A", "B"))))
  > y <- matrix(rnorm(20), nrow=2)
  > res <- row_wilcoxon_twosample(x, y)
  > stopifnot(all.equal(rownames(res), rownames(x)))
  > 
  > # when duplicated - made unique
  > x <- matrix(rnorm(20), nrow=4, dimnames=list(c("A", "A", "B", "B")))
  > y <- matrix(rnorm(20), nrow=4)
  > res <- row_wilcoxon_twosample(x, y)
  > stopifnot(all.equal(rownames(res), make.unique(rownames(x))))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.17    0.07    0.23 
Running the tests in 'tests/wilcoxon_twosample_errors.r' failed.
Complete output:
  > library(matrixTests)
  > source("utils/capture.r")
  > 
  > #--- x argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "x" is missing, with no default'
  > res <- capture(row_wilcoxon_twosample())
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(NULL, 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(c("1", "2"), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(c(TRUE, FALSE), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(complex(c(1,2), c(3,4)), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(iris, 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(as.list(c(1:5)), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"x" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(list(1:5), 1:2))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- y argument errors ---------------------------------------------------------
  > 
  > # cannot be missing
  > err <- 'argument "y" is missing, with no default'
  > res <- capture(row_wilcoxon_twosample(1))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NULL
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(1, NULL))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(1:2, c("1","2")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be logical
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(1:2, c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(1:2, complex(c(1,2), c(3,4))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be data.frame containing some non numeric data
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(1:2, iris))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a list
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(1:2, as.list(c(1:5))))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > err <- '"y" must be a numeric matrix or vector'
  > res <- capture(row_wilcoxon_twosample(1:2, list(1:5)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- alternative argument errors -----------------------------------------------
  > 
  > err <- '"alternative" must be a character vector with length 1 or nrow(x)'
  > 
  > # cannot be NA
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=2:4, alternative=NA))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be numeric
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=2:4, alternative=1))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=2:4, alternative=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=2:4, alternative=list("less")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=2:4, alternative=data.frame("less")))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- 'all "alternative" values must be in: two.sided, less, greater'
  > 
  > # must be in correct set
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=2:4, alternative="ga"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # error produced even when some are correct
  > res <- capture(row_wilcoxon_twosample(x=matrix(1:10, nrow=2), y=matrix(1:10, nrow=2), alternative=c("g","c")))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- null argument errors ------------------------------------------------------
  > 
  > err <- '"null" must be a numeric vector with length 1 or nrow(x)'
  > 
  > # cannot be a character
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null="1"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null=list(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null=data.frame(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- 'all "null" values must be greater than -Inf and lower than Inf'
  > 
  > # cannot be NA
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null=NA_integer_))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be NaN
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null=NaN))
  > stopifnot(all.equal(res$error, err))
  > 
  > # TODO: check if can be made to work with Inf
  > # cannot be Inf
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null=Inf))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be -Inf
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, null=-Inf))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- exact argument errors -----------------------------------------------------
  > 
  > err <- '"exact" must be a logical vector with length 1 or nrow(x)'
  > 
  > # cannot be non-logical NA
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, exact=NA_integer_))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be numeric
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, exact=1))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, exact="TRUE"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, exact=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, exact=list(TRUE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, exact=data.frame(TRUE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- correct argument errors ---------------------------------------------------
  > 
  > err <- 'all "correct" values must be in: TRUE, FALSE'
  > 
  > # cannot be NA
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, correct=NA))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > err <- '"correct" must be a logical vector with length 1 or nrow(x)'
  > 
  > # cannot be numeric
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, correct=0))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be character
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, correct="FALSE"))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be complex
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, correct=complex(1)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be in a list
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, correct=list(FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # cannot be a data frame
  > res <- capture(row_wilcoxon_twosample(x=1:3, y=1:3, correct=data.frame(FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > #--- dimension mismatch errors -------------------------------------------------
  > 
  > # y number of rows must match x number of rows
  > err <- '"x" and "y" must have the same number of rows'
  > x <- matrix(1:10, nrow=2)
  > y <- matrix(1:10, nrow=5)
  > res <- capture(row_wilcoxon_twosample(x, y))
  > stopifnot(all.equal(res$error, err))
  > 
  > # null must match x number of rows
  > err <- '"null" must be a numeric vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > y <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_twosample(x, y, null=c(1,2)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # alternative must match x number of rows
  > err <- '"alternative" must be a character vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > y <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_twosample(x, y, alternative=c("g","l")))
  > stopifnot(all.equal(res$error, err))
  > 
  > # exact must match x number of rows
  > err <- '"exact" must be a logical vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > y <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_twosample(x, y, exact=c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > # correct must match x number of rows
  > err <- '"correct" must be a logical vector with length 1 or nrow(x)'
  > x <- matrix(1:12, nrow=4)
  > y <- matrix(1:12, nrow=4)
  > res <- capture(row_wilcoxon_twosample(x, y, correct=c(TRUE, FALSE)))
  > stopifnot(all.equal(res$error, err))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.09    0.28