|
| 1 | +test_that("LD_reference_options returns all options when NULL", { |
| 2 | + opts <- echoLD:::LD_reference_options(LD_reference = NULL) |
| 3 | + |
| 4 | + testthat::expect_type(opts, "list") |
| 5 | + testthat::expect_true("ukb" %in% names(opts)) |
| 6 | + testthat::expect_true("1kg" %in% names(opts)) |
| 7 | + testthat::expect_true("vcf" %in% names(opts)) |
| 8 | + testthat::expect_true("matrix" %in% names(opts)) |
| 9 | +}) |
| 10 | + |
| 11 | +test_that("LD_reference_options identifies UKB", { |
| 12 | + result <- echoLD:::LD_reference_options( |
| 13 | + LD_reference = "UKB", |
| 14 | + verbose = FALSE |
| 15 | + ) |
| 16 | + testthat::expect_equal(result, "ukb") |
| 17 | +}) |
| 18 | + |
| 19 | +test_that("LD_reference_options identifies 1KG references", { |
| 20 | + r1 <- echoLD:::LD_reference_options( |
| 21 | + LD_reference = "1KGphase1", |
| 22 | + verbose = FALSE |
| 23 | + ) |
| 24 | + r3 <- echoLD:::LD_reference_options( |
| 25 | + LD_reference = "1KGphase3", |
| 26 | + verbose = FALSE |
| 27 | + ) |
| 28 | + testthat::expect_equal(r1, "1kg") |
| 29 | + testthat::expect_equal(r3, "1kg") |
| 30 | +}) |
| 31 | + |
| 32 | +test_that("LD_reference_options identifies VCF files", { |
| 33 | + for (ext in c(".vcf", ".vcf.gz", ".vcf.bgz")) { |
| 34 | + result <- echoLD:::LD_reference_options( |
| 35 | + LD_reference = paste0("/path/to/file", ext), |
| 36 | + verbose = FALSE |
| 37 | + ) |
| 38 | + testthat::expect_equal(result, "vcf", |
| 39 | + info = paste("Failed for extension:", ext)) |
| 40 | + } |
| 41 | +}) |
| 42 | + |
| 43 | +test_that("LD_reference_options identifies matrix files", { |
| 44 | + for (ext in c(".rds", ".rda", ".csv", ".tsv", ".txt")) { |
| 45 | + result <- echoLD:::LD_reference_options( |
| 46 | + LD_reference = paste0("/path/to/file", ext), |
| 47 | + verbose = FALSE |
| 48 | + ) |
| 49 | + testthat::expect_equal(result, "matrix", |
| 50 | + info = paste("Failed for extension:", ext)) |
| 51 | + } |
| 52 | +}) |
| 53 | + |
| 54 | +test_that("LD_reference_options with as_subgroups returns subgroups", { |
| 55 | + opts <- echoLD:::LD_reference_options( |
| 56 | + LD_reference = NULL, |
| 57 | + as_subgroups = TRUE |
| 58 | + ) |
| 59 | + testthat::expect_true("r" %in% names(opts)) |
| 60 | + testthat::expect_true("table" %in% names(opts)) |
| 61 | + testthat::expect_true("Matrix Market" %in% names(opts)) |
| 62 | + # "matrix" should be removed when as_subgroups is TRUE |
| 63 | + testthat::expect_false("matrix" %in% names(opts)) |
| 64 | +}) |
| 65 | + |
| 66 | +test_that("LD_reference_options subgroup identifies R files", { |
| 67 | + result <- echoLD:::LD_reference_options( |
| 68 | + LD_reference = "/path/to/file.rds", |
| 69 | + as_subgroups = TRUE, |
| 70 | + verbose = FALSE |
| 71 | + ) |
| 72 | + testthat::expect_equal(result, "r") |
| 73 | +}) |
| 74 | + |
| 75 | +test_that("LD_reference_options subgroup identifies table files", { |
| 76 | + result <- echoLD:::LD_reference_options( |
| 77 | + LD_reference = "/path/to/file.csv", |
| 78 | + as_subgroups = TRUE, |
| 79 | + verbose = FALSE |
| 80 | + ) |
| 81 | + testthat::expect_equal(result, "table") |
| 82 | +}) |
| 83 | + |
| 84 | +test_that("LD_reference_options subgroup identifies Matrix Market files", { |
| 85 | + result <- echoLD:::LD_reference_options( |
| 86 | + LD_reference = "/path/to/file.mtx", |
| 87 | + as_subgroups = TRUE, |
| 88 | + verbose = FALSE |
| 89 | + ) |
| 90 | + testthat::expect_equal(result, "Matrix Market") |
| 91 | +}) |
0 commit comments