Skip to content

Commit f0b4bb7

Browse files
committed
tinytest step two: convert algorithm and as test files
1 parent 679d958 commit f0b4bb7

File tree

7 files changed

+220
-247
lines changed

7 files changed

+220
-247
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-11-24 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* inst/tinytest/test_algorithm.R: Converted from RUnit to tinytest
4+
* inst/tinytest/test_as.R: Idem
5+
16
2019-11-23 Dirk Eddelbuettel <edd@debian.org>
27

38
* docker/ci/Dockerfile: Add tinytest to ci Docker image

inst/tinytest/test_algorithm.R

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/r -t
2+
#
3+
# Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
4+
#
5+
# This file is part of Rcpp.
6+
#
7+
# Rcpp is free software: you can redistribute it and/or modify it
8+
# under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# Rcpp is distributed in the hope that it will be useful, but
13+
# WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19+
20+
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
21+
22+
if (.runThisTest) exit_file("Skipping 'test_algorithm.R'")
23+
24+
library(Rcpp)
25+
sourceCpp("cpp/algorithm.cpp")
26+
27+
# test.sum <- function() {
28+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
29+
expect_equal(sum(v), sumTest(v, 1, 5))
30+
v <- c(NA, 1.0, 2.0, 3.0, 4.0)
31+
expect_equal(sum(v), sumTest(v, 1, 5))
32+
33+
# test.sum.nona <- function() {
34+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
35+
expect_equal(sum(v), sumTest_nona(v, 1, 5))
36+
37+
# test.prod <- function() {
38+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
39+
expect_equal(prod(v), prodTest(v, 1, 5))
40+
v <- c(NA, 1.0, 2.0, 3.0, 4.0)
41+
expect_equal(prod(v), prodTest(v, 1, 5))
42+
43+
#test.prod.nona <- function() {
44+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
45+
expect_equal(prod(v), prodTest_nona(v, 1, 5))
46+
47+
#test.log <- function() {
48+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
49+
expect_equal(log(v), logTest(v))
50+
v <- c(NA, 1.0, 2.0, 3.0, 4.0)
51+
expect_equal(log(v), logTest(v))
52+
53+
# test.exp <- function() {
54+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
55+
expect_equal(exp(v), expTest(v))
56+
v <- c(NA, 1.0, 2.0, 3.0, 4.0)
57+
expect_equal(exp(v), expTest(v))
58+
59+
# test.sqrt <- function() {
60+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
61+
expect_equal(sqrt(v), sqrtTest(v))
62+
v <- c(NA, 1.0, 2.0, 3.0, 4.0)
63+
expect_equal(sqrt(v), sqrtTest(v))
64+
65+
# test.min <- function() {
66+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
67+
expect_equal(min(v), minTest(v))
68+
v <- c(NA, 1.0, 2.0, 3.0, 4.0)
69+
expect_equal(min(v), minTest(v))
70+
71+
# test.min.nona <- function() {
72+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
73+
expect_equal(min(v), minTest_nona(v))
74+
75+
# test.min.int <- function() {
76+
v <- c(1, 2, 3, 4, 5)
77+
expect_equal(min(v), minTest_int(v))
78+
v <- c(NA, 1, 2, 3, 4)
79+
expect_equal(min(v), minTest_int(v))
80+
81+
# test.min.int.nona <- function() {
82+
v <- c(1, 2, 3, 4, 5)
83+
expect_equal(min(v), minTest_int_nona(v))
84+
85+
# test.max <- function() {
86+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
87+
expect_equal(max(v), maxTest(v))
88+
v <- c(NA, 1.0, 2.0, 3.0, 4.0)
89+
expect_equal(max(v), maxTest(v))
90+
91+
# test.max.nona <- function() {
92+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
93+
expect_equal(max(v), maxTest_nona(v))
94+
95+
# test.max.int <- function() {
96+
v <- c(1, 2, 3, 4, 5)
97+
expect_equal(max(v), maxTest_int(v))
98+
v <- c(NA, 1, 2, 3, 4)
99+
expect_equal(max(v), maxTest_int(v))
100+
101+
# test.max.int.nona <- function() {
102+
v <- c(1, 2, 3, 4, 5)
103+
expect_equal(max(v), maxTest_int_nona(v))
104+
105+
# test.mean <- function() {
106+
v <- c(1.0, 2.0, 3.0, 4.0, 5.0)
107+
expect_equal(mean(v), meanTest(v))
108+
v <- c(1.0, 2.0, 3.0, 4.0, NA)
109+
expect_equal(mean(v), meanTest(v))
110+
v <- c(1.0, 2.0, 3.0, 4.0, NaN)
111+
expect_equal(mean(v), meanTest(v))
112+
v <- c(1.0, 2.0, 3.0, 4.0, 1.0/0.0)
113+
expect_equal(mean(v), meanTest(v))
114+
v <- c(1.0, 2.0, 3.0, 4.0, -1.0/0.0)
115+
expect_equal(mean(v), meanTest(v))
116+
v <- c(1.0, 2.0, 1.0/0.0, NA, NaN)
117+
expect_equal(mean(v), meanTest(v))
118+
v <- c(1.0, 2.0, 1.0/0.0, NaN, NA)
119+
120+
# test.mean.int <- function() {
121+
v <- c(1, 2, 3, 4, 5)
122+
expect_equal(mean(v), meanTest_int(v))
123+
v <- c(1, 2, 3, 4, NA)
124+
expect_equal(mean(v), meanTest_int(v))
125+
126+
#test.mean.logical <- function() {
127+
v <- c(TRUE, FALSE, FALSE)
128+
expect_equal(mean(v), meanTest_logical(v))
129+
v <- c(TRUE, FALSE, FALSE, NA)
130+
expect_equal(mean(v), meanTest_logical(v))

inst/tinytest/test_as.R

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env r
2+
#
3+
# Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
4+
#
5+
# This file is part of Rcpp.
6+
#
7+
# Rcpp is free software: you can redistribute it and/or modify it
8+
# under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# Rcpp is distributed in the hope that it will be useful, but
13+
# WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19+
20+
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
21+
22+
if (.runThisTest) exit_file("Skipping 'test_as.R'")
23+
24+
library(Rcpp)
25+
sourceCpp("cpp/as.cpp")
26+
27+
# test.as.int <- function(){
28+
expect_equal( as_int(10), 10L, info = "as<int>( REALSXP ) " )
29+
expect_equal( as_int(10L), 10L, info = "as<int>( INTSXP ) " )
30+
expect_equal( as_int(as.raw(10L)), 10L, info = "as<int>( RAWSXP ) " )
31+
expect_equal( as_int(TRUE), 1L, info = "as<int>( LGLSXP ) " )
32+
33+
# test.as.double <- function(){
34+
expect_equal( as_double(10), 10.0, info = "as<double>( REALSXP ) " )
35+
expect_equal( as_double(10L), 10.0, info = "as<double>( INTSXP ) " )
36+
expect_equal( as_double(as.raw(10L)), 10.0, info = "as<double>( RAWSXP ) " )
37+
expect_equal( as_double(TRUE), 1.0, info = "as<double>( LGLSXP ) " )
38+
39+
# test.as.raw <- function(){
40+
expect_equal( as_raw(10), as.raw(10), info = "as<Rbyte>( REALSXP ) " )
41+
expect_equal( as_raw(10L), as.raw(10), info = "as<Rbyte>( INTSXP ) " )
42+
expect_equal( as_raw(as.raw(10L)), as.raw(10), info = "as<Rbyte>( RAWSXP ) " )
43+
expect_equal( as_raw(TRUE), as.raw(1), info = "as<Rbyte>( LGLSXP ) " )
44+
45+
# test.as.bool <- function(){
46+
expect_equal( as_bool(10), as.logical(10), info = "as<bool>( REALSXP ) " )
47+
expect_equal( as_bool(10L), as.logical(10), info = "as<bool>( INTSXP ) " )
48+
expect_equal( as_bool(as.raw(10L)), as.logical(10), info = "as<bool>( RAWSXP ) " )
49+
expect_equal( as_bool(TRUE), as.logical(1), info = "as<bool>( LGLSXP ) " )
50+
51+
#test.as.string <- function(){
52+
expect_equal( as_string("foo"), "foo", info = "as<string>( STRSXP ) " )
53+
54+
# test.as.vector.int <- function(){
55+
expect_equal( as_vector_int(1:10), 1:10 , info = "as<vector<int>>( INTSXP ) " )
56+
expect_equal( as_vector_int(as.numeric(1:10)), 1:10 , info = "as<vector<int>>( REALSXP ) " )
57+
expect_equal( as_vector_int(as.raw(1:10)), 1:10 , info = "as<vector<int>>( RAWSXP ) " )
58+
expect_equal( as_vector_int(c(TRUE,FALSE)), 1:0 , info = "as<vector<int>>( LGLSXP ) " )
59+
60+
# test.as.vector.double <- function(){
61+
expect_equal( as_vector_double(1:10), as.numeric(1:10) , info = "as<vector<double>>( INTSXP ) " )
62+
expect_equal( as_vector_double(as.numeric(1:10)), as.numeric(1:10) , info = "as<vector<double>>( REALSXP ) " )
63+
expect_equal( as_vector_double(as.raw(1:10)), as.numeric(1:10), info = "as<vector<double>>( RAWSXP ) " )
64+
expect_equal( as_vector_double(c(TRUE,FALSE)), c(1.0, 0.0) , info = "as<vector<double>>( LGLSXP ) " )
65+
66+
# test.as.vector.raw <- function(){
67+
expect_equal( as_vector_raw(1:10), as.raw(1:10) , info = "as<vector<Rbyte>>( INTSXP ) " )
68+
expect_equal( as_vector_raw(as.numeric(1:10)), as.raw(1:10) , info = "as<vector<Rbyte>>( REALSXP ) " )
69+
expect_equal( as_vector_raw(as.raw(1:10)), as.raw(1:10) , info = "as<vector<Rbyte>>( RAWSXP ) " )
70+
expect_equal( as_vector_raw(c(TRUE,FALSE)), as.raw(1:0) , info = "as<vector<Rbyte>>( LGLSXP ) " )
71+
72+
# test.as.vector.bool <- function(){
73+
expect_equal( as_vector_bool(0:10), as.logical(0:10) , info = "as<vector<bool>>( INTSXP ) " )
74+
expect_equal( as_vector_bool(as.numeric(0:10)), as.logical(0:10) , info = "as<vector<bool>>( REALSXP ) " )
75+
expect_equal( as_vector_bool(as.raw(0:10)), as.logical(0:10) , info = "as<vector<bool>>( RAWSXP ) " )
76+
expect_equal( as_vector_bool(c(TRUE,FALSE)), as.logical(1:0) , info = "as<vector<bool>>( LGLSXP ) " )
77+
78+
# test.as.vector.string <- function(){
79+
expect_equal( as_vector_string(letters), letters , info = "as<vector<string>>( STRSXP ) " )
80+
81+
# test.as.deque.int <- function(){
82+
expect_equal( as_deque_int(1:10), 1:10 , info = "as<deque<int>>( INTSXP ) " )
83+
84+
# test.as.list.int <- function(){
85+
expect_equal( as_list_int(1:10), 1:10 , info = "as<list<int>>( INTSXP ) " )

inst/unitTests/runit.algorithm.R

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

0 commit comments

Comments
 (0)