|
23 | 23 | if (.runThisTest) {
|
24 | 24 |
|
25 | 25 | test.Sugar.var <- function() {
|
26 |
| - f1 <- Rcpp::cppFunction('double myVar(NumericVector x) { return(var(x)); }') |
27 |
| - f2 <- Rcpp::cppFunction('double myVar(IntegerVector x) { return(var(x)); }') |
28 |
| - f3 <- Rcpp::cppFunction('double myVar(ComplexVector x) { return(var(x)); }') |
29 |
| - f4 <- Rcpp::cppFunction('double myVar(LogicalVector x) { return(var(x)); }') |
30 |
| - checkEquals(f1((1:10) * 1.1), var((1:10) * 1.1)) |
31 |
| - checkEquals(f2(1:10), var(1:10)) |
32 |
| - checkEquals(f3(1:10 + (1 + 1i)), var(1:10 + (1 + 1i))) |
33 |
| - checkEquals(f4(c(T, F, T, F, T)), var(c(T, F, T, F, T))) |
| 26 | + fNumeric <- Rcpp::cppFunction('double myVar(NumericVector x) { return(var(x)); }') |
| 27 | + fInteger <- Rcpp::cppFunction('double myVar(IntegerVector x) { return(var(x)); }') |
| 28 | + fComplex <- Rcpp::cppFunction('double myVar(ComplexVector x) { return(var(x)); }') |
| 29 | + fLogical <- Rcpp::cppFunction('double myVar(LogicalVector x) { return(var(x)); }') |
| 30 | + test_data_real <- 1:10 |
| 31 | + checkEquals(fNumeric(test_data_real * 1.1), var(test_data_real * 1.1)) |
| 32 | + checkEquals(fInteger(test_data_real), var(test_data_real)) |
| 33 | + test_data_complex_1 <- complex(real = 5:1, imag = 2:6) |
| 34 | + test_data_complex_2 <- complex(real = 1:5, imag = 6:10) |
| 35 | + test_data_complex_1_known_var <- 5 |
| 36 | + test_data_complex_2_known_var <- 5 |
| 37 | + checkEquals(fComplex(test_data_complex_1), test_data_complex_1_known_var) |
| 38 | + checkEquals(fComplex(test_data_complex_2), test_data_complex_2_known_var) |
| 39 | + test_data_logical <- c(TRUE, FALSE, TRUE, FALSE, TRUE) |
| 40 | + checkEquals(fLogical(test_data_logical), var(test_data_logical)) |
34 | 41 | }
|
35 | 42 |
|
36 | 43 | }
|
0 commit comments