rows <- 800 disc_vars <- sample.int(3, 1) cont_vars <- sample(seq(2, 5), 1) dt <- gen_marg_joint_data(n_obs = rows, n_disc = disc_vars, n_cont = cont_vars, n_lvls = 3, p_outs = 0.05, jp_outs = 0.2, assoc_target = 1, assoc_vars = c(1,2), assoc_type="linear", seed_num = 1) discrete_scores <- disc_scores(data = dt, disc_cols = c(1:disc_vars)) continuous_scores <- cont_scores(data = dt, cont_cols = c((disc_vars+1):(disc_vars+cont_vars))) marginal_outliers <- marg_outs_scores(data = dt, disc_cols = c(1:disc_vars), outscorediscdf = discrete_scores[[2]], outscorecontdf = continuous_scores, outscorediscdfcells = discrete_scores[[3]]) marginal_outliers <- unique(unlist(marginal_outliers)) joint1 <- joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11) joint2 <- joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'conservative', drop_tol = 3, range_tol = 11) joint3 <- joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'bin', drop_tol = 3, range_tol = 11) testthat::test_that("Correct output object.", { testthat::expect_equal(is.numeric(joint1), TRUE) testthat::expect_equal(is.numeric(joint2), TRUE) testthat::expect_equal(is.numeric(joint3), TRUE) }) testthat::test_that("Incorrect input argument values.", { testthat::expect_error(joint_outs(data = as.matrix(dt), marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Data set should be of class 'data.frame'.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = c(marginal_outliers, marginal_outliers[1]), assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Indices of marginal outliers should be unique.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = c(marginal_outliers, 0), assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Indices of marginal outliers should be unique integer values from 1 up to the number of observations in the data.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = c(marginal_outliers, -10), assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Indices of marginal outliers should be unique integer values from 1 up to the number of observations in the data.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = c(marginal_outliers, 29.4), assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Indices of marginal outliers should be unique integer values from 1 up to the number of observations in the data.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = c(marginal_outliers, 2000), assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Indices of marginal outliers should be unique integer values from 1 up to the number of observations in the data.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'random_method', drop_tol = 3, range_tol = 11), "Method not supported - see documentation for supported methods.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 'hi', range_tol = 11), "Argument drop_tol should be a positive number.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = c(3, 12), range_tol = 11), "Argument drop_tol should be a positive number.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = -8, range_tol = 11), "Argument drop_tol should be a positive number.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = -11.1), "Argument range_tol should be a positive integer.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = '11'), "Argument range_tol should be a positive integer.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = -12), "Argument range_tol should be a positive integer from 1 up to 39.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 52), "Argument range_tol should be a positive integer from 1 up to 39.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 0), "Argument range_tol should be a positive integer from 1 up to 39.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = c(1, 2), assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Length of association targets should be equal to length of list of association variables.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = c(1, 1), assoc_vars = list(c((disc_vars+1), (disc_vars+2)), c((disc_vars+1), (disc_vars+2))), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association targets should be unique.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 100, assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association target indices should be unique positive integers, at most equal to the number of variables in the data set.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = c(1, 100), assoc_vars = list(c((disc_vars+1), (disc_vars+2)), c((disc_vars+1), (disc_vars+2))), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association target indices should be unique positive integers, at most equal to the number of variables in the data set.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = 1, assoc_vars = c(3.8, (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association variable indices should be unique positive integers, at most equal to the number of variables in the data set.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = c(1, 2), assoc_vars = list(c((-disc_vars), (disc_vars+2)), c((disc_vars+1), (disc_vars+2))), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association variable indices should be unique positive integers, at most equal to the number of variables in the data set.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = c(1, 2), assoc_vars = list(c((disc_vars+1), (disc_vars+2)), c((0), (disc_vars+2))), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association variable indices should be unique positive integers, at most equal to the number of variables in the data set.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = c(1, disc_vars+1), assoc_vars = list(c((disc_vars+1), (disc_vars+2)), c((disc_vars+1), (disc_vars+2))), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association targets should be of class 'factor'.", fixed = TRUE) testthat::expect_error(joint_outs(data = dt, marg_outs = marginal_outliers, assoc_target = c(disc_vars+1), assoc_vars = c((disc_vars+1), (disc_vars+2)), method = 'consec_angles', drop_tol = 3, range_tol = 11), "Association targets should be of class 'factor'.", fixed = TRUE) #testthat::expect_error(joint_outs(data = dt, # marg_outs = marginal_outliers, # assoc_target = c(1, 2), # assoc_vars = list(c((1), (disc_vars+2)), c((disc_vars+1), (disc_vars+2))), # method = 'consec_angles', # drop_tol = 3, # range_tol = 11), # "Association variables should be of class 'numeric'.", # fixed = TRUE) #testthat::expect_error(joint_outs(data = dt, # marg_outs = marginal_outliers, # assoc_target = c(1), # assoc_vars = c(2), # method = 'consec_angles', # drop_tol = 3, # range_tol = 11), # "Association variables should be of class 'numeric'.", # fixed = TRUE) })