| 1 |
# library(testthat) |
| 2 |
|
| 3 |
context("find_dendrogram (in get_subdendrograms)") |
| 4 |
|
| 5 |
|
| 6 |
test_that("find_dendrogram works", { |
| 7 |
# define dendrogram object to play with: |
| 8 |
dend <- 1:10 %>% |
| 9 |
dist() %>% |
| 10 |
hclust() %>% |
| 11 |
as.dendrogram() %>% |
| 12 |
set("labels_to_character") %>% |
| 13 |
color_branches(k = 5) |
| 14 |
|
| 15 |
selected_labels <- as.character(1:4) |
| 16 |
sub_dend <- find_dendrogram(dend, selected_labels) |
| 17 |
expect_true(nleaves(sub_dend) == 4L) |
| 18 |
|
| 19 |
selected_labels <- as.character(1:5) |
| 20 |
expect_null(find_dendrogram(dend, selected_labels)) |
| 21 |
|
| 22 |
selected_labels <- as.character(1:20) |
| 23 |
expect_null(find_dendrogram(dend, selected_labels)) |
| 24 |
|
| 25 |
# https://stackoverflow.com/questions/3903157/how-can-i-check-whether-a-function-call-results-in-a-warning |
| 26 |
# this function shouldn't return a warning |
| 27 |
selected_labels <- as.character(100:110) |
| 28 |
out <- tryCatch(find_dendrogram(dend, selected_labels),error=function(e) e, warning=function(w) w) |
| 29 |
expect_false(is(out, "warning")) |
| 30 |
|
| 31 |
}) |
| 32 |
|