From 8ded35a724208767cb34531a8ec044ba480e200f Mon Sep 17 00:00:00 2001 From: Mlen-Too Wesley Date: Mon, 25 Nov 2024 20:24:34 -0500 Subject: [PATCH] Add error handling and expectations to tests --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/mtwesley/greta.censored?shareId=XXXX-XXXX-XXXX-XXXX). --- tests/testthat/test-beta_censored.R | 8 ++++++++ tests/testthat/test-exponential_censored.R | 7 +++++++ tests/testthat/test-gamma_censored.R | 8 ++++++++ tests/testthat/test-normal_censored.R | 8 ++++++++ tests/testthat/test-pareto_censored.R | 8 ++++++++ tests/testthat/test-student_censored.R | 9 +++++++++ tests/testthat/test-weibull_censored.R | 8 ++++++++ 7 files changed, 56 insertions(+) diff --git a/tests/testthat/test-beta_censored.R b/tests/testthat/test-beta_censored.R index 245a700..f0998f0 100644 --- a/tests/testthat/test-beta_censored.R +++ b/tests/testthat/test-beta_censored.R @@ -2,6 +2,7 @@ library(greta) library(testthat) +library(reticulate) test_that("beta_censored distribution works correctly", { # Simulate data @@ -42,4 +43,11 @@ test_that("beta_censored distribution works correctly", { # Output results summary(draws) + + # Print Python errors before the expectation + print(py_last_error()) + + # Add meaningful expectations + expect_true(mean(draws$alpha) > 1.5 && mean(draws$alpha) < 2.5) + expect_true(mean(draws$beta) > 4.5 && mean(draws$beta) < 5.5) }) diff --git a/tests/testthat/test-exponential_censored.R b/tests/testthat/test-exponential_censored.R index fac8b9f..5b04b61 100644 --- a/tests/testthat/test-exponential_censored.R +++ b/tests/testthat/test-exponential_censored.R @@ -2,6 +2,7 @@ library(greta) library(testthat) +library(reticulate) test_that("exponential_censored distribution works correctly", { # Simulate data @@ -37,4 +38,10 @@ test_that("exponential_censored distribution works correctly", { # Output results summary(draws) + + # Print Python errors before the expectation + print(py_last_error()) + + # Add meaningful expectations + expect_true(mean(draws$rate) > 0.4 && mean(draws$rate) < 0.6) }) diff --git a/tests/testthat/test-gamma_censored.R b/tests/testthat/test-gamma_censored.R index 4edfb38..17d6cb4 100644 --- a/tests/testthat/test-gamma_censored.R +++ b/tests/testthat/test-gamma_censored.R @@ -2,6 +2,7 @@ library(greta) library(testthat) +library(reticulate) test_that("gamma_censored distribution works correctly", { # Simulate data @@ -40,4 +41,11 @@ test_that("gamma_censored distribution works correctly", { # Output results summary(draws) + + # Print Python errors before the expectation + print(py_last_error()) + + # Add meaningful expectations + expect_true(mean(draws$shape) > 1.5 && mean(draws$shape) < 2.5) + expect_true(mean(draws$rate) > 0.5 && mean(draws$rate) < 1.5) }) diff --git a/tests/testthat/test-normal_censored.R b/tests/testthat/test-normal_censored.R index 1155eb5..037f808 100644 --- a/tests/testthat/test-normal_censored.R +++ b/tests/testthat/test-normal_censored.R @@ -2,6 +2,7 @@ library(greta) library(testthat) +library(reticulate) test_that("normal_censored distribution works correctly", { # Simulate data @@ -40,4 +41,11 @@ test_that("normal_censored distribution works correctly", { # Output results summary(draws) + + # Print Python errors before the expectation + print(py_last_error()) + + # Add meaningful expectations + expect_true(mean(draws$mean) > 1.5 && mean(draws$mean) < 2.5) + expect_true(mean(draws$sd) > 0.5 && mean(draws$sd) < 1.5) }) diff --git a/tests/testthat/test-pareto_censored.R b/tests/testthat/test-pareto_censored.R index 77abbfc..6f6c1f4 100644 --- a/tests/testthat/test-pareto_censored.R +++ b/tests/testthat/test-pareto_censored.R @@ -2,6 +2,7 @@ library(greta) library(testthat) +library(reticulate) test_that("pareto_censored distribution works correctly", { # Simulate data @@ -41,4 +42,11 @@ test_that("pareto_censored distribution works correctly", { # Output results summary(draws) + + # Print Python errors before the expectation + print(py_last_error()) + + # Add meaningful expectations + expect_true(mean(draws$scale) > 0.5 && mean(draws$scale) < 1.5) + expect_true(mean(draws$alpha) > 2 && mean(draws$alpha) < 3) }) diff --git a/tests/testthat/test-student_censored.R b/tests/testthat/test-student_censored.R index 4260ca5..5559198 100644 --- a/tests/testthat/test-student_censored.R +++ b/tests/testthat/test-student_censored.R @@ -2,6 +2,7 @@ library(greta) library(testthat) +library(reticulate) test_that("student_censored distribution works correctly", { # Simulate data @@ -45,4 +46,12 @@ test_that("student_censored distribution works correctly", { # Output results summary(draws) + + # Print Python errors before the expectation + print(py_last_error()) + + # Add meaningful expectations + expect_true(mean(draws$df) > 4.5 && mean(draws$df) < 5.5) + expect_true(mean(draws$loc) > -0.5 && mean(draws$loc) < 0.5) + expect_true(mean(draws$scale) > 0.5 && mean(draws$scale) < 1.5) }) diff --git a/tests/testthat/test-weibull_censored.R b/tests/testthat/test-weibull_censored.R index dfa30c1..1d2815c 100644 --- a/tests/testthat/test-weibull_censored.R +++ b/tests/testthat/test-weibull_censored.R @@ -2,6 +2,7 @@ library(greta) library(testthat) +library(reticulate) test_that("weibull_censored distribution works correctly", { # Simulate data @@ -40,4 +41,11 @@ test_that("weibull_censored distribution works correctly", { # Output results summary(draws) + + # Print Python errors before the expectation + print(py_last_error()) + + # Add meaningful expectations + expect_true(mean(draws$shape) > 1 && mean(draws$shape) < 2) + expect_true(mean(draws$scale) > 0.5 && mean(draws$scale) < 1.5) })