Skip to content

Commit

Permalink
Update monitor_ar_retrieve functions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quishqa committed Feb 15, 2022
1 parent 734666b commit 3d3aaf3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
19 changes: 19 additions & 0 deletions tests/testthat/test-monitor_ar_retrieve_met.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ test_that("multiplication works", {
end_date <- "07/01/2020"
ca_met <- monitor_ar_retrieve_met(start_date, end_date, "CA")

# Testing data.frame dims
expect_equal(ncol(ca_met), 7)
expect_equal(TRUE, ncol(ca_met) <= 145)

# Testing data.frame values
met_means<- colMeans(ca_met[, 2:6], na.rm = TRUE)
expect_equal(met_means["tc"] > 28, met_means["tc"] < 29)
expect_equal(met_means["rh"] > 74, met_means["rh"] < 75)
expect_equal(met_means["ws"] > 0.8, met_means["ws"] < 0.9)
expect_equal(met_means["wd"] > 158, met_means["wd"] < 159)
expect_equal(met_means["p"] > 1007, met_means["p"] < 1008)

# Testing data.frame classes
expect_equal(TRUE, "data.frame" %in% class(ca_met))
expect_equal(TRUE, "character" %in% class(ca_met$aqs))
expect_equal(TRUE, "POSIXct" %in% class(ca_met$date))
expect_equal(TRUE, "numeric" %in% class(ca_met$tc))
expect_equal(TRUE, "numeric" %in% class(ca_met$rh))
expect_equal(TRUE, "numeric" %in% class(ca_met$ws))
expect_equal(TRUE, "numeric" %in% class(ca_met$wd))
expect_equal(TRUE, "numeric" %in% class(ca_met$p))

})
15 changes: 15 additions & 0 deletions tests/testthat/test-monitor_ar_retrieve_met_pol.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ test_that("multiplication works", {
end_date <- "07/01/2020"
ca_all <- monitor_ar_retrieve_met_pol(start_date, end_date, "CA")

# Testing data.frame dims
expect_equal(ncol(ca_all), 14)
expect_equal(TRUE, ncol(ca_all) <= 145)

# Testing data.frame values
all_means<- colMeans(ca_all[, 2:13], na.rm = TRUE)
expect_equal(all_means["tc"] > 28, all_means["tc"] < 29)
expect_equal(all_means["rh"] > 74, all_means["rh"] < 75)
expect_equal(all_means["ws"] > 0.8, all_means["ws"] < 0.9)
expect_equal(all_means["wd"] > 158, all_means["wd"] < 159)
expect_equal(all_means["p"] > 1007, all_means["p"] < 1008)
expect_equal(all_means["o3"] > 33, all_means["o3"] < 35)
expect_equal(all_means["co"] > 0.5, all_means["co"] < 0.6)
expect_equal(all_means["pm10"] > 21, all_means["pm10"] < 22)

# Testing data.frame classes
expect_equal(TRUE, "data.frame" %in% class(ca_all))
expect_equal(TRUE, "numeric" %in% class(ca_all$tc))
expect_equal(TRUE, "numeric" %in% class(ca_all$rh))
Expand Down
16 changes: 15 additions & 1 deletion tests/testthat/test-monitor_ar_retrieve_param.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,24 @@ test_that("MonitorArRetrieve works", {
parameters = "O3",
to_csv = TRUE,
csv_path = csv_path)

# Testing writing output
expect_equal(TRUE,
file.exists(
paste0(csv_path,
"/ESTACAO CENTRO_O3_01-02-2015_01-03-2015.csv")
))

# Testing data.frame output
expect_equal(ncol(ca_o3), 3)
expect_equal(nrow(ca_o3), 672)

# Testing data.frame values
o3_mean <- mean(ca_o3$o3, na.rm = TRUE)
expect_equal(o3_mean > 22, o3_mean < 23)

# Testing data.frame classes
expect_equal(TRUE, "data.frame" %in% class(ca_o3))
expect_equal(TRUE, "character" %in% class(ca_o3$aqs))
expect_equal(TRUE, "POSIXct" %in% class(ca_o3$date))
expect_equal(TRUE, "numeric" %in% class(ca_o3$o3))
})
24 changes: 22 additions & 2 deletions tests/testthat/test-monitor_ar_retrieve_pol.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ test_that("multiplication works", {
end_date <- "07/01/2020"
ca_pol <- monitor_ar_retrieve_pol(start_date, end_date, "CA")

co_mean <- mean(ca_pol, na.rm = TRUE)
expect_equal(co_mean > 0.5, co_mean < 0.52)
# Testing data.frame dims
expect_equal(ncol(ca_pol), 9)
expect_equal(nrow(ca_pol), 144)

# Testing data.frame values
pol_means<- colMeans(ca_pol[, 2:8], na.rm = TRUE)
expect_equal(pol_means["o3"] > 33, pol_means["o3"] < 35)
expect_equal(pol_means["co"] > 0.5, pol_means["co"] < 0.6)
expect_equal(pol_means["pm10"] > 21, pol_means["pm10"] < 22)

# Testind data.frame classes
expect_equal(TRUE, "data.frame" %in% class(ca_pol))
expect_equal(TRUE, "POSIXct" %in% class(ca_pol$date))
expect_equal(TRUE, "numeric" %in% class(ca_pol$o3))
expect_equal(TRUE, "numeric" %in% class(ca_pol$no))
expect_equal(TRUE, "numeric" %in% class(ca_pol$no2))
expect_equal(TRUE, "numeric" %in% class(ca_pol$nox))
expect_equal(TRUE, "numeric" %in% class(ca_pol$co))
expect_equal(TRUE, "numeric" %in% class(ca_pol$pm10))
expect_equal(TRUE, "numeric" %in% class(ca_pol$pm25))
expect_equal(TRUE, "character" %in% class(ca_pol$aqs))

})

0 comments on commit 3d3aaf3

Please sign in to comment.