From eb1dc89d694f24eb8d5a44c5a71b0fac7e3e60d8 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 16:54:43 -0400 Subject: [PATCH 01/13] refactor: existing flow tests --- tests/testthat/test-flow.R | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index d4c783b..d57a0f2 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -1,5 +1,4 @@ -test_that("flow works with single input point", { - +test_that("flow does not throw error with single input point", { taxa <- "total" week = 15 date <- "2022-01-01" @@ -7,27 +6,18 @@ test_that("flow works with single input point", { lon <- -70 direction <- "forward" loc <- paste0(lat, ",", lon) - expect_no_error( res <- flow(loc = loc, week = week, taxa = taxa, direction = direction, n = 10, save_local = TRUE) ) - }) - - -test_that("flow works with single multi-point input", { - +test_that("flow does not throw error with single multi-point input", { taxa <- "total" # all taxa loc <- "42,-70;43,-72;40,-75" # test multi-point week <- 12 direction <- "forward" - expect_no_error( res <- flow(loc = loc, week = week, taxa = taxa, direction = direction, n = 10)) - - - }) From 5ae20e7d87e8eba30dd4f07e87d1ad6a9e2816d6 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 17:00:59 -0400 Subject: [PATCH 02/13] feat: test for flow status --- tests/testthat/test-flow.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index d57a0f2..9f84fc2 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -21,3 +21,13 @@ test_that("flow does not throw error with single multi-point input", { res <- flow(loc = loc, week = week, taxa = taxa, direction = direction, n = 10)) }) + +test_that("status is either success or cached", { + taxa <- "ambduc" + loc <- "42,-70" + week <- 3 + direction <- "forward" + n <- 1 + res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) + expect_true(res$status == "success" || res$status == "cached") +}) From dbc45dcb1ef12ea54d26541a7ac7c98f4cc08e39 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 17:11:19 -0400 Subject: [PATCH 03/13] feat: verify taxa --- tests/testthat/test-flow.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 9f84fc2..6b06c0e 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -31,3 +31,13 @@ test_that("status is either success or cached", { res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) expect_true(res$status == "success" || res$status == "cached") }) + +test_that("result taxa matches input", { + taxa <- "ambduc" + loc <- "42,-70" + week <- 3 + direction <- "forward" + n <- 1 + res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) + expect_true(res$start$taxa == taxa) +}) \ No newline at end of file From 9b614e5a29cdd9d8ea5c0cef3a458c8ee957d757 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 17:16:04 -0400 Subject: [PATCH 04/13] feat: verify flow loc --- tests/testthat/test-flow.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 6b06c0e..e5c1f1c 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -40,4 +40,14 @@ test_that("result taxa matches input", { n <- 1 res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) expect_true(res$start$taxa == taxa) -}) \ No newline at end of file +}) + +test_that("result loc matches input", { + taxa <- "ambduc" + loc <- "42,-70" + week <- 3 + direction <- "forward" + n <- 1 + res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) + expect_true(res$start$loc == loc) +}) From 916679e54433330c98bd6d018bc035312fac7baf Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 17:16:59 -0400 Subject: [PATCH 05/13] feat: verify flow start week --- tests/testthat/test-flow.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index e5c1f1c..9353679 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -51,3 +51,13 @@ test_that("result loc matches input", { res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) expect_true(res$start$loc == loc) }) + +test_that("result start week matches input", { + taxa <- "ambduc" + loc <- "42,-70" + week <- 3 + direction <- "forward" + n <- 1 + res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) + expect_true(res$start$week == week) +}) From 7eb1983fe605cfbc5f93dc57a2f0631970fad765 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 17:35:17 -0400 Subject: [PATCH 06/13] refactor: flow tests --- tests/testthat/test-flow.R | 74 ++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 9353679..f8fb352 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -1,63 +1,51 @@ +# Helper function to return a standardized list of paramaters for testing flow +# These parameters can be used to test fundamental properties of the flow result +standard_flow_input <- function() { + return(list( + taxa = "ambduc", + loc = "42,-70", + week = 15, + direction = "forward", + n = 10, + save_local = TRUE + )) +} + test_that("flow does not throw error with single input point", { - taxa <- "total" - week = 15 - date <- "2022-01-01" - lat <- 42 - lon <- -70 - direction <- "forward" - loc <- paste0(lat, ",", lon) + params <- standard_flow_input() expect_no_error( - res <- flow(loc = loc, week = week, taxa = taxa, - direction = direction, n = 10, save_local = TRUE) - ) + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + ) }) test_that("flow does not throw error with single multi-point input", { - taxa <- "total" # all taxa - loc <- "42,-70;43,-72;40,-75" # test multi-point - week <- 12 - direction <- "forward" + params <- standard_flow_input() + multi_point_loc <- "42,-70;43,-72;40,-75" # test multi-point expect_no_error( - res <- flow(loc = loc, week = week, taxa = taxa, - direction = direction, n = 10)) + res <- flow(loc = multi_point_loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + ) }) test_that("status is either success or cached", { - taxa <- "ambduc" - loc <- "42,-70" - week <- 3 - direction <- "forward" - n <- 1 - res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) + params <- standard_flow_input() + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) expect_true(res$status == "success" || res$status == "cached") }) test_that("result taxa matches input", { - taxa <- "ambduc" - loc <- "42,-70" - week <- 3 - direction <- "forward" - n <- 1 - res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) - expect_true(res$start$taxa == taxa) + params <- standard_flow_input() + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + expect_true(res$start$taxa == params$taxa) }) test_that("result loc matches input", { - taxa <- "ambduc" - loc <- "42,-70" - week <- 3 - direction <- "forward" - n <- 1 - res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) - expect_true(res$start$loc == loc) + params <- standard_flow_input() + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + expect_true(res$start$loc == params$loc) }) test_that("result start week matches input", { - taxa <- "ambduc" - loc <- "42,-70" - week <- 3 - direction <- "forward" - n <- 1 - res <- flow(loc = loc, week = week, taxa = taxa, n = n, direction = direction) - expect_true(res$start$week == week) + params <- standard_flow_input() + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + expect_true(res$start$week == params$week) }) From e5c89172ebd954719bc98fc96392d252855e5b8b Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 17:48:11 -0400 Subject: [PATCH 07/13] feat: verify geotiff link --- tests/testthat/test-flow.R | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index f8fb352..83e759d 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -49,3 +49,12 @@ test_that("result start week matches input", { res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) expect_true(res$start$week == params$week) }) + +test_that("geotiff is a valid AWS link", { + params <- standard_flow_input() + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + expect_true( + grepl("https://avianinfluenza.s3.us-east-2.amazonaws.com/flow/", res$geotiff) || + grepl(paste0(get_s3_config()$local_temp_path, "/"), res$geotiff) + ) +}) From 5876172ca0b2277fb86f6a1a8e730e286ffd8a26 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 17:58:06 -0400 Subject: [PATCH 08/13] feat: verify result length --- tests/testthat/test-flow.R | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 83e759d..101b634 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -32,19 +32,19 @@ test_that("status is either success or cached", { expect_true(res$status == "success" || res$status == "cached") }) -test_that("result taxa matches input", { +test_that("output taxa matches input", { params <- standard_flow_input() res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) expect_true(res$start$taxa == params$taxa) }) -test_that("result loc matches input", { +test_that("output loc matches input", { params <- standard_flow_input() res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) expect_true(res$start$loc == params$loc) }) -test_that("result start week matches input", { +test_that("output week matches input", { params <- standard_flow_input() res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) expect_true(res$start$week == params$week) @@ -58,3 +58,9 @@ test_that("geotiff is a valid AWS link", { grepl(paste0(get_s3_config()$local_temp_path, "/"), res$geotiff) ) }) + +test_that("length of result is n + 1", { + params <- standard_flow_input() + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + expect_true(length(res$result) == (params$n + 1)) +}) From fb1786e0e3a89b8ce9d2a6209f30bdddb4771b20 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 18:08:51 -0400 Subject: [PATCH 09/13] feat: verify result weeks --- tests/testthat/test-flow.R | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 101b634..8b85274 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -64,3 +64,12 @@ test_that("length of result is n + 1", { res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) expect_true(length(res$result) == (params$n + 1)) }) + +test_that("result contents are valid", { + params <- standard_flow_input() + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) + for(i in seq_along(res$result)) { + row <- res$result[[i]] + expect_true(row$week == params$week + i - 1) + } +}) From 464c79bddc7eff07caa284b698183c8c870c1139 Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 18:10:45 -0400 Subject: [PATCH 10/13] feat: verify url and legend of all result weeks --- tests/testthat/test-flow.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 8b85274..0e704df 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -71,5 +71,13 @@ test_that("result contents are valid", { for(i in seq_along(res$result)) { row <- res$result[[i]] expect_true(row$week == params$week + i - 1) + expect_true( + grepl("https://avianinfluenza.s3.us-east-2.amazonaws.com/flow/", row$url) || + grepl(paste0(get_s3_config()$local_temp_path, "/"), row$url) + ) + expect_true( + grepl("https://avianinfluenza.s3.us-east-2.amazonaws.com/flow/", row$legend) || + grepl(paste0(get_s3_config()$local_temp_path, "/"), row$legend) + ) } }) From 1cc404149762eca331dd43afe8c38dd7cf1cdc9a Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 18:17:02 -0400 Subject: [PATCH 11/13] feat: verify status for inflow --- tests/testthat/test-flow.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 0e704df..0712a40 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -26,12 +26,19 @@ test_that("flow does not throw error with single multi-point input", { ) }) -test_that("status is either success or cached", { +test_that("status is either success or cached (outflow)", { params <- standard_flow_input() res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) expect_true(res$status == "success" || res$status == "cached") }) +test_that("status is either success or cached (inflow)", { + params <- standard_flow_input() + direction <- "backward" + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = direction, save_local = params$save_local) + expect_true(res$status == "success" || res$status == "cached") +}) + test_that("output taxa matches input", { params <- standard_flow_input() res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) From 973e2239f0b1f65bbf154006f57e12cd8820ad7b Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 18:18:52 -0400 Subject: [PATCH 12/13] feat: verify types of all result weeks (outflow) --- tests/testthat/test-flow.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 0712a40..0b4f42f 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -72,7 +72,7 @@ test_that("length of result is n + 1", { expect_true(length(res$result) == (params$n + 1)) }) -test_that("result contents are valid", { +test_that("result contents are valid (outflow)", { params <- standard_flow_input() res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = params$direction, save_local = params$save_local) for(i in seq_along(res$result)) { @@ -86,5 +86,6 @@ test_that("result contents are valid", { grepl("https://avianinfluenza.s3.us-east-2.amazonaws.com/flow/", row$legend) || grepl(paste0(get_s3_config()$local_temp_path, "/"), row$legend) ) + expect_true(row$type == "outflow") } }) From 14f0827ebb62f6f6ffd2892b4cfc8983ffa3ff0e Mon Sep 17 00:00:00 2001 From: Atharva Shahane Date: Sun, 28 Sep 2025 18:27:01 -0400 Subject: [PATCH 13/13] feat: result contents for inflow --- tests/testthat/test-flow.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 0b4f42f..c879951 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -89,3 +89,27 @@ test_that("result contents are valid (outflow)", { expect_true(row$type == "outflow") } }) + +test_that("result contents are valid (inflow)", { + params <- standard_flow_input() + direction <- "backward" + res <- flow(loc = params$loc, week = params$week, taxa = params$taxa, n = params$n, direction = direction, save_local = params$save_local) + curr_week <- params$week + for(i in seq_along(res$result)) { + row <- res$result[[i]] + expect_true(row$week == curr_week) + curr_week <- curr_week - 1 + if(curr_week == 0) { + curr_week <- 52 + } + expect_true( + grepl("https://avianinfluenza.s3.us-east-2.amazonaws.com/flow/", row$url) || + grepl(paste0(get_s3_config()$local_temp_path, "/"), row$url) + ) + expect_true( + grepl("https://avianinfluenza.s3.us-east-2.amazonaws.com/flow/", row$legend) || + grepl(paste0(get_s3_config()$local_temp_path, "/"), row$legend) + ) + expect_true(row$type == "inflow") + } +})