Skip to content

Commit a88340d

Browse files
more 0-dimension edge case checks
1 parent 170543e commit a88340d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tests/testthat/_snaps/expect-shape.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434

3535
array(1) has only one dimension.
3636

37+
---
38+
39+
array() has only one dimension.
40+
3741
# at least one argument is required
3842

3943
Code

tests/testthat/test-expect-shape.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,29 @@ test_that("dim compared correctly", {
1313
expect_success(expect_shape(array(dim = 1:3), dim = 1:3))
1414
expect_snapshot_failure(expect_shape(array(dim = 1:3), dim = 1:2))
1515
expect_snapshot_failure(expect_shape(array(dim = 1:3), dim = 1:4))
16+
expect_success(expect_shape(array(), dim = 0L))
17+
dd <- c(0L, 0L, 0L, 5L, 0L, 0L, 0L)
18+
expect_success(expect_shape(array(dim = dd), dim = dd))
1619
})
1720

1821
test_that("nrow compared correctly", {
1922
expect_success(expect_shape(matrix(nrow = 5, ncol = 4), nrow = 5L))
2023
expect_snapshot_failure(expect_shape(matrix(nrow = 5, ncol = 5), nrow = 6L))
2124
expect_success(expect_shape(data.frame(1:10, 11:20), nrow = 10L))
2225
expect_snapshot_failure(expect_shape(1, nrow = 1))
26+
expect_success(expect_shape(array(), nrow = 0L))
27+
dd <- c(0L, 0L, 0L, 5L, 0L, 0L, 0L)
28+
expect_success(expect_shape(array(dim = dd), nrow = 0L))
2329
})
2430

2531
test_that("ncol compared correctly", {
2632
expect_success(expect_shape(matrix(nrow = 5, ncol = 4), ncol = 4L))
2733
expect_snapshot_failure(expect_shape(matrix(nrow = 5, ncol = 5), ncol = 7L))
2834
expect_success(expect_shape(data.frame(1:10, 11:20), ncol = 2L))
2935
expect_snapshot_failure(expect_shape(array(1), ncol = 1))
36+
expect_snapshot_failure(expect_shape(array(), ncol = 0L))
37+
dd <- c(0L, 0L, 0L, 5L, 0L, 0L, 0L)
38+
expect_success(expect_shape(array(dim = dd), ncol = 0L))
3039
})
3140

3241
test_that("uses S4 dim method", {

0 commit comments

Comments
 (0)