Skip to content

Commit

Permalink
Merge pull request #20 from KWB-R/add-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
hsonne committed Jul 22, 2023
2 parents 251c178 + 52d2752 commit e7650de
Show file tree
Hide file tree
Showing 49 changed files with 528 additions and 554 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
5 changes: 5 additions & 0 deletions tests/testthat/_missing-functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test_that("functions are missing", {

expect_error(r2q:::import_hydrology_data)

})
36 changes: 24 additions & 12 deletions tests/testthat/test-function-Input_event.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user hsonne on 2023-07-14 11:50:24.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("Input_event() works", {

f <- r2q:::Input_event
f <- r2q::Input_event

expect_error(
r2q:::Input_event()
# argument "area_runoff" is missing, with no default
)
expect_error(f())

expect_identical(
f(
area_runoff = 0,
Ci_storm = 0,
coeff_runoff = 0,
q_rain = 0,
t_rain = 0
),
0
)

expect_identical(
f(
area_runoff = 1000,
Ci_storm = 1,
coeff_runoff = 1,
q_rain = 1,
t_rain = 1
),
1
)

})
16 changes: 0 additions & 16 deletions tests/testthat/test-function-add_critical_loads.R

This file was deleted.

16 changes: 0 additions & 16 deletions tests/testthat/test-function-add_max_areas.R

This file was deleted.

17 changes: 6 additions & 11 deletions tests/testthat/test-function-area_from_load.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user hsonne on 2023-07-14 11:50:24.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("area_from_load() works", {

f <- r2q:::area_from_load

expect_error(
r2q:::area_from_load()
# argument "load_runoff" is missing, with no default
)
expect_error(f())

expect_identical(
f(load_runoff = 1, Ci_storm = 1, coeff_runoff = 1, q_rain = 1, t_rain = 1),
1000
)

})
57 changes: 45 additions & 12 deletions tests/testthat/test-function-assess_all_hazards.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user hsonne on 2023-07-14 11:50:22.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("assess_all_hazards() works", {

f <- r2q:::assess_all_hazards
f <- r2q::assess_all_hazards

expect_error(
r2q:::assess_all_hazards()
# argument "hazard_list" is missing, with no default
)
expect_error(f())

hazard_list <- list(
x = c(pot_med = 1, pot_q95 = 2),
y = c(pot_med = 3, pot_q95 = 4)
)

site_data <- list(
area_urban_connected = list(Value = 1),
area_urban_connectable = list(Value = 1),
area_plan = list(Value = 1),
area_urban = list(Value = 1),
f_D_is = list(Value = 1),
f_D_pot = list(Value = 1),
Q_event = list(Value = 1),
river_length = list(Value = 100),
cross_section_event = list(Value = 100)
)

c_table <- data.frame(
substance = c("x", "y"),
threshold_type = c("acute", "annual"),
threshold = c(0.1, 0.2),
unit = c("ng", "mg"),
pot_med = c(1, 2),
is_med = c(1, 2),
is_q95 = c(3, 4),
c_river = c(1, 2)
)

expect_error(result <- f(
hazard_list = hazard_list,
site_data = site_data,
c_table = c_table,
q_rain = 1,
t_rain = 1
))

# expect_is(result, "list")
#
# expect_identical(names(result), c(
# "general",
# "planning_pot",
# "planning_scaled"
# ))
})
16 changes: 0 additions & 16 deletions tests/testthat/test-function-assess_discharges.R

This file was deleted.

16 changes: 0 additions & 16 deletions tests/testthat/test-function-calculate_relevant_discharge.R

This file was deleted.

22 changes: 11 additions & 11 deletions tests/testthat/test-function-calculate_tolerable_discharge.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user mzamzo on 2021-11-03 11:55:01.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("calculate_tolerable_discharge() works", {

expect_error(
r2q:::calculate_tolerable_discharge(site_data = NA)
# '' does not exist in current working directory ('C:/Users/mzamzo/Documents/R/git/r2q').
)
f <- r2q::calculate_tolerable_discharge

check <- function(result) {
expect_s3_class(result, "data.frame")
expect_identical(nrow(result), 1L)
}

expect_output(result <- f(verbose = TRUE))
check(result)

expect_silent(result <- f(verbose = FALSE))
check(result)
})
15 changes: 3 additions & 12 deletions tests/testthat/test-function-check_all_substances.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user hsonne on 2023-07-14 11:50:22.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("check_all_substances() works", {

f <- r2q:::check_all_substances

expect_error(
r2q:::check_all_substances()
# argument "c_table" is missing, with no default
)

expect_error(f())
expect_type(f(c_table = data.frame(), c_type = "average"), "list")
expect_type(f(c_table = data.frame(), c_type = "worstcase"), "list")
})
17 changes: 5 additions & 12 deletions tests/testthat/test-function-check_pollutant_impact.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user hsonne on 2023-07-14 11:50:23.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("check_pollutant_impact() works", {

f <- r2q:::check_pollutant_impact
f <- r2q::check_pollutant_impact

expect_error(
r2q:::check_pollutant_impact()
# argument "Ci_river" is missing, with no default
)
expect_error(f())

expect_identical(-Inf, f(Ci_river = 1, Ci_threshold = 0, Ci_storm = 1))
expect_identical(Inf, f(Ci_river = 1, Ci_threshold = 1, Ci_storm = 1))
expect_true(f(Ci_river = 1, Ci_threshold = 1, Ci_storm = 2))
})
48 changes: 36 additions & 12 deletions tests/testthat/test-function-combine_concentration_tables.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user mzamzo on 2021-11-03 11:55:01.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("combine_concentration_tables() works", {

expect_error(
r2q:::combine_concentration_tables()
# argument "threshold_table" is missing, with no default
)
f <- r2q::combine_concentration_tables

expect_error(f())

threshold_table <- data.frame(
substance = "a",
Unit = "b",
threshold = 1,
threshold_type = "c"
)

storm_table <- data.frame(
substance = "a",
unit = "b",
x = 1
)

background_table <- data.frame(
substance = "a",
unit = "b",
y = 2
)

result <- f(
threshold_table = threshold_table,
storm_table = storm_table,
background_table = background_table
)

expect_identical(result, data.frame(
substance = "a",
unit = "b",
threshold = 1,
threshold_type = "c",
c_river = 2,
x = 1
))
})

16 changes: 0 additions & 16 deletions tests/testthat/test-function-criteria_test.R

This file was deleted.

5 changes: 1 addition & 4 deletions tests/testthat/test-function-get_HQ_time_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ test_that("get_HQ_time_interval() works", {

f <- r2q:::get_HQ_time_interval

expect_error(
r2q:::get_HQ_time_interval()
# argument "area_catch" is missing, with no default
)
expect_error(f())

})
18 changes: 8 additions & 10 deletions tests/testthat/test-function-get_Hq1_pnat.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#
# This test file has been generated by kwb.test::create_test_files()
# launched by user mzamzo on 2021-11-03 11:55:01.
# Your are strongly encouraged to modify the dummy functions
# so that real cases are tested. You should then delete this comment.
#

test_that("get_Hq1_pnat() works", {

r2q:::get_Hq1_pnat(slope = 0.1, area_catch = 1)

f <- r2q:::get_Hq1_pnat

expect_identical(f(slope = 0.1, area_catch = 60), 50)
expect_identical(f(slope = 0.1, area_catch = 3), 126)
expect_identical(f(slope = 0.5, area_catch = 100), 100)
expect_identical(f(slope = 0.5, area_catch = 99), 101)
expect_identical(f(slope = 2, area_catch = 400), 150)
expect_identical(f(slope = 2, area_catch = 300), 200)
})

0 comments on commit e7650de

Please sign in to comment.