Skip to content

Commit

Permalink
Test Cases Added (#130)
Browse files Browse the repository at this point in the history
* added coverage for distinct_edges.R

* determining whether tests for zzz.R are valid

* attempt to resolve broken tests in zzz.R

* removed test-zzz.R

* checking to see if previous issues were from new test file

* attempting to add test for .onLoad

* attempting to cover onUnload and detach hooks

* checking if codecov allows Namespace modifications

* got rid of unloadNamespace

* got rid of attachNamespace

* got rid of warning in test-ggdend.R

* undid linewidth change
  • Loading branch information
alecbuetow authored Oct 31, 2024
1 parent c1c132f commit 63af7d7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
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)
})

0 comments on commit 63af7d7

Please sign in to comment.