Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Cases Added #130

Merged
merged 12 commits into from
Oct 31, 2024
2 changes: 1 addition & 1 deletion R/ggdend.R
alecbuetow marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ ggplot.ggdend <- function(data = NULL, mapping = aes(), ..., segments = TRUE, la
data = data$segments, na.rm = na.rm,
aes(
x = .data$x, y = .data$y, xend = .data$xend, yend = .data$yend,
colour = .data$col, linetype = .data$lty, size = .data$lwd
colour = .data$col, linetype = .data$lty, linewidth = .data$lwd
),
lineend = "square"
) +
Expand Down
63 changes: 63 additions & 0 deletions tests/testthat/test-distinct_edges.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ test_that("partition_leaves works", {
# partition_leaves(x)
# plot(x)
expect_identical(partition_leaves(x), list(c(3L, 1L, 2L), 3L, 1:2, 1L, 2L))

# check case where something other than a dendrogram is passed in
x <- matrix(1:4, nrow=2)
expect_error(partition_leaves(x))
})


Expand Down Expand Up @@ -50,4 +54,63 @@ test_that("dist.dendlist work", {
c("1", "2", "3"), c("1", "2", "3")
))
)

# check case where something other than a dendrogram is passed in
x <- matrix(1:4, nrow=2)
expect_error(dist.dendlist(x))
})



test_that("highlight_distinct_edges.dendrogram works", {
dend1 <- as.dendrogram(hclust(dist(iris[1:5, -5]), method = "average"))
dend2 <- as.dendrogram(hclust(dist(iris[2:6, -5]), method = "average"))

# check that edge color was indeed changed to identify which edges differ
result <- highlight_distinct_edges.dendrogram(dend1, dend2, value = 3, edgePar = "col")
expect_identical(attributes(result)$edgePar$col, 3)
})



test_that("highlight_distinct_edges.dendlist works", {
dend1 <- as.dendrogram(hclust(dist(iris[1:5, -5]), method = "average"))
dend2 <- as.dendrogram(hclust(dist(iris[2:6, -5]), method = "average"))
dend_list <- dendlist(dend1, dend2)

# check that edge color was indeed changed to identify which edges differ for both inserted dendrograms
result <- highlight_distinct_edges.dendlist(dend_list, value = 3, edgePar = "col")
expect_identical(attributes(result[[1]])$edgePar$col, 3)
expect_identical(attributes(result[[2]])$edgePar$col, 3)
})



test_that("dend_diff.dendrogram works", {
dend1 <- as.dendrogram(hclust(dist(iris[1:5, -5]), method = "average"))
dend2 <- as.dendrogram(hclust(dist(iris[2:6, -5]), method = "average"))

# check that edge color was indeed changed to identify which edges differ
pdf(file = NULL)
capture.output(suppressWarnings(
result <- dend_diff.dendrogram(dend1, dend2, value = 3, edgePar = "col")
))
dev.off()
expect_identical(result, dendlist(dend1, dend2))
})



test_that("dend_diff.dendlist works", {
dend1 <- as.dendrogram(hclust(dist(iris[1:5, -5]), method = "average"))
dend2 <- as.dendrogram(hclust(dist(iris[2:6, -5]), method = "average"))
dend_list <- dendlist(dend1, dend2)

# check that edge color was indeed changed to identify which edges differ
pdf(file = NULL)
capture.output(suppressWarnings(
result <- dend_diff.dendlist(dend_list, value = 3, edgePar = "col")
))
dev.off()
expect_identical(result, dendlist(dend1, dend2))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# cat("\n")
# library(testthat)


context("onLoad")


test_that("onLoad works", {
# no options for dendextend yet, should be empty
dendextend:::.onLoad()
expect_identical(getOption("dendextend"), NULL)
})

Loading