From d34444148552ca9bdfd98770966baefdf7fa3b00 Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Wed, 1 Feb 2023 11:01:30 -0800 Subject: [PATCH] add test for #42 --- tests/testthat/test-getTaxonAtLevel.R | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-getTaxonAtLevel.R b/tests/testthat/test-getTaxonAtLevel.R index fd7def2..281acc2 100644 --- a/tests/testthat/test-getTaxonAtLevel.R +++ b/tests/testthat/test-getTaxonAtLevel.R @@ -1,7 +1,7 @@ test_that("getTaxonAtLevel works", { # specify alternate levels - expect_equal(getTaxonAtLevel("humic haploxerands", level = "greatgroup"), + expect_equal(getTaxonAtLevel("humic haploxerands", level = "greatgroup"), c(`humic haploxerands` = "haploxerands")) # can't get subgroup (child) from suborder (parent), can get suborder from suborder @@ -9,18 +9,26 @@ test_that("getTaxonAtLevel works", { c(`folists` = NA, `plinthic kandiudults` = "plinthic kandiudults")) # but can do parents of children - expect_equal(getTaxonAtLevel("udifolists", level = "suborder"), + expect_equal(getTaxonAtLevel("udifolists", level = "suborder"), c(`udifolists` = "folists")) - + # default is level="order" - expect_equal(getTaxonAtLevel("udolls"), + expect_equal(getTaxonAtLevel("udolls"), c(`udolls` = "mollisols")) - + + # data.frame result when length(level) > 1 + expect_equal(getTaxonAtLevel(c("haploxerolls", "hapludolls"), level = c("order", "suborder", "greatgroup", "subgroup"), simplify = FALSE), + data.frame(order = c("mollisols", "mollisols"), + suborder = c("xerolls", "udolls"), + greatgroup = c("haploxerolls", "hapludolls"), + subgroup = c(NA_character_, NA_character_), + row.names = c("haploxerolls", "hapludolls"))) + # garbage and 0-character input - g1 <- getTaxonAtLevel("foo") + g1 <- getTaxonAtLevel("foo") g2 <- getTaxonAtLevel("") expect_true(is.na(g1[[1]]) && is.na(g2[[1]])) - + # empty (length 0) and missing (NA) input expect_true(is.na(getTaxonAtLevel(character(0))) && is.na(getTaxonAtLevel(NA))) })