You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2008/06/08 17:29:46 UTC
svn commit: r664513 -
/commons/proper/math/branches/MATH_2_0/src/test/R/testFunctions
Author: psteitz
Date: Sun Jun 8 08:29:46 2008
New Revision: 664513
URL: http://svn.apache.org/viewvc?rev=664513&view=rev
Log:
Support NaN, na, NULL values in assertEquals.
Modified:
commons/proper/math/branches/MATH_2_0/src/test/R/testFunctions
Modified: commons/proper/math/branches/MATH_2_0/src/test/R/testFunctions
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/R/testFunctions?rev=664513&r1=664512&r2=664513&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/R/testFunctions (original)
+++ commons/proper/math/branches/MATH_2_0/src/test/R/testFunctions Sun Jun 8 08:29:46 2008
@@ -30,19 +30,37 @@
# 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