Skip to content

Commit aed009e

Browse files
test() distinguishes NA, NaN in vectors
1 parent 0ef8d1f commit aed009e

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

R/test.data.table.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ test = function(num, x, y=TRUE, ...,
666666
identical(vapply_1c(xc,typeof), vapply_1c(yc,typeof))) return(invisible(TRUE))
667667
}
668668
}
669-
if (is.atomic(x) && is.atomic(y) && isTRUE(all.equal.result<-all.equal(x,y,check.names=!isTRUE(y))) && typeof(x)==typeof(y)) return(invisible(TRUE))
669+
if (is.atomic(x) && is.atomic(y) && isTRUE(all.equal.result<-all.equal(x,y,check.names=!isTRUE(y))) && typeof(x)==typeof(y) && all(is.nan(x)==is.nan(y))) return(invisible(TRUE))
670670
# For test 617 on r-prerel-solaris-sparc on 7 Mar 2013
671671
# nocov start
672672
if (!fail) {
@@ -677,7 +677,7 @@ test = function(num, x, y=TRUE, ...,
677677
if (is.data.table(x)) compactprint(x) else {
678678
if (is.atomic(x) && is.atomic(y) && length(x) == length(y) && identical(dim(x), dim(y))) {
679679
total = length(x)
680-
diff_idx = which(x != y | xor(is.na(x), is.na(y))) # careful to only evaluate '!=' for atomic inputs; which: drop NA-NA
680+
diff_idx = which(x != y | xor(is.na(x), is.na(y)) | xor(is.nan(x), is.nan(y))) # careful to only evaluate '!=' for atomic inputs; which: drop NA-NA
681681
x = x[diff_idx]
682682
nn = length(x)
683683
names(x) = sprintf("%s[%d]", label, diff_idx)

inst/tests/self.Rraw

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ test(1.1, test(0, warning("a"), warning=c("a", "b"), check_value=FALSE), FALSE,
1212
output="Test 0 produced 1 warnings but expected 2\nExpected: a\n b\nObserved: a")
1313
test(1.2, test(0, {warning("a"); warning("b")}, warning="a", check_value=FALSE), FALSE,
1414
output="Test 0 produced 2 warnings but expected 1\nExpected: a\nObserved: a\n b")
15+
16+
# test() distinguishes NA and NaN, especially in vectors
17+
test(2.1, test(0, NA_real_, NaN), FALSE,
18+
output="First 1 different of 1 \\(1 total.*x.*NA.*First 1 different of 1.*y.*NaN")
19+
test(2.2, test(0, list(NA), list(NaN)), FALSE,
20+
output="x = list\\(NA\\).*y = list\\(NaN\\)")
21+
test(2.3, test(0, c(1, NA), c(1, NaN)), FALSE,
22+
output="First 1 different of 1 \\(2 total.*x.*NA.*First 1 different of 1.*y.*NaN")
23+
test(2.4, test(0, c(1, NA, NA, NaN, 2, 3), c(1, NA, NaN, NaN, NA, NaN)), FALSE,
24+
output="First 3 different of 3 \\(6 total.*NA.*2.*3.*First 3 different of 3.*NaN.*NA.*NaN")

0 commit comments

Comments
 (0)