| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
compare <- function(td1, td2, tolerance=100) { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
if (!is(td1, "RUnitTestData")) { |
| 37 |
stop("argument 'td1' has to be of class 'RUnitTestData'.") |
| 38 |
} |
| 39 |
if (!is(td2, "RUnitTestData")) { |
| 40 |
stop("argument 'td2' has to be of class 'RUnitTestData'.") |
| 41 |
} |
| 42 |
if (length(tolerance) != 1 || is.na(tolerance) || tolerance < 0) { |
| 43 |
stop("argument 'tolerance' has to be positive scalar.") |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
commonNames <- function(x1, x2) { |
| 48 |
return(intersect(names(x1), names(x2))) |
| 49 |
} |
| 50 |
compareTiming <- function(x1, x2, tol=0) { |
| 51 |
d <- x1 - x2 |
| 52 |
if (abs(d) > tol) { |
| 53 |
return(d) |
| 54 |
} else { |
| 55 |
return(as.numeric(0)) |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
comparePerSourceFile <- function(sf1,sf2, tol=0) { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
if (length(sf1) == 0 | length(sf2) == 0) { |
| 66 |
cat("\n skipped empty result set:", sf1) |
| 67 |
return(NULL) |
| 68 |
} |
| 69 |
commonTests <- commonNames(sf1, sf2) |
| 70 |
t(sapply(commonTests, function(x, obj1, obj2) { |
| 71 |
|
| 72 |
|
| 73 |
if(obj1[[x]][["kind"]] == obj2[[x]][["kind"]]) { |
| 74 |
if (obj1[[x]][["kind"]] == "success") { |
| 75 |
return(c(x, obj1[[x]][["kind"]], obj1[[x]][["time"]], |
| 76 |
obj2[[x]][["kind"]], obj2[[x]][["time"]], |
| 77 |
compareTiming(obj1[[x]][["time"]], |
| 78 |
obj2[[x]][["time"]], |
| 79 |
tol=tol))) |
| 80 |
} else { |
| 81 |
return(c(x, obj1[[x]][["kind"]], as.numeric(NA), |
| 82 |
obj2[[x]][["kind"]], as.numeric(NA), as.numeric(NA))) |
| 83 |
} |
| 84 |
} else { |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
return(c(x, obj1[[x]][["kind"]], as.numeric(NA), |
| 89 |
obj2[[x]][["kind"]], as.numeric(NA), as.numeric(NA))) |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
}, obj1=sf1, obj2=sf2)) |
| 94 |
} |
| 95 |
|
| 96 |
comparePerSuite <- function(s1,s2, tol=0) { |
| 97 |
|
| 98 |
commonFiles <- intersect(basename(names(s1[["sourceFileResults"]])), |
| 99 |
basename(names(s2[["sourceFileResults"]]))) |
| 100 |
do.call("rbind", sapply(commonFiles, function(x, obj1, obj2) { |
| 101 |
|
| 102 |
idx1 <- match(x, basename(names(obj1))) |
| 103 |
idx2 <- match(x, basename(names(obj2))) |
| 104 |
if (length(idx1) != 1 || is.na(idx1) || length(idx2) != 1 || is.na(idx2)) { |
| 105 |
stop("ambiguous file name.") |
| 106 |
next; |
| 107 |
} |
| 108 |
comparePerSourceFile(obj1[[idx1]], obj2[[idx2]], tol=tol) |
| 109 |
}, obj1=s1[["sourceFileResults"]], obj2=s2[["sourceFileResults"]]) ) |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
commonTestSuites <- commonNames(td1, td2) |
| 117 |
|
| 118 |
res <- matrix(ncol=6, nrow=0) |
| 119 |
colnames(res) <- c("TestCase", "Suite1 State", "Suite1 Timing", "Suite2 State", "Suite2 Timing", "Delta") |
| 120 |
for (ti in seq_along(commonTestSuites)) { |
| 121 |
res <- rbind(res, comparePerSuite(td1[[commonTestSuites[ti]]], td2[[commonTestSuites[ti]]], |
| 122 |
tol=tolerance)) |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
return(res) |
| 127 |
} |
| 128 |
|