tests/testthat/test-internals.R

context("test-internals.R")

test_that("failed patterns", {
  expect_false(
    suppressMessages(validate_date(2017, 12, -1)))
  expect_false(
    suppressMessages(validate_date(-2018, 1, 1)))
  expect_false(
    suppressMessages(validate_date(2017, 13, 1))
  )
  expect_message(
    jma_url(item = "annually", "0010", year = 2017, month = 13),
    "Input arguments should be calender format\nCheck: month"
  )
})

test_that("input arguments validation", {
  expect_true(
    validate_date(2017, 1, 1)
  )
})

test_that("urls", {
  x <-
    jma_url(item = "daily",
            block_no = "0422",
            year = 2017,
            month = 6)
  expect_is(x, "list")
  expect_named(x, c("url", "station_type"))
  expect_equal(
    x,
    list(
      url = "https://www.data.jma.go.jp/stats/etrn/view/daily_a1.php?prec_no=48&block_no=0422&year=2017&month=6&day=&view=", # nolint
      station_type = "a1")
  )
  x <-
    jma_url("annually",
            "0010",
            2017,
            12)
  expect_equal(
    x,
    list(
      url = "https://www.data.jma.go.jp/stats/etrn/view/annually_a.php?prec_no=12&block_no=0010&year=2017&month=12&day=&view=", # nolint
      station_type = "a")
  )
  x <-
    jma_url("nml_ym",
            "47895")
  expect_equal(
    x[[1]],
    "https://www.data.jma.go.jp/stats/etrn/view/nml_sfc_ym.php?prec_no=71&block_no=47895&year=&month=&view="
  )
  x <-
    jma_url("nml_10d",
            "1555")
  expect_equal(
    x[[1]],
    "https://www.data.jma.go.jp/stats/etrn/view/nml_amd_10d.php?prec_no=51&block_no=1555&year=&month=&view="
  )
})

test_that("Set coords", {

  res <-
    check_input_coords(longitude = 140.10, latitude = 36.08, geometry = NULL)
  expect_is(res, "list")
  expect_named(res, c("longitude", "latitude"))

  expect_equivalent(
    check_input_coords(geometry = st_point(c(140.10, 36.08))),
    check_input_coords(longitude = 140.10, latitude = 36.08, geometry = NULL))

  expect_message(
    check_input_coords(longitude = 123.00, latitude = 32.0, geometry = st_point(c(140.10, 36.08)))
  )

})

Try the jmastats package in your browser

Any scripts or data that you put into this service are public.

jmastats documentation built on April 12, 2025, 1:38 a.m.