tests/testthat/test-compute.R

test_that("Test getRmw function", {
  expect_equal(
    getRmw(seq(0, 80, 5), -15),
    c(
      60, 55, 51, 47, 44, 41, 38, 35, 32,
      30, 28, 25, 24, 22, 20, 19, 17
    )
  )
})





test_that("Test Willougbhy / Holland / Boose functions", {
  expect_equal(
    willoughby(seq(1, 100), 20, 50, -15),
    c(
      1.813,
      3.905,
      6.118,
      8.414,
      10.772,
      13.182,
      15.635,
      18.127,
      20.652,
      23.208,
      25.791,
      28.399,
      31.032,
      33.685,
      36.360,
      39.053,
      41.765,
      44.494,
      47.239,
      50.000,
      49.327,
      48.676,
      48.044,
      47.433,
      46.839,
      46.264,
      45.706,
      45.165,
      44.640,
      44.131,
      43.636,
      43.155,
      42.688,
      42.235,
      41.794,
      41.366,
      40.949,
      40.543,
      40.149,
      39.765,
      39.391,
      39.027,
      38.672,
      38.327,
      37.990,
      37.661,
      37.341,
      37.028,
      36.723,
      36.425,
      36.134,
      35.850,
      35.572,
      35.300,
      35.035,
      34.775,
      34.521,
      34.272,
      34.028,
      33.789,
      33.555,
      33.326,
      33.102,
      32.881,
      32.665,
      32.453,
      32.245,
      32.040,
      31.839,
      31.642,
      31.448,
      31.257,
      31.070,
      30.885,
      30.704,
      30.525,
      30.349,
      30.176,
      30.005,
      29.837,
      29.671,
      29.508,
      29.347,
      29.188,
      29.031,
      28.876,
      28.724,
      28.573,
      28.424,
      28.277,
      28.131,
      27.988,
      27.846,
      27.706,
      27.567,
      27.430,
      27.294,
      27.159,
      27.026,
      26.895
    )
  )

  expect_equal(
    holland(seq(1, 100), 20, 50, 1020 * 100, 915 * 100, -15),
    c(
      25.621,
      31.978,
      36.024,
      38.946,
      41.180,
      42.944,
      44.365,
      45.524,
      46.474,
      47.257,
      47.901,
      48.428,
      48.856,
      49.199,
      49.469,
      49.675,
      49.825,
      49.926,
      49.983,
      50.001,
      49.984,
      49.937,
      49.861,
      49.761,
      49.638,
      49.495,
      49.333,
      49.155,
      48.962,
      48.755,
      48.536,
      48.306,
      48.066,
      47.817,
      47.559,
      47.295,
      47.023,
      46.746,
      46.463,
      46.175,
      45.883,
      45.587,
      45.288,
      44.985,
      44.681,
      44.373,
      44.064,
      43.753,
      43.441,
      43.128,
      42.814,
      42.499,
      42.183,
      41.868,
      41.552,
      41.236,
      40.921,
      40.606,
      40.291,
      39.977,
      39.664,
      39.352,
      39.040,
      38.729,
      38.420,
      38.112,
      37.805,
      37.499,
      37.195,
      36.892,
      36.591,
      36.291,
      35.993,
      35.696,
      35.401,
      35.108,
      34.817,
      34.527,
      34.239,
      33.953,
      33.669,
      33.386,
      33.106,
      32.827,
      32.550,
      32.275,
      32.003,
      31.732,
      31.463,
      31.196,
      30.931,
      30.667,
      30.406,
      30.147,
      29.890,
      29.635,
      29.381,
      29.130,
      28.881,
      28.633
    )
  )

  expect_equal(
    boose(
      seq(1, 100),
      20,
      50,
      1020 * 100,
      915 * 100,
      0.1,
      0.1,
      0.25,
      0.25,
      15,
      1,
      -15
    ),
    c(
      19.786,
      23.774,
      26.206,
      27.913,
      29.192,
      30.186,
      30.975,
      31.611,
      32.129,
      32.551,
      32.895,
      33.176,
      33.402,
      33.583,
      33.724,
      33.831,
      33.909,
      33.961,
      33.991,
      34.000,
      33.991,
      33.967,
      33.928,
      33.877,
      33.814,
      33.741,
      33.659,
      33.569,
      33.471,
      33.366,
      33.255,
      33.138,
      33.017,
      32.891,
      32.760,
      32.626,
      32.489,
      32.349,
      32.205,
      32.060,
      31.912,
      31.762,
      31.610,
      31.457,
      31.302,
      31.146,
      30.989,
      30.831,
      30.672,
      30.513,
      30.353,
      30.192,
      30.031,
      29.870,
      29.708,
      29.546,
      29.385,
      29.223,
      29.061,
      28.900,
      28.738,
      28.577,
      28.416,
      28.256,
      28.095,
      27.935,
      27.776,
      27.617,
      27.459,
      27.301,
      27.143,
      26.986,
      26.830,
      26.674,
      26.519,
      26.365,
      26.211,
      26.058,
      25.905,
      25.754,
      25.603,
      25.453,
      25.303,
      25.154,
      25.006,
      24.859,
      24.712,
      24.567,
      24.422,
      24.278,
      24.134,
      23.992,
      23.850,
      23.709,
      23.569,
      23.429,
      23.291,
      23.153,
      23.016,
      22.880
    )
  )
})


test_that("Test computeAsymetry", {
  res <- computeAsymmetry(
    asymmetry = "Chen",
    speed = c(10, 12),
    x = c(1, 2),
    y = c(1, 2),
    vx = 0.1,
    vy = 0.2,
    vh = 5,
    r = c(10, 20),
    rmw = 30,
    lat = 20
  )

  expect_type(res, "list")
  expect_named(res, c("speed", "direction"))
  expect_type(res$speed, "double")
  expect_type(res$direction, "double")

  res <- computeAsymmetry(
    asymmetry = "Chen",
    speed = c(10, 12, 15),
    x = c(1, 2, 3),
    y = c(1, 2, 3),
    vx = 0.1,
    vy = 0.2,
    vh = 5,
    r = c(10, 20, 30),
    rmw = 30,
    lat = 20
  )

  expect_length(res$speed, 3)
  expect_length(res$direction, 3)

  expect_true(all(res$direction >= 0))
  expect_true(all(res$direction <= 360))

  args <- list(
    asymmetry = "Chen",
    speed = 10,
    x = 1,
    y = 1,
    vx = 0.1,
    vy = 0.2,
    vh = 5,
    r = 10,
    rmw = 30
  )

  res_north <- do.call(computeAsymmetry, c(args, list(lat = 20)))
  res_south <- do.call(computeAsymmetry, c(args, list(lat = -20)))

  expect_type(res_north$direction, "double")
  expect_type(res_south$direction, "double")
})

test_that("Test stormDisplacement function", {
  # Displacement of 1deg in longitude in one hour.
  expect_equal(
    stormDisplacement(c(0, 1), c(0, 0), 60),
    list(stormSpeed = c(30.92208, 30.92208078), vxDeg = c(1, 1), vyDeg = c(0, 0))
  )
  # Displacement of 1deg in latitude in one hour.
  expect_equal(
    stormDisplacement(c(0, 0), c(1, 0), 60),
    list(stormSpeed = c(30.7151079, 30.7151079), vxDeg = c(0, 0), vyDeg = c(-1, -1))
  )
  # Displacement of 1deg in lat + lon in 3h.
  expect_equal(
    stormDisplacement(c(1, 0), c(1, 0), 180),
    list(stormSpeed = c(14.5277378, 14.5277378), vxDeg = c(-0.33333333, -0.33333333), vyDeg = c(-0.33333333, -0.33333333))
  )
})

test_that("Test computeDirection function", {
  expect_equal(computeDirection(1, 1, 30), 135)
  expect_equal(computeDirection(1, -1, 30), 225)
  expect_equal(computeDirection(-1, -1, 30), 315)
  expect_equal(computeDirection(-1, 1, 30), 45)

  expect_equal(computeDirection(0, 1, 30), 90)
  expect_equal(computeDirection(1, 0, 30), 180)
  expect_equal(computeDirection(0, -1, 30), 270)
  expect_equal(computeDirection(-1, 0, 30), 0)

  expect_equal(computeDirection(1, 1, -30), 315)
  expect_equal(computeDirection(1, -1, -30), 45)
  expect_equal(computeDirection(-1, -1, -30), 135)
  expect_equal(computeDirection(-1, 1, -30), 225)

  expect_equal(computeDirection(0, 1, -30), 270)
  expect_equal(computeDirection(1, 0, -30), 0)
  expect_equal(computeDirection(0, -1, -30), 90)
  expect_equal(computeDirection(-1, 0, -30), 180)
})


test_that("Test computeDirection function with land-interaction for Boose model", {
  expect_equal(computeDirection(1, 1, 30, 1), 95)
  expect_equal(computeDirection(1, 1, 30, 0), 115)
  expect_equal(computeDirection(1, -1, 30, 1), 185)
  expect_equal(computeDirection(1, -1, 30, 0), 205)
  expect_equal(computeDirection(-1, 1, 30, 1), 5)
  expect_equal(computeDirection(-1, 1, 30, 0), 25)

  expect_equal(computeDirection(1, 1, -30, 1), 355)
  expect_equal(computeDirection(1, 1, -30, 0), 335)
  expect_equal(computeDirection(-1, -1, -30, 1), 175)
  expect_equal(computeDirection(-1, -1, -30, 0), 155)
})

Try the StormR package in your browser

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

StormR documentation built on July 15, 2026, 5:08 p.m.