From ec79637749d300ab4ca170805c673905e52d67dd Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 22 Apr 2015 13:42:10 +0200 Subject: Add simplest PEC soil calcs, use testthat --- pkg/tests/testthat/H_sw_D4_pond.rds | Bin 0 -> 243113 bytes pkg/tests/testthat/H_sw_R1_stream_events.rds | Bin 0 -> 332 bytes pkg/tests/testthat/H_sw_R1_stream_windows.rds | Bin 0 -> 234 bytes pkg/tests/testthat/test_PEC_soil.R | 13 +++++++++++++ pkg/tests/testthat/test_TOXSWA_cwa.R | 25 +++++++++++++++++++++++++ 5 files changed, 38 insertions(+) create mode 100644 pkg/tests/testthat/H_sw_D4_pond.rds create mode 100644 pkg/tests/testthat/H_sw_R1_stream_events.rds create mode 100644 pkg/tests/testthat/H_sw_R1_stream_windows.rds create mode 100644 pkg/tests/testthat/test_PEC_soil.R create mode 100644 pkg/tests/testthat/test_TOXSWA_cwa.R (limited to 'pkg/tests/testthat') diff --git a/pkg/tests/testthat/H_sw_D4_pond.rds b/pkg/tests/testthat/H_sw_D4_pond.rds new file mode 100644 index 0000000..9ad8194 Binary files /dev/null and b/pkg/tests/testthat/H_sw_D4_pond.rds differ diff --git a/pkg/tests/testthat/H_sw_R1_stream_events.rds b/pkg/tests/testthat/H_sw_R1_stream_events.rds new file mode 100644 index 0000000..3e2828e Binary files /dev/null and b/pkg/tests/testthat/H_sw_R1_stream_events.rds differ diff --git a/pkg/tests/testthat/H_sw_R1_stream_windows.rds b/pkg/tests/testthat/H_sw_R1_stream_windows.rds new file mode 100644 index 0000000..29e13f2 Binary files /dev/null and b/pkg/tests/testthat/H_sw_R1_stream_windows.rds differ diff --git a/pkg/tests/testthat/test_PEC_soil.R b/pkg/tests/testthat/test_PEC_soil.R new file mode 100644 index 0000000..27b2eb7 --- /dev/null +++ b/pkg/tests/testthat/test_PEC_soil.R @@ -0,0 +1,13 @@ +library(pfm) +context("Simple PEC soil calculations") + +test_that("PEC_soil calculates correctly", { + # Application of 100 g/ha gives 0.133 mg/kg under default assumptions + expect_equal(PEC_soil(100), 0.1 * 4/3) + + # or 0.1 mg/kg assuming 25% interception + expect_equal(PEC_soil(100, interception = 0.25), 0.1) + + # Mixing depth of 1 cm gives five-fold PEC + expect_equal(PEC_soil(100, interception = 0.25, mixing_depth = 1), 0.5) +}) diff --git a/pkg/tests/testthat/test_TOXSWA_cwa.R b/pkg/tests/testthat/test_TOXSWA_cwa.R new file mode 100644 index 0000000..d91b79a --- /dev/null +++ b/pkg/tests/testthat/test_TOXSWA_cwa.R @@ -0,0 +1,25 @@ +library(pfm) +context("Read and analyse TOXSWA cwa files") + +test_that("TOXSWA cwa file is correctly read", { + H_sw_D4_pond <- read.TOXSWA_cwa("00001p_pa.cwa", + basedir = "SwashProjects/project_H_sw/TOXSWA", + zipfile = system.file("testdata/SwashProjects.zip", + package = "pfm")) + expect_equal_to_reference(H_sw_D4_pond, file = "H_sw_D4_pond.rds") +}) + +test_that("Getting events and moving window analysis works", { + H_sw_R1_stream <- read.TOXSWA_cwa("00003s_pa.cwa", + basedir = "SwashProjects/project_H_sw/TOXSWA", + zipfile = system.file("testdata/SwashProjects.zip", + package = "pfm")) + + # Event analysis with two different thresholds + H_sw_R1_stream$get_events(c(2, 10)) + expect_equal_to_reference(H_sw_R1_stream$events, file = "H_sw_R1_stream_events.rds") + + # Moving window analysis + H_sw_R1_stream$moving_windows(c(7, 21)) + expect_equal_to_reference(H_sw_R1_stream$windows, file = "H_sw_R1_stream_windows.rds") +}) -- cgit v1.2.1