Skip to content

Commit 99ea11e

Browse files
committed
tinytest step sixteen: sugar_var and support
1 parent b388150 commit 99ea11e

File tree

7 files changed

+83
-105
lines changed

7 files changed

+83
-105
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
* inst/tinytest/test_string.R: Idem
3737
* inst/tinytest/test_subset.R: Idem
3838
* inst/tinytest/test_sugar.R: Idem
39+
* inst/tinytest/test_sugar_var.R: Idem
40+
* inst/tinytest/test_support.R: Idem
3941

4042
2019-11-23 Dirk Eddelbuettel <edd@debian.org>
4143

inst/tinytest/test_rcpp_package_skeleton.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
## override -- skipping test for now (need to rebuild binary)
2222
.runThisTest <- FALSE
2323

24-
if (!.runThisTest) exit_file("Skipping, set 'RunAllRcppTests=yes' to run.")
24+
if (!.runThisTest) exit_file("Skipping 'test_rcpp_package_skeleton'") #, set 'RunAllRcppTests=yes' to run.")
2525

2626
library(Rcpp)
2727

inst/tinytest/test_sugar_var.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
## Copyright (C) 2015 - 2019 Wush Wu
3+
##
4+
## This file is part of Rcpp.
5+
##
6+
## Rcpp is free software: you can redistribute it and/or modify it
7+
## under the terms of the GNU General Public License as published by
8+
## the Free Software Foundation, either version 2 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## Rcpp is distributed in the hope that it will be useful, but
12+
## WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU General Public License
17+
## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
18+
19+
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
20+
21+
if (!.runThisTest) exit_file("Skipping, set 'RunAllRcppTests=yes' to run.")
22+
23+
library(Rcpp)
24+
25+
# test.Sugar.var <- function() {
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+
expect_equal(fNumeric(test_data_real * 1.1), var(test_data_real * 1.1))
32+
expect_equal(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+
expect_equal(fComplex(test_data_complex_1), test_data_complex_1_known_var)
38+
expect_equal(fComplex(test_data_complex_2), test_data_complex_2_known_var)
39+
test_data_logical <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
40+
expect_equal(fLogical(test_data_logical), var(test_data_logical))

inst/tinytest/test_support.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
## Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
3+
##
4+
## This file is part of Rcpp.
5+
##
6+
## Rcpp is free software: you can redistribute it and/or modify it
7+
## under the terms of the GNU General Public License as published by
8+
## the Free Software Foundation, either version 2 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## Rcpp is distributed in the hope that it will be useful, but
12+
## WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU General Public License
17+
## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
18+
19+
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
20+
21+
if (!.runThisTest) exit_file("Skipping, set 'RunAllRcppTests=yes' to run.")
22+
23+
library(Rcpp)
24+
sourceCpp("cpp/support.cpp")
25+
26+
# test.plus.REALSXP <- function(){
27+
expect_equal(plus_REALSXP(), list(NA_real_,NA_real_,NA_real_) , info = " REALSXP + REALSXP" )
28+
29+
# test.times.REALSXP <- function(){
30+
expect_equal(times_REALSXP(), list(NA_real_,NA_real_,NA_real_) , info = " REALSXP * REALSXP" )
31+
32+
# test.divides.REALSXP <- function(){
33+
expect_equal(divides_REALSXP(), list(NA_real_,NA_real_,NA_real_) , info = " REALSXP / REALSXP" )
34+
35+
# test.minus.REALSXP <- function(){
36+
expect_equal(minus_REALSXP(), list(NA_real_,NA_real_,NA_real_) , info = " REALSXP - REALSXP" )
37+
38+
# test.functions.REALSXP <- function(){
39+
expect_equal(functions_REALSXP(), list( rep(NA_real_, 20L), rep(NA_real_, 6L) ) ,
40+
info = "function(NA_REAL)" )

inst/unitTests/runit.sugar.var.R

Lines changed: 0 additions & 43 deletions
This file was deleted.

inst/unitTests/runit.support.R

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)