File: runit.dispatch.R

package info (click to toggle)
rcpp 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,344 kB
  • sloc: ansic: 43,817; cpp: 39,947; sh: 51; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 3,272 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env r
# -*- mode: R; tab-width: 4; -*-
#
# Copyright (C) 2009 - 2016  Dirk Eddelbuettel and Romain Francois
# Copyright (C) 2016         Dirk Eddelbuettel, Romain Francois and Nathan Russell
#
# This file is part of Rcpp.
#
# Rcpp is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Rcpp is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.

.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"

if (.runThisTest) {
    .setUp <- Rcpp:::unitTestSetup("dispatch.cpp")
    
    test.RawVector <- function() {
        x <- as.raw(0:9)
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (raw)")
    }

    test.ComplexVector <- function() {
        x <- as.complex(0:9)
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (complex)")
    }
    
    test.IntegerVector <- function() {
        x <- as.integer(0:9)
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (integer)")
    }
    
    test.NumericVector <- function() {
        x <- as.numeric(0:9)
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (numeric)")
    }
    
    test.ExpressionVector <- function() {
        x <- expression(rnorm, rnorm(10), mean(1:10))
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (expression)")
    }
    
    test.GenericVector <- function() {
        x <- list("foo", 10L, 10.2, FALSE)
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (list)")
    }
    
    test.CharacterVector <- function() {
        x <- as.character(0:9)
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (character)")
    }
    
    test.RawMatrix <- function() {
        x <- matrix(as.raw(0:9), ncol = 2L)
        checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (raw)")
    }
    
    test.ComplexMatrix <- function() {
        x <- matrix(as.complex(0:9), ncol = 2L)
        checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (complex)")
    }
    
    test.IntegerMatrix <- function() {
        x <- matrix(as.integer(0:9), ncol = 2L)
        checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (integer)")
    }
    
    test.NumericMatrix <- function() {
        x <- matrix(as.numeric(0:9), ncol = 2L)
        checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (numeric)")
    }
    
    test.GenericMatrix <- function() {
        x <- matrix(lapply(0:9, function(.) 0:9), ncol = 2L)
        checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (list)")
    }
    
    test.CharacterMatrix <- function() {
        x <- matrix(as.character(0:9), ncol = 2L)
        checkEquals(first_cell(x), x[1, 1, drop = FALSE], msg = "RCPP_RETURN_MATRIX (character)")
    }
    
}