Skip to content

Commit

Permalink
Completing cetesb_retrieve function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quishqa committed Feb 15, 2022
1 parent b5e5435 commit 29eb915
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
24 changes: 21 additions & 3 deletions tests/testthat/test-cetesb_retrieve_met.R
Expand Up @@ -2,10 +2,28 @@ test_that("CetesbRetrieveMet works", {

load("sysdata.rda")

pin_pol <- cetesb_retrieve_met(u,p,aqs_code = 99,
pin_met <- cetesb_retrieve_met(u,p,aqs_code = 99,
start_date = "01/01/2020",
end_date = "07/01/2020")

expect_equal(ncol(pin_pol), 7)
expect_equal(nrow(pin_pol), 169)
# Testing data.frame dims
expect_equal(ncol(pin_met), 7)
expect_equal(nrow(pin_met), 169)

# Testing data.frame values
param_means<- colMeans(pin_met[, 2:6], na.rm = TRUE)
expect_equal(param_means["tc"] > 23, param_means["tc"] < 24)
expect_equal(param_means["rh"] > 74, param_means["rh"] < 75)
expect_equal(param_means["ws"] > 1, param_means["ws"] < 2)
expect_equal(param_means["wd"] > 238, param_means["wd"] < 239)

# Testing data.frame classes
expect_equal(TRUE, "data.frame" %in% class(pin_met))
expect_equal(TRUE, "character" %in% class(pin_met$aqs))
expect_equal(TRUE, "POSIXct" %in% class(pin_met$date))
expect_equal(TRUE, "numeric" %in% class(pin_met$tc))
expect_equal(TRUE, "numeric" %in% class(pin_met$rh))
expect_equal(TRUE, "numeric" %in% class(pin_met$ws))
expect_equal(TRUE, "numeric" %in% class(pin_met$wd))
expect_equal(TRUE, "numeric" %in% class(pin_met$p))
})
17 changes: 17 additions & 0 deletions tests/testthat/test-cetesb_retrieve_met_pol.R
Expand Up @@ -6,8 +6,25 @@ test_that("CetesbRetrieveMetPol", {
start_date = "01/01/2020",
end_date = "07/01/2020")

# Testing data.frame dims
expect_equal(ncol(pinheiros), 14)
expect_equal(nrow(pinheiros), 169)

# Testing data.frame values
param_means<- colMeans(pinheiros[, 2:13], na.rm = TRUE)
expect_equal(param_means["tc"] > 23, param_means["tc"] < 24)
expect_equal(param_means["rh"] > 74, param_means["rh"] < 75)
expect_equal(param_means["ws"] > 1, param_means["ws"] < 2)
expect_equal(param_means["wd"] > 238, param_means["wd"] < 239)
expect_equal(param_means["o3"] > 27, param_means["o3"] < 28)
expect_equal(param_means["no"] > 8, param_means["no"] < 9)
expect_equal(param_means["no2"] > 26, param_means["no2"] < 27)
expect_equal(param_means["nox"] > 20, param_means["nox"] < 21)
expect_equal(param_means["co"] > 0.3, param_means["co"] < 0.4)
expect_equal(param_means["pm10"] > 19, param_means["pm10"] < 20)
expect_equal(param_means["pm25"] > 5, param_means["pm25"] < 6)

# Testing data.frame classes
expect_equal(TRUE, "data.frame" %in% class(pinheiros))
expect_equal(TRUE, "numeric" %in% class(pinheiros$tc))
expect_equal(TRUE, "numeric" %in% class(pinheiros$rh))
Expand Down
22 changes: 20 additions & 2 deletions tests/testthat/test-cetesb_retrieve_param.R
@@ -1,4 +1,4 @@
test_that("CetesbRetrieveParam works!", {
test_that("cetesb_retrieve_param works!", {

load("sysdata.rda")

Expand All @@ -8,10 +8,28 @@ test_that("CetesbRetrieveParam works!", {
pin_param <- cetesb_retrieve_param(u,p,c("o3","NOX", "VV"), 99,
"01/01/2020", "07/01/2020",
to_csv = TRUE, csv_path = csv_path)

# Testing writing output
expect_equal(TRUE,
file.exists(
paste0(csv_path,
"/Pinheiros_O3_NOX_VV_01-01-2020_07-01-2020.csv")
))

# Testing data.frame dims
expect_equal(ncol(pin_param), 5)
expect_equal(nrow(pin_param), 169)

# Testing data.frame values
param_means<- colMeans(pin_param[, 3:5], na.rm = TRUE)
expect_equal(param_means["nox"] > 20, param_means["nox"] < 21)
expect_equal(param_means["o3"] > 27, param_means["o3"] < 28)
expect_equal(param_means["ws"] > 1, param_means["ws"] < 2)

# Testing data.frame classes
expect_equal(TRUE, "data.frame" %in% class(pin_param))
expect_equal(TRUE, "character" %in% class(pin_param$aqs))
expect_equal(TRUE, "POSIXct" %in% class(pin_param$date))
expect_equal(TRUE, "numeric" %in% class(pin_param$o3))
expect_equal(TRUE, "numeric" %in% class(pin_param$nox))
expect_equal(TRUE, "numeric" %in% class(pin_param$ws))
})
3 changes: 2 additions & 1 deletion tests/testthat/test-cetesb_retrieve_pol.R
@@ -1,4 +1,4 @@
test_that("cetesb_retrieve_pol.R works", {
test_that("cetesb_retrieve_pol.R works!", {

load("sysdata.rda")

Expand All @@ -21,6 +21,7 @@ test_that("cetesb_retrieve_pol.R works", {

# Testing data.frame classes
expect_equal(TRUE, "data.frame" %in% class(pin_pol))
expect_equal(TRUE, "POSIXct" %in% class(pin_pol$date))
expect_equal(TRUE, "numeric" %in% class(pin_pol$o3))
expect_equal(TRUE, "numeric" %in% class(pin_pol$no))
expect_equal(TRUE, "numeric" %in% class(pin_pol$no2))
Expand Down

0 comments on commit 29eb915

Please sign in to comment.