From 623f49846f1c20b5b5f45b3974a5cc63dc271ba3 Mon Sep 17 00:00:00 2001 From: Walmes Zeviani <walmes@ufpr.br> Date: Tue, 17 May 2016 23:23:56 -0300 Subject: [PATCH] =?UTF-8?q?Adicona=20o=20dir=20tests/=20e=20arquivos=20com?= =?UTF-8?q?=20testes=20nas=20fun=C3=A7=C3=B5es=20de=20ll.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DESCRIPTION | 3 ++- tests/testthat.R | 4 ++++ tests/testthat/test_funprobs.R | 11 +++++++++++ tests/testthat/test_logliks.R | 27 +++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test_funprobs.R create mode 100644 tests/testthat/test_logliks.R diff --git a/DESCRIPTION b/DESCRIPTION index 221860d..ff1d055 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,6 +46,7 @@ Suggests: knitr, rmarkdown, shiny, - rpanel + rpanel, + testthat VignetteBuilder: knitr RoxygenNote: 5.0.1 diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..8cd71f9 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(MRDCr) + +test_check("MRDCr") diff --git a/tests/testthat/test_funprobs.R b/tests/testthat/test_funprobs.R new file mode 100644 index 0000000..96a74ea --- /dev/null +++ b/tests/testthat/test_funprobs.R @@ -0,0 +1,11 @@ +context("Testa as Funções de Probabilidade") + +test_that("Iguais a Poisson", { + y <- 0:30 + lambda <- 30 * runif(1) + py_pois <- dpois(x = y, lambda = lambda) + py_pgnz <- dpgnz(y = y, lambda = lambda, alpha = 0) + py_gcnt <- dgcnt(y = y, lambda = lambda, alpha = 1) + expect_equal(py_pgnz, py_pois) + expect_equal(py_gcnt, py_pois) +}) diff --git a/tests/testthat/test_logliks.R b/tests/testthat/test_logliks.R new file mode 100644 index 0000000..cd38a87 --- /dev/null +++ b/tests/testthat/test_logliks.R @@ -0,0 +1,27 @@ +context("Testa as Funções de Log-Verossimilhança") + +test_that("Tem os mesmo argumentos", { + apropos("formals") + a_gcnt <- as.list(formals(llgcnt)) + a_pgnz <- as.list(formals(llpgnz)) + expect_equal(a_gcnt, a_pgnz) +}) + +test_that("São iguais a Poisson", { + y <- 0:10 + X <- cbind(y * 0 + 1) + lamb <- 10 * runif(1) + ll_pois <- -sum(dpois(x = y, lambda = lamb, log = TRUE)) + ll_pgnz <- llpgnz(params = c(0, log(lamb)), y = y, X = X) + ll_gcnt <- llgcnt(params = c(log(1), log(lamb)), y = y, X = X) + expect_equal(ll_pgnz, expected = ll_pois) + expect_equal(ll_gcnt, expected = ll_pois) +}) + +test_that("Inteiros negativos resultam em Warning", { + y <- -4:-1 + X <- cbind(y * 0 + 1) + lamb <- 10 * runif(1) + expect_warning(llpgnz(params = c(0, log(lamb)), y = y, X = X)) + expect_warning(llgcnt(params = c(log(1), log(lamb)), y = y, X = X)) +}) -- GitLab