Support NaN, na, NULL values in assertEquals.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@664513 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2b8b57d394
commit
78cb3a131d
|
@ -30,19 +30,37 @@ options(digits=12) # display 12 digits throughout
|
|||
# Tests to see if <expected> and <observed> are within <tol> of
|
||||
# one another in the sup norm.
|
||||
#
|
||||
# Returns 1 if no pair of corresponding entries differs by more than abs;
|
||||
# Returns 1 if no pair of corresponding non-NULL, non-NaN, non-na entries
|
||||
# differs by more than abs and NULLs, NaNs, na's correspond;
|
||||
# otherwise displays <message> and returns 0.
|
||||
# Works for both vectors and scalar values.
|
||||
#
|
||||
assertEquals <- function(expected, observed, tol, message) {
|
||||
if(any(abs(expected - observed) > tol)) {
|
||||
failed <- 0
|
||||
if (any(is.na(observed) != is.na(expected))) {
|
||||
failed <- 1
|
||||
}
|
||||
if (any(is.null(observed) != is.null(expected))) {
|
||||
failed <- 1
|
||||
}
|
||||
if (any(is.nan(expected) != is.nan(observed))) {
|
||||
failed <- 1
|
||||
}
|
||||
if (any(is.na(expected) != is.na(observed))) {
|
||||
failed <- 1
|
||||
}
|
||||
if (!failed) {
|
||||
if(any(abs(observed - expected) > tol, na.rm = TRUE)) {
|
||||
failed <- 1
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
cat("FAILURE: ",message,"\n")
|
||||
cat("EXPECTED: ",expected,"\n")
|
||||
cat("OBSERVED: ",observed,"\n")
|
||||
return(0)
|
||||
} else {
|
||||
return(1)
|
||||
}
|
||||
cat("TOLERANCE: ",tol,"\n")
|
||||
}
|
||||
return(!failed)
|
||||
}
|
||||
#------------------------------------------------------------------------------
|
||||
# Display functions
|
||||
|
|
Loading…
Reference in New Issue