Skip to content

Commit

Permalink
Add error handling and expectations to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwesley committed Nov 26, 2024
1 parent 8b1c82c commit 8ded35a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/testthat/test-beta_censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(greta)
library(testthat)
library(reticulate)

test_that("beta_censored distribution works correctly", {
# Simulate data
Expand Down Expand Up @@ -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)
})
7 changes: 7 additions & 0 deletions tests/testthat/test-exponential_censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(greta)
library(testthat)
library(reticulate)

test_that("exponential_censored distribution works correctly", {
# Simulate data
Expand Down Expand Up @@ -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)
})
8 changes: 8 additions & 0 deletions tests/testthat/test-gamma_censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(greta)
library(testthat)
library(reticulate)

test_that("gamma_censored distribution works correctly", {
# Simulate data
Expand Down Expand Up @@ -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)
})
8 changes: 8 additions & 0 deletions tests/testthat/test-normal_censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(greta)
library(testthat)
library(reticulate)

test_that("normal_censored distribution works correctly", {
# Simulate data
Expand Down Expand Up @@ -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)
})
8 changes: 8 additions & 0 deletions tests/testthat/test-pareto_censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(greta)
library(testthat)
library(reticulate)

test_that("pareto_censored distribution works correctly", {
# Simulate data
Expand Down Expand Up @@ -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)
})
9 changes: 9 additions & 0 deletions tests/testthat/test-student_censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(greta)
library(testthat)
library(reticulate)

test_that("student_censored distribution works correctly", {
# Simulate data
Expand Down Expand Up @@ -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)
})
8 changes: 8 additions & 0 deletions tests/testthat/test-weibull_censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(greta)
library(testthat)
library(reticulate)

test_that("weibull_censored distribution works correctly", {
# Simulate data
Expand Down Expand Up @@ -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)
})

0 comments on commit 8ded35a

Please sign in to comment.