Skip to content

Commit

Permalink
Added new test to check that eval_monomials and eval_poly are consist…
Browse files Browse the repository at this point in the history
…ent with each other
  • Loading branch information
moralapablo committed Nov 20, 2024
1 parent 893c4ae commit 137592f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/testthat/test-eval_monomials.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,23 @@ test_that("(Monomials) Multiple polynomial evaluation and multiple observations

expect_equal(eval_monomials(poly, newdata), aux_expected)
})


test_that("(Monomials) Check that adding the monomials gives the final poly prediction", {

# With intercept and unnordered labels
poly <- list()
poly$values <- matrix(c(1,-1,1,
2,3,-2), ncol = 2, byrow = FALSE)
poly$labels <- list(c(2),c(0),c(2,1))

newdata <- rbind(c(5,2), c(-1,5.4))

A <- eval_poly(poly, newdata)
B <- eval_monomials(poly, newdata)

C <- cbind(rowSums(B[,,1]), rowSums(B[,,2]))

expect_equal(A, C)

})

0 comments on commit 137592f

Please sign in to comment.