diff --git a/tests/testthat/_snaps/layout_quad.md b/tests/testthat/_snaps/layout_quad.md
new file mode 100644
index 00000000..6cd1c9bb
--- /dev/null
+++ b/tests/testthat/_snaps/layout_quad.md
@@ -0,0 +1,124 @@
+# add `align` object works well
+
+ Cannot add `align_dendro()` to `quad_free()`
+ i `quad_free()` cannot align observations in vertical direction
+
+---
+
+ Cannot add `ggalign()` to `quad_free()`
+ i `quad_free()` cannot align observations in vertical direction
+
+---
+
+ Cannot add `align_kmeans(3L)` to `quad_free()`
+ i `quad_free()` cannot align observations in horizontal direction
+
+# add `stack_layout()` builds well
+
+ Cannot add `stack_freev()` to `quad_free()`
+ i no active annotation stack
+ i try to activate an annotation stack with `anno_*()`
+
+---
+
+ Cannot add `stack_freev()` to `quad_free()`
+ i top annotation stack already exists
+
+---
+
+ Cannot add `(stack_freev() + quad_free(mpg) + quad_free(mpg))` to `quad_free()`
+ i annotation stack cannot contain nested layout
+
+---
+
+ Cannot add `stack_freeh()` to `quad_free()`
+ i only vertical stack is allowed in top annotation
+
+---
+
+ Cannot add `stack_alignv()` to a `quad_free()`
+ i `quad_free()` cannot align observations in vertical direction
+
+---
+
+ Cannot add `stack_alignh()` to `quad_alignh()`
+ i no active annotation stack
+ i try to activate an annotation stack with `anno_*()`
+
+---
+
+ Cannot add `stack_freev()` to `quad_alignh()`
+ i no active annotation stack
+ i try to activate an annotation stack with `anno_*()`
+
+---
+
+ Cannot add `stack_freev()` to `quad_alignh()`
+ i top annotation stack already exists
+
+---
+
+ object 'mpsmall_matg' not found
+
+---
+
+ Cannot add `(stack_freev() + quad_free(mpg) + quad_free(mpg))` to `quad_alignh()`
+ i annotation stack cannot contain nested layout
+
+---
+
+ Cannot add `(stack_alignh() + ggheatmap(small_mat) + ggheatmap(small_mat))` to `quad_alignh()`
+ i annotation stack cannot contain nested layout
+
+---
+
+ Cannot add `stack_freeh()` to `quad_alignh()`
+ i only vertical stack is allowed in top annotation
+
+---
+
+ Cannot add `stack_alignv()` to a `quad_alignh()`
+ i `quad_alignh()` cannot align observations in vertical direction
+
+---
+
+ Cannot add `stack_alignv()` to `quad_alignv()`
+ i no active annotation stack
+ i try to activate an annotation stack with `anno_*()`
+
+---
+
+ Cannot add `stack_freeh()` to `quad_alignv()`
+ i no active annotation stack
+ i try to activate an annotation stack with `anno_*()`
+
+---
+
+ Cannot add `stack_freeh()` to `quad_alignv()`
+ i top annotation stack already exists
+
+---
+
+ Cannot add `stack_alignv()` to `quad_alignv()`
+ i left annotation stack already exists
+
+---
+
+ Cannot add `(stack_freeh() + quad_free(mpg) + quad_free(mpg))` to `quad_alignv()`
+ i annotation stack cannot contain nested layout
+
+---
+
+ Cannot add `(stack_alignv() + ggheatmap(small_mat) + ggheatmap(small_mat))` to `quad_alignv()`
+ i annotation stack cannot contain nested layout
+
+---
+
+ Cannot add `stack_freeh()` to `quad_alignv()`
+ i only vertical stack is allowed in top annotation
+
+---
+
+ Cannot add `stack_alignh()` to `quad_alignv()`
+ i only vertical stack is allowed in top annotation
+
diff --git a/tests/testthat/_snaps/layout_quad/quad-alignh-add-stack-alignh-in-the-top.svg b/tests/testthat/_snaps/layout_quad/quad-alignh-add-stack-alignh-in-the-top.svg
new file mode 100644
index 00000000..efa9afa2
--- /dev/null
+++ b/tests/testthat/_snaps/layout_quad/quad-alignh-add-stack-alignh-in-the-top.svg
@@ -0,0 +1,429 @@
+
+
diff --git a/tests/testthat/_snaps/layout_quad/quad-alignv-add-stack-alignv-in-the-top.svg b/tests/testthat/_snaps/layout_quad/quad-alignv-add-stack-alignv-in-the-top.svg
new file mode 100644
index 00000000..a0f6805b
--- /dev/null
+++ b/tests/testthat/_snaps/layout_quad/quad-alignv-add-stack-alignv-in-the-top.svg
@@ -0,0 +1,433 @@
+
+
diff --git a/tests/testthat/_snaps/layout_stack.md b/tests/testthat/_snaps/layout_stack.md
index a883392d..deca240f 100644
--- a/tests/testthat/_snaps/layout_stack.md
+++ b/tests/testthat/_snaps/layout_stack.md
@@ -80,3 +80,8 @@
you must provide `data` argument in `quad_free()`
i no data was found in `stack_align()`
+# add `with_quad()` works as expected
+
+ Cannot add `with_quad(geom_point())` to `stack_align()`
+ i Did you forget to add a `quad_layout()`?
+
diff --git a/tests/testthat/test-layout_quad.R b/tests/testthat/test-layout_quad.R
index fd630137..f6255c40 100644
--- a/tests/testthat/test-layout_quad.R
+++ b/tests/testthat/test-layout_quad.R
@@ -64,13 +64,13 @@ testthat::test_that("add `align` object works well", {
# quad_free()
# cannot add align objects in `quad_free()`
- expect_error(quad_free(small_mat) +
+ expect_snapshot_error(quad_free(small_mat) +
quad_anno("t") +
align_dendro())
- expect_error(quad_free(small_mat) +
+ expect_snapshot_error(quad_free(small_mat) +
quad_anno("t") +
ggalign())
- expect_error({
+ expect_snapshot_error({
set.seed(1L)
quad_free(small_mat) +
quad_anno("l") +
@@ -102,6 +102,38 @@ testthat::test_that("add `align` object works well", {
)
})
+testthat::test_that("add `align` object builds well", {
+ set.seed(1L)
+ small_mat <- matrix(rnorm(72), nrow = 8)
+ rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
+ colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
+
+ # quad_alignh()
+ expect_doppelganger(
+ "alignh-layout-annotation",
+ quad_alignh(small_mat) +
+ geom_boxplot(aes(value, .row_names)) +
+ quad_anno("l") +
+ align_dendro(k = 3L) +
+ ggalign(data = rowSums) +
+ geom_bar(aes(value, y = .y, fill = .panel),
+ stat = "identity", orientation = "y"
+ )
+ )
+
+ # quad_alignv()
+ expect_doppelganger(
+ "alignv-layout-annotation",
+ quad_alignv(small_mat) +
+ geom_boxplot(aes(.column_names, value)) +
+ quad_anno("t") +
+ align_dendro(k = 3L) +
+ ggalign(data = rowSums) +
+ geom_bar(aes(.x, value, fill = .panel), stat = "identity")
+ )
+})
+
+
testthat::test_that("add `with_quad()` works as expected", {
set.seed(1L)
small_mat <- matrix(rnorm(72), nrow = 8)
@@ -162,72 +194,144 @@ testthat::test_that("add `with_quad()` works as expected", {
)
})
-testthat::test_that("add `stack_layout()` works as expected", {
+testthat::test_that("add `stack_layout()` builds well", {
set.seed(1L)
small_mat <- matrix(rnorm(72), nrow = 8)
rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
# quad_free() ------------------------------------------
- expect_error(quad_free(mpg) + stack_freev())
+ expect_snapshot_error(quad_free(mpg) + stack_freev())
# annotaion has been initialized
- expect_error(quad_free(mpg) + anno_top() + stack_freev())
+ expect_snapshot_error(quad_free(mpg) + anno_top() + stack_freev())
# add nested layout
- expect_error(quad_free(mpg) + anno_top(initialize = FALSE) +
+ expect_snapshot_error(quad_free(mpg) + anno_top(initialize = FALSE) +
(stack_freev() + quad_free(mpg) + quad_free(mpg)))
# incompatible direction
- expect_error(quad_free(mpg) + anno_top(initialize = FALSE) +
+ expect_snapshot_error(quad_free(mpg) + anno_top(initialize = FALSE) +
stack_freeh())
# incompatible aligning type
- expect_error(quad_free(mpg) + anno_top(initialize = FALSE) +
+ expect_snapshot_error(quad_free(mpg) + anno_top(initialize = FALSE) +
stack_alignv())
# quad_alignh() ---------------------------------------
- expect_error(quad_alignh(small_mat) + stack_alignh())
- expect_error(quad_alignh(small_mat) + stack_freev())
+ expect_snapshot_error(quad_alignh(small_mat) + stack_alignh())
+ expect_snapshot_error(quad_alignh(small_mat) + stack_freev())
# annotaion has been initialized
- expect_error(quad_alignh(small_mat) +
+ expect_snapshot_error(quad_alignh(small_mat) +
anno_top(initialize = TRUE) +
stack_freev())
- expect_error(quad_alignh(mpsmall_matg) + anno_left() + stack_alignh())
+ expect_snapshot_error(
+ quad_alignh(mpsmall_matg) + anno_left() + stack_alignh()
+ )
# add nested layout
- expect_error(quad_alignh(small_mat) + anno_top(initialize = FALSE) +
- (stack_freev() + quad_free(mpg) + quad_free(mpg)))
- expect_error(quad_alignh(small_mat) + anno_left(initialize = FALSE) +
- (stack_alignh() + ggheatmap(small_mat) + ggheatmap(small_mat)))
+ expect_snapshot_error(
+ quad_alignh(small_mat) + anno_top(initialize = FALSE) +
+ (stack_freev() + quad_free(mpg) + quad_free(mpg))
+ )
+ expect_snapshot_error(
+ quad_alignh(small_mat) + anno_left(initialize = FALSE) +
+ (stack_alignh() + ggheatmap(small_mat) + ggheatmap(small_mat))
+ )
# incompatible direction
- expect_error(quad_alignh(small_mat) + anno_top(initialize = FALSE) +
- stack_freeh())
+ expect_snapshot_error(
+ quad_alignh(small_mat) + anno_top(initialize = FALSE) +
+ stack_freeh()
+ )
# incompatible aligning type
- expect_error(quad_alignh(small_mat) + anno_top(initialize = FALSE) +
- stack_alignv())
+ expect_snapshot_error(
+ quad_alignh(small_mat) + anno_top(initialize = FALSE) +
+ stack_alignv()
+ )
+ # update coords correctly
+ quad <- quad_alignh(small_mat) +
+ anno_right() +
+ anno_left(size = 0.2, initialize = FALSE) +
+ (stack_alignh(small_mat) + align_dendro(k = 4))
+ expect_identical(quad@horizontal, quad@left@layout)
+ expect_identical(quad@horizontal, quad@right@layout)
+
+ quad <- quad_alignh(small_mat) +
+ anno_left() +
+ anno_right(size = 0.2, initialize = FALSE) +
+ (stack_alignh(small_mat) + align_dendro(k = 4))
+ expect_identical(quad@horizontal, quad@right@layout)
+ expect_identical(quad@horizontal, quad@left@layout)
# quad_alignv() ---------------------------------------
- expect_error(quad_alignv(small_mat) + stack_alignv())
- expect_error(quad_alignv(small_mat) + stack_freeh())
+ expect_snapshot_error(quad_alignv(small_mat) + stack_alignv())
+ expect_snapshot_error(quad_alignv(small_mat) + stack_freeh())
# annotaion has been initialized
- expect_error(quad_alignv(small_mat) + anno_top() + stack_freeh())
- expect_error(quad_alignv(small_mat) + anno_left(initialize = TRUE) +
- stack_alignv())
+ expect_snapshot_error(quad_alignv(small_mat) + anno_top() + stack_freeh())
+ expect_snapshot_error(
+ quad_alignv(small_mat) + anno_left(initialize = TRUE) +
+ stack_alignv()
+ )
# add nested layout
- expect_error(quad_alignv(small_mat) + anno_top(initialize = FALSE) +
- (stack_freeh() + quad_free(mpg) + quad_free(mpg)))
- expect_error(quad_alignv(small_mat) + anno_left(initialize = FALSE) +
- (stack_alignv() + ggheatmap(small_mat) + ggheatmap(small_mat)))
+ expect_snapshot_error(
+ quad_alignv(small_mat) + anno_top(initialize = FALSE) +
+ (stack_freeh() + quad_free(mpg) + quad_free(mpg))
+ )
+ expect_snapshot_error(
+ quad_alignv(small_mat) + anno_left(initialize = FALSE) +
+ (stack_alignv() + ggheatmap(small_mat) + ggheatmap(small_mat))
+ )
# incompatible direction
- expect_error(quad_alignv(small_mat) + anno_top(initialize = FALSE) +
- stack_freeh())
+ expect_snapshot_error(
+ quad_alignv(small_mat) + anno_top(initialize = FALSE) +
+ stack_freeh()
+ )
# incompatible aligning type
- expect_error(quad_alignv(small_mat) + anno_top(initialize = FALSE) +
- stack_alignh())
+ expect_snapshot_error(
+ quad_alignv(small_mat) + anno_top(initialize = FALSE) +
+ stack_alignh()
+ )
+
+ # update coords correctly
+ quad <- quad_alignv(small_mat) +
+ anno_bottom() +
+ anno_top(size = 0.2, initialize = FALSE) +
+ (stack_alignv(t(small_mat)) + align_dendro(k = 4))
+ expect_identical(quad@vertical, quad@top@layout)
+ expect_identical(quad@vertical, quad@bottom@layout)
+
+ quad <- quad_alignv(small_mat) +
+ anno_top() +
+ anno_bottom(size = 0.2, initialize = FALSE) +
+ (stack_alignv(t(small_mat)) + align_dendro(k = 4))
+ expect_identical(quad@vertical, quad@bottom@layout)
+ expect_identical(quad@vertical, quad@top@layout)
+})
+
+testthat::test_that("add `stack_layout()` builds well", {
+ set.seed(1L)
+ small_mat <- matrix(rnorm(72), nrow = 8)
+ rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
+ colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
+
+ # quad_free() ------------------------------------------
+ expect_doppelganger(
+ "quad_alignh, add stack_alignh() in the top",
+ quad_alignh(small_mat) +
+ anno_left(size = 0.2, initialize = FALSE) +
+ (stack_alignh(small_mat) + align_dendro(k = 4))
+ )
+
+ # quad_alignv() ---------------------------------------
+ expect_doppelganger(
+ "quad_alignv, add stack_alignv() in the top",
+ quad_alignv(small_mat) +
+ anno_top(size = 0.2, initialize = FALSE) +
+ (stack_alignv(t(small_mat)) + align_dendro(k = 4))
+ )
})
testthat::test_that("`ggsave()` works well", {
diff --git a/tests/testthat/test-layout_stack.R b/tests/testthat/test-layout_stack.R
index b4194e72..0391b483 100644
--- a/tests/testthat/test-layout_stack.R
+++ b/tests/testthat/test-layout_stack.R
@@ -367,6 +367,9 @@ testthat::test_that("add `with_quad()` works as expected", {
small_mat <- matrix(rnorm(72), nrow = 8)
rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
+ expect_snapshot_error(stack_alignv(small_mat) +
+ align_dendro() +
+ with_quad(geom_point()))
expect_doppelganger(
"subtract_with_quad_default",
stack_alignv(small_mat) +