test_Jeffreys <- function(n.iter) {
  for(i in 1:n.iter) {
    set.seed(i)
    X1 <- mvtnorm::rmvnorm(100, sigma = diag(0.1 * i + 0.5, 5), mean = rep(1, 5))
    X2 <- as.data.frame(mvtnorm::rmvnorm(100, mean = rep(0, 5), sigma = diag(1, 5)))
    set.seed(i)
    res.Jeffreys <- DataSimilarity::Jeffreys(X1, X2, seed = i)
    
    testthat::test_that("output type", {
      # check length and names of output
      testthat::expect_length(res.Jeffreys, 7)
      testthat::expect_named(res.Jeffreys, c("statistic", "p.value", "estimate",
                                        "alternative", "method", "data.name", 
                                        "parameters"))
      # statistic and p values are not NA
      testthat::expect_false(is.na(res.Jeffreys$statistic))
      # output should be numeric
      testthat::expect_s3_class(res.Jeffreys, "htest")
    })
    
    res.Jeffreys.1 <- DataSimilarity::Jeffreys(X1[, 1, drop = FALSE], 
                                               X2[, 1, drop = FALSE], 
                                               seed = i)
    
    testthat::test_that("output type", {
      # check length and names of output
      testthat::expect_length(res.Jeffreys.1, 7)
      testthat::expect_named(res.Jeffreys.1, c("statistic", "p.value", "estimate",
                                             "alternative", "method", "data.name", 
                                             "parameters"))
      # statistic and p values are not NA
      testthat::expect_false(is.na(res.Jeffreys.1$statistic))
      # output should be numeric
      testthat::expect_s3_class(res.Jeffreys.1, "htest")
    })
    
    testthat::test_that("NA action", {
      set.seed(i)
      X1.NA <- matrix(rnorm(1000), ncol = 10)
      X2.NA <- matrix(rnorm(1000, mean = 0.5), ncol = 10)
      X1.NA[sample(length(X1.NA), 0.05 * length(X1.NA))] <- NA
      X2.NA[sample(length(X2.NA), 0.01 * length(X2.NA))] <- NA
      
      testthat::expect_no_error(suppressWarnings(DataSimilarity::Jeffreys(X1.NA, X2.NA, seed = i)))
      testthat::expect_warning(DataSimilarity::Jeffreys(X1.NA, X2.NA, seed = i))
      testthat::expect_false(suppressWarnings(is.na(DataSimilarity::Jeffreys(X1.NA, X2.NA, seed = i)$statistic)))
    }) 
  }
}

set.seed(0305)
test_Jeffreys(1)
