File: test-1-dendrogram.R

package info (click to toggle)
r-cran-ggdendro 0.1.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 368 kB
  • sloc: sh: 13; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 909 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Test functionality using testthat library
#
# Author: Andrie
#------------------------------------------------------------------------------


test_that("data_dendrogram() returns a correct classes", {
  hc <- hclust(dist(USArrests), "ave")
  dhc <- as.dendrogram(hc)

  expect_s3_class(dendro_data(dhc, type = "rectangle"), "dendro")

  ddata <- dendro_data(dhc, type = "rectangle")
  expect_s3_class(ddata$segments, "data.frame")
  expect_s3_class(ddata$labels, "data.frame")
  expect_equal(nrow(ddata$segments), 196)

  ddata <- dendro_data(dhc, type = "triangle")
  expect_s3_class(ddata$segments, "data.frame")
  expect_s3_class(ddata$labels, "data.frame")
  expect_equal(nrow(ddata$segments), 98)
})

#------------------------------------------------------------------------------

test_that("undefined model type throws error", {
  expect_error(dendro_data(USArrests))
})