1### runit.nPairs.R 2###------------------------------------------------------------------------ 3### What: Number of variable pairs - unit tests 4### $Id$ 5### Time-stamp: <2008-12-30 18:24:59 ggorjan> 6###------------------------------------------------------------------------ 7 8### {{{ --- Test setup --- 9 10if(FALSE) { 11 library("RUnit") 12 library("gdata") 13} 14 15### }}} 16### {{{ --- nPairs --- 17 18test.nPairs <- function() 19{ 20 ## 'x' must be a data.frame or a matrix 21 x <- rpois(100, lambda=10) 22 checkException(nPairs(x=x)) 23 checkException(nPairs(x=table(x))) 24 25 test <- data.frame(V1=c(1, 2, 3, 4, 5), 26 V2=c(NA, 2, 3, 4, 5), 27 V3=c(1, NA, NA, NA, NA), 28 V4=c(1, 2, 3, NA, NA)) 29 testCheck <- matrix(data=as.integer(c(5, 4, 1, 3, 30 4, 4, 0, 2, 31 1, 0, 1, 1, 32 3, 2, 1, 3)), 33 nrow=4, ncol=4, byrow=TRUE) 34 class(testCheck) <- c("nPairs", class(testCheck)) 35 36 testCheckNames <- testCheck 37 colnames(testCheckNames) <- rownames(testCheckNames) <- colnames(test) 38 39 checkIdentical(nPairs(x=test), testCheckNames) 40 checkIdentical(nPairs(x=test, names=FALSE), testCheck) 41 checkIdentical(nPairs(x=as.matrix(test)), testCheckNames) 42 checkIdentical(nPairs(x=as.matrix(test), names=FALSE), testCheck) 43 44 testCheck <- cbind(testCheckNames, as.integer(c(5, 4, 0, 0))) 45 class(testCheck) <- class(testCheckNames) 46 colnames(testCheck) <- c(colnames(test), "all") 47 checkIdentical(nPairs(x=test, margin=TRUE), testCheck) 48 49 testCheckSumm <- matrix(data=as.integer(c(0, 1, 4, 2, 50 0, 0, 4, 2, 51 0, 1, 0, 0, 52 0, 1, 2, 0)), 53 nrow=4, ncol=4, byrow=TRUE) 54 dimnames(testCheckSumm) <- dimnames(testCheckNames) 55 tmp <- summary(nPairs(x=test)) 56 checkEquals(tmp, testCheckSumm) 57} 58 59 60### }}} 61### {{{ Dear Emacs 62### Local variables: 63### folded-file: t 64### end: 65### }}} 66 67###------------------------------------------------------------------------ 68### runit.nPairs.R ends here 69