Skip to content

Commit

Permalink
test(depth/yield): breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dimfalk committed Mar 6, 2024
1 parent 9e98c15 commit 3826d11
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 38 deletions.
9 changes: 6 additions & 3 deletions tests/testthat/test-as_depth.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ test_that("Function working as intended with numeric.", {

test_that("Function working as intended with units.", {

expect_equal(as_depth(units::as_units(843.3, "l s-1 ha-1"), d = units::as_units(5, "min")), units::as_units(25.3, "mm"))
expect_equal(as_depth(units::as_units(843.3, "l s-1 ha-1"), d = units::as_units(5, "min")),
units::as_units(25.3, "mm"))

expect_equal(as_depth(units::as_units(126.9, "l s-1 ha-1"), d = units::as_units(60, "min")), units::as_units(45.7, "mm"))
expect_equal(as_depth(units::as_units(126.9, "l s-1 ha-1"), d = units::as_units(60, "min")),
units::as_units(45.7, "mm"))

expect_equal(as_depth(units::as_units(13.9, "l s-1 ha-1"), d = units::as_units(1440, "min")), units::as_units(120.1, "mm"))
expect_equal(as_depth(units::as_units(13.9, "l s-1 ha-1"), d = units::as_units(1440, "min")),
units::as_units(120.1, "mm"))
})
9 changes: 6 additions & 3 deletions tests/testthat/test-as_yield.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ test_that("Function working as intended with numeric.", {

test_that("Function working as intended with units", {

expect_equal(as_yield(units::as_units(25.3, "mm"), d = units::as_units(5, "min")), units::as_units(843.3, "l s-1 ha-1"))
expect_equal(as_yield(units::as_units(25.3, "mm"), d = units::as_units(5, "min")),
units::as_units(843.3, "l s-1 ha-1"))

expect_equal(as_yield(units::as_units(45.7, "mm"), d = units::as_units(60, "min")), units::as_units(126.9, "l s-1 ha-1"))
expect_equal(as_yield(units::as_units(45.7, "mm"), d = units::as_units(60, "min")),
units::as_units(126.9, "l s-1 ha-1"))

expect_equal(as_yield(units::as_units(120.5, "mm"), d = units::as_units(1440, "min")), units::as_units(13.9, "l s-1 ha-1"))
expect_equal(as_yield(units::as_units(120.5, "mm"), d = units::as_units(1440, "min")),
units::as_units(13.9, "l s-1 ha-1"))
})
45 changes: 30 additions & 15 deletions tests/testthat/test-get_depth.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
test_that("Getting precipitation depths for DWD-KOSTRA-2010R works.", {

expect_equal(get_depth(kostra_ref, d = 5, tn = 1), units::as_units(5.6, "mm"))
expect_equal(get_depth(kostra_ref, d = 5, tn = 1),
units::as_units(5.6, "mm"))

expect_equal(get_depth(kostra_ref, d = 4320, tn = 1), units::as_units(49.8, "mm"))
expect_equal(get_depth(kostra_ref, d = 4320, tn = 1),
units::as_units(49.8, "mm"))

expect_equal(get_depth(kostra_ref, d = 5, tn = 100), units::as_units(14.4, "mm"))
expect_equal(get_depth(kostra_ref, d = 5, tn = 100),
units::as_units(14.4, "mm"))

expect_equal(get_depth(kostra_ref, d = 4320, tn = 100), units::as_units(108.1, "mm"))
expect_equal(get_depth(kostra_ref, d = 4320, tn = 100),
units::as_units(108.1, "mm"))
})

test_that("Getting precipitation depths (considering uncertainties) for DWD-KOSTRA-2010R works.", {

expect_equal(get_depth(kostra_ref, d = 1440, tn = 5, uc = TRUE), units::as_units(c(46.7, 57.1), "mm"))
expect_equal(get_depth(kostra_ref, d = 1440, tn = 5, uc = TRUE),
units::as_units(c(46.7, 57.1), "mm"))

expect_equal(get_depth(kostra_ref, d = 1440, tn = 50, uc = TRUE), units::as_units(c(63.7, 86.1), "mm"))
expect_equal(get_depth(kostra_ref, d = 1440, tn = 50, uc = TRUE),
units::as_units(c(63.7, 86.1), "mm"))

expect_equal(get_depth(kostra_ref, d = 1440, tn = 100, uc = TRUE), units::as_units(c(65.4, 98.2), "mm"))
expect_equal(get_depth(kostra_ref, d = 1440, tn = 100, uc = TRUE),
units::as_units(c(65.4, 98.2), "mm"))
})

test_that("Getting precipitation depths for stats from DWA-A 531 works.", {

expect_equal(get_depth(stats_ref, d = 5, tn = 1), units::as_units(6.1, "mm"))
expect_equal(get_depth(stats_ref, d = 5, tn = 1),
units::as_units(6.1, "mm"))

expect_equal(get_depth(stats_ref, d = 4320, tn = 1), units::as_units(47.4, "mm"))
expect_equal(get_depth(stats_ref, d = 4320, tn = 1),
units::as_units(47.4, "mm"))

expect_equal(get_depth(stats_ref, d = 5, tn = 100), units::as_units(14.2, "mm"))
expect_equal(get_depth(stats_ref, d = 5, tn = 100),
units::as_units(14.2, "mm"))

expect_equal(get_depth(stats_ref, d = 4320, tn = 100), units::as_units(102.2, "mm"))
expect_equal(get_depth(stats_ref, d = 4320, tn = 100),
units::as_units(102.2, "mm"))
})

test_that("Getting precipitation depths for PEN works.", {

expect_equal(get_depth(pen_ref, d = 5, tn = 200), units::as_units(19.1, "mm"))
expect_equal(get_depth(pen_ref, d = 5, tn = 200),
units::as_units(19.1, "mm"))

expect_equal(get_depth(pen_ref, d = 4320, tn = 200), units::as_units(142.5, "mm"))
expect_equal(get_depth(pen_ref, d = 4320, tn = 200),
units::as_units(142.5, "mm"))

expect_equal(get_depth(pen_ref, d = 5, tn = 10000), units::as_units(29.5, "mm"))
expect_equal(get_depth(pen_ref, d = 5, tn = 10000),
units::as_units(29.5, "mm"))

expect_equal(get_depth(pen_ref, d = 4320, tn = 10000), units::as_units(214.6, "mm"))
expect_equal(get_depth(pen_ref, d = 4320, tn = 10000),
units::as_units(214.6, "mm"))
})
51 changes: 34 additions & 17 deletions tests/testthat/test-get_returnp.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,66 @@
test_that("Getting return periods for DWD-KOSTRA-2010R works.", {

expect_equal(get_returnp(kostra_ref, hn = 30.2, d = 1440), units::as_units(c(0, 1), "a"))
expect_equal(get_returnp(kostra_ref, hn = 30.2, d = 1440),
units::as_units(c(0, 1), "a"))

expect_equal(get_returnp(kostra_ref, hn = 42.8, d = 1440), units::as_units(c(2, 2), "a"))
expect_equal(get_returnp(kostra_ref, hn = 42.8, d = 1440),
units::as_units(c(2, 2), "a"))

expect_equal(get_returnp(kostra_ref, hn = 72.3, d = 1440), units::as_units(c(30, 50), "a"))
expect_equal(get_returnp(kostra_ref, hn = 72.3, d = 1440),
units::as_units(c(30, 50), "a"))

expect_equal(get_returnp(kostra_ref, hn = 81.0, d = 1440), units::as_units(c(50, 100), "a"))
expect_equal(get_returnp(kostra_ref, hn = 81.0, d = 1440),
units::as_units(c(50, 100), "a"))

expect_equal(get_returnp(kostra_ref, hn = 86.3, d = 1440), units::as_units(c(100, Inf), "a"))
expect_equal(get_returnp(kostra_ref, hn = 86.3, d = 1440),
units::as_units(c(100, Inf), "a"))
})

test_that("Getting interpolated return periods for DWD-KOSTRA-2010R works.", {

expect_error(get_returnp(kostra_ref, hn = 30.2, d = 1440, interpolate = TRUE))

expect_equal(get_returnp(kostra_ref, hn = 42.8, d = 1440, interpolate = TRUE), units::as_units(2, "a"))
expect_equal(get_returnp(kostra_ref, hn = 42.8, d = 1440, interpolate = TRUE),
units::as_units(2, "a"))

expect_equal(get_returnp(kostra_ref, hn = 72.3, d = 1440, interpolate = TRUE), units::as_units(39.9, "a"))
expect_equal(get_returnp(kostra_ref, hn = 72.3, d = 1440, interpolate = TRUE),
units::as_units(39.9, "a"))

expect_equal(get_returnp(kostra_ref, hn = 81.0, d = 1440, interpolate = TRUE), units::as_units(94.4, "a"))
expect_equal(get_returnp(kostra_ref, hn = 81.0, d = 1440, interpolate = TRUE),
units::as_units(94.4, "a"))

expect_error(get_returnp(kostra_ref, hn = 86.3, d = 1440, interpolate = TRUE))
})

test_that("Getting return periods for PEN works.", {

expect_equal(get_returnp(pen_ref, hn = 68.2, d = 60), units::as_units(c(0, 200), "a"))
expect_equal(get_returnp(pen_ref, hn = 68.2, d = 60),
units::as_units(c(0, 200), "a"))

expect_equal(get_returnp(pen_ref, hn = 77.7, d = 60), units::as_units(c(500, 500), "a"))
expect_equal(get_returnp(pen_ref, hn = 77.7, d = 60),
units::as_units(c(500, 500), "a"))

expect_equal(get_returnp(pen_ref, hn = 80, d = 60), units::as_units(c(500, 1000), "a"))
expect_equal(get_returnp(pen_ref, hn = 80, d = 60),
units::as_units(c(500, 1000), "a"))

expect_equal(get_returnp(pen_ref, hn = 110, d = 60), units::as_units(c(10000, Inf), "a"))
expect_equal(get_returnp(pen_ref, hn = 110, d = 60),
units::as_units(c(10000, Inf), "a"))
})

test_that("Getting return periods for stats from DWA-A 531 works.", {

expect_equal(get_returnp(stats_ref, hn = 30.2, d = 1440), units::as_units(c(0, 1), "a"))
expect_equal(get_returnp(stats_ref, hn = 30.2, d = 1440),
units::as_units(c(0, 1), "a"))

expect_equal(get_returnp(stats_ref, hn = 40.7, d = 1440), units::as_units(c(2, 2), "a"))
expect_equal(get_returnp(stats_ref, hn = 40.7, d = 1440),
units::as_units(c(2, 2), "a"))

expect_equal(get_returnp(stats_ref, hn = 72.3, d = 1440), units::as_units(c(33, 50), "a"))
expect_equal(get_returnp(stats_ref, hn = 72.3, d = 1440),
units::as_units(c(33, 50), "a"))

expect_equal(get_returnp(stats_ref, hn = 81.0, d = 1440), units::as_units(c(50, 100), "a"))
expect_equal(get_returnp(stats_ref, hn = 81.0, d = 1440),
units::as_units(c(50, 100), "a"))

expect_equal(get_returnp(stats_ref, hn = 86.3, d = 1440), units::as_units(c(100, Inf), "a"))
expect_equal(get_returnp(stats_ref, hn = 86.3, d = 1440),
units::as_units(c(100, Inf), "a"))
})

0 comments on commit 3826d11

Please sign in to comment.