Skip to content

Commit

Permalink
Update test-evalMissingData.R
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Nov 18, 2023
1 parent 3e73f31 commit 15f808d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions tests/testthat/test-evalMissingData.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ sobrante,A,0,5,18,0,5.8
sobrante,Ab,5,10,16,2,5.7
sobrante,Bt1,10,28,15,21,5.8
sobrante,Bt2,28,51,NA,NA,NA
sobrante,Cd,51,74,20,12,6.2'), stringsAsFactors=FALSE)
sobrante,Cd,51,74,20,12,6.2'), stringsAsFactors = FALSE)

# establish site-level data
s <- data.frame(
series=c('auburn', 'dunstone', 'sobrante'),
precip=c(24, 30, 32),
stringsAsFactors=FALSE
series = c('auburn', 'dunstone', 'sobrante'),
precip = c(24, 30, 32),
stringsAsFactors = FALSE
)

# upgrade to SoilProfile Collection object
Expand All @@ -38,24 +38,34 @@ test_that("runs as expected", {
# does it run?
e.rel <- evalMissingData(d, vars = c('clay', 'frags', 'ph'), name = 'name', method = 'relative')
e.abs <- evalMissingData(d, vars = c('clay', 'frags', 'ph'), name = 'name', method = 'absolute')
e.hz <- evalMissingData(d, vars = c('clay', 'frags', 'ph'), name = 'name', method = 'horizon')

# result is a numeric vector
expect_true(inherits(e.rel, 'numeric'))
expect_true(inherits(e.abs, 'numeric'))
expect_true(inherits(e.hz, 'numeric'))

# there should be no NA
# there should be no NA in profile-level summaries
expect_true(all(is.na(e.rel) == FALSE))
expect_true(all(is.na(e.abs) == FALSE))

# expected lengths
expect_true(length(e.rel) == length(d))
expect_true(length(e.abs) == length(d))
expect_true(length(e.hz) == nrow(d))

# check against hand-computed results
# as.vector removes names attr
# auburn
expect_equal(as.vector(e.rel[1]), 22 / 25, tolerance=0.001)
expect_equal(as.vector(e.abs[1]), 22 , tolerance=0.001)
expect_equal(as.vector(e.rel[1]), 22 / 25, tolerance = 0.001)
expect_equal(as.vector(e.abs[1]), 22 , tolerance = 0.001)
# first hz of auburn is missing pH
expect_equal(as.vector(e.hz[1]), 2/3, tolerance = 0.001)


# dunstone
expect_equal(as.vector(e.rel[2]), 1.000, tolerance=0.001)
expect_equal(as.vector(e.abs[2]), 31, tolerance=0.001)
expect_equal(as.vector(e.rel[2]), 1.000, tolerance = 0.001)
expect_equal(as.vector(e.abs[2]), 31, tolerance = 0.001)

# sobrante
expect_equal(as.vector(e.rel[3]), 28 / 51, tolerance=0.001)
Expand Down

0 comments on commit 15f808d

Please sign in to comment.