test_that("simulate_data works with censoring.", {
  n_cov = 0
  n_per_cluster = 15
  n_cluster = 20
  n = n_cluster * n_per_cluster
  G = rep(1:n_cluster, each = n_per_cluster)
  Z = matrix(rnorm(n*n_cov,0,1),ncol = n_cov)
  df = simulate_data(G,Z,prop = 0.6,beta = c(),theta = 0.3,cens = TRUE)
  expect_equal(check_data_format(df), T)
})

test_that("simulate_data works without censoring.", {
  n_cov = 0
  n_per_cluster = 15
  n_cluster = 20
  n = n_cluster * n_per_cluster
  G = rep(1:n_cluster, each = n_per_cluster)
  Z = matrix(rnorm(n*n_cov,0,1),ncol = n_cov)
  df = simulate_data(G,Z,prop = 0.6,beta = c(),theta = 0.3,cens = FALSE)
  expect_equal(check_data_format(df), T)
})

test_that("simulate_data works when the variance of the frailty effect is equal to 0.", {
  n_cov = 0
  n_per_cluster = 15
  n_cluster = 20
  n = n_cluster * n_per_cluster
  G = rep(1:n_cluster, each = n_per_cluster)
  Z = matrix(rnorm(n*n_cov,0,1),ncol = n_cov)
  df = simulate_data(G,Z,prop = 0.6,beta = c(),theta = 0,cens = TRUE)
  expect_equal(check_data_format(df), T)
})

test_that("When beta is not defined, simulate_data does not work.",{
  n_cov = 2
  n_per_cluster = 15
  n_cluster = 20
  n = n_cluster * n_per_cluster
  G = rep(1:n_cluster, each = n_per_cluster)
  Z = matrix(rnorm(n*n_cov,0,1),ncol = n_cov)
  expect_error(simulate_data(G,Z,prop = 0.6,beta = NULL,theta = 0.3,cens = FALSE), "You must provide beta when Z is given.")
})

test_that("When the length of beta and the length of the covariable of an individual are not the same, simulate_data does not work.",{
  n_cov = 2
  n_per_cluster = 15
  n_cluster = 20
  n = n_cluster * n_per_cluster
  G = rep(1:n_cluster, each = n_per_cluster)
  Z = matrix(rnorm(n*n_cov,0,1),ncol = n_cov)
  expect_error(simulate_data(G,Z,prop = 0.6,beta = c(1),theta = 0.3,cens = FALSE), "Length of beta must match the number of columns in Z.")
})

test_that("When the sample size does not match the number of cluster observations, simulate_data does not work.",{
  n_cov = 2
  n_per_cluster = 15
  n_cluster = 20
  n = n_cluster * n_per_cluster
  G = rep(1:(n_cluster-1), each = n_per_cluster)
  Z = matrix(rnorm(n*n_cov,0,1),ncol = n_cov)
  expect_error(simulate_data(G,Z,prop = 0.6,beta = c(1,0),theta = 0.3,cens = FALSE), "The sample size does not match the number of cluster observations.")
})
