tests/testthat/test_method_predict.R

context("method predict")

test_that("polyMatrix by number", {
  init_data()

  expect_equal(predict(pm_first, 0), matrix(c(1, 0, 3, 1, 2, 0, 0, 0, 1), 3, 3))
  expect_equal(predict(pm_first, 1), matrix(c(4, 4, 3, 5, 2, 6, 3, 0, 1), 3, 3))
  expect_equal(predict(pm_first, -1), matrix(c(2, -2, 3, 5, 2, 6, -3, 0, 1), 3, 3))
})

test_that("polyMatrix by polynomial", {
  init_data()

  expect_equal(predict(pm_first, p(1, 1)),
               parse.polyMatrix(
                 "   4 + 5x + 2x^2,    5 + 8x + 4x^2,   3 + 3x",
                 "    4 + 5x + x^2,                2,        0",
                 "               3,   6 + 12x + 6x^2,        1"
               ))
  predict(pm_first, p(1, 1))
})

test_that("char poly of polyMatrix", {
  expect_equal(predict(pmcp, 0), p(1, 1))
  expect_equal(predict(pmcp, 1), p(0, 2, 1))
  expect_equal(predict(pmcp, p(0, 1)), p(1, 1, 0, -1, 2))
})

Try the polyMatrix package in your browser

Any scripts or data that you put into this service are public.

polyMatrix documentation built on July 18, 2021, 5:06 p.m.