[Swift-commit] r3601 - SwiftApps/SwiftR/Swift/tests
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Sat Sep 4 19:47:13 CDT 2010
Author: wilde
Date: 2010-09-04 19:47:13 -0500 (Sat, 04 Sep 2010)
New Revision: 3601
Modified:
SwiftApps/SwiftR/Swift/tests/TestSwift.R
Log:
Considerable reworking of the tests, into their first really useful state.
Modified: SwiftApps/SwiftR/Swift/tests/TestSwift.R
===================================================================
--- SwiftApps/SwiftR/Swift/tests/TestSwift.R 2010-09-04 02:31:42 UTC (rev 3600)
+++ SwiftApps/SwiftR/Swift/tests/TestSwift.R 2010-09-05 00:47:13 UTC (rev 3601)
@@ -1,41 +1,284 @@
-require(boot)
-#source("Swift.R")
+
+##### Setup
+
require(Swift)
-sumcrits <- function(duckdata,dogdata) { sum( duckdata$plumage, dogdata$mvo ) }
+cat("\n*** Starting test group 1 - functions on simple data structures ***\n\n")
-args=list(ducks,dogs)
-arglist = rep(list(args),9)
+##### Test 1.1
-###
-require("boot")
-sumcrits <- function(duckdata,dogdata) { sum( duckdata$plumage, dogdata$mvo ) }
+cat("\n*** Starting test 1.1 ***\n\n")
-args=list(ducks,dogs)
-arglist = rep(list(args),9)
-res = swiftapply(sumcrits,arglist)
+sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
+data(cars)
+data(trees)
-res = swiftapply(sumcrits,arglist,callsperbatch=10)
+args=list(trees,cars)
+arglist = rep(list(args),1)
-res = swiftapply(sumcrits,arglist,callsperbatch=2)
+cat("Test of local do.call(sumstuff)\n")
+localres = do.call(sumstuff,args)
+cat("local result=\n")
+print(localres)
-res = swiftapply(sumcrits,arglist,callsperbatch=3)
+cat("\nTest of swiftapply(sumstuff,arglist)\n")
+swiftres = swiftapply(sumstuff,arglist)
+cat("Swift result:\n")
+print(swiftres)
-# res = swiftapply(sumcrits,arglist,callsperbatch=2,site="pbs")
-###
+if(identical(localres,swiftres[[1]])) {
+ cat("\n==> test 1.1 passed\n")
+} else {
+ cat("\n==> test 1.1 FAILED !!!!!\n")
+}
-if(TRUE) { # Basic tests
+##### Test 1.2
- res = do.call(sumcrits,args)
- cat("Test of do.call(sumcrits)\n")
- print(res)
+# test 10 remote calls
- cat("\nTest of swiftapply(sumcrits,arglist)\n")
- res = swiftapply(sumcrits,arglist)
- print(res)
+sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
+data(cars)
+data(trees)
+
+args=list(trees,cars)
+arglist <- rep(list(args),10)
+
+cat("\n*** Test 1.2.1: 10 calls to substuff()\n")
+swiftres <- swiftapply(sumstuff,arglist)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !identical(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,swiftres[[i]]))
+ }
}
+if(diffs == 0) {
+ cat("\n==> test 1.2.1 passed\n")
+} else {
+ cat("\n!!!==> test 1.2.1 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+cat("\n*** Test 1.2.2: 10 calls to substuff() - callsperbatch=10\n")
+swiftres = swiftapply(sumstuff,arglist,callsperbatch=10)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !identical(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,swiftres[[i]]))
+ }
+}
+
+if(diffs == 0) {
+ cat("\n==> test 1.2.2 passed\n")
+} else {
+ cat("\n!!!==> test 1.2.2 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+cat("\n*** Test 1.2.3: 10 calls to substuff() - callsperbatch=2\n")
+swiftres = swiftapply(sumstuff,arglist,callsperbatch=2)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !identical(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,swiftres[[i]]))
+ }
+}
+
+if(diffs == 0) {
+ cat("\n==> test 1.2.3 passed\n")
+} else {
+ cat("\n!!!==> test 1.2.3 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+cat("\n*** Test 1.2.4: 10 calls to substuff() - callsperbatch=3\n")
+swiftres = swiftapply(sumstuff,arglist,callsperbatch=3)
+swiftres <- swiftapply(sumstuff,arglist)
+cat("Swift result:\n")
+format(swiftres)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !identical(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,swiftres[[i]]))
+ }
+}
+
+if(diffs == 0) {
+ cat("\n==> test 1.2.4 passed\n")
+} else {
+ cat("\n!!!==> test 1.2.4 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+# swiftres = swiftapply(sumstuff,arglist,callsperbatch=2,site="pbs")
+# test variations on local vs ssh vs pbs; coasters vs non; etc.
+
+
+
+##### Test Group 2
+
+cat("\n*** Starting test group 2 - test matrix passing***\n")
+
+matfunc <- function( m1, m2 )
+{
+ (1/m1) %*% m2
+}
+
+n <- 5
+m1 <- array(sin(1:n**2), dim=c(n,n))
+m2 <- t(m1)
+
+localres = matfunc(m1,m2)
+
+cat("\n*** Test 2.1: 100 calls to matfunc(dim=5x5) - callsperbatch=9\n")
+
+args=list(m1,m2)
+arglist <- rep(list(args),100)
+
+swiftres = swiftapply(matfunc,arglist,callsperbatch=9)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !all.equal(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,format(swiftres[[i]])))
+ }
+}
+
+if(diffs == 0) {
+ cat("\n==> test 2.1 passed\n")
+} else {
+ cat("\n!!!==> test 2.2 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+n <- 237
+m1 <- array(sin(1:n**2), dim=c(n,n))
+m2 <- t(m1)
+
+localres = matfunc(m1,m2)
+
+cat("\n*** Test 2.2: 123 calls to matfunc(dim=500x500) - callsperbatch=7\n")
+
+args=list(m1,m2)
+arglist <- rep(list(args),123)
+
+swiftres = swiftapply(matfunc,arglist,callsperbatch=7)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !all.equal(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,format(swiftres[[i]])))
+ }
+}
+
+if(diffs == 0) {
+ cat("\n==> test 2.2 passed\n")
+} else {
+ cat("\n!!!==> test 2.2 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+
+##### Test Group 3
+
+cat("\n*** Starting test group 3 - test list element and name passing***\n")
+
+# Test if list element names are being sent and returned correctly
+
+n <- 5
+m1 <- array(sin(1:n**2), dim=c(n,n))
+m2 <- t(m1)
+
+inlist = list()
+inlist[[1]]=123
+inlist[[2]]=456
+inlist$name1=789
+inlist$name2=987
+inlist$mat1 = m1
+inlist[[99]] = m2
+
+listfunc <- function(ilist)
+{
+ olist = ilist
+ olist$sum = ilist[[1]] + ilist[[2]] + ilist$name1 + ilist$name2
+ olist$names = names(ilist)
+ olist$mprod = ilist$mat1 %*% ilist[[99]]
+ return(olist)
+}
+localres = listfunc(inlist)
+
+cat("\n*** Starting test 3.1 - 4 calls in one batch of 5 ***\n")
+
+args=list(inlist)
+arglist <- rep(list(args),4)
+
+swiftres = swiftapply(listfunc,arglist,callsperbatch=5)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !all.equal(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,format(swiftres[[i]])))
+ }
+}
+
+if(diffs == 0) {
+ cat("\n==> test 3.1 passed\n")
+} else {
+ cat("\n!!!==> test 3.1 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+cat("\n*** Starting test 3.2 - 99 calls in batches of 11 ***\n")
+
+args=list(inlist)
+arglist <- rep(list(args),99)
+
+swiftres = swiftapply(listfunc,arglist,callsperbatch=11)
+
+diffs <- 0
+for(i in 1:length(swiftres) ) {
+ if( !all.equal(swiftres[[i]],localres) ) {
+ diffs <- diffs + 1
+ if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i,format(swiftres[[i]])))
+ }
+}
+
+if(diffs == 0) {
+ cat("\n==> test 3.2 passed\n")
+} else {
+ cat("\n!!!==> test 3.2 failed.\n")
+ cat(sprintf(" %d result elements failed to match.\n",diffs));
+ failures=failures+1
+}
+
+
+
+
if(FALSE) { # Test various batch sizes
cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=10)\n")
More information about the Swift-commit
mailing list