|
| 1 | +#!/usr/bin/env r |
| 2 | +# -*- mode: R; tab-width: 4; -*- |
| 3 | +# |
| 4 | +# Copyright (C) 2009 - 2014 Dirk Eddelbuettel and Romain Francois |
| 5 | +# |
| 6 | +# This file is part of Rcpp. |
| 7 | +# |
| 8 | +# Rcpp is free software: you can redistribute it and/or modify it |
| 9 | +# under the terms of the GNU General Public License as published by |
| 10 | +# the Free Software Foundation, either version 2 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | +# |
| 13 | +# Rcpp is distributed in the hope that it will be useful, but |
| 14 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU General Public License |
| 19 | +# along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + |
| 21 | +.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" |
| 22 | + |
| 23 | +if (.runThisTest) { |
| 24 | + .setUp <- Rcpp:::unitTestSetup("dispatch.cpp") |
| 25 | + |
| 26 | + test.RawVector <- function() { |
| 27 | + x <- as.raw(0:9) |
| 28 | + checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (raw)") |
| 29 | + } |
| 30 | + |
| 31 | + test.ExpressionVector <- function() { |
| 32 | + x <- as.expression(0:9) |
| 33 | + checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (expression)") |
| 34 | + } |
| 35 | + |
| 36 | + test.ComplexVector <- function() { |
| 37 | + x <- as.complex(0:9) |
| 38 | + checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (complex)") |
| 39 | + } |
| 40 | + |
| 41 | + test.IntegerVector <- function() { |
| 42 | + x <- as.integer(0:9) |
| 43 | + checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (integer)") |
| 44 | + } |
| 45 | + |
| 46 | + test.NumericVector <- function() { |
| 47 | + x <- as.numeric(0:9) |
| 48 | + checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (numeric)") |
| 49 | + } |
| 50 | + |
| 51 | + test.GenericVector <- function() { |
| 52 | + x <- as.list(0:9) |
| 53 | + checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (list)") |
| 54 | + } |
| 55 | + |
| 56 | + test.CharacterVector <- function() { |
| 57 | + x <- as.character(0:9) |
| 58 | + checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (character)") |
| 59 | + } |
| 60 | + |
| 61 | + test.RawMatrix <- function() { |
| 62 | + x <- matrix(as.raw(0:9), ncol = 2L) |
| 63 | + checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (raw)") |
| 64 | + } |
| 65 | + |
| 66 | + test.ExpressionMatrix <- function() { |
| 67 | + x <- matrix(as.expression(0:9), ncol = 2L) |
| 68 | + checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (expression)") |
| 69 | + } |
| 70 | + |
| 71 | + test.ComplexMatrix <- function() { |
| 72 | + x <- matrix(as.complex(0:9), ncol = 2L) |
| 73 | + checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (complex)") |
| 74 | + } |
| 75 | + |
| 76 | + test.IntegerMatrix <- function() { |
| 77 | + x <- matrix(as.integer(0:9), ncol = 2L) |
| 78 | + checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (integer)") |
| 79 | + } |
| 80 | + |
| 81 | + test.NumericMatrix <- function() { |
| 82 | + x <- matrix(as.numeric(0:9), ncol = 2L) |
| 83 | + checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (numeric)") |
| 84 | + } |
| 85 | + |
| 86 | + test.GenericMatrix <- function() { |
| 87 | + x <- matrix(lapply(0:9, function(.) as.list(0:9)), ncol = 2L) |
| 88 | + checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (list)") |
| 89 | + } |
| 90 | + |
| 91 | + test.CharacterMatrix <- function() { |
| 92 | + x <- matrix(as.character(0:9), ncol = 2L) |
| 93 | + checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (character)") |
| 94 | + } |
| 95 | + |
| 96 | +} |
0 commit comments