From 304bee499d3155d01d1f057ca9f8348f10443850 Mon Sep 17 00:00:00 2001 From: mikejohnson51 Date: Sun, 26 May 2024 17:04:14 -0600 Subject: [PATCH] reduce needed tests --- tests/testthat/test-get_subset.R | 149 +++---------------------------- 1 file changed, 14 insertions(+), 135 deletions(-) diff --git a/tests/testthat/test-get_subset.R b/tests/testthat/test-get_subset.R index 74f715f..abf024a 100644 --- a/tests/testthat/test-get_subset.R +++ b/tests/testthat/test-get_subset.R @@ -7,13 +7,19 @@ lyrs = c('divides', 'flowlines', 'network') outfile <- 'subset_test.gpkg' library(sf) +network <- 's3://lynker-spatial/hydrofabric/v2.2/reference/conus_network' + +test = open_dataset(network) %>% + filter(hl_uri == "Gages-06752260") %>% + collect() + # --------------------- Reference fabric ---------------------------# # Test with an comid and network file test_that("Terminal point check for comid passed", { get_subset(outfile = outfile, - comid = 718648, + comid = 2899997, source = source, type = type, lyrs = lyrs, @@ -25,145 +31,18 @@ test_that("Terminal point check for comid passed", { subset_network <- read_sf("subset_test.gpkg", layer = "network") # Flowlines - expect_equal(nrow(subset_flowpaths), 5) - expect_equal(unique(subset_flowpaths$vpuid), "01") - expect_equal(min(subset_flowpaths$mainstemlp), 1923133) - expect_equal(max(subset_flowpaths$mainstemlp), 1923137) - - # Divides - expect_equal(nrow(subset_divides), 5) - expect_equal(unique(subset_divides$vpuid), "01") - - # Network - expect_equal(nrow(subset_network), 6) - expect_equal(unique(subset_network$vpuid), "01") - - unlink(outfile) -}) - -# Test with an id and network file -test_that("Terminal point check for id passed", { - - get_subset(outfile = outfile, - id = 923, - source = source, - type = type, - lyrs = lyrs, - hf_version = hf_version, - overwrite = TRUE) - - subset_flowpaths <- read_sf("subset_test.gpkg", layer = "flowlines") - subset_divides <- read_sf("subset_test.gpkg", layer = "divides") - subset_network <- read_sf("subset_test.gpkg", layer = "network") - - # Flowlines - expect_equal(nrow(subset_flowpaths), 3) - expect_equal(unique(subset_flowpaths$vpuid), "01") - - - # Divides - expect_equal(nrow(subset_divides), 3) - expect_equal(unique(subset_divides$vpuid), "01") - - # Network - expect_equal(nrow(subset_network), 3) - expect_equal(unique(subset_network$vpuid), "01") - - unlink(outfile) - -}) - -# Test with an nldi_feature -test_that("Terminal point check for nldi_feature passed", { - - get_subset(outfile = outfile, - nldi_feature = list(featureSource = "nwissite", - featureID = "USGS-08279500"), - source = source, - type = type, - lyrs = lyrs, - hf_version = hf_version, - overwrite = TRUE) - - subset_flowpaths <- read_sf("subset_test.gpkg", layer = "flowlines") - subset_divides <- read_sf("subset_test.gpkg", layer = "divides") - subset_network <- read_sf("subset_test.gpkg", layer = "network") - - # Flowlines - expect_equal(nrow(subset_flowpaths), 3375) - expect_equal(unique(subset_flowpaths$vpuid), "13") + expect_equal(nrow(subset_flowpaths), 1129) + expect_equal(unique(subset_flowpaths$vpuid), "10L") + expect_equal(min(subset_flowpaths$mainstemlp), 1113198) - # Divides - expect_equal(nrow(subset_divides), 3354) - expect_equal(unique(subset_divides$vpuid), "13") - - # Network - expect_equal(nrow(subset_network), 3446) - expect_equal(unique(subset_network$vpuid), "13") - - unlink(outfile) - -}) - -# Test with an poi_id and network file -test_that("Terminal point check for poi_id passed", { - - get_subset(outfile = outfile, - poi_id = 111, - source = source, - type = type, - lyrs = lyrs, - hf_version = hf_version, - overwrite = TRUE) - - subset_flowpaths <- read_sf("subset_test.gpkg", layer = "flowlines") - subset_divides <- read_sf("subset_test.gpkg", layer = "divides") - subset_network <- read_sf("subset_test.gpkg", layer = "network") - - # Flowlines - expect_equal(nrow(subset_flowpaths), 23) - expect_equal(unique(subset_flowpaths$vpuid), "01") - - # Divides - expect_equal(nrow(subset_divides), 23) - expect_equal(unique(subset_divides$vpuid), "01") - - # Network - expect_equal(nrow(subset_network), 23) - expect_equal(unique(subset_network$vpuid), "01") - - unlink(outfile) -}) - -# Test with an hl_uri and network file -test_that("Terminal point check for hl_uri passed", { - - get_subset(outfile = outfile, - hl_uri = 'HUC12-010100070603', - source = source, - type = type, - lyrs = lyrs, - hf_version = hf_version, - overwrite = TRUE) - - subset_flowpaths <- read_sf("subset_test.gpkg", layer = "flowlines") - subset_divides <- read_sf("subset_test.gpkg", layer = "divides") - subset_network <- read_sf("subset_test.gpkg", layer = "network") - - # Flowlines - expect_equal(nrow(subset_flowpaths), 130) - expect_equal(unique(subset_flowpaths$vpuid), "01") # Divides - expect_equal(nrow(subset_divides), 127) - expect_equal(unique(subset_divides$vpuid), "01") + expect_equal(nrow(subset_divides), 1129) + expect_equal(unique(subset_divides$vpuid), "10L") # Network - expect_equal(nrow(subset_network), 135) - expect_equal(unique(subset_network$vpuid), "01") + expect_equal(nrow(subset_network), 1145) + expect_equal(unique(subset_network$vpuid), "10L") unlink(outfile) - }) - -unlink(outfile) \ No newline at end of file