tests/testthat/test_plots.R

context("plots")

test_that("all of our plots produce nice gglot2 objects", {
  # helper function
  expect_is_ggplot = function(pl) {
    expect_is(pl, c("gg", "ggplot"))
  }

  # more than three dimensions not "plotable"
  x = generateRandomNetwork(n.points = 10L, n.dim = 3L)
  expect_error(autoplot(x))

  # no cluster, no depots
  x = generateRandomNetwork(n.points = 20L)
  expect_is_ggplot(autoplot(x))
  expect_is_ggplot(autoplot(x, path = sample(1:20)))
  expect_is_ggplot(autoplot(x, path = sample(1:10), close.path = TRUE, path.colour = "tomato"))
  expect_is_ggplot(autoplot(x, path = list(a = sample(1:10), b = sample(1:10))))
  expect_is_ggplot(autoplot(x, path = list(sample(1:10), sample(1:10))))

  # no cluster, with depots
  x = generateRandomNetwork(n.points = 20L, n.depots = 2L, upper = 100)
  expect_is_ggplot(autoplot(x))

  # some clusters, no depots
  x = generateClusteredNetwork(n.points = 20L, n.cluster = 2L)
  expect_is_ggplot(autoplot(x))

  # some clusters, with depots
  x = generateClusteredNetwork(n.points = 20L, n.cluster = 2L, n.depots = 2L)
  expect_is_ggplot(autoplot(x))

  # autoplot morphed instance
  x = generateRandomNetwork(n.points = 10L, upper = 20)
  y = generateClusteredNetwork(n.points = 10L, n.cluster = 2L, upper = 60)
  z = morphInstances(x, y, alpha = 0.3)
  expect_is_ggplot(autoplot(z))

  for (show.arrows in c(TRUE, FALSE)) {
    for (do.facets in c(TRUE, FALSE)) {
      pl = visualizeMorphing(x, y, arrows = show.arrows, in.one.plot = do.facets)
      expect_is_ggplot(pl)
    }
  }

  # test visualization of point matchings
  x = generateRandomNetwork(n.points = 10L)
  y = generateClusteredNetwork(n.points = 10L, n.cluster = 2L)
  pm = getOptimalPointMatching(x$coordinates, y$coordinates)
  pl = visualizePointMatching(x, y, pm, highlight.longest = 3L)
  expect_is_ggplot(pl)
  # should work when passing matrices only as well
  pl = visualizePointMatching(x$coordinates, y$coordinates, pm, highlight.longest = 3L)
  expect_is_ggplot(pl)
})
jakobbossek/salesperson documentation built on Dec. 11, 2021, 4:54 a.m.