Skip to content

Commit

Permalink
removed not used code from get_uid, added get_uid tests, #436
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jun 26, 2015
1 parent 63055e5 commit 62321ed
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
1 change: 0 additions & 1 deletion R/get_uid.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ get_uid <- function(sciname, ask = TRUE, verbose = TRUE, rows = NA, modifier = N
if (!is.null(modifier)) sciname <- paste0(sciname, sprintf("[%s]", modifier))
url <- paste("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=taxonomy&term=",
sciname, sep = "")
if (!is.null(division_query)) url <- paste0(url, sprintf(" AND %s[Division]", division_query))
if (!is.null(rank_query)) url <- paste0(url, sprintf(" AND %s[Rank]", rank_query))
url <- URLencode(url)
errors_to_catch <- c("Could not resolve host: eutils.ncbi.nlm.nih.gov")
Expand Down
46 changes: 43 additions & 3 deletions tests/testthat/test-get_uid.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,56 @@
context("get_uid")

test_that("get_uid returns the correct value", {
expect_that(is.na(get_uid(c("Chironomus riparius", "aaa"), verbose=FALSE)[2]),
expect_that(is.na(get_uid(c("Chironomus riparius", "aaa"), verbose=FALSE)[2]),
is_true())
})

test_that("get_uid returns the correct class", {
expect_that(get_uid(c("Chironomus riparius", "Chaetopteryx"), verbose=FALSE),
expect_that(get_uid(c("Chironomus riparius", "Chaetopteryx"), verbose=FALSE),
is_a("uid"))
})

test_that("get_uid accepts ask-argument", {
expect_that(is.na(get_uid('Dugesia', ask = FALSE, verbose=FALSE)),
expect_that(is.na(get_uid('Dugesia', ask = FALSE, verbose=FALSE)),
is_true())
})

test_that("get_uid query modifiers work", {
### w/ modifiers to the name
mod1 <- get_uid(sciname = "Aratinga", verbose=FALSE)
mod2 <- get_uid(sciname = "Aratinga", modifier = "Organism", rows = 1, verbose=FALSE)

expect_is(mod1, "uid")
expect_is(mod2, "uid")
expect_equal(mod1[[1]], "12945")
expect_equal(mod2[[1]], "867384")

### w/ rank query
rq1 <- get_uid(sciname = "Pinus", rank_query = "genus", verbose=FALSE)
rq2 <- get_uid(sciname = "Pinus", rank_query = "subgenus", verbose=FALSE)

expect_is(rq1, "uid")
expect_is(rq2, "uid")
expect_equal(rq1[[1]], "3337")
expect_equal(rq2[[1]], "139271")
})

test_that("get_uid filtering works", {
### w/ division
df1 <- get_uid(sciname = "Echinacea", division_filter = "eudicots", verbose=FALSE)
df2 <- get_uid(sciname = "Echinacea", division_filter = "sea urchins", verbose=FALSE)

expect_is(df1, "uid")
expect_is(df2, "uid")
expect_equal(df1[[1]], "53747")
expect_equal(df2[[1]], "7674")

## Rank example
rf1 <- get_uid(sciname = "Pinus", rank_filter = "genus", rows = 2, verbose=FALSE)
rf2 <- get_uid(sciname = "Pinus", rank_filter = "subgenus", verbose=FALSE)

expect_is(rf1, "uid")
expect_is(rf2, "uid")
expect_equal(rf1[[1]], "3337")
expect_equal(rf2[[1]], "139271")
})

0 comments on commit 62321ed

Please sign in to comment.