Skip to content

Commit

Permalink
test(obs_*)
Browse files Browse the repository at this point in the history
fixes #9
  • Loading branch information
dimfalk committed Jan 2, 2025
1 parent 12145d9 commit 6e64f67
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: HPBdata
Title: Meteorological observations at 'Hohenpeißenberg' site (Bavaria, Germany)
Version: 0.1.4
Version: 0.1.5
Date: 2025-01-02
Authors@R:
person("Dimitri", "Falk", , "falk.dimitri@eglv.de", role = c("aut", "cre"))
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## run before tests, but not loaded via `load_all()` and not installed with package

library(xts)
81 changes: 81 additions & 0 deletions tests/testthat/test-obs_10min.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
test_that("Class is unchanged.", {

expect_equal(class(obs_10min), "list")

expect_s3_class(obs_10min[[1]], c("xts", "zoo"))
})

test_that("Dimensions are unchanged.", {

expect_equal(length(obs_10min), 9)

expect_equal(length(obs_10min[[1]]), 1581036)
})

test_that("Names are unchanged.", {

cnames <- c("PP_10", "TT_10", "TM5_10", "RF_10", "FF_10", "DD_10", "GS_10",
"SD_10", "RWS_10")

expect_equal(names(obs_10min), cnames)

expect_equal(names(obs_10min[[1]]), "PP_10")
})

test_that("Types are unchanged.", {

expect_equal(typeof(obs_10min), "list")

expect_equal(typeof(obs_10min[[1]]), "double")
})

test_that("Checksum is unchanged.", {

expect_equal(sum(obs_10min[[1]], na.rm = TRUE), 1390216543)

expect_equal(is.na(obs_10min[[1]]) |> sum(), 43010)
})

test_that("Time range is unchanged.", {

rng <- zoo::index(obs_10min[[1]]) |> range()

expect_equal(class(rng), c("POSIXct", "POSIXt"))

expect_equal(as.character(rng[1]), "1993-12-09 13:50:00")

expect_equal(as.character(rng[2]), "2023-12-31 23:40:00")
})

test_that("Attributes are unchanged.", {

expect_equal(attr(obs_10min[[1]], "STAT_ID"), "02290")

expect_equal(attr(obs_10min[[1]], "STAT_NAME"), "Hohenpeißenberg")

expect_equal(attr(obs_10min[[1]], "X"), 11.0108)

expect_equal(attr(obs_10min[[1]], "Y"), 47.8009)

expect_equal(attr(obs_10min[[1]], "Z"), 977)

expect_equal(attr(obs_10min[[1]], "TZONE"), "UTC")

expect_equal(attr(obs_10min[[1]], "PARAMETER"), "Luftdruck")

expect_equal(attr(obs_10min[[1]], "TS_START"), structure(755445000, class = c("POSIXct", "POSIXt"), tzone = "UTC"))

expect_equal(attr(obs_10min[[1]], "TS_END"), structure(1704066000, class = c("POSIXct", "POSIXt"), tzone = "UTC"))

expect_equal(attr(obs_10min[[1]], "TS_TYPE"), "measurement")

expect_equal(attr(obs_10min[[1]], "MEAS_INTERVALTYPE"), TRUE)

expect_equal(attr(obs_10min[[1]], "MEAS_BLOCKING"), "left")

expect_equal(attr(obs_10min[[1]], "MEAS_RESOLUTION"), 10)

expect_equal(attr(obs_10min[[1]], "MEAS_UNIT"), "hPa")

expect_equal(attr(obs_10min[[1]], "MEAS_STATEMENT"), "mean")
})
81 changes: 81 additions & 0 deletions tests/testthat/test-obs_1d.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
test_that("Class is unchanged.", {

expect_equal(class(obs_1d), "list")

expect_s3_class(obs_1d[[1]], c("xts", "zoo"))
})

test_that("Dimensions are unchanged.", {

expect_equal(length(obs_1d), 13)

expect_equal(length(obs_1d[[1]]), 88753)
})

test_that("Names are unchanged.", {

cnames <- c("FX", "FM", "RSK", "SDK", "SHK_TAG", "NM", "VPM", "PM", "TMK",
"UPM", "TXK", "TNK", "TGK")

expect_equal(names(obs_1d), cnames)

expect_equal(names(obs_1d[[1]]), "FX")
})

test_that("Types are unchanged.", {

expect_equal(typeof(obs_1d), "list")

expect_equal(typeof(obs_1d[[1]]), "double")
})

test_that("Checksum is unchanged.", {

expect_equal(sum(obs_1d[[1]], na.rm = TRUE), 341110.2)

expect_equal(is.na(obs_1d[[1]]) |> sum(), 62190)
})

test_that("Time range is unchanged.", {

rng <- zoo::index(obs_1d[[1]]) |> range()

expect_equal(class(rng), c("POSIXct", "POSIXt"))

expect_equal(as.character(rng[1]), "1781-01-01")

expect_equal(as.character(rng[2]), "2023-12-31")
})

test_that("Attributes are unchanged.", {

expect_equal(attr(obs_1d[[1]], "STAT_ID"), "02290")

expect_equal(attr(obs_1d[[1]], "STAT_NAME"), "Hohenpeißenberg")

expect_equal(attr(obs_1d[[1]], "X"), 11.0108)

expect_equal(attr(obs_1d[[1]], "Y"), 47.8009)

expect_equal(attr(obs_1d[[1]], "Z"), 977)

expect_equal(attr(obs_1d[[1]], "TZONE"), "UTC")

expect_equal(attr(obs_1d[[1]], "PARAMETER"), "Windgeschwindigkeit")

expect_equal(attr(obs_1d[[1]], "TS_START"), structure(-5964192000, class = c("POSIXct", "POSIXt"), tzone = "UTC"))

expect_equal(attr(obs_1d[[1]], "TS_END"), structure(1703980800, class = c("POSIXct", "POSIXt"), tzone = "UTC"))

expect_equal(attr(obs_1d[[1]], "TS_TYPE"), "measurement")

expect_equal(attr(obs_1d[[1]], "MEAS_INTERVALTYPE"), TRUE)

expect_equal(attr(obs_1d[[1]], "MEAS_BLOCKING"), "left")

expect_equal(attr(obs_1d[[1]], "MEAS_RESOLUTION"), 1440)

expect_equal(attr(obs_1d[[1]], "MEAS_UNIT"), "m s-1")

expect_equal(attr(obs_1d[[1]], "MEAS_STATEMENT"), "max")
})
80 changes: 80 additions & 0 deletions tests/testthat/test-obs_1min.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
test_that("Class is unchanged.", {

expect_equal(class(obs_1min), "list")

expect_s3_class(obs_1min[[1]], c("xts", "zoo"))
})

test_that("Dimensions are unchanged.", {

expect_equal(length(obs_1min), 1)

expect_equal(length(obs_1min[[1]]), 15517000)
})

test_that("Names are unchanged.", {

cname <- "RWH_RS_01"

expect_equal(names(obs_1min), cname)

expect_equal(names(obs_1min[[1]]), "RWH_RS_01")
})

test_that("Types are unchanged.", {

expect_equal(typeof(obs_1min), "list")

expect_equal(typeof(obs_1min[[1]]), "double")
})

test_that("Checksum is unchanged.", {

expect_equal(sum(obs_1min[[1]], na.rm = TRUE), 33986.81)

expect_equal(is.na(obs_1min[[1]]) |> sum(), 718)
})

test_that("Time range is unchanged.", {

rng <- zoo::index(obs_1min[[1]]) |> range()

expect_equal(class(rng), c("POSIXct", "POSIXt"))

expect_equal(as.character(rng[1]), "1994-07-01 06:20:00")

expect_equal(as.character(rng[2]), "2023-12-31 22:59:00")
})

test_that("Attributes are unchanged.", {

expect_equal(attr(obs_1min[[1]], "STAT_ID"), "02290")

expect_equal(attr(obs_1min[[1]], "STAT_NAME"), "Hohenpeißenberg")

expect_equal(attr(obs_1min[[1]], "X"), 11.0108)

expect_equal(attr(obs_1min[[1]], "Y"), 47.8009)

expect_equal(attr(obs_1min[[1]], "Z"), 977)

expect_equal(attr(obs_1min[[1]], "TZONE"), "UTC")

expect_equal(attr(obs_1min[[1]], "PARAMETER"), NULL)

expect_equal(attr(obs_1min[[1]], "TS_START"), structure(773043600, class = c("POSIXct", "POSIXt"), tzone = "UTC"))

expect_equal(attr(obs_1min[[1]], "TS_END"), structure(1704063540, class = c("POSIXct", "POSIXt"), tzone = "UTC"))

expect_equal(attr(obs_1min[[1]], "TS_TYPE"), "measurement")

expect_equal(attr(obs_1min[[1]], "MEAS_INTERVALTYPE"), TRUE)

expect_equal(attr(obs_1min[[1]], "MEAS_BLOCKING"), "left")

expect_equal(attr(obs_1min[[1]], "MEAS_RESOLUTION"), 1)

expect_equal(attr(obs_1min[[1]], "MEAS_UNIT"), NULL)

expect_equal(attr(obs_1min[[1]], "MEAS_STATEMENT"), NULL)
})

0 comments on commit 6e64f67

Please sign in to comment.