eugh
This commit is contained in:
parent
9be1c72a03
commit
57cdc92a2a
@ -1,22 +1,9 @@
|
||||
# overload input/return types
|
||||
sample_num <- ts_function(
|
||||
sample,
|
||||
x = ts_numeric(0),
|
||||
result = ts_numeric(1)
|
||||
)
|
||||
|
||||
sampler <- ts_function(
|
||||
function() {
|
||||
list(
|
||||
sample_one = sample_num(0)
|
||||
)
|
||||
},
|
||||
result = ts_list(
|
||||
num = sample_num
|
||||
)
|
||||
)
|
||||
|
||||
ts_compile(d_normal)
|
||||
|
||||
|
||||
# ts_compile(d_normal)
|
||||
|
||||
# compile to:
|
||||
# const sampler = R.ocap(
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# # optional, check arguments - useful for debugging/development
|
||||
# check_args(match.call(), formals())
|
||||
|
||||
test_that("function definitions", {
|
||||
test_that("anonomous function definitions", {
|
||||
add <- ts_function(
|
||||
function(a = ts_numeric(1), b = ts_numeric(1)) a + b,
|
||||
result = ts_numeric(1)
|
||||
@ -10,3 +10,34 @@ test_that("function definitions", {
|
||||
expect_equal(add(1, 2), 3)
|
||||
expect_error(add("a", 2))
|
||||
})
|
||||
|
||||
test_that("named function definitions", {
|
||||
sample_num <- ts_function(
|
||||
sample,
|
||||
x = ts_numeric(),
|
||||
result = ts_numeric()
|
||||
)
|
||||
|
||||
x <- sample_num(1:10)
|
||||
expect_true(all(x %in% 1:10))
|
||||
expect_error(sample_num("a"))
|
||||
})
|
||||
|
||||
test_that("function with complex return types", {
|
||||
sampler <- ts_function(
|
||||
function(x = ts_numeric()) {
|
||||
list(
|
||||
get = function(n) sample(x, n)
|
||||
)
|
||||
},
|
||||
result = ts_list(
|
||||
get = ts_function(
|
||||
NULL,
|
||||
n = ts_integer(1),
|
||||
result = ts_numeric(1)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
s <- sampler(1:10)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user