Permalink
Browse files

Add tests for finite.cases()

  • Loading branch information...
wch committed Oct 24, 2012
1 parent f4f59c5 commit 909ff1e90da481e981d16a4e92ce53613a9ca3dc
Showing with 22 additions and 0 deletions.
  1. +22 −0 inst/tests/test-utilities.r
@@ -0,0 +1,22 @@
+context("Utilities")
+
+test_that("finite.cases.data.frame", {
+ # All finite --------------------------------------------------------------
+ expect_identical(finite.cases(data.frame(x=4)), TRUE) # 1x1
+ expect_identical(finite.cases(data.frame(x=4, y=11)), TRUE) # 1x2
+ expect_identical(finite.cases(data.frame(x=4:5)), c(TRUE, TRUE)) # 2x1
+ expect_identical(finite.cases(data.frame(x=4:5, y=11:12)), c(TRUE, TRUE)) # 2x2
+
+ # Has one NA --------------------------------------------------------------
+ expect_identical(finite.cases(data.frame(x=NA)), FALSE) # 1x1
+ expect_identical(finite.cases(data.frame(x=4, y=NA)), FALSE) # 1x2
+ expect_identical(finite.cases(data.frame(x=c(4,NA))), c(TRUE, FALSE)) # 2x1
+ expect_identical(finite.cases(data.frame(x=c(4,NA), y=c(11,NA))), c(TRUE, FALSE)) # 2x2
+ expect_identical(finite.cases(data.frame(x=c(4,NA), y=c(NA,12))), c(FALSE, FALSE)) # 2x2
+ expect_identical(finite.cases(data.frame(x=c(4,5), y=c(NA,12))), c(FALSE, TRUE)) # 2x2
+
+ # Testing NaN and Inf, using miscellaneous data shapes --------------------
+ expect_identical(finite.cases(data.frame(x=c(4,NaN))), c(TRUE, FALSE))
+ expect_identical(finite.cases(data.frame(x=Inf)), FALSE)
+ expect_identical(finite.cases(data.frame(x=c(4,5), y=c(-Inf,12))), c(FALSE, TRUE))
+})

0 comments on commit 909ff1e

Please sign in to comment.