Skip to content

Commit 170543e

Browse files
new edge tests, improve structure
1 parent 3710870 commit 170543e

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

tests/testthat/_snaps/expect-shape.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# shape computed correctly
1+
# length compared correctly
22

33
`object` has length 1, not length 2.
44

5-
---
5+
# dim compared correctly
66

77
matrix(nrow = 6, ncol = 3) has shape (6, 3), not (6, 2).
88

@@ -12,13 +12,21 @@
1212

1313
---
1414

15+
array(dim = 1:3) has 3 dimensions, not 2
16+
17+
---
18+
19+
array(dim = 1:3) has 3 dimensions, not 4
20+
21+
# nrow compared correctly
22+
1523
matrix(nrow = 5, ncol = 5) has 5 rows, not 6.
1624

1725
---
1826

1927
1 has no dimensions.
2028

21-
---
29+
# ncol compared correctly
2230

2331
matrix(nrow = 5, ncol = 5) has 5 columns, not 7.
2432

tests/testthat/test-expect-shape.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
test_that("shape computed correctly", {
2-
# equivalent to expect_length
1+
test_that("length compared correctly", {
32
expect_success(expect_shape(1, length = 1))
43
expect_snapshot_failure(expect_shape(1, length = 2))
54
expect_success(expect_shape(1:10, length = 10))
65
expect_success(expect_shape(letters[1:5], length = 5))
6+
})
77

8-
# testing dim()
8+
test_that("dim compared correctly", {
99
expect_success(expect_shape(matrix(nrow = 5, ncol = 4), dim = c(5L, 4L)))
1010
expect_snapshot_failure(expect_shape(matrix(nrow = 6, ncol = 3), dim = c(6L, 2L)))
1111
expect_snapshot_failure(expect_shape(matrix(nrow = 6, ncol = 3), dim = c(7L, 3L)))
1212
expect_success(expect_shape(data.frame(1:10, 11:20), dim = c(10, 2)))
1313
expect_success(expect_shape(array(dim = 1:3), dim = 1:3))
14+
expect_snapshot_failure(expect_shape(array(dim = 1:3), dim = 1:2))
15+
expect_snapshot_failure(expect_shape(array(dim = 1:3), dim = 1:4))
16+
})
1417

15-
# testing nrow=
18+
test_that("nrow compared correctly", {
1619
expect_success(expect_shape(matrix(nrow = 5, ncol = 4), nrow = 5L))
1720
expect_snapshot_failure(expect_shape(matrix(nrow = 5, ncol = 5), nrow = 6L))
1821
expect_success(expect_shape(data.frame(1:10, 11:20), nrow = 10L))
1922
expect_snapshot_failure(expect_shape(1, nrow = 1))
23+
})
2024

21-
# testing ncol=
25+
test_that("ncol compared correctly", {
2226
expect_success(expect_shape(matrix(nrow = 5, ncol = 4), ncol = 4L))
2327
expect_snapshot_failure(expect_shape(matrix(nrow = 5, ncol = 5), ncol = 7L))
2428
expect_success(expect_shape(data.frame(1:10, 11:20), ncol = 2L))

0 commit comments

Comments
 (0)