Skip to content

Commit

Permalink
Add context to mlg tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zkamvar committed Aug 7, 2016
1 parent 28d2be0 commit a168027
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: poppr
Type: Package
Title: Genetic Analysis of Populations with Mixed Reproduction
Version: 2.2.0.99-26
Version: 2.2.0.99-31
Date: 2016-08-07
Authors@R: c(person(c("Zhian", "N."), "Kamvar", role = c("cre", "aut"),
email = "kamvarz@science.oregonstate.edu"),
Expand Down
55 changes: 36 additions & 19 deletions tests/testthat/test-mlg.R
@@ -1,4 +1,4 @@
context("Multilocus genotype tests")
context("Basic multilocus genotype tests")

data(Pinf, package = "poppr")
data(Aeut, package = "poppr")
Expand All @@ -14,6 +14,7 @@ ntab <- mlg.table(nancycats, plot = FALSE)
sim <- adegenet::glSim(10, 1e2, ploidy = 2, parallel = FALSE)
lu <- function(x) length(unique(x))


test_that("multilocus genotype vector is same length as samples", {
expect_equal(length(amlg), nInd(Aeut))
expect_equal(length(pmlg), nInd(partial_clone))
Expand All @@ -23,6 +24,28 @@ test_that("multilocus genotype vector is same length as samples", {
expect_equal(lu(nmlg), mlg(nancycats, quiet = TRUE))
})


test_that("subsetting and resetting MLGs works", {
pmlg <- mlg.vector(Pinf)
pres <- mlg.vector(Pinf, reset = TRUE)
fullmlg <- mlg(Pinf[loc = locNames(Pinf)[-c(1:5)]], quiet = TRUE)
realmlg <- mlg(Pinf[loc = locNames(Pinf)[-c(1:5)], mlg.reset = TRUE], quiet = TRUE)
expect_equal(pmlg, Pinf@mlg[])
expect_false(identical(pmlg, pres))
expect_equal(Pinf[mlg.reset = TRUE]@mlg[], pres)
expect_gt(fullmlg, realmlg)
mll(Pinf) <- "original"
expect_equal(mll(mll.reset(Pinf, TRUE)), pres)
mll.custom(Pinf) <- paste("MLL", mll(Pinf))
cmll <- as.numeric(as.character(mll(mll.reset(Pinf, "custom"))))
comll <- as.numeric(as.character(mll(mll.reset(Pinf, c("custom", "original")))))
expect_equal(cmll, pmlg)
expect_equal(comll, pres)
})


context("Basic clone correction tests")

test_that("clone correction works for specified levels and throws errors", {
skip_on_cran()
strata(aclone) <- other(aclone)[[1]][-1]
Expand All @@ -43,6 +66,8 @@ test_that("clone correction works for specified levels and throws errors", {
expect_warning(clonecorrect(ac), "Strata is not set for ac")
})

context("mlg.table tests")

test_that("multilocus genotype matrix matches mlg.vector and data", {
expect_equal(nrow(atab), nPop(Aeut))
expect_equal(nrow(ptab), nPop(partial_clone))
Expand Down Expand Up @@ -70,6 +95,7 @@ test_that("multilocus genotype matrix can utilize strata", {
expect_equal(nrow(pcont), 2)
})

context("mll and nmll function tests")
test_that("mll and nmll works for genind objects", {
expect_warning(atest <- mll(Aeut, "original"))
nAeut <- nmll(Aeut)
Expand All @@ -90,6 +116,8 @@ test_that("mll can convert a numeric mlg slot to MLG", {
expect_is(Pinf@mlg, "MLG")
})

context("MLG class printing")

test_that("MLG class can print expected", {
mll(Pinf) <- "original"
expect_output(show(Pinf@mlg), "86 original mlgs.")
Expand All @@ -100,6 +128,8 @@ test_that("MLG class can print expected", {
mll(Pinf) <- "original"
})

context("mlg.crosspop tests")

test_that("mlg.crosspop will work with subsetted genclone objects", {
strata(Aeut) <- other(Aeut)$population_hierarchy
agc <- as.genclone(Aeut)
Expand Down Expand Up @@ -138,6 +168,8 @@ test_that("mlg.crosspop can take sublist and blacklist", {
expect_equivalent(mlg.crosspop(Athena, sublist = 1:10, blacklist = "1", quiet = TRUE), expectation)
})

context("mlg.id tests")

test_that("mlg.id Aeut works", {
expected_output <- structure(list(`1` = "055", `2` = c("101", "103"), `3` = "111",
`4` = "112", `5` = "110", `6` = "102", `7` = "020", `8` = "007",
Expand Down Expand Up @@ -252,24 +284,7 @@ test_that("mlg.id Pinf works", {
expect_equal(names(x[1]), "1")
})


test_that("subsetting and resetting MLGs works", {
pmlg <- mlg.vector(Pinf)
pres <- mlg.vector(Pinf, reset = TRUE)
fullmlg <- mlg(Pinf[loc = locNames(Pinf)[-c(1:5)]], quiet = TRUE)
realmlg <- mlg(Pinf[loc = locNames(Pinf)[-c(1:5)], mlg.reset = TRUE], quiet = TRUE)
expect_equal(pmlg, Pinf@mlg[])
expect_false(identical(pmlg, pres))
expect_equal(Pinf[mlg.reset = TRUE]@mlg[], pres)
expect_gt(fullmlg, realmlg)
mll(Pinf) <- "original"
expect_equal(mll(mll.reset(Pinf, TRUE)), pres)
mll.custom(Pinf) <- paste("MLL", mll(Pinf))
cmll <- as.numeric(as.character(mll(mll.reset(Pinf, "custom"))))
comll <- as.numeric(as.character(mll(mll.reset(Pinf, c("custom", "original")))))
expect_equal(cmll, pmlg)
expect_equal(comll, pres)
})
context("mll.reset tests")

test_that("mll.reset works with non-MLG class slots", {
skip_on_cran()
Expand All @@ -296,6 +311,8 @@ test_that("mll.reset will reset subset genclone with no MLG class", {
expect_equal(suppressWarnings(monpop[loc = 1:2] %>% mll.reset(TRUE) %>% nmll()), 14L)
})

context("mlg.filter tests")

test_that("multilocus genotype filtering functions correctly", {
skip_on_cran()
# amlg <- mlg.vector(Aeut)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-msn.R
@@ -1,5 +1,3 @@
context("Minimum spanning network functions")

options(warn = -1)
ucl <- function(x){
unclass(x$graph)[-10]
Expand Down

0 comments on commit a168027

Please sign in to comment.