tests/testthat/test-near_find_xx_gage.R

# test for near gage and lag functions
test_that("find_ds_gage works", {
  out <- find_ds_gage(10)
  expect_equal(out$index,2)
  expect_equal(out$distance_to_gage,20)
  expect_equal(out$gage_name,"ThirtyMile" )
  rm(out)
  out1 <- find_ds_gage(38)
  expect_equal(out1$index, 3)
  expect_equal(out1$distance_to_gage,23)
  expect_equal(out1$gage_name,"LCR")
  rm(out1)
  out2 <- find_ds_gage(170)
  expect_equal(out2$index, NA)
  expect_equal(out2$distance_to_gage,NA)
  expect_equal(out2$gage_name,NA)
})

test_that("find_us_gage works", {
  out <- find_us_gage(10)
  expect_equal(out$index,1)
  expect_equal(out$distance_to_gage,-10)
  expect_equal(out$gage_name,"LeesFerry" )
  rm(out)
  out1 <- find_us_gage(38)
  expect_equal(out1$index, 2)
  expect_equal(out1$distance_to_gage,-8)
  expect_equal(out1$gage_name,"ThirtyMile")
  rm(out1)
  out2 <- find_us_gage(170)
  expect_equal(out2$index, 5)
  expect_equal(out2$distance_to_gage,-4)
  expect_equal(out2$gage_name,"NationalCanyon")
  rm(out2)
  out3 <- find_us_gage(226)
  expect_equal(out3$index, NA)
  expect_equal(out3$distance_to_gage,NA)
  expect_equal(out3$gage_name,NA)
  rm(out3)
})

test_that("find_nr_gage works",{
  out <- find_nr_gage(15)
  expect_equal(out$index,1)
  expect_equal(out$distance_to_gage,-15)
  expect_equal(out$gage_name,"LeesFerry" )
  rm(out)
  out1 <- find_nr_gage(15.1)
  expect_equal(out1$index,2)
  expect_equal(out1$distance_to_gage,14.9)
  expect_equal(out1$gage_name,"ThirtyMile" )
  rm(out1)
  out2 <- find_nr_gage(226)
  expect_equal(out2$index,NA)
  expect_equal(out2$distance_to_gage,NA)
  expect_equal(out2$gage_name,NA)
  rm(out2)
})

test_that("find_lag_time works",{
  out <- find_lag_time(30.7)
  expect_equal(out$nearest_gage, "ThirtyMile" )
  expect_equal(out$nearest_gage_index, 2)
  test_duration = lubridate::duration(846.359999999, units = 'seconds')
  expect_equal(out$lagtime, test_duration)
})
Ryan-Lima/gRandcanyonsand documentation built on Aug. 13, 2021, 7:38 a.m.