tests/testthat/test-plotBehaviour.R

test_that("Tests checkInputsPlotBehaviour function", {
  msw <- spatialBehaviour(pam, verbose = 0)

  # Checking sts input
  expect_error(
    checkInputsPlotBehaviour(
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking rasterProduct input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking colorPalette input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = TRUE,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = c(1, 2, 3),
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking xlim/ylim input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = "132",
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = 160,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = c(400, 500),
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = "-50",
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = 60,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = c(-100, 100),
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking labels input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = "TRUE",
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = 1,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking by input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = TRUE,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = "hui",
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 5.6,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = c(1, 2),
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking pos input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = TRUE,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = "hui",
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 5.6,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = -2,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 5,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = c(1, 2),
      dynamicPlot = FALSE
    )
  )

  # Checking main input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = TRUE,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = 3,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = c("pam", "cyclone"),
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking legends input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = 1,
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = TRUE,
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = c("topleft", "topright"),
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "top",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = FALSE
    )
  )

  # Checking dynamicPlot input
  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = 1
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = "1"
    )
  )

  expect_error(
    checkInputsPlotBehaviour(
      sts = pam,
      rasterProduct = msw,
      colorPalette = NULL,
      main = NULL,
      legends = "topleft",
      xlim = NULL,
      ylim = NULL,
      labels = FALSE,
      by = 8,
      pos = 3,
      dynamicPlot = c(TRUE, TRUE)
    )
  )
})


test_that("plotBehaviour works without errors", {
  msw <- spatialBehaviour(pam, verbose = 0)

  pdf(NULL)
  # Basic call (non-dynamic)
  expect_silent(plotBehaviour(pam, msw))

  # Call with custom xlim/ylim
  expect_silent(plotBehaviour(pam, msw, xlim = c(160, 180), ylim = c(-20, 0)))

  # Call with dynamicPlot = TRUE
  expect_silent(plotBehaviour(pam, msw, dynamicPlot = TRUE))

  # Call with labels
  expect_silent(plotBehaviour(pam, msw, labels = TRUE, by = 1, pos = 3))

  dev.off()
})

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.