From 137592f7a06b4c9edaa45792878e1010be8ca07a Mon Sep 17 00:00:00 2001 From: moralapablo Date: Wed, 20 Nov 2024 12:14:58 +0100 Subject: [PATCH] Added new test to check that eval_monomials and eval_poly are consistent with each other --- tests/testthat/test-eval_monomials.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/testthat/test-eval_monomials.R b/tests/testthat/test-eval_monomials.R index 0f101be..4d4ec11 100644 --- a/tests/testthat/test-eval_monomials.R +++ b/tests/testthat/test-eval_monomials.R @@ -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) + +})