diff --git a/tests/testthat/functions.R b/tests/testthat/functions.R index 8fe3ae9..f6216c8 100644 --- a/tests/testthat/functions.R +++ b/tests/testthat/functions.R @@ -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( diff --git a/tests/testthat/test-functions.R b/tests/testthat/test-functions.R index 0560c45..7027171 100644 --- a/tests/testthat/test-functions.R +++ b/tests/testthat/test-functions.R @@ -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) +})