-
Notifications
You must be signed in to change notification settings - Fork 340
Expect shape #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expect shape #1469
Changes from 4 commits
66b166a
d4853ff
69c410a
e89fff9
cdb15a2
268aee8
89c0c82
b74737f
769ccc1
9aede6f
dd23081
eb0dc5a
1a020dc
ffde38b
0661094
ac0acbc
150425b
53b0ee8
a72708b
da7fdf2
d873766
3710870
170543e
a88340d
e35122a
ff4d7c5
4bc32fc
1bdf1cd
3ed14c4
58654fb
ff4c894
2ca461b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| test_that("shape computed correctly", { | ||
MichaelChirico marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # equivalent to expect_length | ||
| expect_success(expect_shape(1, 1)) | ||
| expect_failure(expect_shape(1, 2), "has length 1, not length 2.") | ||
| expect_success(expect_shape(1:10, 10)) | ||
| expect_success(expect_shape(letters[1:5], 5)) | ||
|
|
||
| # testing dim() | ||
| expect_success(expect_shape(matrix(nrow = 5, ncol = 4), c(5L, 4L))) | ||
| expect_failure(expect_shape(matrix(nrow = 6, ncol = 3), c(6L, 2L))) | ||
|
||
| expect_failure(expect_shape(matrix(nrow = 6, ncol = 3), c(7L, 3L))) | ||
| expect_success(expect_shape(data.frame(1:10, 11:20), c(10, 2))) | ||
| expect_success(expect_shape(array(dim = 1:3), 1:3)) | ||
|
|
||
| # testing nrow= | ||
| expect_success(expect_shape(matrix(nrow = 5, ncol = 4), nrow = 5L)) | ||
| expect_failure(expect_shape(matrix(nrow = 5, ncol = 5), nrow = 6L)) | ||
| expect_success(expect_shape(data.frame(1:10, 11:20), nrow = 10L)) | ||
|
|
||
| # testing ncol= | ||
| expect_success(expect_shape(matrix(nrow = 5, ncol = 4), ncol = 4L)) | ||
| expect_failure(expect_shape(matrix(nrow = 5, ncol = 5), ncol = 7L)) | ||
| expect_success(expect_shape(data.frame(1:10, 11:20), ncol = 2L)) | ||
|
|
||
| # testing nrow= and ncol= | ||
| expect_success(expect_shape(matrix(nrow = 5, ncol = 4), nrow = 5L, ncol = 4L)) | ||
| expect_failure(expect_shape(matrix(nrow = 5, ncol = 5), nrow = 6L, ncol = 5L)) | ||
| expect_success(expect_shape(data.frame(1:10, 11:20), nrow = 10L, ncol = 2L)) | ||
| expect_success(expect_shape(array(dim = 5:7), nrow = 5L, ncol = 6L)) | ||
|
|
||
| # precedence of manual nrow/ncol over shape | ||
| expect_success(expect_shape(matrix(nrow = 7, ncol = 10), 1:2, nrow = 7L)) | ||
| expect_success(expect_shape(matrix(nrow = 7, ncol = 10), 1:2, ncol = 10L)) | ||
| }) | ||
|
|
||
| test_that("uses S4 dim method", { | ||
| A <- setClass("ExpectShapeA", slots = c(x = "numeric", y = "numeric")) | ||
| setMethod("dim", "ExpectShapeA", function(x) 8:10) | ||
| expect_success(expect_shape(A(x = 1:9, y = 3), 8:10)) | ||
| }) | ||
|
|
||
| test_that("returns input", { | ||
| x <- list(1:10, letters) | ||
| out <- expect_shape(x, 2) | ||
| expect_identical(out, x) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.