Skip to content

Commit

Permalink
expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Sep 9, 2024
1 parent 3edf7d2 commit d074679
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions cpp11eigentest/tests/testthat/test-typedefs.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,70 @@
test_that("elemental tests for vectors", {
x <- c(1.0, 2.0, 3.0)
expect_equal(x, typedef_Col_double(x))

x[1] <- NA
expect_equal(x, typedef_Col_double(x))

x[1] <- NaN
expect_equal(x, typedef_Col_double(x))

x[1] <- Inf
expect_equal(x, typedef_Col_double(x))

x[1] <- -Inf
expect_equal(x, typedef_Col_double(x))

y <- c(1L, 2L, 3L)
expect_equal(y, typedef_Col_int(y))

y[1] <- NA
expect_equal(y, typedef_Col_int(y))

y[1] <- NaN
expect_error(typedef_Col_int(y), "expected 'integer' actual 'double'")
expect_equal(y, typedef_Col_double(y))

y[1] <- Inf
expect_error(typedef_Col_int(y), "expected 'integer' actual 'double'")
expect_equal(y, typedef_Col_double(y))

y[1] <- -Inf
expect_error(typedef_Col_int(y), "expected 'integer' actual 'double'")
expect_equal(y, typedef_Col_double(y))
})

test_that("elemental tests for matrices", {
set.seed(1234)
x <- matrix(rnorm(4), nrow = 2)
expect_equal(x, typedef_Mat_double(x))

x[1,1] <- NA
expect_equal(x, typedef_Mat_double(x))

x[1,1] <- NaN
expect_equal(x, typedef_Mat_double(x))

x[1,1] <- Inf
expect_equal(x, typedef_Mat_double(x))

x[1,1] <- -Inf
expect_equal(x, typedef_Mat_double(x))

y <- matrix(rpois(4,1), nrow = 2)
expect_equal(y, typedef_Mat_int(y))

y[1,1] <- NA
expect_equal(y, typedef_Mat_int(y))

y[1,1] <- NaN
expect_error(typedef_Mat_int(y), "expected 'integer' actual 'double'")
expect_equal(y, typedef_Mat_double(y))

y[1,1] <- Inf
expect_error(typedef_Mat_int(y), "expected 'integer' actual 'double'")
expect_equal(y, typedef_Mat_double(y))

y[1,1] <- -Inf
expect_error(typedef_Mat_int(y), "expected 'integer' actual 'double'")
expect_equal(y, typedef_Mat_double(y))
})

0 comments on commit d074679

Please sign in to comment.