-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tests; add NEWS; add documentation (#179)
- Loading branch information
Showing
3 changed files
with
59 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,44 @@ | ||
context("win.ia tests") | ||
options(poppr.debug = FALSE) | ||
set.seed(999) | ||
chrom_pos <- vapply(1:10, function(i) sort(sample(1e3, 100)), integer(100)) %>% | ||
as.vector() | ||
chromo <- rep(1:10, each = 100) | ||
real_pos <- chrom_pos + 1000*(chromo - 1) + 1#+ 100*(chromo - 1) + 1 | ||
set.seed(999) | ||
x <- glSim(n.ind = 10, n.snp.nonstruc = 5e2, n.snp.struc = 5e2, ploidy = 2, | ||
parallel = FALSE) | ||
|
||
|
||
test_that("win.ia will throw an error if duplicate positions are found", { | ||
x.naive <- win.ia(x) | ||
options(poppr.debug = TRUE) | ||
expect_output(x.naive <- win.ia(x), "[|=]{2,}") | ||
position(x) <- chrom_pos | ||
expect_equal(length(x.naive), 10L) | ||
expect_error(win.ia(x), "chromosome") | ||
options(poppr.debug = FALSE) | ||
}) | ||
|
||
test_that("win.ia will throw a warning if chromosome_buffer is specified", { | ||
expect_warning(x.naive <- win.ia(x, quiet = TRUE, chromosome_buffer = FALSE), "deprecated") | ||
}) | ||
|
||
test_that("win.ia will use chromosome structure", { | ||
skip_on_cran() | ||
position(x) <- chrom_pos | ||
chromosome(x) <- chromo | ||
x.chrom.bt <- win.ia(x) | ||
expect_equal(sum(is.na(x.chrom.bt) & !is.nan(x.chrom.bt)), 9L) | ||
expect_equal(length(x.chrom.bt), 109L) | ||
x.chrom.bt <- win.ia(x, quiet = TRUE) | ||
expect_equal(length(x.chrom.bt), 100L) | ||
expect_equal(names(x.chrom.bt), as.character(rep(1:10, each = 10))) | ||
}) | ||
|
||
test_that("win.ia will take into account chromosome buffer", { | ||
test_that("win.ia will always start at the beginning of the chromosome", { | ||
skip_on_cran() | ||
position(x) <- chrom_pos | ||
chromosome(x) <- chromo | ||
x.chrom.bf <- win.ia(x, chromosome_buffer = FALSE) | ||
chromosome(x) <- NULL | ||
position(x) <- real_pos | ||
x.real <- win.ia(x) | ||
expect_equal(length(x.chrom.bf), 100L) | ||
expect_equal(length(x.chrom.bf), length(x.real)) | ||
expect_equal(x.chrom.bf, x.real, check.attributes = FALSE) | ||
x.chrom.bf <- win.ia(x, window = 300L, quiet = TRUE) | ||
x.by.chrom <- lapply(levels(chromosome(x)), function(i) win.ia(x[, chromosome(x) == i], window = 300L, quiet = TRUE)) | ||
# There should be 4 windows per chromosome. | ||
expect_equal(length(x.chrom.bf), 40L) | ||
# Using the function with and without chromosome structure should not matter. | ||
expect_equal(x.chrom.bf, unlist(x.by.chrom, use.names = FALSE), check.attributes = FALSE) | ||
|
||
}) | ||
|