diff --git a/R/persistence.R b/R/persistence.R index 7a72da7..af03777 100644 --- a/R/persistence.R +++ b/R/persistence.R @@ -467,18 +467,10 @@ diagram_transform <- function(data, diagram) { x = (data$x + data$y) / 2, y = ifelse( is.infinite(data$x) & is.infinite(data$y), + # accommodate landscape horizons 0, (data$y - data$x) / 2 ) ) ) } - -diagram_slope <- function(diagram) { - switch( - match.arg(diagram, c("flat", "diagonal", "landscape")), - flat = 0, - diagonal = 1, - landscape = 0 - ) -} diff --git a/tests/testthat/test-persistence.R b/tests/testthat/test-persistence.R index 00ae202..c08090d 100644 --- a/tests/testthat/test-persistence.R +++ b/tests/testthat/test-persistence.R @@ -1,4 +1,33 @@ +test_that("`diagram_transform()` correctly transforms key points", { + d <- data.frame( + x = c(-Inf, 0, 0, exp(1), exp(1), pi, Inf), + y = c(-Inf, 0, 1, exp(1), pi, Inf, Inf) + ) + + # diagonal transform (do nothing) + d_diag <- diagram_transform(d, "diagonal") + expect_identical(d, d_diag) + + # flat transform + d2 <- d + d2$y <- d$y - d$x + d_flat <- diagram_transform(d, "flat") + expect_identical(d2, d_flat) + + # landscape transform + d3 <- transform( + d, + x = (x + y) / 2, + y = (y - x) / 2 + ) + # accommodate landscape horizons + d3$y[c(1L, nrow(d3))] <- 0 + d_land <- diagram_transform(d, "landscape") + expect_identical(d3, d_land) + +}) + # ggplot object tests ---------------------------------------------------------- # sample data set