Skip to content

Commit

Permalink
rm duplicate diagram_slope + write test for diagram_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
corybrunson committed Mar 30, 2024
1 parent 92b3402 commit 3048eaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
10 changes: 1 addition & 9 deletions R/persistence.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
29 changes: 29 additions & 0 deletions tests/testthat/test-persistence.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3048eaa

Please sign in to comment.