# Tests for Random Effects Functions # Note: Random effects functionality is currently a placeholder/stub # These tests verify function signatures and expected behavior test_that("gmm_survey_re exists and has correct signature", { # Function should exist expect_true(exists("gmm_survey_re")) expect_true(is.function(gmm_survey_re)) # Should be exported expect_true("gmm_survey_re" %in% getNamespaceExports("surveymixr")) }) test_that("gmm_survey_re gives informative error for unimplemented functionality", { # Create simple test data sim_data <- simulate_gmm_survey( n_individuals = 50, n_times = 3, n_classes = 2, seed = 777 ) # Should throw informative error about pending implementation expect_error( gmm_survey_re( data = sim_data, id = "id", time = "time", outcome = "outcome", n_classes = 2, random = ~ 1, # Random intercepts starts = 5, verbose = FALSE ), "Full implementation pending" ) }) test_that("gmm_survey_re validates random formula", { sim_data <- simulate_gmm_survey( n_individuals = 50, n_times = 3, n_classes = 2, seed = 778 ) # Should error if random is not a formula expect_error( gmm_survey_re( data = sim_data, id = "id", time = "time", outcome = "outcome", n_classes = 2, random = "not_a_formula", # Invalid starts = 5, verbose = FALSE ), "random must be a formula" ) }) test_that("get_random_effects exists and has correct signature", { # Function should exist expect_true(exists("get_random_effects")) expect_true(is.function(get_random_effects)) # Should be exported expect_true("get_random_effects" %in% getNamespaceExports("surveymixr")) }) test_that("calculate_icc exists and has correct signature", { # Function should exist expect_true(exists("calculate_icc")) expect_true(is.function(calculate_icc)) # Should be exported expect_true("calculate_icc" %in% getNamespaceExports("surveymixr")) }) test_that("variance_components exists and has correct signature", { # Function should exist expect_true(exists("variance_components")) expect_true(is.function(variance_components)) # Should be exported expect_true("variance_components" %in% getNamespaceExports("surveymixr")) }) test_that("SurveyMixrRE class is defined", { skip("SurveyMixrRE class not yet fully implemented - pending v0.3.0") # S4 class should exist expect_true("SurveyMixrRE" %in% getClasses()) # Should be exported expect_true("SurveyMixrRE" %in% getNamespaceExports("surveymixr")) # Should inherit from SurveyMixr expect_true("SurveyMixr" %in% extends("SurveyMixrRE")) }) test_that("plot_random_effects exists", { # Function should exist expect_true(exists("plot_random_effects")) expect_true(is.function(plot_random_effects)) # Should be exported expect_true("plot_random_effects" %in% getNamespaceExports("surveymixr")) }) # Future tests (activate once implementation is complete): # # test_that("gmm_survey_re fits model with random intercepts", { # sim_data <- simulate_gmm_survey( # n_individuals = 150, # n_times = 4, # n_classes = 2, # seed = 801 # ) # # fit <- gmm_survey_re( # data = sim_data, # id = "id", # time = "time", # outcome = "outcome", # n_classes = 2, # random = ~ 1, # starts = 10, # verbose = FALSE # ) # # expect_s4_class(fit, "SurveyMixrRE") # expect_true(fit@convergence_info$converged) # expect_true(!is.null(fit@random_effects)) # expect_true(!is.null(fit@variance_components)) # }) # # test_that("gmm_survey_re fits model with random slopes", { # sim_data <- simulate_gmm_survey( # n_individuals = 150, # n_times = 4, # n_classes = 2, # seed = 802 # ) # # fit <- gmm_survey_re( # data = sim_data, # id = "id", # time = "time", # outcome = "outcome", # n_classes = 2, # random = ~ 1 + time, # Random intercepts and slopes # starts = 10, # verbose = FALSE # ) # # expect_s4_class(fit, "SurveyMixrRE") # expect_true(ncol(fit@variance_components[[1]]) == 2) # 2x2 covariance matrix # }) # # test_that("get_random_effects extracts BLUPs correctly", { # # (Implementation pending) # }) # # test_that("calculate_icc computes ICC for each class", { # # (Implementation pending) # }) # # test_that("variance_components returns proper covariance matrices", { # # (Implementation pending) # })