-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest-rev.R
More file actions
40 lines (36 loc) · 931 Bytes
/
Copy pathtest-rev.R
File metadata and controls
40 lines (36 loc) · 931 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
test_that("rev() reverses vectors", {
fn_dbl <- function(x) {
declare(type(x = double(NA)))
rev(x)
}
expect_quick_identical(
fn_dbl,
list(as.double(1:5)),
list(as.double(c(2, -1, 3, 0)))
)
fn_int <- function(x) {
declare(type(x = integer(NA)))
rev(x)
}
expect_quick_identical(fn_int, list(as.integer(c(1, 0, -3, 2))))
# Logical arguments are passed via the bind(c) interface as integer storage.
fn_lgl <- function(x) {
declare(type(x = logical(NA)))
rev(x)
}
expect_quick_identical(fn_lgl, list(c(TRUE, FALSE, TRUE, FALSE)))
})
test_that("rev() hoists array expressions", {
fn <- function(x) {
declare(type(x = double(NA)))
rev(x + 1)
}
expect_quick_identical(fn, list(as.double(1:6)))
})
test_that("rev() is a no-op for scalars", {
fn <- function(x) {
declare(type(x = double(1)))
rev(x)
}
expect_quick_identical(fn, list(as.double(3)))
})